Strabon
changeset 1536:f287cc1b8b99
Added capability to Strabon-Endpoint for the user to supply and store his unique Google Maps API Key.
- The context path of the endpoint is not restricted when a Google Maps API Key is provided
- Users that do not supply a key can still run the application as before
- The context path of the endpoint is not restricted when a Google Maps API Key is provided
- Users that do not supply a key can still run the application as before
author | Theofilos Ioannidis <tioannid@yahoo.com> |
---|---|
date | Wed Oct 04 11:55:13 2017 +0300 (2017-10-04) |
parents | c18b84e14117 |
children | 3843718cc980 |
files | endpoint/WebContent/WEB-INF/beans.xml endpoint/WebContent/WEB-INF/connection.properties endpoint/WebContent/connection.jsp endpoint/WebContent/query.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ChangeConnectionBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ConnectionBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java |
line diff
1.1 --- a/endpoint/WebContent/WEB-INF/beans.xml Tue Sep 22 20:56:35 2015 +0300 1.2 +++ b/endpoint/WebContent/WEB-INF/beans.xml Wed Oct 04 11:55:13 2017 +0300 1.3 @@ -1,27 +1,27 @@ 1.4 <?xml version="1.0" encoding="UTF-8"?> 1.5 <beans xmlns="http://www.springframework.org/schema/beans" 1.6 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 1.7 - xsi:schemaLocation="http://www.springframework.org/schema/beans 1.8 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 1.9 + xsi:schemaLocation="http://www.springframework.org/schema/beans 1.10 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" 1.11 - xmlns:jaxws="http://cxf.apache.org/jaxws" 1.12 - jaxws:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> 1.13 + xmlns:jaxws="http://cxf.apache.org/jaxws" 1.14 + jaxws:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> 1.15 1.16 - <bean id="serverProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 1.17 - <property name="locations"> 1.18 - <list> 1.19 - <value>WEB-INF/connection.properties</value> 1.20 - </list> 1.21 - </property> 1.22 - </bean> 1.23 + <bean id="serverProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 1.24 + <property name="locations"> 1.25 + <list> 1.26 + <value>WEB-INF/connection.properties</value> 1.27 + </list> 1.28 + </property> 1.29 + </bean> 1.30 1.31 - <bean id="capsBean" class="eu.earthobservatory.org.StrabonEndpoint.capabilities.CapabilitiesDelegateBean" destroy-method="destroy"> 1.32 - <!-- specify which implementation of the Capabilities interface shall be used --> 1.33 - <!-- true : AutoDiscoveryCapabilities --> 1.34 - <!-- false: EndpointCapabilities --> 1.35 - <constructor-arg type="boolean"> 1.36 + <bean id="capsBean" class="eu.earthobservatory.org.StrabonEndpoint.capabilities.CapabilitiesDelegateBean" destroy-method="destroy"> 1.37 + <!-- specify which implementation of the Capabilities interface shall be used --> 1.38 + <!-- true : AutoDiscoveryCapabilities --> 1.39 + <!-- false: EndpointCapabilities --> 1.40 + <constructor-arg type="boolean"> 1.41 <value>false</value> 1.42 </constructor-arg> 1.43 - </bean> 1.44 + </bean> 1.45 1.46 <bean 1.47 id="strabonBean" 1.48 @@ -40,7 +40,7 @@ 1.49 1.50 <constructor-arg type="java.lang.String" > 1.51 <!-- Password --> 1.52 - <value>${password}</value> 1.53 + <value>${password}</value> 1.54 </constructor-arg> 1.55 1.56 <constructor-arg type="int" > 1.57 @@ -63,6 +63,11 @@ 1.58 <value>${dbengine}</value> 1.59 </constructor-arg> 1.60 1.61 + <constructor-arg type="java.lang.String" > 1.62 + <!-- Google Maps Key --> 1.63 + <value>${googlemapskey}</value> 1.64 + </constructor-arg> 1.65 + 1.66 <constructor-arg type="int" > 1.67 <!-- Query limit --> 1.68 <value>0</value> 1.69 @@ -72,8 +77,8 @@ 1.70 <!-- Load from File --> 1.71 <value>true</value> 1.72 </constructor-arg> 1.73 - 1.74 - <!-- Boolean variable linkURL in stSPARQLResultsHTMLWriter.java (line 115) to change the links between web and describe --> 1.75 + 1.76 + <!-- Boolean variable linkURL in stSPARQLResultsHTMLWriter.java (line 115) to change the links between web and describe --> 1.77 1.78 <constructor-arg type="java.lang.String" > 1.79 <!-- Default prefixes --> 1.80 @@ -93,181 +98,181 @@ 1.81 PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 1.82 PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/> 1.83 ]]> 1.84 -</value> 1.85 + </value> 1.86 </constructor-arg> 1.87 1.88 <constructor-arg> 1.89 - <list> 1.90 - <list> 1.91 - <!-- Single valued elements correspond to headers --> 1.92 - <value>Discovery Queries</value> 1.93 - </list> 1.94 - <list> 1.95 - <!-- Bean --> 1.96 - <value>Query</value> 1.97 - <!-- Format --> 1.98 - <value>HTML</value> 1.99 - <!-- Label --> 1.100 - <value>Find all triples in the dataset.</value> 1.101 - <!-- Statement --> 1.102 - <value><![CDATA[ 1.103 + <list> 1.104 + <list> 1.105 + <!-- Single valued elements correspond to headers --> 1.106 + <value>Discovery Queries</value> 1.107 + </list> 1.108 + <list> 1.109 + <!-- Bean --> 1.110 + <value>Query</value> 1.111 + <!-- Format --> 1.112 + <value>HTML</value> 1.113 + <!-- Label --> 1.114 + <value>Find all triples in the dataset.</value> 1.115 + <!-- Statement --> 1.116 + <value><![CDATA[ 1.117 SELECT * 1.118 WHERE { 1.119 ?s ?p ?o 1.120 } 1.121 ]]></value> 1.122 - <!-- Description --> 1.123 - <value></value> 1.124 - <!-- Hander (plain, download, map or map_local)--> 1.125 - <value>Plain</value> 1.126 - </list> 1.127 - <list> 1.128 - <!-- Bean --> 1.129 - <value>Query</value> 1.130 - <!-- Format --> 1.131 - <value>HTML</value> 1.132 - <!-- Label --> 1.133 - <value>Select all distinct subjects that appear in the dataset.</value> 1.134 - <!-- Statement --> 1.135 - <value><![CDATA[ 1.136 + <!-- Description --> 1.137 + <value></value> 1.138 + <!-- Hander (plain, download, map or map_local)--> 1.139 + <value>Plain</value> 1.140 + </list> 1.141 + <list> 1.142 + <!-- Bean --> 1.143 + <value>Query</value> 1.144 + <!-- Format --> 1.145 + <value>HTML</value> 1.146 + <!-- Label --> 1.147 + <value>Select all distinct subjects that appear in the dataset.</value> 1.148 + <!-- Statement --> 1.149 + <value><![CDATA[ 1.150 SELECT DISTINCT (?s AS ?subject) 1.151 WHERE { 1.152 ?s ?p ?o 1.153 } 1.154 ]]></value> 1.155 - <!-- Description --> 1.156 - <value></value> 1.157 - <!-- Hander (plain, download, map or map_local)--> 1.158 - <value>Plain</value> 1.159 - </list> 1.160 - <list> 1.161 - <!-- Bean --> 1.162 - <value>Query</value> 1.163 - <!-- Format --> 1.164 - <value>HTML</value> 1.165 - <!-- Label --> 1.166 - <value>Select all distinct predicates that appear in the dataset.</value> 1.167 - <!-- Statement --> 1.168 - <value><![CDATA[ 1.169 + <!-- Description --> 1.170 + <value></value> 1.171 + <!-- Hander (plain, download, map or map_local)--> 1.172 + <value>Plain</value> 1.173 + </list> 1.174 + <list> 1.175 + <!-- Bean --> 1.176 + <value>Query</value> 1.177 + <!-- Format --> 1.178 + <value>HTML</value> 1.179 + <!-- Label --> 1.180 + <value>Select all distinct predicates that appear in the dataset.</value> 1.181 + <!-- Statement --> 1.182 + <value><![CDATA[ 1.183 SELECT DISTINCT (?p AS ?predicate) 1.184 WHERE { 1.185 ?s ?p ?o 1.186 } 1.187 ]]></value> 1.188 - <!-- Description --> 1.189 - <value></value> 1.190 - <!-- Hander (plain, download, map or map_local)--> 1.191 - <value>Plain</value> 1.192 - </list> 1.193 + <!-- Description --> 1.194 + <value></value> 1.195 + <!-- Hander (plain, download, map or map_local)--> 1.196 + <value>Plain</value> 1.197 + </list> 1.198 1.199 - <list> 1.200 - <!-- Bean --> 1.201 - <value>Query</value> 1.202 - <!-- Format --> 1.203 - <value>HTML</value> 1.204 - <!-- Label --> 1.205 - <value>Select all distinct objets that appear in the dataset.</value> 1.206 - <!-- Statement --> 1.207 - <value><![CDATA[ 1.208 + <list> 1.209 + <!-- Bean --> 1.210 + <value>Query</value> 1.211 + <!-- Format --> 1.212 + <value>HTML</value> 1.213 + <!-- Label --> 1.214 + <value>Select all distinct objets that appear in the dataset.</value> 1.215 + <!-- Statement --> 1.216 + <value><![CDATA[ 1.217 SELECT DISTINCT (?o AS ?object) 1.218 WHERE { 1.219 ?s ?p ?o 1.220 } 1.221 ]]></value> 1.222 - <!-- Description --> 1.223 - <value></value> 1.224 - <!-- Hander (plain, download, map or map_local)--> 1.225 - <value>Plain</value> 1.226 - </list> 1.227 - <list> 1.228 - <!-- Bean --> 1.229 - <value>Query</value> 1.230 - <!-- Format --> 1.231 - <value>HTML</value> 1.232 - <!-- Label --> 1.233 - <value>Find all distinct classes of the dataset.</value> 1.234 - <!-- Statement --> 1.235 - <value><![CDATA[PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 1.236 + <!-- Description --> 1.237 + <value></value> 1.238 + <!-- Hander (plain, download, map or map_local)--> 1.239 + <value>Plain</value> 1.240 + </list> 1.241 + <list> 1.242 + <!-- Bean --> 1.243 + <value>Query</value> 1.244 + <!-- Format --> 1.245 + <value>HTML</value> 1.246 + <!-- Label --> 1.247 + <value>Find all distinct classes of the dataset.</value> 1.248 + <!-- Statement --> 1.249 + <value><![CDATA[PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 1.250 1.251 SELECT DISTINCT (?o AS ?class) 1.252 WHERE { 1.253 ?s rdf:type ?o 1.254 } 1.255 ]]></value> 1.256 - <!-- Description --> 1.257 - <value></value> 1.258 - <!-- Hander (plain, download, map or map_local)--> 1.259 - <value>Plain</value> 1.260 - </list> 1.261 + <!-- Description --> 1.262 + <value></value> 1.263 + <!-- Hander (plain, download, map or map_local)--> 1.264 + <value>Plain</value> 1.265 + </list> 1.266 1.267 - <list> 1.268 - <!-- Bean --> 1.269 - <value>Query</value> 1.270 - <!-- Format --> 1.271 - <value>HTML</value> 1.272 - <!-- Label --> 1.273 - <value>Find the number of triples that appear in the dataset.</value> 1.274 - <!-- Statement --> 1.275 - <value><![CDATA[SELECT (COUNT(?s) AS ?NumOfTriples) 1.276 + <list> 1.277 + <!-- Bean --> 1.278 + <value>Query</value> 1.279 + <!-- Format --> 1.280 + <value>HTML</value> 1.281 + <!-- Label --> 1.282 + <value>Find the number of triples that appear in the dataset.</value> 1.283 + <!-- Statement --> 1.284 + <value><![CDATA[SELECT (COUNT(?s) AS ?NumOfTriples) 1.285 WHERE { 1.286 ?s ?p ?o 1.287 } 1.288 ]]></value> 1.289 - <!-- Description --> 1.290 - <value></value> 1.291 - <!-- Hander (plain, download, map or map_local)--> 1.292 - <value>Plain</value> 1.293 - </list> 1.294 - <list> 1.295 - <!-- Bean --> 1.296 - <value>Query</value> 1.297 - <!-- Format --> 1.298 - <value>HTML</value> 1.299 - <!-- Label --> 1.300 - <value>Present the first ten triples of the dataset.</value> 1.301 - <!-- Statement --> 1.302 - <value><![CDATA[SELECT * 1.303 + <!-- Description --> 1.304 + <value></value> 1.305 + <!-- Hander (plain, download, map or map_local)--> 1.306 + <value>Plain</value> 1.307 + </list> 1.308 + <list> 1.309 + <!-- Bean --> 1.310 + <value>Query</value> 1.311 + <!-- Format --> 1.312 + <value>HTML</value> 1.313 + <!-- Label --> 1.314 + <value>Present the first ten triples of the dataset.</value> 1.315 + <!-- Statement --> 1.316 + <value><![CDATA[SELECT * 1.317 WHERE { 1.318 ?s ?p ?o 1.319 } 1.320 LIMIT 10 1.321 ]]></value> 1.322 - <!-- Description --> 1.323 - <value></value> 1.324 - <!-- Hander (plain, download, map or map_local)--> 1.325 - <value>Plain</value> 1.326 - </list> 1.327 + <!-- Description --> 1.328 + <value></value> 1.329 + <!-- Hander (plain, download, map or map_local)--> 1.330 + <value>Plain</value> 1.331 + </list> 1.332 1.333 - <list> 1.334 - <!-- Single valued elements correspond to headers --> 1.335 - <value>Explore/Modify operations</value> 1.336 - </list> 1.337 - <list> 1.338 - <!-- Link to bean: two arguemnts --> 1.339 - <value>Store</value> 1.340 - <value>store.jsp</value> 1.341 - </list> 1.342 - <list> 1.343 - <!-- Link to bean: two arguemnts --> 1.344 - <value>Query/Update</value> 1.345 - <value>query.jsp</value> 1.346 - </list> 1.347 - <list> 1.348 - <!-- Link to bean: two arguemnts --> 1.349 - <value>Describe</value> 1.350 - <value>describe.jsp</value> 1.351 - </list> 1.352 - <list> 1.353 - <!-- Link to bean: two arguemnts --> 1.354 - <value>Browse</value> 1.355 - <value>browse.jsp</value> 1.356 - </list> 1.357 - <list> 1.358 - <!-- Link to bean: two arguemnts --> 1.359 - <value>Configuration</value> 1.360 - <value>connection.jsp</value> 1.361 - </list> 1.362 + <list> 1.363 + <!-- Single valued elements correspond to headers --> 1.364 + <value>Explore/Modify operations</value> 1.365 + </list> 1.366 + <list> 1.367 + <!-- Link to bean: two arguemnts --> 1.368 + <value>Store</value> 1.369 + <value>store.jsp</value> 1.370 + </list> 1.371 + <list> 1.372 + <!-- Link to bean: two arguemnts --> 1.373 + <value>Query/Update</value> 1.374 + <value>query.jsp</value> 1.375 + </list> 1.376 + <list> 1.377 + <!-- Link to bean: two arguemnts --> 1.378 + <value>Describe</value> 1.379 + <value>describe.jsp</value> 1.380 + </list> 1.381 + <list> 1.382 + <!-- Link to bean: two arguemnts --> 1.383 + <value>Browse</value> 1.384 + <value>browse.jsp</value> 1.385 + </list> 1.386 + <list> 1.387 + <!-- Link to bean: two arguemnts --> 1.388 + <value>Configuration</value> 1.389 + <value>connection.jsp</value> 1.390 + </list> 1.391 </list> 1.392 - </constructor-arg> 1.393 + </constructor-arg> 1.394 </bean> 1.395 </beans>
2.1 --- a/endpoint/WebContent/WEB-INF/connection.properties Tue Sep 22 20:56:35 2015 +0300 2.2 +++ b/endpoint/WebContent/WEB-INF/connection.properties Wed Oct 04 11:55:13 2017 +0300 2.3 @@ -2,5 +2,6 @@ 2.4 port=5432 2.5 dbengine=postgis 2.6 password=postgres 2.7 -dbname=endpoint 2.8 +dbname=homework2 2.9 username=postgres 2.10 +googlemapskey=null 2.11 \ No newline at end of file
3.1 --- a/endpoint/WebContent/connection.jsp Tue Sep 22 20:56:35 2015 +0300 3.2 +++ b/endpoint/WebContent/connection.jsp Wed Oct 04 11:55:13 2017 +0300 3.3 @@ -96,6 +96,10 @@ 3.4 </SELECT> 3.5 </TD> 3.6 </TR> 3.7 + <TR> 3.8 + <TD valign="top" class="style4">Google Maps API Key:</TD> 3.9 + <TD><input type="text" name="googlemapskey" value="<%=request.getAttribute("googlemapskey")%>"/></TD> 3.10 + </TR> 3.11 <TR> 3.12 <TD colspan=2><input type="submit" value="Connect"/></TD> 3.13 </TR>
4.1 --- a/endpoint/WebContent/query.jsp Tue Sep 22 20:56:35 2015 +0300 4.2 +++ b/endpoint/WebContent/query.jsp Wed Oct 04 11:55:13 2017 +0300 4.3 @@ -12,501 +12,505 @@ 4.4 <jsp:directive.page import="eu.earthobservatory.org.StrabonEndpoint.Common"/> 4.5 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4.6 <html> 4.7 -<head> 4.8 - <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 4.9 - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 4.10 - <script type="text/javascript" src="js/more_link.js"></script> 4.11 - <link rel="stylesheet" href="style.css" type="text/css" /> 4.12 - <script type="text/javascript" src="js/timemap/jquery-1.6.2.min.js"></script> 4.13 - <script type="text/javascript" src="js/timemap/mxn.js?(googlev3)"></script> 4.14 - <script type="text/javascript" src="js/timemap/timeline-1.2.js"></script> 4.15 - <script src="js/timemap/timemap.js" type="text/javascript"></script> 4.16 - <script src="js/timemap/param.js" type="text/javascript"></script> 4.17 - <script src="js/timemap/xml.js" type="text/javascript"></script> 4.18 - <script src="js/timemap/kml.js" type="text/javascript"></script> 4.19 - <script type="text/javascript"> 4.20 - function toggleMe(a) { 4.21 - var e = document.getElementById(a); 4.22 - if (!e) { 4.23 - return true; 4.24 - } 4.25 - if (e.style.display == "none") { 4.26 - e.style.display = "block"; 4.27 - } else { 4.28 - e.style.display = "none"; 4.29 - } 4.30 - return true; 4.31 - } 4.32 - </script> 4.33 - <script> 4.34 - $(document).ready(function() { 4.35 - var showChar = 100; 4.36 - var ellipsestext = "..."; 4.37 - var moretext = "more"; 4.38 - var lesstext = "less"; 4.39 - $('.more').each(function() { 4.40 - var content = $(this).html(); 4.41 + <head> 4.42 + <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 4.43 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 4.44 + <script type="text/javascript" src="js/more_link.js"></script> 4.45 + <link rel="stylesheet" href="style.css" type="text/css" /> 4.46 + <script type="text/javascript" src="js/timemap/jquery-1.6.2.min.js"></script> 4.47 + <script type="text/javascript" src="js/timemap/mxn.js?(googlev3)"></script> 4.48 + <script type="text/javascript" src="js/timemap/timeline-1.2.js"></script> 4.49 + <script src="js/timemap/timemap.js" type="text/javascript"></script> 4.50 + <script src="js/timemap/param.js" type="text/javascript"></script> 4.51 + <script src="js/timemap/xml.js" type="text/javascript"></script> 4.52 + <script src="js/timemap/kml.js" type="text/javascript"></script> 4.53 + <script type="text/javascript"> 4.54 + function toggleMe(a) { 4.55 + var e = document.getElementById(a); 4.56 + if (!e) { 4.57 + return true; 4.58 + } 4.59 + if (e.style.display == "none") { 4.60 + e.style.display = "block"; 4.61 + } else { 4.62 + e.style.display = "none"; 4.63 + } 4.64 + return true; 4.65 + } 4.66 + </script> 4.67 + <script> 4.68 + $(document).ready(function () { 4.69 + var showChar = 100; 4.70 + var ellipsestext = "..."; 4.71 + var moretext = "more"; 4.72 + var lesstext = "less"; 4.73 + $('.more').each(function () { 4.74 + var content = $(this).html(); 4.75 + 4.76 + if (content.length > showChar) { 4.77 + 4.78 + var c = content.substr(0, showChar); 4.79 + var h = content.substr(showChar - 1, content.length - showChar); 4.80 + 4.81 + var html = c + '<span class="moreelipses">' + ellipsestext + '</span> <span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>'; 4.82 + 4.83 + $(this).html(html); 4.84 + } 4.85 + 4.86 + }); 4.87 + 4.88 + $(".morelink").click(function () { 4.89 + if ($(this).hasClass("less")) { 4.90 + $(this).removeClass("less"); 4.91 + $(this).html(moretext); 4.92 + } else { 4.93 + $(this).addClass("less"); 4.94 + $(this).html(lesstext); 4.95 + } 4.96 + $(this).parent().prev().toggle(); 4.97 + $(this).prev().toggle(); 4.98 + return false; 4.99 + }); 4.100 + }); 4.101 + </script> 4.102 + <% 4.103 + // get the reference to StrabonBeanWrapper 4.104 + StrabonBeanWrapper strabonWrapper; 4.105 + //String arr = new String[2]; 4.106 + int i; 4.107 + ArrayList<String> arr = new ArrayList<String>(2); 4.108 + String gChartString=null; 4.109 + ServletContext context; 4.110 + context = getServletContext(); 4.111 + WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context); 4.112 + strabonWrapper=(StrabonBeanWrapper) applicationContext.getBean("strabonBean"); 4.113 4.114 - if(content.length > showChar) { 4.115 + // get query parameter or attribute (the attribute comes from ConnectionBean) 4.116 + String query = strabonWrapper.getPrefixes(); 4.117 + if (request.getParameter("query") != null) { 4.118 + query = request.getParameter("query"); 4.119 + 4.120 + } else if (request.getAttribute("query") != null) { 4.121 + query = (String) request.getAttribute("query"); 4.122 + 4.123 + } 4.124 4.125 - var c = content.substr(0, showChar); 4.126 - var h = content.substr(showChar-1, content.length - showChar); 4.127 + if ("null".equals(query)) { 4.128 + query = ""; 4.129 + } 4.130 4.131 - var html = c + '<span class="moreelipses">'+ellipsestext+'</span> <span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">'+moretext+'</a></span>'; 4.132 - 4.133 - $(this).html(html); 4.134 - } 4.135 - 4.136 - }); 4.137 - 4.138 - $(".morelink").click(function(){ 4.139 - if($(this).hasClass("less")) { 4.140 - $(this).removeClass("less"); 4.141 - $(this).html(moretext); 4.142 - } else { 4.143 - $(this).addClass("less"); 4.144 - $(this).html(lesstext); 4.145 - } 4.146 - $(this).parent().prev().toggle(); 4.147 - $(this).prev().toggle(); 4.148 - return false; 4.149 - }); 4.150 - }); 4.151 -</script> 4.152 - <% 4.153 - // get the reference to StrabonBeanWrapper 4.154 - StrabonBeanWrapper strabonWrapper; 4.155 - //String arr = new String[2]; 4.156 - int i; 4.157 - ArrayList<String> arr = new ArrayList<String>(2); 4.158 - String gChartString=null; 4.159 - ServletContext context; 4.160 - context = getServletContext(); 4.161 - WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context); 4.162 - strabonWrapper=(StrabonBeanWrapper) applicationContext.getBean("strabonBean"); 4.163 - 4.164 - // get query parameter or attribute (the attribute comes from ConnectionBean) 4.165 - String query = strabonWrapper.getPrefixes(); 4.166 - if (request.getParameter("query") != null) { 4.167 - query = request.getParameter("query"); 4.168 + // get format parameter or attribute (the attribute comes from ConnectionBean) 4.169 + String selFormat = "HTML"; 4.170 + if (request.getParameter("format") != null) { 4.171 + selFormat = request.getParameter("format"); 4.172 4.173 - } else if (request.getAttribute("query") != null) { 4.174 - query = (String) request.getAttribute("query"); 4.175 + } else if (request.getAttribute("format") != null) { 4.176 + selFormat = (String) request.getAttribute("format"); 4.177 4.178 - } 4.179 - 4.180 - if ("null".equals(query)) { 4.181 - query = ""; 4.182 - } 4.183 - 4.184 - // get format parameter or attribute (the attribute comes from ConnectionBean) 4.185 - String selFormat = "HTML"; 4.186 - if (request.getParameter("format") != null) { 4.187 - selFormat = request.getParameter("format"); 4.188 + } 4.189 4.190 - } else if (request.getAttribute("format") != null) { 4.191 - selFormat = (String) request.getAttribute("format"); 4.192 + // get handle parameter or attribute (the attribute comes from ConnectionBean) 4.193 + String handle = ""; 4.194 + if (request.getParameter("handle") != null) { 4.195 + handle = request.getParameter("handle"); 4.196 4.197 - } 4.198 + } else if (request.getAttribute("handle") != null) { 4.199 + handle = (String) request.getAttribute("handle"); 4.200 4.201 - // get handle parameter or attribute (the attribute comes from ConnectionBean) 4.202 - String handle = ""; 4.203 - if (request.getParameter("handle") != null) { 4.204 - handle = request.getParameter("handle"); 4.205 - 4.206 - } else if (request.getAttribute("handle") != null) { 4.207 - handle = (String) request.getAttribute("handle"); 4.208 - 4.209 - } 4.210 + } 4.211 4.212 - if (request.getAttribute("pathToKML") != null) { 4.213 - if (request.getAttribute("handle").toString().contains("map")) { 4.214 -%> 4.215 - <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> 4.216 - <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> 4.217 - <script type="text/javascript" src="js/geoxml3-kmz.js"></script> 4.218 - <script type="text/javascript" src="js/ProjectedOverlay.js"></script> 4.219 -<% 4.220 - } 4.221 -%> 4.222 + if (request.getAttribute("pathToKML") != null) { 4.223 + if (request.getAttribute("handle").toString().contains("map")) { 4.224 + %> 4.225 + <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> 4.226 + <script type="text/javascript" src="<%=request.getAttribute("googlemapsAPIscriptsource")%>"></script> 4.227 + <script type="text/javascript" src="js/geoxml3-kmz.js"></script> 4.228 + <script type="text/javascript" src="js/ProjectedOverlay.js"></script> 4.229 + <% 4.230 + } 4.231 + %> 4.232 4.233 - <script type="text/javascript"> 4.234 - 4.235 - //listener for the event 'bounds_changed' 4.236 - function addListener(map){ 4.237 + <script type="text/javascript"> 4.238 + 4.239 + //listener for the event 'bounds_changed' 4.240 + function addListener(map) { 4.241 + 4.242 + google.maps.event.addListener(map, 'bounds_changed', function () { 4.243 + // get the new bounds 4.244 + var bounds = map.getBounds(); 4.245 + var northEast = bounds.getNorthEast(); 4.246 + var southWest = bounds.getSouthWest(); 4.247 + 4.248 + var x1 = northEast.lng().toFixed(2); 4.249 + var y1 = northEast.lat().toFixed(2); 4.250 + 4.251 + var x2 = southWest.lng().toFixed(2); 4.252 + var y2 = southWest.lat().toFixed(2); 4.253 + 4.254 + var polygon = "\"POLYGON((" + 4.255 + x1 + " " + y2 + ", " + 4.256 + x2 + " " + y2 + ", " + 4.257 + x2 + " " + y1 + ", " + 4.258 + x1 + " " + y1 + ", " + 4.259 + x1 + " " + y2 + "))\"" + 4.260 + "^^<http\://www.opengis.net/ont/geosparql#wktLiteral>"; 4.261 + 4.262 + document.getElementById('bounds').value = polygon; 4.263 + 4.264 + }); 4.265 + } 4.266 + 4.267 + function initialize() { 4.268 + var myOptions = { 4.269 + zoom: 11, 4.270 + mapTypeId: google.maps.MapTypeId.ROADMAP, 4.271 + zoomControl: true 4.272 + }; 4.273 + 4.274 + // get KML filename 4.275 + var kml = '<%=request.getAttribute("pathToKML")%>'; 4.276 + var map; 4.277 + // create map 4.278 + <%if(request.getAttribute("handle").toString().contains("timemap")){ %> 4.279 + map = tm.getNativeMap(); 4.280 + map.setOptions(myOptions); 4.281 + <%} else {%> 4.282 + var map = new google.maps.Map(document.getElementById("map"), myOptions); 4.283 + <%}%> 4.284 + <% if (request.getAttribute("pathToKML") == null) {%> 4.285 + // center at Brahames 4.286 + map.setCenter(new google.maps.LatLng(37.92253, 23.72275)); 4.287 + <%}%> 4.288 + 4.289 + addListener(map); 4.290 + 4.291 + 4.292 + <%if ("map_local".equals(request.getAttribute("handle"))) {%> 4.293 + // display using geoxml3 4.294 + var myParser = new geoXML3.parser({map: map}); 4.295 + myParser.parse(kml); 4.296 + <%} else {%> 4.297 + var ctaLayer = new google.maps.KmlLayer(kml); 4.298 + ctaLayer.setMap(map); 4.299 + <%}%> 4.300 + 4.301 + <%if (("map".equals(request.getAttribute("handle"))) || ("map_local".equals(request.getAttribute("handle"))) 4.302 + || ("timemap".equals(request.getAttribute("handle")))) {%> 4.303 + $('html, body').animate({ 4.304 + scrollTop: $("#divResultsStart").offset().top 4.305 + }, 1500); 4.306 + 4.307 + <%}%> 4.308 + 4.309 + 4.310 + } 4.311 + </script> 4.312 + <% } else { %> 4.313 + <script type="text/javascript"> 4.314 + function initialize() { 4.315 + <% 4.316 + if (query != "" || selFormat != "" || handle != "") { 4.317 + %> 4.318 + $('html, body').animate({ 4.319 + scrollTop: $("#divResultsStart").offset().top 4.320 + }, 1000); 4.321 + <%}%> 4.322 + } 4.323 + </script> 4.324 + <%}%> 4.325 + 4.326 + <!-- jQuery start --> 4.327 + <link type="text/css" href="style-menu.css" rel="stylesheet" /> 4.328 + <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script> 4.329 + <script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script> 4.330 + <script type="text/javascript"> 4.331 + $(function () { 4.332 + // Accordion 4.333 + $("#accordion").accordion({ 4.334 + header: "h3", 4.335 + fillSpace: true, 4.336 + navigation: true, 4.337 + collapsible: true 4.338 + }); 4.339 + //hover states on the static widgets 4.340 + $('#dialog_link, ul#icons li').hover( 4.341 + function () { 4.342 + $(this).addClass('ui-state-hover'); 4.343 + }, 4.344 + function () { 4.345 + $(this).removeClass('ui-state-hover'); 4.346 + } 4.347 + ); 4.348 + }); 4.349 + </script> 4.350 + <style type="text/css"> 4.351 + /*demo page css*/ 4.352 + body{ font: 90% "Trebuchet MS", sans-serif; margin: 50px;} 4.353 + .container { height:410px; width:165px;} 4.354 + .demoHeaders { margin-top: 1em;} 4.355 + #dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;} 4.356 + #dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;} 4.357 + ul#icons {margin: 0; padding: 0;} 4.358 + ul#icons li {margin: 1px; position: relative; padding: 1px 0; cursor: pointer; float: left; list-style: none;} 4.359 + ul#icons span.ui-icon {float: left; margin: 0 1px;} 4.360 + </style> 4.361 + 4.362 + <script type="text/javascript"> 4.363 + 4.364 + var tm; 4.365 + $(function () { 4.366 + var myOptions = { 4.367 + zoom: 11, 4.368 + mapTypeId: google.maps.MapTypeId.ROADMAP, 4.369 + zoomControl: true, 4.370 + scrollwheel: true 4.371 + 4.372 + }; 4.373 + 4.374 + var map = new google.maps.Map(document.getElementById("map"), myOptions); 4.375 + tm = TimeMap.init({ 4.376 + // Id of map div element (required) 4.377 + mapId: "map", 4.378 + timelineId: "timeline", // Id of timeline div element (required) 4.379 + options: { 4.380 + eventIconPath: "images/" 4.381 + }, 4.382 + datasets: [ 4.383 + { 4.384 + title: "Visualization of timestamps", 4.385 + theme: "red", 4.386 + type: "kml", // Data to be loaded in KML - must be a local URL 4.387 + options: { 4.388 + url: <% if(request.getAttribute("pathToKML") != null){ 4.389 + out.println("\""+request.getAttribute("pathToKML")+"\""); 4.390 + }%> // KML file to load 4.391 + } 4.392 + } 4.393 + ], 4.394 + bandInfo: [ 4.395 + { 4.396 + width: "85%", 4.397 + intervalUnit: Timeline.DateTime.DAY, 4.398 + intervalPixels: 210 4.399 + }, 4.400 + { 4.401 + width: "15%", 4.402 + intervalUnit: Timeline.DateTime.WEEK, 4.403 + intervalPixels: 150, 4.404 + showEventText: false, 4.405 + trackHeight: 0.2, 4.406 + trackGap: 0.2 4.407 + } 4.408 + ] 4.409 + }); 4.410 + 4.411 + 4.412 + }); 4.413 + 4.414 + 4.415 + </script> 4.416 + 4.417 + 4.418 + <link href="js/timemap/examples.css" type="text/css" rel="stylesheet"/> 4.419 + <style> 4.420 + div#timelinecontainer{ height: 310px; } 4.421 + div#mapcontainer{ height: 600px; } 4.422 + </style> 4.423 + 4.424 + <!-- jQuery end --> 4.425 + 4.426 + <title>Strabon Endpoint</title> 4.427 + <!--Load the AJAX API--> 4.428 + <script type="text/javascript" src="https://www.google.com/jsapi"></script> 4.429 + <script type="text/javascript"> 4.430 + 4.431 + // Load the Visualization API and the piechart package. 4.432 + google.load('visualization', '1.0', {'packages': ['corechart']}); 4.433 + 4.434 + google.setOnLoadCallback(drawChart); 4.435 + 4.436 + // Set a callback to run when the Google Visualization API is loaded. 4.437 + 4.438 + 4.439 + // Callback that creates and populates a data table, 4.440 + // instantiates the pie chart, passes in the data and 4.441 + // draws it. 4.442 + 4.443 + 4.444 + 4.445 + function drawChart() { 4.446 + 4.447 + // Create the data table. 4.448 + var data = new google.visualization.DataTable(); 4.449 + <% if (request.getAttribute("format")!=null && request.getAttribute("response") != null) { 4.450 + if (request.getAttribute("format").equals("CHART")) { 4.451 + out.println(request.getAttribute("response")); 4.452 + %> 4.453 + 4.454 + 4.455 + chart.draw(data, options); 4.456 + 4.457 + <%}}%> 4.458 + } 4.459 + </script> 4.460 + 4.461 + 4.462 + </head> 4.463 + <body topmargin="0" leftmargin="0" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" onload="initialize()"> 4.464 + 4.465 + <!-- include TELEIOS header and description --> 4.466 + <%@ include file="header.html"%> 4.467 + <!-- include TELEIOS header and description --> 4.468 + 4.469 + <FORM enctype="UTF-8" accept-charset="UTF-8" method="post" action="Query"> 4.470 + <INPUT type=hidden name="view" value="HTML"/> 4.471 + 4.472 + <table border="0" width="100%"> 4.473 + <tr> 4.474 + <td width="90" valign="top"> 4.475 + <table border="0" cellspacing="0" cellpadding="0" width="165"> 4.476 + <tr><td id="twidth"> 4.477 + <div class="container"> 4.478 + <div id="accordion"> 4.479 + <% 4.480 + 4.481 + Iterator <StrabonBeanWrapperConfiguration> entryListIterator = strabonWrapper.getEntries().iterator(); 4.482 + boolean first = true; 4.483 + String hash = ""; 4.484 + while(entryListIterator.hasNext()) 4.485 + { 4.486 + StrabonBeanWrapperConfiguration entry = entryListIterator.next(); 4.487 + 4.488 + if (entry.isHeader()) { 4.489 + if (!first) { 4.490 + %> 4.491 + </div></div> 4.492 + <% 4.493 + } else { 4.494 + first = false; 4.495 + } 4.496 + 4.497 + String label=entry.getLabel(); 4.498 + String style = "", href = ""; 4.499 + hash = new Integer(Math.abs(label.hashCode())).toString(); 4.500 + href="href=\"#"+hash+"\""; 4.501 + %> 4.502 + <div><h3><a <%=style%> <%=href%>><%=label%></a></h3><div> 4.503 + <% 4.504 + } else if (entry.isBean()) { 4.505 + String label=entry.getLabel(); 4.506 + String bean=entry.getBean(); 4.507 + if(bean.equals("browse.jsp") || bean.equals("ChangeConnection")) 4.508 + continue; 4.509 + String style = "", href = ""; 4.510 + hash = new Integer(Math.abs(label.hashCode()*bean.hashCode())).toString(); 4.511 + href = "\"" +bean + "#"+ hash+"\""; 4.512 + style = "class=\"navText\""; 4.513 + %> 4.514 + <b>·</b> <a class="linkText" href=<%=href%>><%=label%></a><br/> 4.515 + <% 4.516 + } else { 4.517 + String href="\""+URLEncoder.encode(entry.getBean(),"utf-8")+"?view=HTML&handle="+entry.getHandle()+"&query="+URLEncoder.encode(entry.getStatement(),"utf-8")+"&format="+URLEncoder.encode(entry.getFormat(),"utf-8")+(hash == "" ? "" : "#" + hash)+"\""; 4.518 + String title="\""+entry.getTitle()+"\""; 4.519 + String label=entry.getLabel(); 4.520 + %> 4.521 + <b>·</b> <a class="linkText" href=<%=href%> title=<%=title%>><%=label%></a><br/> 4.522 + <% 4.523 4.524 - google.maps.event.addListener(map, 'bounds_changed', function() { 4.525 - // get the new bounds 4.526 - var bounds = map.getBounds(); 4.527 - var northEast = bounds.getNorthEast(); 4.528 - var southWest = bounds.getSouthWest(); 4.529 - 4.530 - var x1 = northEast.lng().toFixed(2); 4.531 - var y1 = northEast.lat().toFixed(2); 4.532 - 4.533 - var x2 = southWest.lng().toFixed(2); 4.534 - var y2 = southWest.lat().toFixed(2); 4.535 - 4.536 - var polygon = "\"POLYGON((" + 4.537 - x1 + " " + y2 + ", " + 4.538 - x2 + " " + y2 + ", " + 4.539 - x2 + " " + y1 + ", " + 4.540 - x1 + " " + y1 + ", " + 4.541 - x1 + " " + y2 + "))\"" + 4.542 - "^^<http\://www.opengis.net/ont/geosparql#wktLiteral>"; 4.543 - 4.544 - document.getElementById('bounds').value=polygon; 4.545 - 4.546 - }); 4.547 - } 4.548 - 4.549 - function initialize() { 4.550 - var myOptions = { 4.551 - zoom: 11, 4.552 - mapTypeId: google.maps.MapTypeId.ROADMAP, 4.553 - zoomControl: true 4.554 - }; 4.555 - 4.556 - // get KML filename 4.557 - var kml = '<%=request.getAttribute("pathToKML")%>'; 4.558 - var map; 4.559 - // create map 4.560 - <%if(request.getAttribute("handle").toString().contains("timemap")){ %> 4.561 - map = tm.getNativeMap(); 4.562 - map.setOptions(myOptions); 4.563 - <%} else {%> 4.564 - var map = new google.maps.Map(document.getElementById("map"), myOptions); 4.565 - <%}%> 4.566 - <% if (request.getAttribute("pathToKML") == null) {%> 4.567 - // center at Brahames 4.568 - map.setCenter(new google.maps.LatLng(37.92253, 23.72275)); 4.569 - <%}%> 4.570 - 4.571 - addListener(map); 4.572 + } 4.573 + } 4.574 + %> 4.575 + </div> 4.576 + </div> 4.577 + </td> 4.578 + </tr> 4.579 + <!-- 4.580 + <tr><td width="90" class="style4"><a href="describe.jsp" class="navText">Describe</a></td></tr> 4.581 + <tr><td width="90" class="style4"><a href="store.jsp" class="navText" title="Store triples">Store</a></td></tr> 4.582 + --> 4.583 + </table> 4.584 + </td> 4.585 + <td width="*" valign="top" > 4.586 + <table cellspacing="5"> 4.587 + <%if (request.getAttribute("info") != null) { %> 4.588 + <!-- Info Message --> 4.589 + <TR><TD colspan=2> 4.590 + <CENTER><P><%=request.getAttribute("info") %></P></CENTER> 4.591 + </TD></TR> 4.592 + <!-- Info Message --> 4.593 + <%}%> 4.594 + <tr> 4.595 + <td id="output" colspan=2> 4.596 + <div style="font-size:13px"> 4.597 + You must be logged in to perform update queries, or run in localhost. 4.598 + </div> 4.599 + </td> 4.600 + </tr> 4.601 + <tr> 4.602 + <td id="output" style="width: 150px">stSPARQL Query:</td> 4.603 + <td id="output"><textarea name="query" title="pose your query/update here" rows="20" cols="100"><%=query%></textarea></td> 4.604 + </tr> 4.605 + <tr> 4.606 + <td id="output">Output Format:</td> 4.607 + <td id="output"> 4.608 + <select name="format" title="select one of the following output format types"> 4.609 + <% 4.610 + for (String format : Common.registeredQueryResultsFormatNames) {%> 4.611 + <OPTION value="<%=format%>"<%=format.equals(selFormat) ? "selected":""%>><%=format%></OPTION> 4.612 + <%}%> 4.613 + </select> 4.614 + </td> 4.615 + </tr> 4.616 + <tr> 4.617 + <td id="output">View Result:</td> 4.618 + <td id="output"> 4.619 + <SELECT name="handle" title="select how you would like to view the result"> 4.620 + <OPTION value="plain"<%= ("plain".equals(handle)) ? "selected":""%>>Plain</OPTION> 4.621 + <OPTION value="download"<%= ("download".equals(handle)) ? "selected":""%>>Download</OPTION> 4.622 + <OPTION value="map"<%= ("map".equals(handle)) ? "selected":""%>>On a map</OPTION> 4.623 + <OPTION value="map_local"<%= ("map_local".equals(handle)) ? "selected":""%>>On a map (localhost)</OPTION> 4.624 + <OPTION value="timemap"<%= ("timemap".equals(handle)) ? "selected":""%>>On a timemap</OPTION> 4.625 + </SELECT> 4.626 + </td> 4.627 + </tr> 4.628 4.629 - 4.630 - <%if ("map_local".equals(request.getAttribute("handle"))) {%> 4.631 - // display using geoxml3 4.632 - var myParser = new geoXML3.parser({map: map}); 4.633 - myParser.parse(kml); 4.634 - <%} else {%> 4.635 - var ctaLayer = new google.maps.KmlLayer(kml); 4.636 - ctaLayer.setMap(map); 4.637 - <%}%> 4.638 - 4.639 - <%if (("map".equals(request.getAttribute("handle"))) || ("map_local".equals(request.getAttribute("handle"))) 4.640 - || ("timemap".equals(request.getAttribute("handle")))) {%> 4.641 - $('html, body').animate({ 4.642 - scrollTop: $("#divResultsStart").offset().top 4.643 - }, 1500); 4.644 - 4.645 - <%}%> 4.646 - 4.647 - 4.648 - } 4.649 - </script> 4.650 - <% } else { %> 4.651 - <script type="text/javascript"> 4.652 - function initialize() { 4.653 - <% 4.654 - if (query != "" || selFormat != "" || handle != "") { 4.655 - %> 4.656 - $('html, body').animate({ 4.657 - scrollTop: $("#divResultsStart").offset().top 4.658 - }, 1000); 4.659 - <%}%> 4.660 - } 4.661 - </script> 4.662 - <%}%> 4.663 + <tr> 4.664 + <td id="output">Map Bounds:</td> 4.665 + <td id="output"> 4.666 + <textarea readonly id='bounds' rows="1" cols="100"></textarea> 4.667 + </td> 4.668 + </tr> 4.669 4.670 - <!-- jQuery start --> 4.671 - <link type="text/css" href="style-menu.css" rel="stylesheet" /> 4.672 - <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script> 4.673 - <script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script> 4.674 - <script type="text/javascript"> 4.675 - $(function(){ 4.676 - // Accordion 4.677 - $("#accordion").accordion({ 4.678 - header: "h3", 4.679 - fillSpace: true, 4.680 - navigation: true, 4.681 - collapsible: true 4.682 - }); 4.683 - //hover states on the static widgets 4.684 - $('#dialog_link, ul#icons li').hover( 4.685 - function() { $(this).addClass('ui-state-hover'); }, 4.686 - function() { $(this).removeClass('ui-state-hover'); } 4.687 - ); 4.688 - }); 4.689 - </script> 4.690 - <style type="text/css"> 4.691 - /*demo page css*/ 4.692 - body{ font: 90% "Trebuchet MS", sans-serif; margin: 50px;} 4.693 - .container { height:410px; width:165px;} 4.694 - .demoHeaders { margin-top: 1em;} 4.695 - #dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;} 4.696 - #dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;} 4.697 - ul#icons {margin: 0; padding: 0;} 4.698 - ul#icons li {margin: 1px; position: relative; padding: 1px 0; cursor: pointer; float: left; list-style: none;} 4.699 - ul#icons span.ui-icon {float: left; margin: 0 1px;} 4.700 - </style> 4.701 - 4.702 - <script type="text/javascript"> 4.703 + <tr> 4.704 + <td colspan=2 id="output"><br/><center> 4.705 + <input type="submit" title="execute query" value="Query" name="submit" style="width: 350px" /> 4.706 + <input type="submit" title="execute update" value="Update" name="submit" style="width: 350px"/></center><br/></td> 4.707 + </tr> 4.708 4.709 -var tm; 4.710 -$(function() { 4.711 - var myOptions = { 4.712 - zoom: 11, 4.713 - mapTypeId: google.maps.MapTypeId.ROADMAP, 4.714 - zoomControl: true, 4.715 - scrollwheel : true 4.716 4.717 - }; 4.718 - 4.719 - var map = new google.maps.Map(document.getElementById("map"), myOptions); 4.720 - tm = TimeMap.init({ 4.721 - // Id of map div element (required) 4.722 - mapId: "map", 4.723 - timelineId: "timeline", // Id of timeline div element (required) 4.724 - options: { 4.725 - eventIconPath: "images/" 4.726 - }, 4.727 - datasets: [ 4.728 - { 4.729 - title: "Visualization of timestamps", 4.730 - theme: "red", 4.731 - type: "kml", // Data to be loaded in KML - must be a local URL 4.732 - options: { 4.733 - url: <% if(request.getAttribute("pathToKML") != null){ 4.734 - out.println("\""+request.getAttribute("pathToKML")+"\""); 4.735 - }%> // KML file to load 4.736 - } 4.737 - } 4.738 - ], 4.739 - bandInfo: [ 4.740 - { 4.741 - width: "85%", 4.742 - intervalUnit: Timeline.DateTime.DAY, 4.743 - intervalPixels: 210 4.744 - }, 4.745 - { 4.746 - width: "15%", 4.747 - intervalUnit: Timeline.DateTime.WEEK, 4.748 - intervalPixels: 150, 4.749 - showEventText: false, 4.750 - trackHeight: 0.2, 4.751 - trackGap: 0.2 4.752 - } 4.753 - ] 4.754 - }); 4.755 - 4.756 - 4.757 -}); 4.758 - 4.759 4.760 - </script> 4.761 - 4.762 - 4.763 - <link href="js/timemap/examples.css" type="text/css" rel="stylesheet"/> 4.764 - <style> 4.765 - div#timelinecontainer{ height: 310px; } 4.766 - div#mapcontainer{ height: 600px; } 4.767 - </style> 4.768 - 4.769 - <!-- jQuery end --> 4.770 - 4.771 - <title>Strabon Endpoint</title> 4.772 - <!--Load the AJAX API--> 4.773 - <script type="text/javascript" src="https://www.google.com/jsapi"></script> 4.774 - <script type="text/javascript"> 4.775 - 4.776 - // Load the Visualization API and the piechart package. 4.777 - google.load('visualization', '1.0', {'packages':['corechart']}); 4.778 - 4.779 - google.setOnLoadCallback(drawChart); 4.780 - 4.781 - // Set a callback to run when the Google Visualization API is loaded. 4.782 - 4.783 - 4.784 - // Callback that creates and populates a data table, 4.785 - // instantiates the pie chart, passes in the data and 4.786 - // draws it. 4.787 - 4.788 - 4.789 - 4.790 - function drawChart() { 4.791 - 4.792 - // Create the data table. 4.793 - var data = new google.visualization.DataTable(); 4.794 - <% if (request.getAttribute("format")!=null && request.getAttribute("response") != null) { 4.795 - if (request.getAttribute("format").equals("CHART")) { 4.796 - out.println(request.getAttribute("response")); 4.797 - %> 4.798 - 4.799 - 4.800 - chart.draw(data, options); 4.801 - 4.802 - <%}}%> 4.803 - } 4.804 - </script> 4.805 - 4.806 - 4.807 -</head> 4.808 -<body topmargin="0" leftmargin="0" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" onload="initialize()"> 4.809 - 4.810 -<!-- include TELEIOS header and description --> 4.811 -<%@ include file="header.html"%> 4.812 -<!-- include TELEIOS header and description --> 4.813 - 4.814 -<FORM enctype="UTF-8" accept-charset="UTF-8" method="post" action="Query"> 4.815 -<INPUT type=hidden name="view" value="HTML"/> 4.816 - 4.817 -<table border="0" width="100%"> 4.818 -<tr> 4.819 - <td width="90" valign="top"> 4.820 - <table border="0" cellspacing="0" cellpadding="0" width="165"> 4.821 - <tr><td id="twidth"> 4.822 - <div class="container"> 4.823 - <div id="accordion"> 4.824 - <% 4.825 - 4.826 - Iterator <StrabonBeanWrapperConfiguration> entryListIterator = strabonWrapper.getEntries().iterator(); 4.827 - boolean first = true; 4.828 - String hash = ""; 4.829 - while(entryListIterator.hasNext()) 4.830 - { 4.831 - StrabonBeanWrapperConfiguration entry = entryListIterator.next(); 4.832 - 4.833 - if (entry.isHeader()) { 4.834 - if (!first) { 4.835 - %> 4.836 - </div></div> 4.837 - <% 4.838 - } else { 4.839 - first = false; 4.840 - } 4.841 - 4.842 - String label=entry.getLabel(); 4.843 - String style = "", href = ""; 4.844 - hash = new Integer(Math.abs(label.hashCode())).toString(); 4.845 - href="href=\"#"+hash+"\""; 4.846 - %> 4.847 - <div><h3><a <%=style%> <%=href%>><%=label%></a></h3><div> 4.848 - <% 4.849 - } else if (entry.isBean()) { 4.850 - String label=entry.getLabel(); 4.851 - String bean=entry.getBean(); 4.852 - if(bean.equals("browse.jsp") || bean.equals("ChangeConnection")) 4.853 - continue; 4.854 - String style = "", href = ""; 4.855 - hash = new Integer(Math.abs(label.hashCode()*bean.hashCode())).toString(); 4.856 - href = "\"" +bean + "#"+ hash+"\""; 4.857 - style = "class=\"navText\""; 4.858 - %> 4.859 - <b>·</b> <a class="linkText" href=<%=href%>><%=label%></a><br/> 4.860 - <% 4.861 - } else { 4.862 - String href="\""+URLEncoder.encode(entry.getBean(),"utf-8")+"?view=HTML&handle="+entry.getHandle()+"&query="+URLEncoder.encode(entry.getStatement(),"utf-8")+"&format="+URLEncoder.encode(entry.getFormat(),"utf-8")+(hash == "" ? "" : "#" + hash)+"\""; 4.863 - String title="\""+entry.getTitle()+"\""; 4.864 - String label=entry.getLabel(); 4.865 - %> 4.866 - <b>·</b> <a class="linkText" href=<%=href%> title=<%=title%>><%=label%></a><br/> 4.867 - <% 4.868 - 4.869 - } 4.870 - } 4.871 - %> 4.872 - </div> 4.873 - </div> 4.874 - </td> 4.875 -</tr> 4.876 -<!-- 4.877 -<tr><td width="90" class="style4"><a href="describe.jsp" class="navText">Describe</a></td></tr> 4.878 -<tr><td width="90" class="style4"><a href="store.jsp" class="navText" title="Store triples">Store</a></td></tr> 4.879 - --> 4.880 -</table> 4.881 -</td> 4.882 -<td width="*" valign="top" > 4.883 -<table cellspacing="5"> 4.884 -<%if (request.getAttribute("info") != null) { %> 4.885 - <!-- Info Message --> 4.886 - <TR><TD colspan=2> 4.887 - <CENTER><P><%=request.getAttribute("info") %></P></CENTER> 4.888 - </TD></TR> 4.889 - <!-- Info Message --> 4.890 -<%}%> 4.891 -<tr> 4.892 - <td id="output" colspan=2> 4.893 - <div style="font-size:13px"> 4.894 - You must be logged in to perform update queries, or run in localhost. 4.895 - </div> 4.896 - </td> 4.897 -</tr> 4.898 -<tr> 4.899 -<td id="output" style="width: 150px">stSPARQL Query:</td> 4.900 -<td id="output"><textarea name="query" title="pose your query/update here" rows="20" cols="100"><%=query%></textarea></td> 4.901 -</tr> 4.902 -<tr> 4.903 - <td id="output">Output Format:</td> 4.904 - <td id="output"> 4.905 - <select name="format" title="select one of the following output format types"> 4.906 - <% 4.907 - for (String format : Common.registeredQueryResultsFormatNames) {%> 4.908 - <OPTION value="<%=format%>"<%=format.equals(selFormat) ? "selected":""%>><%=format%></OPTION> 4.909 - <%}%> 4.910 - </select> 4.911 - </td> 4.912 -</tr> 4.913 -<tr> 4.914 - <td id="output">View Result:</td> 4.915 - <td id="output"> 4.916 - <SELECT name="handle" title="select how you would like to view the result"> 4.917 - <OPTION value="plain"<%= ("plain".equals(handle)) ? "selected":""%>>Plain</OPTION> 4.918 - <OPTION value="download"<%= ("download".equals(handle)) ? "selected":""%>>Download</OPTION> 4.919 - <OPTION value="map"<%= ("map".equals(handle)) ? "selected":""%>>On a map</OPTION> 4.920 - <OPTION value="map_local"<%= ("map_local".equals(handle)) ? "selected":""%>>On a map (localhost)</OPTION> 4.921 - <OPTION value="timemap"<%= ("timemap".equals(handle)) ? "selected":""%>>On a timemap</OPTION> 4.922 - </SELECT> 4.923 - </td> 4.924 -</tr> 4.925 - 4.926 -<tr> 4.927 - <td id="output">Map Bounds:</td> 4.928 - <td id="output"> 4.929 - <textarea readonly id='bounds' rows="1" cols="100"></textarea> 4.930 - </td> 4.931 -</tr> 4.932 - 4.933 -<tr> 4.934 -<td colspan=2 id="output"><br/><center> 4.935 -<input type="submit" title="execute query" value="Query" name="submit" style="width: 350px" /> 4.936 -<input type="submit" title="execute update" value="Update" name="submit" style="width: 350px"/></center><br/></td> 4.937 -</tr> 4.938 - 4.939 - 4.940 - 4.941 -<% if (request.getAttribute("error") != null) {%> 4.942 - <!-- Error Message --> 4.943 - <TR> 4.944 - <TD id="output">Result: </TD><TD id="output"><%=request.getAttribute("error") %></TD> 4.945 - </TR> 4.946 - <!-- Error Message --> 4.947 -<%}%> 4.948 -</table></td></tr></table><br/><br/> 4.949 -</form> 4.950 -<a name="#results"> </a> 4.951 -<div id="divResultsStart"></div> 4.952 + <% if (request.getAttribute("error") != null) {%> 4.953 + <!-- Error Message --> 4.954 + <TR> 4.955 + <TD id="output">Result: </TD><TD id="output"><%=request.getAttribute("error") %></TD> 4.956 + </TR> 4.957 + <!-- Error Message --> 4.958 + <%}%> 4.959 + </table></td></tr></table><br/><br/> 4.960 + </form> 4.961 + <a name="#results"> </a> 4.962 + <div id="divResultsStart"></div> 4.963 + <!-- Response --> 4.964 + <% if(request.getAttribute("format") == null || !request.getAttribute("format").equals("CHART")){ 4.965 + if (request.getAttribute("response") != null) { 4.966 + if (Common.getHTMLFormat().equals(request.getParameter("format"))) {%> 4.967 + <%=request.getAttribute("response")%> 4.968 + <%} else { %> 4.969 + <PRE><%=request.getAttribute("response") %></PRE> 4.970 + <%}%> 4.971 + <%}}%> 4.972 <!-- Response --> 4.973 -<% if(request.getAttribute("format") == null || !request.getAttribute("format").equals("CHART")){ 4.974 - if (request.getAttribute("response") != null) { 4.975 - if (Common.getHTMLFormat().equals(request.getParameter("format"))) {%> 4.976 - <%=request.getAttribute("response")%> 4.977 - <%} else { %> 4.978 - <PRE><%=request.getAttribute("response") %></PRE> 4.979 - <%}%> 4.980 -<%}}%> 4.981 - <!-- Response --> 4.982 -<% if (request.getAttribute("pathToKML") != null && request.getAttribute("handle").toString().contains("timemap")) { %> 4.983 + <% if (request.getAttribute("pathToKML") != null && request.getAttribute("handle").toString().contains("timemap")) { %> 4.984 <div id="timemap"> 4.985 <div id="timelinecontainer"> 4.986 <div id="timeline"></div> 4.987 @@ -515,10 +519,10 @@ 4.988 <div id="map"></div> 4.989 </div> 4.990 </div> 4.991 -<%} else {%> 4.992 + <%} else {%> 4.993 <div id="map"></div> 4.994 - <%} %> 4.995 -<div id="divResultsEnd" style="height: 1px; width 1px"></div> 4.996 + <%} %> 4.997 +<div id="divResultsEnd" style="height: 1px; width: 1px"></div> 4.998 <div id="chart_div"></div> 4.999 </body> 4.1000 </html>
5.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ChangeConnectionBean.java Tue Sep 22 20:56:35 2015 +0300 5.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ChangeConnectionBean.java Wed Oct 04 11:55:13 2017 +0300 5.3 @@ -43,7 +43,7 @@ 5.4 5.5 public void init(ServletConfig servletConfig) throws ServletException { 5.6 super.init(servletConfig); 5.7 - 5.8 + 5.9 // get the context of the servlet 5.10 context = getServletContext(); 5.11 5.12 @@ -69,6 +69,7 @@ 5.13 request.setAttribute("hostname", strabonWrapper.getHostName()); 5.14 request.setAttribute("port", strabonWrapper.getPort()); 5.15 request.setAttribute("dbengine", strabonWrapper.getDBEngine()); 5.16 + request.setAttribute("googlemapskey", strabonWrapper.getGooglemapskey()); 5.17 5.18 // pass the other parameters as well 5.19 request.setAttribute("query", request.getParameter("query"));
6.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ConnectionBean.java Tue Sep 22 20:56:35 2015 +0300 6.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/ConnectionBean.java Wed Oct 04 11:55:13 2017 +0300 6.3 @@ -126,7 +126,8 @@ 6.4 request.getParameter("password"), 6.5 request.getParameter("port"), 6.6 request.getParameter("hostname"), 6.7 - request.getParameter("dbengine")); 6.8 + request.getParameter("dbengine"), 6.9 + request.getParameter("googlemapskey")); 6.10 6.11 // pass the query, format, and the handle that had been issued to the dispatcher 6.12 request.setAttribute("query", request.getAttribute("query")); 6.13 @@ -150,7 +151,8 @@ 6.14 request.getParameter("password"), 6.15 request.getParameter("port"), 6.16 request.getParameter("hostname"), 6.17 - request.getParameter("dbengine")); 6.18 + request.getParameter("dbengine"), 6.19 + request.getParameter("googlemapskey")); 6.20 6.21 if (logger.isInfoEnabled()) { 6.22 logger.info("[StrabonEndpoint.ConnectionBean] New connection details succesfully saved."); 6.23 @@ -171,6 +173,7 @@ 6.24 request.setAttribute("port", request.getParameter("port")); 6.25 request.setAttribute("hostname", request.getParameter("hostname")); 6.26 request.setAttribute("dbengine", request.getParameter("dbengine")); 6.27 + request.setAttribute("googlemapskey", request.getParameter("googlemapskey")); 6.28 6.29 dispatcher = request.getRequestDispatcher("/connection.jsp"); 6.30 6.31 @@ -182,7 +185,7 @@ 6.32 } 6.33 6.34 private void saveNewConnectionDetails(String dbname, String username, String password, 6.35 - String port, String hostname, String dbengine) throws IOException { 6.36 + String port, String hostname, String dbengine, String googlemapskey) throws IOException { 6.37 Properties properties = new Properties(); 6.38 6.39 synchronized (lock) { 6.40 @@ -199,6 +202,7 @@ 6.41 properties.setProperty("port", port); 6.42 properties.setProperty("hostname", hostname); 6.43 properties.setProperty("dbengine", dbengine); 6.44 + properties.setProperty("googlemapskey", googlemapskey); 6.45 6.46 // store them 6.47 properties.store(new FileOutputStream(context.getRealPath(CONNECTION_PROPERTIES_FILE)), null);
7.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java Tue Sep 22 20:56:35 2015 +0300 7.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java Wed Oct 04 11:55:13 2017 +0300 7.3 @@ -2,9 +2,9 @@ 7.4 * This Source Code Form is subject to the terms of the Mozilla Public 7.5 * License, v. 2.0. If a copy of the MPL was not distributed with this 7.6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7.7 - * 7.8 + * 7.9 * Copyright (C) 2010, 2011, 2012, 2013, 2014 Pyravlos Team 7.10 - * 7.11 + * 7.12 * http://www.strabon.di.uoa.gr/ 7.13 */ 7.14 package eu.earthobservatory.org.StrabonEndpoint; 7.15 @@ -43,7 +43,7 @@ 7.16 import eu.earthobservatory.utils.Format; 7.17 7.18 /** 7.19 - * 7.20 + * 7.21 * @author Kostis Kyzirakos <kkyzir@di.uoa.gr> 7.22 * @author Manos Karpathiotakis <mk@di.uoa.gr> 7.23 * @author Charalampos Nikolaou <charnik@di.uoa.gr> 7.24 @@ -52,380 +52,377 @@ 7.25 */ 7.26 public class QueryBean extends HttpServlet { 7.27 7.28 - private static final long serialVersionUID = -378175118289907707L; 7.29 + private static final long serialVersionUID = -378175118289907707L; 7.30 7.31 - private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.QueryBean.class); 7.32 - 7.33 - /** 7.34 - * Attributes carrying values to be rendered by the query.jsp file 7.35 - */ 7.36 - private static final String ERROR = "error"; 7.37 - private static final String RESPONSE = "response"; 7.38 - 7.39 - /** 7.40 - * Error returned by QueryBean 7.41 - */ 7.42 - private static final String PARAM_ERROR = "stSPARQL Query Results Format or SPARQL query are not set or are invalid."; 7.43 - 7.44 - /** 7.45 - * The context of the servlet 7.46 - */ 7.47 - private ServletContext context; 7.48 - 7.49 - /** 7.50 - * Wrapper over Strabon 7.51 - */ 7.52 - private StrabonBeanWrapper strabonWrapper; 7.53 - 7.54 - /** 7.55 - * The name of the temporary directory to store KML/KMZ files 7.56 - * for presentation in Google Maps 7.57 - */ 7.58 - private String tempDirectory; 7.59 - 7.60 - /** 7.61 - * The absolute path of the temporary directory 7.62 - */ 7.63 - private String basePath; 7.64 - 7.65 - /** 7.66 - * The name of this web application 7.67 - */ 7.68 - private String appName; 7.69 - 7.70 + private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.QueryBean.class); 7.71 7.72 - public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 7.73 - doPost(request, response); 7.74 - } 7.75 + /** 7.76 + * Attributes carrying values to be rendered by the query.jsp file 7.77 + */ 7.78 + private static final String ERROR = "error"; 7.79 + private static final String RESPONSE = "response"; 7.80 7.81 - public void init(ServletConfig servletConfig) throws ServletException { 7.82 - super.init(servletConfig); 7.83 + /** 7.84 + * Error returned by QueryBean 7.85 + */ 7.86 + private static final String PARAM_ERROR = "stSPARQL Query Results Format or SPARQL query are not set or are invalid."; 7.87 7.88 - // get the context of the servlet 7.89 - context = getServletContext(); 7.90 - 7.91 - // get the context of the application 7.92 - WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context); 7.93 + /** 7.94 + * The context of the servlet 7.95 + */ 7.96 + private ServletContext context; 7.97 7.98 - // the the strabon wrapper 7.99 - strabonWrapper = (StrabonBeanWrapper) applicationContext.getBean("strabonBean"); 7.100 - 7.101 - 7.102 - // get the name of this web application 7.103 - appName = context.getContextPath().replace("/", ""); 7.104 - 7.105 - } 7.106 + /** 7.107 + * Wrapper over Strabon 7.108 + */ 7.109 + private StrabonBeanWrapper strabonWrapper; 7.110 7.111 - public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 7.112 - request.setCharacterEncoding("UTF-8"); 7.113 - 7.114 - // check connection details 7.115 - if (strabonWrapper.getStrabon() == null) { 7.116 - RequestDispatcher dispatcher = request.getRequestDispatcher("/connection.jsp"); 7.117 - 7.118 - // pass the current details of the connection 7.119 - request.setAttribute("username", strabonWrapper.getUsername()); 7.120 - request.setAttribute("password", strabonWrapper.getPassword()); 7.121 - request.setAttribute("dbname", strabonWrapper.getDatabaseName()); 7.122 - request.setAttribute("hostname", strabonWrapper.getHostName()); 7.123 - request.setAttribute("port", strabonWrapper.getPort()); 7.124 - request.setAttribute("dbengine", strabonWrapper.getDBEngine()); 7.125 - 7.126 - // pass the other parameters as well 7.127 - request.setAttribute("query", request.getParameter("query")); 7.128 - if(request.getParameter("format").equalsIgnoreCase("PIECHART") || 7.129 - request.getParameter("format").equalsIgnoreCase("AREACHART")|| 7.130 - request.getParameter("format").equalsIgnoreCase("COLUMNCHART")){ 7.131 - request.setAttribute("format", "CHART"); 7.132 - } else{ 7.133 - request.setAttribute("format", request.getParameter("format")); 7.134 - } 7.135 - request.setAttribute("handle", request.getParameter("handle")); 7.136 - 7.137 - 7.138 - // forward the request 7.139 - dispatcher.forward(request, response); 7.140 - 7.141 - } else { 7.142 - 7.143 - if (Common.VIEW_TYPE.equals(request.getParameter(Common.VIEW))) { 7.144 - // HTML visual interface 7.145 - processVIEWRequest(request, response); 7.146 - 7.147 - 7.148 - } else {// invoked as a service 7.149 - processRequest(request, response); 7.150 - } 7.151 - } 7.152 - } 7.153 + /** 7.154 + * The name of the temporary directory to store KML/KMZ files for 7.155 + * presentation in Google Maps 7.156 + */ 7.157 + private String tempDirectory; 7.158 7.159 - /** 7.160 - * Processes the request made by a client of the endpoint that uses it as a service. 7.161 - * 7.162 + /** 7.163 + * The absolute path of the temporary directory 7.164 + */ 7.165 + private String basePath; 7.166 + 7.167 + /** 7.168 + * The name of this web application 7.169 + */ 7.170 + private String appName; 7.171 + 7.172 + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 7.173 + doPost(request, response); 7.174 + } 7.175 + 7.176 + public void init(ServletConfig servletConfig) throws ServletException { 7.177 + super.init(servletConfig); 7.178 + 7.179 + // get the context of the servlet 7.180 + context = getServletContext(); 7.181 + 7.182 + // get the context of the application 7.183 + WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context); 7.184 + 7.185 + // the the strabon wrapper 7.186 + strabonWrapper = (StrabonBeanWrapper) applicationContext.getBean("strabonBean"); 7.187 + 7.188 + // get the name of this web application 7.189 + appName = context.getContextPath().replace("/", ""); 7.190 + 7.191 + } 7.192 + 7.193 + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 7.194 + request.setCharacterEncoding("UTF-8"); 7.195 + 7.196 + // check connection details 7.197 + if (strabonWrapper.getStrabon() == null) { 7.198 + RequestDispatcher dispatcher = request.getRequestDispatcher("/connection.jsp"); 7.199 + 7.200 + // pass the current details of the connection 7.201 + request.setAttribute("username", strabonWrapper.getUsername()); 7.202 + request.setAttribute("password", strabonWrapper.getPassword()); 7.203 + request.setAttribute("dbname", strabonWrapper.getDatabaseName()); 7.204 + request.setAttribute("hostname", strabonWrapper.getHostName()); 7.205 + request.setAttribute("port", strabonWrapper.getPort()); 7.206 + request.setAttribute("dbengine", strabonWrapper.getDBEngine()); 7.207 + request.setAttribute("googlemapskey", strabonWrapper.getDBEngine()); 7.208 + 7.209 + // pass the other parameters as well 7.210 + request.setAttribute("query", request.getParameter("query")); 7.211 + if (request.getParameter("format").equalsIgnoreCase("PIECHART") 7.212 + || request.getParameter("format").equalsIgnoreCase("AREACHART") 7.213 + || request.getParameter("format").equalsIgnoreCase("COLUMNCHART")) { 7.214 + request.setAttribute("format", "CHART"); 7.215 + } else { 7.216 + request.setAttribute("format", request.getParameter("format")); 7.217 + } 7.218 + request.setAttribute("handle", request.getParameter("handle")); 7.219 + 7.220 + // forward the request 7.221 + dispatcher.forward(request, response); 7.222 + 7.223 + } else { 7.224 + // add googlemapsAPIscriptsource attribute for Google API script source tag 7.225 + request.setAttribute("googlemapsAPIscriptsource", strabonWrapper.googleMapsAPIScriptSourceForJSP()); 7.226 + 7.227 + if (Common.VIEW_TYPE.equals(request.getParameter(Common.VIEW))) { 7.228 + // HTML visual interface 7.229 + processVIEWRequest(request, response); 7.230 + 7.231 + } else {// invoked as a service 7.232 + processRequest(request, response); 7.233 + } 7.234 + } 7.235 + } 7.236 + 7.237 + /** 7.238 + * Processes the request made by a client of the endpoint that uses it as a 7.239 + * service. 7.240 + * 7.241 * @param request 7.242 * @param response 7.243 - * @throws IOException 7.244 + * @throws IOException 7.245 */ 7.246 - private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { 7.247 - ServletOutputStream out = response.getOutputStream(); 7.248 - 7.249 - // get desired formats (we check only the Accept header) 7.250 - List<stSPARQLQueryResultFormat> formats = parseMultiValuedAcceptHeader(request.getHeader("accept")); 7.251 - 7.252 - // get the query and the limit 7.253 - String query = request.getParameter("query"); 7.254 - String maxLimit = request.getParameter("maxLimit"); 7.255 - 7.256 - // check for required parameters 7.257 - if (formats.size() == 0 || query == null) { 7.258 - logger.error("[StrabonEndpoint.QueryBean] {}", PARAM_ERROR); 7.259 - response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 7.260 - out.print(ResponseMessages.getXMLHeader()); 7.261 - out.print(ResponseMessages.getXMLException(PARAM_ERROR)); 7.262 - out.print(ResponseMessages.getXMLFooter()); 7.263 - 7.264 - } else { 7.265 - // just use the first specified format 7.266 - stSPARQLQueryResultFormat format = formats.get(0); 7.267 - 7.268 - // do not decode the SPARQL query (see bugs #65 and #49) 7.269 - //query = URLDecoder.decode(request.getParameter("query"), "UTF-8"); 7.270 - query = request.getParameter("query"); 7.271 - 7.272 - response.setContentType(format.getDefaultMIMEType()); 7.273 - 7.274 - try { 7.275 - query = strabonWrapper.addLimit(query, maxLimit); 7.276 - strabonWrapper.query(query, format.getName(), out); 7.277 - response.setStatus(HttpServletResponse.SC_OK); 7.278 - 7.279 - } catch (Exception e) { 7.280 - logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); 7.281 - response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 7.282 - out.print(ResponseMessages.getXMLHeader()); 7.283 - out.print(ResponseMessages.getXMLException(e.getMessage())); 7.284 - out.print(ResponseMessages.getXMLFooter()); 7.285 - } 7.286 - } 7.287 - 7.288 - out.flush(); 7.289 - } 7.290 - 7.291 - /** 7.292 - * Processes the request made from the HTML visual interface of Strabon Endpoint. 7.293 - * 7.294 + private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { 7.295 + ServletOutputStream out = response.getOutputStream(); 7.296 + 7.297 + // get desired formats (we check only the Accept header) 7.298 + List<stSPARQLQueryResultFormat> formats = parseMultiValuedAcceptHeader(request.getHeader("accept")); 7.299 + 7.300 + // get the query and the limit 7.301 + String query = request.getParameter("query"); 7.302 + String maxLimit = request.getParameter("maxLimit"); 7.303 + 7.304 + // check for required parameters 7.305 + if (formats.size() == 0 || query == null) { 7.306 + logger.error("[StrabonEndpoint.QueryBean] {}", PARAM_ERROR); 7.307 + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 7.308 + out.print(ResponseMessages.getXMLHeader()); 7.309 + out.print(ResponseMessages.getXMLException(PARAM_ERROR)); 7.310 + out.print(ResponseMessages.getXMLFooter()); 7.311 + 7.312 + } else { 7.313 + // just use the first specified format 7.314 + stSPARQLQueryResultFormat format = formats.get(0); 7.315 + 7.316 + // do not decode the SPARQL query (see bugs #65 and #49) 7.317 + //query = URLDecoder.decode(request.getParameter("query"), "UTF-8"); 7.318 + query = request.getParameter("query"); 7.319 + 7.320 + response.setContentType(format.getDefaultMIMEType()); 7.321 + 7.322 + try { 7.323 + query = strabonWrapper.addLimit(query, maxLimit); 7.324 + strabonWrapper.query(query, format.getName(), out); 7.325 + response.setStatus(HttpServletResponse.SC_OK); 7.326 + 7.327 + } catch (Exception e) { 7.328 + logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); 7.329 + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 7.330 + out.print(ResponseMessages.getXMLHeader()); 7.331 + out.print(ResponseMessages.getXMLException(e.getMessage())); 7.332 + out.print(ResponseMessages.getXMLFooter()); 7.333 + } 7.334 + } 7.335 + 7.336 + out.flush(); 7.337 + } 7.338 + 7.339 + /** 7.340 + * Processes the request made from the HTML visual interface of Strabon 7.341 + * Endpoint. 7.342 + * 7.343 * @param request 7.344 * @param response 7.345 * @throws ServletException 7.346 * @throws IOException 7.347 */ 7.348 - private void processVIEWRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 7.349 - RequestDispatcher dispatcher; 7.350 + private void processVIEWRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 7.351 + RequestDispatcher dispatcher; 7.352 7.353 - // check whether Update submit button was fired 7.354 - String reqFuncionality = (request.getParameter("submit") == null) ? "" : request.getParameter("submit"); 7.355 + // check whether Update submit button was fired 7.356 + String reqFuncionality = (request.getParameter("submit") == null) ? "" : request.getParameter("submit"); 7.357 7.358 - if (reqFuncionality.equals("Update")) { 7.359 - // get the dispatcher for forwarding the rendering of the response 7.360 - dispatcher = request.getRequestDispatcher("/Update"); 7.361 - dispatcher.forward(request, response); 7.362 - 7.363 - } else { 7.364 - // do not decode the SPARQL query (see bugs #65 and #49) 7.365 - //String query = URLDecoder.decode(request.getParameter("query"), "UTF-8"); 7.366 - 7.367 - String query = request.getParameter("query"); 7.368 - String format = request.getParameter("format"); 7.369 - String handle = request.getParameter("handle"); 7.370 - String maxLimit = request.getParameter("maxLimit"); 7.371 - 7.372 - // get stSPARQLQueryResultFormat from given format name 7.373 - TupleQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format); 7.374 - 7.375 - if (query == null || format == null || queryResultFormat == null) { 7.376 - dispatcher = request.getRequestDispatcher("query.jsp"); 7.377 - request.setAttribute(ERROR, PARAM_ERROR); 7.378 - dispatcher.forward(request, response); 7.379 - 7.380 - } else { 7.381 - query = strabonWrapper.addLimit(query, maxLimit); 7.382 - if ("download".equals(handle)) { // download as attachment 7.383 - ServletOutputStream out = response.getOutputStream(); 7.384 - 7.385 - response.setContentType(queryResultFormat.getDefaultMIMEType()); 7.386 - response.setHeader("Content-Disposition", 7.387 - "attachment; filename=results." + 7.388 - queryResultFormat.getDefaultFileExtension() + "; " + 7.389 - queryResultFormat.getCharset()); 7.390 - 7.391 - try { 7.392 - strabonWrapper.query(query, format, out); 7.393 - response.setStatus(HttpServletResponse.SC_OK); 7.394 - 7.395 - } catch (Exception e) { 7.396 - response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 7.397 - out.print(ResponseMessages.getXMLHeader()); 7.398 - out.print(ResponseMessages.getXMLException(e.getMessage())); 7.399 - out.print(ResponseMessages.getXMLFooter()); 7.400 - } 7.401 - 7.402 - out.flush(); 7.403 - 7.404 - } else if (("map".equals(handle) || "map_local".equals(handle) || "timemap".equals(handle)) && 7.405 - (queryResultFormat == stSPARQLQueryResultFormat.KML || 7.406 - queryResultFormat == stSPARQLQueryResultFormat.KMZ) ) { 7.407 - // show map (only valid for KML/KMZ) 7.408 - 7.409 - // get dispatcher 7.410 - dispatcher = request.getRequestDispatcher("query.jsp"); 7.411 - 7.412 - // re-assign handle 7.413 - request.setAttribute("handle", handle); 7.414 - 7.415 - SecureRandom random = new SecureRandom(); 7.416 - String temp = new BigInteger(130, random).toString(32); 7.417 - 7.418 - // the temporary KML/KMZ file to create in the server 7.419 - String tempKMLFile = temp + "." + queryResultFormat.getDefaultFileExtension();; 7.420 - 7.421 - try{ 7.422 - Date date = new Date(); 7.423 - 7.424 - // get the absolute path of the temporary directory 7.425 - if(!request.getParameter("handle").toString().contains("timemap")){ 7.426 - tempDirectory = appName + "-temp"; 7.427 - 7.428 - basePath = context.getRealPath("/") + "/../ROOT/" + tempDirectory + "/"; 7.429 - // fix the temporary directory for this web application 7.430 - 7.431 - FileUtils.forceMkdir(new File(basePath)); 7.432 + if (reqFuncionality.equals("Update")) { 7.433 + // get the dispatcher for forwarding the rendering of the response 7.434 + dispatcher = request.getRequestDispatcher("/Update"); 7.435 + dispatcher.forward(request, response); 7.436 7.437 - @SuppressWarnings("unchecked") 7.438 - Iterator<File> it = FileUtils.iterateFiles(new File(basePath), null, false); 7.439 - while(it.hasNext()){ 7.440 - File tbd = new File((it.next()).getAbsolutePath()); 7.441 - if (FileUtils.isFileOlder(new File(tbd.getAbsolutePath()), date.getTime())){ 7.442 - FileUtils.forceDelete(new File(tbd.getAbsolutePath())); 7.443 - } 7.444 - } 7.445 - } else{ //timemap case 7.446 - tempDirectory = "js/timemap"; 7.447 - basePath = context.getRealPath("/") + tempDirectory + "/"; 7.448 - // fix the temporary directory for this web application 7.449 - } 7.450 + } else { 7.451 + // do not decode the SPARQL query (see bugs #65 and #49) 7.452 + //String query = URLDecoder.decode(request.getParameter("query"), "UTF-8"); 7.453 7.454 + String query = request.getParameter("query"); 7.455 + String format = request.getParameter("format"); 7.456 + String handle = request.getParameter("handle"); 7.457 + String maxLimit = request.getParameter("maxLimit"); 7.458 7.459 - // fix the temporary directory for this web application 7.460 - 7.461 - // create temporary KML/KMZ file 7.462 - File file = new File(basePath + tempKMLFile); 7.463 - // if file does not exist, then create it 7.464 - if(!file.exists()){ 7.465 - file.createNewFile(); 7.466 - } 7.467 - 7.468 - try { 7.469 - // query and write the result in the temporary KML/KMZ file 7.470 - FileOutputStream fos = new FileOutputStream(basePath + tempKMLFile); 7.471 - strabonWrapper.query(query, format, fos); 7.472 - fos.close(); 7.473 - 7.474 - if(request.getParameter("handle").toString().contains("timemap")){ 7.475 - request.setAttribute("pathToKML", tempDirectory+"/"+ tempKMLFile); 7.476 - }else { 7.477 - request.setAttribute("pathToKML", 7.478 - request.getScheme() + "://" + 7.479 - request.getServerName() + ":" + request.getServerPort() + 7.480 - "/" + tempDirectory + "/" + tempKMLFile); 7.481 - } 7.482 - 7.483 - } catch (MalformedQueryException e) { 7.484 - logger.error("[StrabonEndpoint.QueryBean] Error during querying. {}", e.getMessage()); 7.485 - request.setAttribute(ERROR, e.getMessage()); 7.486 - 7.487 - } catch (Exception e) { 7.488 - logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); 7.489 - request.setAttribute(ERROR, e.getMessage()); 7.490 - } 7.491 - 7.492 - dispatcher.forward(request, response); 7.493 + // get stSPARQLQueryResultFormat from given format name 7.494 + TupleQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format); 7.495 7.496 - } catch(IOException e) { 7.497 - logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); 7.498 - } 7.499 + if (query == null || format == null || queryResultFormat == null) { 7.500 + dispatcher = request.getRequestDispatcher("query.jsp"); 7.501 + request.setAttribute(ERROR, PARAM_ERROR); 7.502 + dispatcher.forward(request, response); 7.503 7.504 - } else { // "plain" is assumed as the default 7.505 - dispatcher = request.getRequestDispatcher("query.jsp"); 7.506 - ByteArrayOutputStream bos = new ByteArrayOutputStream(); 7.507 - 7.508 - try { 7.509 - strabonWrapper.query(query, format, bos); 7.510 - if (format.equals(Common.getHTMLFormat())) { 7.511 - request.setAttribute(RESPONSE, bos.toString()); 7.512 - } 7.513 - else if(format.equals(Format.PIECHART.toString()) 7.514 - || format.equals(Format.AREACHART.toString()) 7.515 - || format.equals(Format.COLUMNCHART.toString())){ 7.516 - request.setAttribute("format","CHART"); 7.517 - request.setAttribute(RESPONSE, strabonWrapper.getgChartString()); 7.518 - } 7.519 - 7.520 - else { 7.521 - request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString())); 7.522 - } 7.523 - 7.524 - } catch (MalformedQueryException e) { 7.525 - logger.error("[StrabonEndpoint.QueryBean] Error during querying. {}", e.getMessage()); 7.526 - request.setAttribute(ERROR, e.getMessage()); 7.527 - 7.528 - } catch (Exception e) { 7.529 - logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); 7.530 - request.setAttribute(ERROR, e.getMessage()); 7.531 - 7.532 - } finally { 7.533 - dispatcher.forward(request, response); 7.534 - } 7.535 - } 7.536 - } 7.537 - } 7.538 - } 7.539 - 7.540 - /** 7.541 - * Given an Accept header, it parses it and extracts the mime types for the accepted formats. 7.542 - * The header might contain multiple accepted values and qvalues as well, however, qvalues 7.543 - * are ignored. The extracted mime types are then transformed to stSPARQLQueryResultFormat 7.544 - * and a list of such objects is returned. If a mimetype is not valid, then it is ignored. 7.545 - * If all mimetypes are invalid, then the returned list has zero elements, but it is not 7.546 - * null. 7.547 - * 7.548 - * @param header 7.549 - * @return 7.550 - */ 7.551 - private List<stSPARQLQueryResultFormat> parseMultiValuedAcceptHeader(String header) { 7.552 - List<stSPARQLQueryResultFormat> formats = new ArrayList<stSPARQLQueryResultFormat>(); 7.553 - 7.554 - StringTokenizer token = new StringTokenizer(header, ", "); 7.555 - 7.556 - while (token.hasMoreTokens()) { 7.557 - String value = token.nextToken(); 7.558 - 7.559 - // value might contain qvalues (e.g., "text/plain; q=0.2") 7.560 - // for the time being, we just discard them 7.561 - int idx_sep_cut = value.indexOf(';'); 7.562 - if (idx_sep_cut > 0) { 7.563 - value = value.substring(0, idx_sep_cut); 7.564 - } 7.565 - 7.566 - // get the stSPARQL Query Result format 7.567 - stSPARQLQueryResultFormat format = stSPARQLQueryResultFormat.forMIMEType(value); 7.568 - 7.569 - // keep only the valid formats (non-null) 7.570 - if (format != null) { 7.571 - formats.add(format); 7.572 - } 7.573 - } 7.574 + } else { 7.575 + query = strabonWrapper.addLimit(query, maxLimit); 7.576 + if ("download".equals(handle)) { // download as attachment 7.577 + ServletOutputStream out = response.getOutputStream(); 7.578 + 7.579 + response.setContentType(queryResultFormat.getDefaultMIMEType()); 7.580 + response.setHeader("Content-Disposition", 7.581 + "attachment; filename=results." 7.582 + + queryResultFormat.getDefaultFileExtension() + "; " 7.583 + + queryResultFormat.getCharset()); 7.584 + 7.585 + try { 7.586 + strabonWrapper.query(query, format, out); 7.587 + response.setStatus(HttpServletResponse.SC_OK); 7.588 + 7.589 + } catch (Exception e) { 7.590 + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); 7.591 + out.print(ResponseMessages.getXMLHeader()); 7.592 + out.print(ResponseMessages.getXMLException(e.getMessage())); 7.593 + out.print(ResponseMessages.getXMLFooter()); 7.594 + } 7.595 + 7.596 + out.flush(); 7.597 + 7.598 + } else if (("map".equals(handle) || "map_local".equals(handle) || "timemap".equals(handle)) 7.599 + && (queryResultFormat == stSPARQLQueryResultFormat.KML 7.600 + || queryResultFormat == stSPARQLQueryResultFormat.KMZ)) { 7.601 + // show map (only valid for KML/KMZ) 7.602 + 7.603 + // get dispatcher 7.604 + dispatcher = request.getRequestDispatcher("query.jsp"); 7.605 + 7.606 + // re-assign handle 7.607 + request.setAttribute("handle", handle); 7.608 + 7.609 + SecureRandom random = new SecureRandom(); 7.610 + String temp = new BigInteger(130, random).toString(32); 7.611 + 7.612 + // the temporary KML/KMZ file to create in the server 7.613 + String tempKMLFile = temp + "." + queryResultFormat.getDefaultFileExtension();; 7.614 + 7.615 + try { 7.616 + Date date = new Date(); 7.617 + 7.618 + // get the absolute path of the temporary directory 7.619 + if (!request.getParameter("handle").toString().contains("timemap")) { 7.620 + tempDirectory = appName + "-temp"; 7.621 + 7.622 + basePath = context.getRealPath("/") + "/../ROOT/" + tempDirectory + "/"; 7.623 + // fix the temporary directory for this web application 7.624 + 7.625 + FileUtils.forceMkdir(new File(basePath)); 7.626 + 7.627 + @SuppressWarnings("unchecked") 7.628 + Iterator<File> it = FileUtils.iterateFiles(new File(basePath), null, false); 7.629 + while (it.hasNext()) { 7.630 + File tbd = new File((it.next()).getAbsolutePath()); 7.631 + if (FileUtils.isFileOlder(new File(tbd.getAbsolutePath()), date.getTime())) { 7.632 + FileUtils.forceDelete(new File(tbd.getAbsolutePath())); 7.633 + } 7.634 + } 7.635 + } else { //timemap case 7.636 + tempDirectory = "js/timemap"; 7.637 + basePath = context.getRealPath("/") + tempDirectory + "/"; 7.638 + // fix the temporary directory for this web application 7.639 + } 7.640 + 7.641 + // fix the temporary directory for this web application 7.642 + // create temporary KML/KMZ file 7.643 + File file = new File(basePath + tempKMLFile); 7.644 + // if file does not exist, then create it 7.645 + if (!file.exists()) { 7.646 + file.createNewFile(); 7.647 + } 7.648 + 7.649 + try { 7.650 + // query and write the result in the temporary KML/KMZ file 7.651 + FileOutputStream fos = new FileOutputStream(basePath + tempKMLFile); 7.652 + strabonWrapper.query(query, format, fos); 7.653 + fos.close(); 7.654 + 7.655 + if (request.getParameter("handle").toString().contains("timemap")) { 7.656 + request.setAttribute("pathToKML", tempDirectory + "/" + tempKMLFile); 7.657 + } else { 7.658 + request.setAttribute("pathToKML", 7.659 + request.getScheme() + "://" 7.660 + + request.getServerName() + ":" + request.getServerPort() 7.661 + + "/" + tempDirectory + "/" + tempKMLFile); 7.662 + } 7.663 + 7.664 + } catch (MalformedQueryException e) { 7.665 + logger.error("[StrabonEndpoint.QueryBean] Error during querying. {}", e.getMessage()); 7.666 + request.setAttribute(ERROR, e.getMessage()); 7.667 + 7.668 + } catch (Exception e) { 7.669 + logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); 7.670 + request.setAttribute(ERROR, e.getMessage()); 7.671 + } 7.672 + 7.673 + dispatcher.forward(request, response); 7.674 + 7.675 + } catch (IOException e) { 7.676 + logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); 7.677 + } 7.678 + 7.679 + } else { // "plain" is assumed as the default 7.680 + dispatcher = request.getRequestDispatcher("query.jsp"); 7.681 + ByteArrayOutputStream bos = new ByteArrayOutputStream(); 7.682 + 7.683 + try { 7.684 + strabonWrapper.query(query, format, bos); 7.685 + if (format.equals(Common.getHTMLFormat())) { 7.686 + request.setAttribute(RESPONSE, bos.toString()); 7.687 + } else if (format.equals(Format.PIECHART.toString()) 7.688 + || format.equals(Format.AREACHART.toString()) 7.689 + || format.equals(Format.COLUMNCHART.toString())) { 7.690 + request.setAttribute("format", "CHART"); 7.691 + request.setAttribute(RESPONSE, strabonWrapper.getgChartString()); 7.692 + } else { 7.693 + request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString())); 7.694 + } 7.695 + 7.696 + } catch (MalformedQueryException e) { 7.697 + logger.error("[StrabonEndpoint.QueryBean] Error during querying. {}", e.getMessage()); 7.698 + request.setAttribute(ERROR, e.getMessage()); 7.699 + 7.700 + } catch (Exception e) { 7.701 + logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e); 7.702 + request.setAttribute(ERROR, e.getMessage()); 7.703 + 7.704 + } finally { 7.705 + dispatcher.forward(request, response); 7.706 + } 7.707 + } 7.708 + } 7.709 + } 7.710 + } 7.711 + 7.712 + /** 7.713 + * Given an Accept header, it parses it and extracts the mime types for the 7.714 + * accepted formats. The header might contain multiple accepted values and 7.715 + * qvalues as well, however, qvalues are ignored. The extracted mime types 7.716 + * are then transformed to stSPARQLQueryResultFormat and a list of such 7.717 + * objects is returned. If a mimetype is not valid, then it is ignored. If 7.718 + * all mimetypes are invalid, then the returned list has zero elements, but 7.719 + * it is not null. 7.720 + * 7.721 + * @param header 7.722 + * @return 7.723 + */ 7.724 + private List<stSPARQLQueryResultFormat> parseMultiValuedAcceptHeader(String header) { 7.725 + List<stSPARQLQueryResultFormat> formats = new ArrayList<stSPARQLQueryResultFormat>(); 7.726 + 7.727 + StringTokenizer token = new StringTokenizer(header, ", "); 7.728 + 7.729 + while (token.hasMoreTokens()) { 7.730 + String value = token.nextToken(); 7.731 + 7.732 + // value might contain qvalues (e.g., "text/plain; q=0.2") 7.733 + // for the time being, we just discard them 7.734 + int idx_sep_cut = value.indexOf(';'); 7.735 + if (idx_sep_cut > 0) { 7.736 + value = value.substring(0, idx_sep_cut); 7.737 + } 7.738 + 7.739 + // get the stSPARQL Query Result format 7.740 + stSPARQLQueryResultFormat format = stSPARQLQueryResultFormat.forMIMEType(value); 7.741 + 7.742 + // keep only the valid formats (non-null) 7.743 + if (format != null) { 7.744 + formats.add(format); 7.745 + } 7.746 + } 7.747 7.748 return formats; 7.749 - } 7.750 + } 7.751 7.752 }
8.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java Tue Sep 22 20:56:35 2015 +0300 8.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java Wed Oct 04 11:55:13 2017 +0300 8.3 @@ -2,9 +2,9 @@ 8.4 * This Source Code Form is subject to the terms of the Mozilla Public 8.5 * License, v. 2.0. If a copy of the MPL was not distributed with this 8.6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8.7 - * 8.8 + * 8.9 * Copyright (C) 2010, 2011, 2012, 2013 Pyravlos Team 8.10 - * 8.11 + * 8.12 * http://www.strabon.di.uoa.gr/ 8.13 */ 8.14 package eu.earthobservatory.org.StrabonEndpoint; 8.15 @@ -33,495 +33,509 @@ 8.16 import eu.earthobservatory.runtime.generaldb.Strabon; 8.17 import eu.earthobservatory.utils.Format; 8.18 8.19 +public class StrabonBeanWrapper implements org.springframework.beans.factory.DisposableBean { 8.20 8.21 -public class StrabonBeanWrapper implements org.springframework.beans.factory.DisposableBean { 8.22 - 8.23 - private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper.class); 8.24 - 8.25 - private static final String FILE_PROTOCOL = "file"; 8.26 - 8.27 - private String serverName; 8.28 - private int port; 8.29 - private String databaseName; 8.30 - private String user; 8.31 - private String password; 8.32 - private String dbBackend; 8.33 - private int maxLimit; 8.34 - private boolean loadFromFile; 8.35 - private String prefixes; 8.36 - 8.37 - private Strabon strabon = null; 8.38 - 8.39 - private String gChartString =" "; 8.40 - 8.41 - private boolean checkForLockTable; 8.42 - private List<StrabonBeanWrapperConfiguration> entries; 8.43 + private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper.class); 8.44 8.45 - public StrabonBeanWrapper(String databaseName, String user, String password, 8.46 - int port, String serverName, boolean checkForLockTable, String dbBackend, 8.47 - int maxLimit, boolean loadFromFile,String prefixes, List<List<String>> args) { 8.48 - this.serverName = serverName; 8.49 - this.port = port; 8.50 - this.databaseName = databaseName; 8.51 - this.user = user; 8.52 - this.password = password; 8.53 - this.checkForLockTable = checkForLockTable; 8.54 - this.dbBackend = dbBackend; 8.55 - this.maxLimit = maxLimit; 8.56 - this.loadFromFile = loadFromFile; 8.57 - this.prefixes = prefixes; 8.58 - this.entries = new ArrayList<StrabonBeanWrapperConfiguration>(args.size()); 8.59 - 8.60 - Iterator<List<String>> entryit = args.iterator(); 8.61 - 8.62 - while (entryit.hasNext()) { 8.63 - List<String> list = entryit.next(); 8.64 - Iterator<String> it = list.iterator(); 8.65 - 8.66 - while (it.hasNext()) { 8.67 - int items = 0; 8.68 - //Header:label 8.69 - //Bean :label bean 8.70 - //Entry :label bean statement format title handle 8.71 - String param1 = "", param2 = "", param3 = "", param4 = "", param5="", param6=""; 8.72 - 8.73 - if (it.hasNext()) { 8.74 - param1 = it.next(); 8.75 - items++; 8.76 - } 8.77 - if (it.hasNext()) { 8.78 - param2 = it.next(); 8.79 - items++; 8.80 - } 8.81 - if (it.hasNext()) { 8.82 - param3 = it.next(); 8.83 - items++; 8.84 - } 8.85 - if (it.hasNext()) { 8.86 - param4 = it.next(); 8.87 - items++; 8.88 - } 8.89 - if (it.hasNext()) { 8.90 - param5 = it.next(); 8.91 - items++; 8.92 - } 8.93 - if (it.hasNext()) { 8.94 - param6 = it.next(); 8.95 - items++; 8.96 - } 8.97 - 8.98 - if (items == 1) { 8.99 - //the first element corresponds to the label 8.100 - StrabonBeanWrapperConfiguration entry = new StrabonBeanWrapperConfiguration(param1); 8.101 - this.entries.add(entry); 8.102 - } else if (items == 2) { 8.103 - //the first element corresponds to the label 8.104 - StrabonBeanWrapperConfiguration entry = new StrabonBeanWrapperConfiguration(param1, param2); 8.105 - this.entries.add(entry); 8.106 - } else if (items == 6) { 8.107 - StrabonBeanWrapperConfiguration entry = new StrabonBeanWrapperConfiguration(param3, param1, param4, param2, param5, param6); 8.108 - this.entries.add(entry); 8.109 - } 8.110 - 8.111 - 8.112 - } 8.113 - } 8.114 + private static final String FILE_PROTOCOL = "file"; 8.115 8.116 - init(); 8.117 - } 8.118 + private String serverName; 8.119 + private int port; 8.120 + private String databaseName; 8.121 + private String user; 8.122 + private String password; 8.123 + private String dbBackend; 8.124 + private String googlemapskey; 8.125 + private int maxLimit; 8.126 + private boolean loadFromFile; 8.127 + private String prefixes; 8.128 8.129 - public boolean init() { 8.130 - if (this.strabon == null) { 8.131 - try { 8.132 - logger.warn("[StrabonEndpoint] Strabon not initialized yet."); 8.133 - logger.warn("[StrabonEndpoint] Initializing Strabon."); 8.134 - //logger.info("[StrabonEndpoint] Connection details:\n" + this.getDetails()); 8.135 - 8.136 - // initialize Strabon according to user preference 8.137 - if (Common.DBBACKEND_MONETDB.equalsIgnoreCase(dbBackend)) { 8.138 - this.strabon = new eu.earthobservatory.runtime.monetdb.Strabon(databaseName, user, password, port, serverName, checkForLockTable); 8.139 - 8.140 - } else { 8.141 - // check whether the user typed wrong database backend and report 8.142 - if (!Common.DBBACKEND_POSTGIS.equalsIgnoreCase(dbBackend)) { 8.143 - logger.warn("[StrabonEndpoint] Unknown database backend \""+dbBackend+"\". Assuming PostGIS."); 8.144 - } 8.145 - 8.146 - // use PostGIS as the default database backend 8.147 - this.strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, user, password, port, serverName, checkForLockTable); 8.148 - } 8.149 + private Strabon strabon = null; 8.150 8.151 - installSIGTERMHandler(this.strabon); 8.152 - 8.153 - } catch (Exception e) { 8.154 - logger.error("[StrabonEndpoint] Exception occured while creating Strabon. {}\n{}", e.getMessage(), this.getDetails()); 8.155 - return false; 8.156 - } 8.157 - } 8.158 + private String gChartString = " "; 8.159 8.160 - return true; 8.161 - } 8.162 + private boolean checkForLockTable; 8.163 + private List<StrabonBeanWrapperConfiguration> entries; 8.164 8.165 - /** 8.166 - * Registers a handler for SIGTERM signals, like Ctrl-C. One may send such a signal 8.167 - * at the command prompt, when running Strabon Endpoint from the command line, i.e., 8.168 - * using the endpoint-exec module. 8.169 - * 8.170 - * @param strabon The strabon instance 8.171 - */ 8.172 - private static void installSIGTERMHandler(final Strabon strabon) { 8.173 - if (logger.isDebugEnabled()) { 8.174 - logger.info("[StrabonEndpoint] Installing handler for SIGTERM signals..."); 8.175 - } 8.176 - 8.177 - // register the handler 8.178 - Runtime.getRuntime().addShutdownHook(new Thread() { 8.179 - 8.180 - @Override 8.181 - public void run() { 8.182 - // just call the Strabon.close() method 8.183 - strabon.close(); 8.184 - } 8.185 - }); 8.186 - 8.187 - if (logger.isDebugEnabled()) { 8.188 - logger.info("[StrabonEndpoint] Handler for SIGTERM signals installed successfully."); 8.189 - } 8.190 - } 8.191 - 8.192 - public Strabon getStrabon() { 8.193 - return strabon; 8.194 - } 8.195 + public StrabonBeanWrapper(String databaseName, String user, String password, 8.196 + int port, String serverName, boolean checkForLockTable, String dbBackend, 8.197 + String googlemapskey, int maxLimit, boolean loadFromFile, String prefixes, List<List<String>> args) { 8.198 + this.serverName = serverName; 8.199 + this.port = port; 8.200 + this.databaseName = databaseName; 8.201 + this.user = user; 8.202 + this.password = password; 8.203 + this.checkForLockTable = checkForLockTable; 8.204 + this.dbBackend = dbBackend; 8.205 + this.googlemapskey = googlemapskey; 8.206 + this.maxLimit = maxLimit; 8.207 + this.loadFromFile = loadFromFile; 8.208 + this.prefixes = prefixes; 8.209 + this.entries = new ArrayList<StrabonBeanWrapperConfiguration>(args.size()); 8.210 8.211 - public void setStrabon(Strabon strabon) { 8.212 - this.strabon = strabon; 8.213 - } 8.214 + Iterator<List<String>> entryit = args.iterator(); 8.215 8.216 - public void closeConnection() { 8.217 - if (strabon != null) { 8.218 - strabon.close(); 8.219 - strabon = null; 8.220 - } 8.221 - } 8.222 - 8.223 - public void destroy() throws Exception { 8.224 - if (strabon != null) { 8.225 - strabon.close(); 8.226 - 8.227 - // deregister jdbc driver 8.228 - strabon.deregisterDriver(); 8.229 - } 8.230 - } 8.231 + while (entryit.hasNext()) { 8.232 + List<String> list = entryit.next(); 8.233 + Iterator<String> it = list.iterator(); 8.234 8.235 - public void query(String queryString, String answerFormatStrabon, OutputStream out) 8.236 - throws MalformedQueryException, RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, ClassNotFoundException { 8.237 - logger.info("[StrabonEndpoint] Received SELECT query."); 8.238 - if ((this.strabon == null) && (!init())) { 8.239 - throw new RepositoryException("Could not connect to Strabon."); 8.240 - } 8.241 - if(answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString()) || answerFormatStrabon.equalsIgnoreCase( Format.AREACHART.toString())|| 8.242 - answerFormatStrabon.equalsIgnoreCase( Format.COLUMNCHART.toString())){ 8.243 - TupleQueryResult result = (TupleQueryResult) strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out); 8.244 - List<String> bindingNames = result.getBindingNames(); 8.245 - if(bindingNames.size() !=2 && answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString())){ 8.246 - logger.error("Strabon endpoint: to display results in a pie chart, exactly TWO variables must be projected"); 8.247 - } 8.248 - else{ 8.249 - if(answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString())){ 8.250 - 8.251 - ArrayList<String> arr = new ArrayList<String>(2); 8.252 - arr.add(0, bindingNames.get(0)); 8.253 - arr.add(1, bindingNames.get(1)); 8.254 + while (it.hasNext()) { 8.255 + int items = 0; 8.256 + //Header:label 8.257 + //Bean :label bean 8.258 + //Entry :label bean statement format title handle 8.259 + String param1 = "", param2 = "", param3 = "", param4 = "", param5 = "", param6 = ""; 8.260 8.261 - gChartString ="var data = new google.visualization.DataTable();"; 8.262 - gChartString += "data.addColumn('string',\'"+arr.get(0)+"');\n"; 8.263 - gChartString += "data.addColumn('number',\'"+arr.get(1)+"');\n"; 8.264 - 8.265 - while(result.hasNext()){ 8.266 - BindingSet bindings = result.next(); 8.267 - arr.add(0, bindings.getValue(bindingNames.get(0)).stringValue()); 8.268 - arr.add(1, bindings.getValue(bindingNames.get(1)).stringValue()); 8.269 - 8.270 - gChartString += "data.addRow([\'"+withoutPrefix(arr.get(0))+"\', "+ 8.271 - arr.get(1).replace("\"", "").replace("^^","").replace("<http://www.w3.org/2001/XMLSchema#integer>","")+"]);\n"; 8.272 - } 8.273 - gChartString += "var options = {'title':'','width':1000, 'height':1000, is3D: true};\n"; 8.274 - gChartString += "var chart = new google.visualization.PieChart(document.getElementById('chart_div'));\n"; 8.275 - 8.276 - 8.277 - } 8.278 - else { 8.279 - 8.280 - String chartType; 8.281 - int varNum = bindingNames.size(); 8.282 + if (it.hasNext()) { 8.283 + param1 = it.next(); 8.284 + items++; 8.285 + } 8.286 + if (it.hasNext()) { 8.287 + param2 = it.next(); 8.288 + items++; 8.289 + } 8.290 + if (it.hasNext()) { 8.291 + param3 = it.next(); 8.292 + items++; 8.293 + } 8.294 + if (it.hasNext()) { 8.295 + param4 = it.next(); 8.296 + items++; 8.297 + } 8.298 + if (it.hasNext()) { 8.299 + param5 = it.next(); 8.300 + items++; 8.301 + } 8.302 + if (it.hasNext()) { 8.303 + param6 = it.next(); 8.304 + items++; 8.305 + } 8.306 8.307 - gChartString = "var data = google.visualization.arrayToDataTable([["; 8.308 - for(int j=0; j<varNum; j++){ 8.309 - String chartValue =bindingNames.get(j); 8.310 - gChartString += "'"+chartValue+"'"; 8.311 - 8.312 - if(j != varNum-1){ 8.313 - gChartString+=","; 8.314 - } 8.315 - } 8.316 - gChartString += "],"; 8.317 - 8.318 - while(result.hasNext()){ 8.319 - BindingSet bindings = result.next(); 8.320 - gChartString += "["; 8.321 - for(int j=0; j<varNum; j++){ 8.322 - 8.323 - String chartValue =bindings.getValue(bindingNames.get(j)).stringValue(); 8.324 - if(j==0){ //the first variable is a string variable. 8.325 - gChartString += "'"+withoutPrefix(chartValue).replace("\"", "")+"'"; 8.326 - } 8.327 - else{ //numeric value 8.328 - gChartString += withoutPrefix(chartValue).replace("\"", ""); 8.329 - } 8.330 - if(j != varNum-1){ 8.331 - gChartString+=","; 8.332 - } 8.333 - } 8.334 - gChartString += "],"; 8.335 - } 8.336 - if(answerFormatStrabon.equalsIgnoreCase(Format.AREACHART.toString())){ 8.337 - chartType = "AreaChart"; 8.338 - }else{ 8.339 - chartType = "ColumnChart"; 8.340 - } 8.341 - gChartString += "]);"; 8.342 - gChartString += " var options = {title: '', hAxis: {title:'"+ bindingNames.get(0) +"', titleTextStyle: {color: \'red\'}}};"; 8.343 - gChartString += "var chart = new google.visualization."+chartType+"(document.getElementById('chart_div')); \n"; 8.344 - 8.345 - } 8.346 - 8.347 - 8.348 - }} 8.349 - else{ 8.350 - strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out); 8.351 - } 8.352 - 8.353 - } 8.354 - 8.355 - /** 8.356 - * Wrapper around Strabon.describeOp which takes an OutputStream to use for writing 8.357 - * the answer to a DESCRIBE query. 8.358 - * 8.359 - * @param queryString 8.360 - * @param answerFormatStrabon 8.361 - * @param out 8.362 - * @throws MalformedQueryException 8.363 - * @throws RepositoryException 8.364 - * @throws QueryEvaluationException 8.365 - * @throws TupleQueryResultHandlerException 8.366 - * @throws IOException 8.367 - * @throws ClassNotFoundException 8.368 - */ 8.369 - public void describe(String queryString, String answerFormatStrabon, OutputStream out) 8.370 - throws MalformedQueryException, RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, ClassNotFoundException { 8.371 - logger.info("[StrabonEndpoint] Received DESCRIBE query."); 8.372 - if ((this.strabon == null) && (!init())) { 8.373 - throw new RepositoryException("Could not connect to Strabon."); 8.374 - } 8.375 + if (items == 1) { 8.376 + //the first element corresponds to the label 8.377 + StrabonBeanWrapperConfiguration entry = new StrabonBeanWrapperConfiguration(param1); 8.378 + this.entries.add(entry); 8.379 + } else if (items == 2) { 8.380 + //the first element corresponds to the label 8.381 + StrabonBeanWrapperConfiguration entry = new StrabonBeanWrapperConfiguration(param1, param2); 8.382 + this.entries.add(entry); 8.383 + } else if (items == 6) { 8.384 + StrabonBeanWrapperConfiguration entry = new StrabonBeanWrapperConfiguration(param3, param1, param4, param2, param5, param6); 8.385 + this.entries.add(entry); 8.386 + } 8.387 8.388 - strabon.describe(queryString, answerFormatStrabon, strabon.getSailRepoConnection(), out); 8.389 - } 8.390 + } 8.391 + } 8.392 8.393 - public Object update(String updateString, String answerFormatStrabon) 8.394 - throws MalformedQueryException, RepositoryException, QueryEvaluationException, 8.395 - TupleQueryResultHandlerException, IOException, ClassNotFoundException { 8.396 - logger.info("[StrabonEndpoint] Received UPDATE query."); 8.397 - logger.info("[StrabonEndpoint] Answer format: " + answerFormatStrabon); 8.398 - 8.399 - if ((this.strabon == null) && (!init())) { 8.400 - throw new RepositoryException("Could not connect to Strabon."); 8.401 - } 8.402 + init(); 8.403 + } 8.404 8.405 - strabon.update(updateString, strabon.getSailRepoConnection()); 8.406 - return "OK!"; 8.407 - } 8.408 + public boolean init() { 8.409 + if (this.strabon == null) { 8.410 + try { 8.411 + logger.warn("[StrabonEndpoint] Strabon not initialized yet."); 8.412 + logger.warn("[StrabonEndpoint] Initializing Strabon."); 8.413 + //logger.info("[StrabonEndpoint] Connection details:\n" + this.getDetails()); 8.414 8.415 - /** 8.416 - * Store the given data in the given format into Strabon repository. If url is true, then 8.417 - * input comes from a URL. 8.418 - * 8.419 - * Returns true on success, false otherwise. 8.420 - * 8.421 - * @param source_data 8.422 - * @param format 8.423 - * @param url 8.424 - * @return 8.425 - * @throws MalformedQueryException 8.426 - * @throws RepositoryException 8.427 - * @throws InvalidDatasetFormatFault 8.428 - * @throws RDFHandlerException 8.429 - * @throws RDFParseException 8.430 - * @throws QueryEvaluationException 8.431 - * @throws TupleQueryResultHandlerException 8.432 - * @throws IOException 8.433 - * @throws ClassNotFoundException 8.434 - */ 8.435 - public boolean store(String src, String context, String format, Boolean inference, Boolean url) throws RepositoryException, RDFParseException, RDFHandlerException, IOException, InvalidDatasetFormatFault { 8.436 - logger.info("[StrabonEndpoint] Received STORE request."); 8.437 - 8.438 - if ((this.strabon == null) && (!init())) { 8.439 - throw new RepositoryException("Could not connect to Strabon."); 8.440 - } 8.441 + // initialize Strabon according to user preference 8.442 + if (Common.DBBACKEND_MONETDB.equalsIgnoreCase(dbBackend)) { 8.443 + this.strabon = new eu.earthobservatory.runtime.monetdb.Strabon(databaseName, user, password, port, serverName, checkForLockTable); 8.444 8.445 - if (url) { 8.446 - URL source = new URL(src); 8.447 - if (source.getProtocol().equalsIgnoreCase(FILE_PROTOCOL) && !loadFromFile) { 8.448 - // it would be a security issue if we read from the server's filesystem 8.449 - throw new IllegalArgumentException("The protocol of the URL should be one of http or ftp."); 8.450 - } 8.451 - 8.452 - } 8.453 + } else { 8.454 + // check whether the user typed wrong database backend and report 8.455 + if (!Common.DBBACKEND_POSTGIS.equalsIgnoreCase(dbBackend)) { 8.456 + logger.warn("[StrabonEndpoint] Unknown database backend \"" + dbBackend + "\". Assuming PostGIS."); 8.457 + } 8.458 8.459 - strabon.storeInRepo(src, null, context, format, inference); 8.460 - 8.461 - logger.info("[StrabonEndpoint] STORE was successful."); 8.462 - 8.463 - return true; 8.464 - } 8.465 + // use PostGIS as the default database backend 8.466 + this.strabon = new eu.earthobservatory.runtime.postgis.Strabon(databaseName, user, password, port, serverName, checkForLockTable); 8.467 + } 8.468 8.469 - public void setConnectionDetails(String dbname, String username, String password, String port, String hostname, String dbengine) { 8.470 - this.databaseName = dbname; 8.471 - this.user = username; 8.472 - this.password = password; 8.473 - try { 8.474 - this.port = Integer.valueOf(port); 8.475 - } catch (NumberFormatException e) { 8.476 - this.port = 5432; 8.477 - } 8.478 - this.serverName = hostname; 8.479 - this.dbBackend = dbengine; 8.480 - this.checkForLockTable = true; 8.481 - } 8.482 - 8.483 - public String getUsername() { 8.484 - return user; 8.485 - } 8.486 - 8.487 - public String getPassword() { 8.488 - return password; 8.489 - } 8.490 - 8.491 - public String getDatabaseName() { 8.492 - return databaseName; 8.493 - } 8.494 - 8.495 - public String getDBEngine() { 8.496 - return dbBackend; 8.497 - } 8.498 - 8.499 - public int getPort() { 8.500 - return port; 8.501 - } 8.502 - 8.503 - public String getHostName() { 8.504 - return serverName; 8.505 - } 8.506 - 8.507 - private String getDetails() { 8.508 - String details = "-----------------------------------------\n"; 8.509 - details += "host : " + serverName + "\n"; 8.510 - details += "port : " + port + "\n"; 8.511 - details += "database : " + databaseName + "\n"; 8.512 - details += "user : " + user + "\n"; 8.513 - details += "password : " + password + "\n"; 8.514 - details += "-----------------------------------------\n"; 8.515 + installSIGTERMHandler(this.strabon); 8.516 8.517 - return details; 8.518 - } 8.519 + } catch (Exception e) { 8.520 + logger.error("[StrabonEndpoint] Exception occured while creating Strabon. {}\n{}", e.getMessage(), this.getDetails()); 8.521 + return false; 8.522 + } 8.523 + } 8.524 8.525 - public List<StrabonBeanWrapperConfiguration> getEntries() { 8.526 - return this.entries; 8.527 - } 8.528 - 8.529 - public void setEntries(List<StrabonBeanWrapperConfiguration> entries) { 8.530 - this.entries = entries; 8.531 - } 8.532 - 8.533 - public StrabonBeanWrapperConfiguration getEntry(int i) { 8.534 - if (i < 0 || i >= this.entries.size()) 8.535 - return null; 8.536 - 8.537 - return this.entries.get(i); 8.538 - } 8.539 - 8.540 - /* 8.541 + return true; 8.542 + } 8.543 + 8.544 + /** 8.545 + * Registers a handler for SIGTERM signals, like Ctrl-C. One may send such a 8.546 + * signal at the command prompt, when running Strabon Endpoint from the 8.547 + * command line, i.e., using the endpoint-exec module. 8.548 + * 8.549 + * @param strabon The strabon instance 8.550 + */ 8.551 + private static void installSIGTERMHandler(final Strabon strabon) { 8.552 + if (logger.isDebugEnabled()) { 8.553 + logger.info("[StrabonEndpoint] Installing handler for SIGTERM signals..."); 8.554 + } 8.555 + 8.556 + // register the handler 8.557 + Runtime.getRuntime().addShutdownHook(new Thread() { 8.558 + 8.559 + @Override 8.560 + public void run() { 8.561 + // just call the Strabon.close() method 8.562 + strabon.close(); 8.563 + } 8.564 + }); 8.565 + 8.566 + if (logger.isDebugEnabled()) { 8.567 + logger.info("[StrabonEndpoint] Handler for SIGTERM signals installed successfully."); 8.568 + } 8.569 + } 8.570 + 8.571 + public Strabon getStrabon() { 8.572 + return strabon; 8.573 + } 8.574 + 8.575 + public void setStrabon(Strabon strabon) { 8.576 + this.strabon = strabon; 8.577 + } 8.578 + 8.579 + public void closeConnection() { 8.580 + if (strabon != null) { 8.581 + strabon.close(); 8.582 + strabon = null; 8.583 + } 8.584 + } 8.585 + 8.586 + public void destroy() throws Exception { 8.587 + if (strabon != null) { 8.588 + strabon.close(); 8.589 + 8.590 + // deregister jdbc driver 8.591 + strabon.deregisterDriver(); 8.592 + } 8.593 + } 8.594 + 8.595 + public void query(String queryString, String answerFormatStrabon, OutputStream out) 8.596 + throws MalformedQueryException, RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, ClassNotFoundException { 8.597 + logger.info("[StrabonEndpoint] Received SELECT query."); 8.598 + if ((this.strabon == null) && (!init())) { 8.599 + throw new RepositoryException("Could not connect to Strabon."); 8.600 + } 8.601 + if (answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString()) || answerFormatStrabon.equalsIgnoreCase(Format.AREACHART.toString()) 8.602 + || answerFormatStrabon.equalsIgnoreCase(Format.COLUMNCHART.toString())) { 8.603 + TupleQueryResult result = (TupleQueryResult) strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out); 8.604 + List<String> bindingNames = result.getBindingNames(); 8.605 + if (bindingNames.size() != 2 && answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString())) { 8.606 + logger.error("Strabon endpoint: to display results in a pie chart, exactly TWO variables must be projected"); 8.607 + } else { 8.608 + if (answerFormatStrabon.equalsIgnoreCase(Format.PIECHART.toString())) { 8.609 + 8.610 + ArrayList<String> arr = new ArrayList<String>(2); 8.611 + arr.add(0, bindingNames.get(0)); 8.612 + arr.add(1, bindingNames.get(1)); 8.613 + 8.614 + gChartString = "var data = new google.visualization.DataTable();"; 8.615 + gChartString += "data.addColumn('string',\'" + arr.get(0) + "');\n"; 8.616 + gChartString += "data.addColumn('number',\'" + arr.get(1) + "');\n"; 8.617 + 8.618 + while (result.hasNext()) { 8.619 + BindingSet bindings = result.next(); 8.620 + arr.add(0, bindings.getValue(bindingNames.get(0)).stringValue()); 8.621 + arr.add(1, bindings.getValue(bindingNames.get(1)).stringValue()); 8.622 + 8.623 + gChartString += "data.addRow([\'" + withoutPrefix(arr.get(0)) + "\', " 8.624 + + arr.get(1).replace("\"", "").replace("^^", "").replace("<http://www.w3.org/2001/XMLSchema#integer>", "") + "]);\n"; 8.625 + } 8.626 + gChartString += "var options = {'title':'','width':1000, 'height':1000, is3D: true};\n"; 8.627 + gChartString += "var chart = new google.visualization.PieChart(document.getElementById('chart_div'));\n"; 8.628 + 8.629 + } else { 8.630 + 8.631 + String chartType; 8.632 + int varNum = bindingNames.size(); 8.633 + 8.634 + gChartString = "var data = google.visualization.arrayToDataTable([["; 8.635 + for (int j = 0; j < varNum; j++) { 8.636 + String chartValue = bindingNames.get(j); 8.637 + gChartString += "'" + chartValue + "'"; 8.638 + 8.639 + if (j != varNum - 1) { 8.640 + gChartString += ","; 8.641 + } 8.642 + } 8.643 + gChartString += "],"; 8.644 + 8.645 + while (result.hasNext()) { 8.646 + BindingSet bindings = result.next(); 8.647 + gChartString += "["; 8.648 + for (int j = 0; j < varNum; j++) { 8.649 + 8.650 + String chartValue = bindings.getValue(bindingNames.get(j)).stringValue(); 8.651 + if (j == 0) { //the first variable is a string variable. 8.652 + gChartString += "'" + withoutPrefix(chartValue).replace("\"", "") + "'"; 8.653 + } else { //numeric value 8.654 + gChartString += withoutPrefix(chartValue).replace("\"", ""); 8.655 + } 8.656 + if (j != varNum - 1) { 8.657 + gChartString += ","; 8.658 + } 8.659 + } 8.660 + gChartString += "],"; 8.661 + } 8.662 + if (answerFormatStrabon.equalsIgnoreCase(Format.AREACHART.toString())) { 8.663 + chartType = "AreaChart"; 8.664 + } else { 8.665 + chartType = "ColumnChart"; 8.666 + } 8.667 + gChartString += "]);"; 8.668 + gChartString += " var options = {title: '', hAxis: {title:'" + bindingNames.get(0) + "', titleTextStyle: {color: \'red\'}}};"; 8.669 + gChartString += "var chart = new google.visualization." + chartType + "(document.getElementById('chart_div')); \n"; 8.670 + 8.671 + } 8.672 + 8.673 + } 8.674 + } else { 8.675 + strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), out); 8.676 + } 8.677 + 8.678 + } 8.679 + 8.680 + /** 8.681 + * Wrapper around Strabon.describeOp which takes an OutputStream to use for 8.682 + * writing the answer to a DESCRIBE query. 8.683 + * 8.684 + * @param queryString 8.685 + * @param answerFormatStrabon 8.686 + * @param out 8.687 + * @throws MalformedQueryException 8.688 + * @throws RepositoryException 8.689 + * @throws QueryEvaluationException 8.690 + * @throws TupleQueryResultHandlerException 8.691 + * @throws IOException 8.692 + * @throws ClassNotFoundException 8.693 + */ 8.694 + public void describe(String queryString, String answerFormatStrabon, OutputStream out) 8.695 + throws MalformedQueryException, RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, ClassNotFoundException { 8.696 + logger.info("[StrabonEndpoint] Received DESCRIBE query."); 8.697 + if ((this.strabon == null) && (!init())) { 8.698 + throw new RepositoryException("Could not connect to Strabon."); 8.699 + } 8.700 + 8.701 + strabon.describe(queryString, answerFormatStrabon, strabon.getSailRepoConnection(), out); 8.702 + } 8.703 + 8.704 + public Object update(String updateString, String answerFormatStrabon) 8.705 + throws MalformedQueryException, RepositoryException, QueryEvaluationException, 8.706 + TupleQueryResultHandlerException, IOException, ClassNotFoundException { 8.707 + logger.info("[StrabonEndpoint] Received UPDATE query."); 8.708 + logger.info("[StrabonEndpoint] Answer format: " + answerFormatStrabon); 8.709 + 8.710 + if ((this.strabon == null) && (!init())) { 8.711 + throw new RepositoryException("Could not connect to Strabon."); 8.712 + } 8.713 + 8.714 + strabon.update(updateString, strabon.getSailRepoConnection()); 8.715 + return "OK!"; 8.716 + } 8.717 + 8.718 + /** 8.719 + * Store the given data in the given format into Strabon repository. If url 8.720 + * is true, then input comes from a URL. 8.721 + * 8.722 + * Returns true on success, false otherwise. 8.723 + * 8.724 + * @param source_data 8.725 + * @param format 8.726 + * @param url 8.727 + * @return 8.728 + * @throws MalformedQueryException 8.729 + * @throws RepositoryException 8.730 + * @throws InvalidDatasetFormatFault 8.731 + * @throws RDFHandlerException 8.732 + * @throws RDFParseException 8.733 + * @throws QueryEvaluationException 8.734 + * @throws TupleQueryResultHandlerException 8.735 + * @throws IOException 8.736 + * @throws ClassNotFoundException 8.737 + */ 8.738 + public boolean store(String src, String context, String format, Boolean inference, Boolean url) throws RepositoryException, RDFParseException, RDFHandlerException, IOException, InvalidDatasetFormatFault { 8.739 + logger.info("[StrabonEndpoint] Received STORE request."); 8.740 + 8.741 + if ((this.strabon == null) && (!init())) { 8.742 + throw new RepositoryException("Could not connect to Strabon."); 8.743 + } 8.744 + 8.745 + if (url) { 8.746 + URL source = new URL(src); 8.747 + if (source.getProtocol().equalsIgnoreCase(FILE_PROTOCOL) && !loadFromFile) { 8.748 + // it would be a security issue if we read from the server's filesystem 8.749 + throw new IllegalArgumentException("The protocol of the URL should be one of http or ftp."); 8.750 + } 8.751 + 8.752 + } 8.753 + 8.754 + strabon.storeInRepo(src, null, context, format, inference); 8.755 + 8.756 + logger.info("[StrabonEndpoint] STORE was successful."); 8.757 + 8.758 + return true; 8.759 + } 8.760 + 8.761 + public void setConnectionDetails(String dbname, String username, String password, String port, String hostname, String dbengine, String googlemapskey) { 8.762 + this.databaseName = dbname; 8.763 + this.user = username; 8.764 + this.password = password; 8.765 + try { 8.766 + this.port = Integer.valueOf(port); 8.767 + } catch (NumberFormatException e) { 8.768 + this.port = 5432; 8.769 + } 8.770 + this.serverName = hostname; 8.771 + this.dbBackend = dbengine; 8.772 + this.googlemapskey = googlemapskey; 8.773 + this.checkForLockTable = true; 8.774 + } 8.775 + 8.776 + public String getUsername() { 8.777 + return user; 8.778 + } 8.779 + 8.780 + public String getPassword() { 8.781 + return password; 8.782 + } 8.783 + 8.784 + public String getDatabaseName() { 8.785 + return databaseName; 8.786 + } 8.787 + 8.788 + public String getDBEngine() { 8.789 + return dbBackend; 8.790 + } 8.791 + 8.792 + public int getPort() { 8.793 + return port; 8.794 + } 8.795 + 8.796 + public String getHostName() { 8.797 + return serverName; 8.798 + } 8.799 + 8.800 + private String getDetails() { 8.801 + String details = "-----------------------------------------\n"; 8.802 + details += "host : " + serverName + "\n"; 8.803 + details += "port : " + port + "\n"; 8.804 + details += "database : " + databaseName + "\n"; 8.805 + details += "user : " + user + "\n"; 8.806 + details += "password : " + password + "\n"; 8.807 + details += "dbengine : " + dbBackend + "\n"; 8.808 + details += "googlemapskey : " + googlemapskey + "\n"; 8.809 + details += "-----------------------------------------\n"; 8.810 + 8.811 + return details; 8.812 + } 8.813 + 8.814 + public List<StrabonBeanWrapperConfiguration> getEntries() { 8.815 + return this.entries; 8.816 + } 8.817 + 8.818 + public void setEntries(List<StrabonBeanWrapperConfiguration> entries) { 8.819 + this.entries = entries; 8.820 + } 8.821 + 8.822 + public StrabonBeanWrapperConfiguration getEntry(int i) { 8.823 + if (i < 0 || i >= this.entries.size()) { 8.824 + return null; 8.825 + } 8.826 + 8.827 + return this.entries.get(i); 8.828 + } 8.829 + 8.830 + /* 8.831 * Limit the number of solutions returned. 8.832 * */ 8.833 - public String addLimit(String queryString, String maxLimit){ 8.834 - String limitedQuery = queryString; 8.835 - String lowerLimit = null; 8.836 - int max; 8.837 - 8.838 - if(maxLimit == null) 8.839 - max = this.maxLimit; 8.840 - else 8.841 - max = Integer.valueOf(maxLimit); 8.842 - 8.843 - if(max > 0) 8.844 - { 8.845 - queryString = queryString.trim(); 8.846 - Pattern limitPattern = Pattern.compile("limit(\\s*)(\\d+)(\\s*)(offset(\\s*)\\d+)?$", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); 8.847 - Matcher limitMatcher = limitPattern.matcher(queryString); 8.848 - 8.849 - // check whether the query contains a limit clause 8.850 - if(limitMatcher.find()) 8.851 - { 8.852 - Pattern rowsNumberPattern = Pattern.compile("\\d+"); 8.853 - Matcher rowsNumberMatcher = rowsNumberPattern.matcher(limitMatcher.group()); 8.854 - rowsNumberMatcher.find(); 8.855 - 8.856 - // if the initial limit is greater than the maximum, set it to the maximum 8.857 - if(Integer.valueOf(rowsNumberMatcher.group()) > max) 8.858 - { 8.859 - lowerLimit = rowsNumberMatcher.replaceFirst(String.valueOf(max)); 8.860 - limitedQuery = limitMatcher.replaceFirst(lowerLimit); 8.861 - } 8.862 - } 8.863 - else // add a limit to the query 8.864 - limitedQuery = queryString+" limit "+max; 8.865 - } 8.866 - return limitedQuery; 8.867 - } 8.868 - 8.869 - public String getPrefixes() { 8.870 - return prefixes; 8.871 - } 8.872 + public String addLimit(String queryString, String maxLimit) { 8.873 + String limitedQuery = queryString; 8.874 + String lowerLimit = null; 8.875 + int max; 8.876 8.877 - 8.878 + if (maxLimit == null) { 8.879 + max = this.maxLimit; 8.880 + } else { 8.881 + max = Integer.valueOf(maxLimit); 8.882 + } 8.883 8.884 - public String getgChartString() { 8.885 - return gChartString; 8.886 - } 8.887 + if (max > 0) { 8.888 + queryString = queryString.trim(); 8.889 + Pattern limitPattern = Pattern.compile("limit(\\s*)(\\d+)(\\s*)(offset(\\s*)\\d+)?$", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); 8.890 + Matcher limitMatcher = limitPattern.matcher(queryString); 8.891 8.892 - public void setgChartString(String gChartString) { 8.893 - this.gChartString = gChartString; 8.894 - } 8.895 - 8.896 - 8.897 - public String withoutPrefix(String inputURI){ 8.898 - int index; 8.899 - 8.900 - if(!inputURI.contains("http") ){ //plain literal case- no prefixes to remove 8.901 - return inputURI; 8.902 - } 8.903 - else{ //URI case 8.904 - //removing prefixes so that they will not be displayed in the chart 8.905 - if(inputURI.lastIndexOf('#') > inputURI.lastIndexOf('/')){ 8.906 - index = inputURI.lastIndexOf('#')+1; 8.907 - } 8.908 - else{ 8.909 - index = inputURI.lastIndexOf("/")+1; 8.910 - } 8.911 - 8.912 - int endIndex= inputURI.length(); 8.913 - return inputURI.substring(index, endIndex ); 8.914 + // check whether the query contains a limit clause 8.915 + if (limitMatcher.find()) { 8.916 + Pattern rowsNumberPattern = Pattern.compile("\\d+"); 8.917 + Matcher rowsNumberMatcher = rowsNumberPattern.matcher(limitMatcher.group()); 8.918 + rowsNumberMatcher.find(); 8.919 8.920 - } 8.921 - } 8.922 + // if the initial limit is greater than the maximum, set it to the maximum 8.923 + if (Integer.valueOf(rowsNumberMatcher.group()) > max) { 8.924 + lowerLimit = rowsNumberMatcher.replaceFirst(String.valueOf(max)); 8.925 + limitedQuery = limitMatcher.replaceFirst(lowerLimit); 8.926 + } 8.927 + } else // add a limit to the query 8.928 + { 8.929 + limitedQuery = queryString + " limit " + max; 8.930 + } 8.931 + } 8.932 + return limitedQuery; 8.933 + } 8.934 + 8.935 + public String getPrefixes() { 8.936 + return prefixes; 8.937 + } 8.938 + 8.939 + public String getgChartString() { 8.940 + return gChartString; 8.941 + } 8.942 + 8.943 + public void setgChartString(String gChartString) { 8.944 + this.gChartString = gChartString; 8.945 + } 8.946 + 8.947 + public String withoutPrefix(String inputURI) { 8.948 + int index; 8.949 + 8.950 + if (!inputURI.contains("http")) { //plain literal case- no prefixes to remove 8.951 + return inputURI; 8.952 + } else { //URI case 8.953 + //removing prefixes so that they will not be displayed in the chart 8.954 + if (inputURI.lastIndexOf('#') > inputURI.lastIndexOf('/')) { 8.955 + index = inputURI.lastIndexOf('#') + 1; 8.956 + } else { 8.957 + index = inputURI.lastIndexOf("/") + 1; 8.958 + } 8.959 + 8.960 + int endIndex = inputURI.length(); 8.961 + return inputURI.substring(index, endIndex); 8.962 + 8.963 + } 8.964 + } 8.965 + 8.966 + public String getGooglemapskey() { 8.967 + return googlemapskey; 8.968 + } 8.969 + 8.970 + 8.971 + public String googleMapsAPIScriptSourceForJSP() { 8.972 + /* returns the correct script source string to use in JSP 8.973 + i.e. query.jsp 8.974 + If the googlemapskey is null then assumes this is an already 8.975 + registered host for Google, therefore uses the old script source, 8.976 + otherwise uses the new script source 8.977 + */ 8.978 + String scriptSource; 8.979 + if (googlemapskey.equals("") || googlemapskey.equals("null")) { 8.980 + scriptSource = "http://maps.googleapis.com/maps/api/js?sensor=false"; 8.981 + } else { 8.982 + // scriptSource = "https://maps.googleapis.com/maps/api/js?key=" + googlemapskey + "&callback=initMap"; 8.983 + scriptSource = "https://maps.googleapis.com/maps/api/js?key=" + googlemapskey; 8.984 + } 8.985 + return scriptSource; 8.986 + } 8.987 } 8.988 -