Strabon
changeset 1137:edf25917969d
addresses #38: added download button in describe.jsp
author | Stella Giannakopoulou <sgian@di.uoa.gr> |
---|---|
date | Tue Apr 30 14:04:56 2013 +0300 (2013-04-30) |
parents | 40fe983c1488 |
children | 148e7194be4b |
files | endpoint/WebContent/describe.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java |
line diff
1.1 --- a/endpoint/WebContent/describe.jsp Mon Apr 29 18:05:34 2013 +0300 1.2 +++ b/endpoint/WebContent/describe.jsp Tue Apr 30 14:04:56 2013 +0300 1.3 @@ -21,6 +21,18 @@ 1.4 return true; 1.5 } 1.6 </script> 1.7 + 1.8 + <%String handle = ""; 1.9 + if (request.getParameter("handle") != null) 1.10 + { 1.11 + handle = request.getParameter("handle"); 1.12 + 1.13 + } 1.14 + else if (request.getAttribute("handle") != null) 1.15 + { 1.16 + handle = (String) request.getAttribute("handle"); 1.17 + 1.18 + }%> 1.19 </head> 1.20 <body topmargin="0" leftmargin="0" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"> 1.21 1.22 @@ -57,6 +69,16 @@ 1.23 <input type="submit" title="execute DESCRIBE query" value="Describe" name="submit" style="width: 400px"/><br/> 1.24 </center><br/></td> 1.25 </tr> 1.26 +<tr> 1.27 +<td id="output"><center>View Result:<br/> 1.28 + <SELECT name="handle" title="select how you would like to view the result"> 1.29 + <OPTION value="plain"<%= ("plain".equals(handle)) ? "selected":""%>>Plain</OPTION> 1.30 + <OPTION value="download"<%= ("download".equals(handle)) ? "selected":""%>>Download</OPTION> 1.31 + </SELECT></center> 1.32 + </td> 1.33 + <td colspan=2> </td> 1.34 +</tr> 1.35 + 1.36 1.37 <% if (request.getAttribute("error") != null) {%> 1.38 <!-- Error Message -->
2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java Mon Apr 29 18:05:34 2013 +0300 2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java Tue Apr 30 14:04:56 2013 +0300 2.3 @@ -111,30 +111,57 @@ 2.4 2.5 String query = URLDecoder.decode(request.getParameter("query"), "UTF-8"); 2.6 String format = request.getParameter("format"); 2.7 - 2.8 - if (format == null || query == null) { 2.9 + String handle = request.getParameter("handle"); 2.10 + RDFFormat rdfFormat = RDFFormat.valueOf(format); 2.11 + 2.12 + if (format == null || query == null || rdfFormat == null) { 2.13 request.setAttribute(ERROR, PARAM_ERROR); 2.14 dispatcher.forward(request, response); 2.15 2.16 } else { 2.17 - // set the query and format to be selected in the rendered page 2.18 + // set the query, format and handle to be selected in the rendered page 2.19 //request.setAttribute("query", URLDecoder.decode(query, "UTF-8")); 2.20 //request.setAttribute("format", URLDecoder.decode(reqFormat, "UTF-8")); 2.21 + //request.setAttribute("handle", URLDecoder.decode(handle, "UTF-8")); 2.22 2.23 - try { 2.24 - ByteArrayOutputStream bos = new ByteArrayOutputStream(); 2.25 - 2.26 - strabonWrapper.describe(query, format, bos); 2.27 + if ("download".equals(handle)) { // download as attachment 2.28 + ServletOutputStream out = response.getOutputStream(); 2.29 2.30 - request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString())); 2.31 - 2.32 - } catch (Exception e) { 2.33 - request.setAttribute(ERROR, e.getMessage()); 2.34 + response.setContentType(rdfFormat.getDefaultMIMEType()); 2.35 + response.setHeader("Content-Disposition", 2.36 + "attachment; filename=results." + 2.37 + rdfFormat.getDefaultFileExtension() + "; " + 2.38 + rdfFormat.getCharset()); 2.39 + 2.40 + try { 2.41 + strabonWrapper.describe(query, format, out); 2.42 + response.setStatus(HttpServletResponse.SC_OK); 2.43 + 2.44 + } catch (Exception e) { 2.45 + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 2.46 + out.print(ResponseMessages.getXMLHeader()); 2.47 + out.print(ResponseMessages.getXMLException(e.getMessage())); 2.48 + out.print(ResponseMessages.getXMLFooter()); 2.49 + } 2.50 + 2.51 + out.flush(); 2.52 + 2.53 } 2.54 - 2.55 - dispatcher.forward(request, response); 2.56 + else //plain 2.57 + { 2.58 + try { 2.59 + ByteArrayOutputStream bos = new ByteArrayOutputStream(); 2.60 + 2.61 + strabonWrapper.describe(query, format, bos); 2.62 + 2.63 + request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString())); 2.64 + 2.65 + } catch (Exception e) { 2.66 + request.setAttribute(ERROR, e.getMessage()); 2.67 + } 2.68 + dispatcher.forward(request, response); 2.69 + } 2.70 } 2.71 - 2.72 } 2.73 2.74 /**