Strabon
changeset 1190:a5340fe30e7f
more changes to support charts
author | Konstantina Bereta <Konstantina.Bereta@di.uoa.gr> |
---|---|
date | Mon Jul 08 00:18:21 2013 +0300 (2013-07-08) |
parents | c99b065768d9 |
children | 98aae21ffe72 |
files | endpoint/WebContent/query.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java |
line diff
1.1 --- a/endpoint/WebContent/query.jsp Fri Jul 05 17:39:45 2013 +0300 1.2 +++ b/endpoint/WebContent/query.jsp Mon Jul 08 00:18:21 2013 +0300 1.3 @@ -7,6 +7,7 @@ 1.4 <%@page import="java.util.List"%> 1.5 <%@page import="java.util.Iterator"%> 1.6 <%@page import="org.openrdf.query.TupleQueryResult"%> 1.7 +<%@page import="org.openrdf.query.BindingSet"%> 1.8 <jsp:directive.page import="eu.earthobservatory.org.StrabonEndpoint.Common"/> 1.9 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 1.10 <html> 1.11 @@ -67,6 +68,10 @@ 1.12 <% 1.13 // get the reference to StrabonBeanWrapper 1.14 StrabonBeanWrapper strabonWrapper; 1.15 + String label1= "placeholder"; 1.16 + String label2= "placeholder"; 1.17 + TupleQueryResult result = null; 1.18 + 1.19 ServletContext context; 1.20 context = getServletContext(); 1.21 WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context); 1.22 @@ -207,21 +212,21 @@ 1.23 1.24 // Set a callback to run when the Google Visualization API is loaded. 1.25 1.26 - 1.27 + google.setOnLoadCallback(drawChart); 1.28 + 1.29 // Callback that creates and populates a data table, 1.30 // instantiates the pie chart, passes in the data and 1.31 // draws it. 1.32 1.33 - <% if (request.getAttribute("response") != null) { 1.34 - if (request.getParameter("format").equals("CHART")) { 1.35 - TupleQueryResult result= request.getAttribute("response"); 1.36 - String label1 = esult.getBindingNames().get(0).toString(); 1.37 - String label2 = esult.getBindingNames().get(1).toString(); 1.38 - 1.39 - google.setOnLoadCallback(drawChart); 1.40 - }%> 1.41 + 1.42 1.43 function drawChart() { 1.44 + 1.45 + <% if (request.getAttribute("response") != null) { 1.46 + if (request.getParameter("format").equals("CHART")) { 1.47 + result= (TupleQueryResult) request.getAttribute("response"); 1.48 + label1 = result.getBindingNames().get(0).toString(); 1.49 + label2 = result.getBindingNames().get(1).toString();%> 1.50 1.51 // Create the data table. 1.52 var data = new google.visualization.DataTable(); 1.53 @@ -232,8 +237,9 @@ 1.54 1.55 <% 1.56 while(result.hasNext()){ 1.57 - %> data.addRow('string', <%=result.next().getValue(label1).toString()%>); 1.58 - data.addRow('number', <%=Integer.parseInt(result.next().getValue(label2).toString())%>); 1.59 + BindingSet bindings = result.next(); 1.60 + %> data.addRow('string', <%=bindings.getValue(label1).toString()%>); 1.61 + data.addRow('number', <%=Integer.parseInt(bindings.getValue(label2).toString())%>); 1.62 <% } %> 1.63 // Set chart options 1.64 var options = {'title':'Displaying results in chart', 1.65 @@ -243,6 +249,8 @@ 1.66 // Instantiate and draw our chart, passing in some options. 1.67 var chart = new google.visualization.PieChart(document.getElementById('chart_div')); 1.68 chart.draw(data, options); 1.69 + 1.70 + <%}}%> 1.71 } 1.72 </script> 1.73 </head>
2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java Fri Jul 05 17:39:45 2013 +0300 2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java Mon Jul 08 00:18:21 2013 +0300 2.3 @@ -16,6 +16,8 @@ 2.4 import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 2.5 import org.openrdf.rio.RDFFormat; 2.6 2.7 +import eu.earthobservatory.utils.Format; 2.8 + 2.9 /** 2.10 * Keeps common variables shared by beans and .jsp pages. 2.11 * 2.12 @@ -86,6 +88,7 @@ 2.13 registeredQueryResultsFormatNames.add(format.getName()); 2.14 //} 2.15 } 2.16 + 2.17 } 2.18 2.19 /**
3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java Fri Jul 05 17:39:45 2013 +0300 3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java Mon Jul 08 00:18:21 2013 +0300 3.3 @@ -334,7 +334,7 @@ 3.4 request.setAttribute(RESPONSE, bos.toString()); 3.5 } 3.6 else if(format.equals(Format.CHART)){ 3.7 - request.setAttribute(RESPONSE, strabonWrapper.getResult()); 3.8 + request.setAttribute(RESPONSE, strabonWrapper.getResult().toString()); 3.9 } 3.10 else { 3.11 request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString()));
4.1 --- a/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java Fri Jul 05 17:39:45 2013 +0300 4.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java Mon Jul 08 00:18:21 2013 +0300 4.3 @@ -72,6 +72,9 @@ 4.4 public static final stSPARQLQueryResultFormat HTML = new stSPARQLQueryResultFormat("HTML", 4.5 Arrays.asList("text/html"), Charset.forName("UTF-8"), Arrays.asList("html", "htm")); 4.6 4.7 + public static final stSPARQLQueryResultFormat CHART = new stSPARQLQueryResultFormat("CHART", 4.8 + Arrays.asList("text/plain"), Charset.forName("UTF-8"), Arrays.asList("chart", "chart")); 4.9 + 4.10 /** 4.11 * The available stSPARQLQuery Result Formats 4.12 */ 4.13 @@ -85,6 +88,8 @@ 4.14 register(GEOJSON); 4.15 register(TSV); 4.16 register(HTML); 4.17 + register(CHART); 4.18 + 4.19 } 4.20 4.21 /**