Strabon

view endpoint/WebContent/query.jsp @ 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
author Theofilos Ioannidis <tioannid@yahoo.com>
date Wed Oct 04 11:55:13 2017 +0300 (2017-10-04)
parents a1137629f208
children
line source
1 <%@page import="java.net.URLEncoder"%>
2 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
3 <%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
4 <%@page import="org.springframework.web.context.WebApplicationContext"%>
5 <%@page import="eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper"%>
6 <%@page import="eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapperConfiguration"%>
7 <%@page import="java.util.List"%>
8 <%@page import="java.util.ArrayList"%>
9 <%@page import="java.util.Iterator"%>
10 <%@page import="org.openrdf.query.TupleQueryResult"%>
11 <%@page import="org.openrdf.query.BindingSet"%>
12 <jsp:directive.page import="eu.earthobservatory.org.StrabonEndpoint.Common"/>
13 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
14 <html>
15 <head>
16 <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
17 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
18 <script type="text/javascript" src="js/more_link.js"></script>
19 <link rel="stylesheet" href="style.css" type="text/css" />
20 <script type="text/javascript" src="js/timemap/jquery-1.6.2.min.js"></script>
21 <script type="text/javascript" src="js/timemap/mxn.js?(googlev3)"></script>
22 <script type="text/javascript" src="js/timemap/timeline-1.2.js"></script>
23 <script src="js/timemap/timemap.js" type="text/javascript"></script>
24 <script src="js/timemap/param.js" type="text/javascript"></script>
25 <script src="js/timemap/xml.js" type="text/javascript"></script>
26 <script src="js/timemap/kml.js" type="text/javascript"></script>
27 <script type="text/javascript">
28 function toggleMe(a) {
29 var e = document.getElementById(a);
30 if (!e) {
31 return true;
32 }
33 if (e.style.display == "none") {
34 e.style.display = "block";
35 } else {
36 e.style.display = "none";
37 }
38 return true;
39 }
40 </script>
41 <script>
42 $(document).ready(function () {
43 var showChar = 100;
44 var ellipsestext = "...";
45 var moretext = "more";
46 var lesstext = "less";
47 $('.more').each(function () {
48 var content = $(this).html();
50 if (content.length > showChar) {
52 var c = content.substr(0, showChar);
53 var h = content.substr(showChar - 1, content.length - showChar);
55 var html = c + '<span class="moreelipses">' + ellipsestext + '</span>&nbsp;<span class="morecontent"><span>' + h + '</span>&nbsp;&nbsp;<a href="" class="morelink">' + moretext + '</a></span>';
57 $(this).html(html);
58 }
60 });
62 $(".morelink").click(function () {
63 if ($(this).hasClass("less")) {
64 $(this).removeClass("less");
65 $(this).html(moretext);
66 } else {
67 $(this).addClass("less");
68 $(this).html(lesstext);
69 }
70 $(this).parent().prev().toggle();
71 $(this).prev().toggle();
72 return false;
73 });
74 });
75 </script>
76 <%
77 // get the reference to StrabonBeanWrapper
78 StrabonBeanWrapper strabonWrapper;
79 //String arr = new String[2];
80 int i;
81 ArrayList<String> arr = new ArrayList<String>(2);
82 String gChartString=null;
83 ServletContext context;
84 context = getServletContext();
85 WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context);
86 strabonWrapper=(StrabonBeanWrapper) applicationContext.getBean("strabonBean");
88 // get query parameter or attribute (the attribute comes from ConnectionBean)
89 String query = strabonWrapper.getPrefixes();
90 if (request.getParameter("query") != null) {
91 query = request.getParameter("query");
93 } else if (request.getAttribute("query") != null) {
94 query = (String) request.getAttribute("query");
96 }
98 if ("null".equals(query)) {
99 query = "";
100 }
102 // get format parameter or attribute (the attribute comes from ConnectionBean)
103 String selFormat = "HTML";
104 if (request.getParameter("format") != null) {
105 selFormat = request.getParameter("format");
107 } else if (request.getAttribute("format") != null) {
108 selFormat = (String) request.getAttribute("format");
110 }
112 // get handle parameter or attribute (the attribute comes from ConnectionBean)
113 String handle = "";
114 if (request.getParameter("handle") != null) {
115 handle = request.getParameter("handle");
117 } else if (request.getAttribute("handle") != null) {
118 handle = (String) request.getAttribute("handle");
120 }
122 if (request.getAttribute("pathToKML") != null) {
123 if (request.getAttribute("handle").toString().contains("map")) {
124 %>
125 <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
126 <script type="text/javascript" src="<%=request.getAttribute("googlemapsAPIscriptsource")%>"></script>
127 <script type="text/javascript" src="js/geoxml3-kmz.js"></script>
128 <script type="text/javascript" src="js/ProjectedOverlay.js"></script>
129 <%
130 }
131 %>
133 <script type="text/javascript">
135 //listener for the event 'bounds_changed'
136 function addListener(map) {
138 google.maps.event.addListener(map, 'bounds_changed', function () {
139 // get the new bounds
140 var bounds = map.getBounds();
141 var northEast = bounds.getNorthEast();
142 var southWest = bounds.getSouthWest();
144 var x1 = northEast.lng().toFixed(2);
145 var y1 = northEast.lat().toFixed(2);
147 var x2 = southWest.lng().toFixed(2);
148 var y2 = southWest.lat().toFixed(2);
150 var polygon = "\"POLYGON((" +
151 x1 + " " + y2 + ", " +
152 x2 + " " + y2 + ", " +
153 x2 + " " + y1 + ", " +
154 x1 + " " + y1 + ", " +
155 x1 + " " + y2 + "))\"" +
156 "^^<http\://www.opengis.net/ont/geosparql#wktLiteral>";
158 document.getElementById('bounds').value = polygon;
160 });
161 }
163 function initialize() {
164 var myOptions = {
165 zoom: 11,
166 mapTypeId: google.maps.MapTypeId.ROADMAP,
167 zoomControl: true
168 };
170 // get KML filename
171 var kml = '<%=request.getAttribute("pathToKML")%>';
172 var map;
173 // create map
174 <%if(request.getAttribute("handle").toString().contains("timemap")){ %>
175 map = tm.getNativeMap();
176 map.setOptions(myOptions);
177 <%} else {%>
178 var map = new google.maps.Map(document.getElementById("map"), myOptions);
179 <%}%>
180 <% if (request.getAttribute("pathToKML") == null) {%>
181 // center at Brahames
182 map.setCenter(new google.maps.LatLng(37.92253, 23.72275));
183 <%}%>
185 addListener(map);
188 <%if ("map_local".equals(request.getAttribute("handle"))) {%>
189 // display using geoxml3
190 var myParser = new geoXML3.parser({map: map});
191 myParser.parse(kml);
192 <%} else {%>
193 var ctaLayer = new google.maps.KmlLayer(kml);
194 ctaLayer.setMap(map);
195 <%}%>
197 <%if (("map".equals(request.getAttribute("handle"))) || ("map_local".equals(request.getAttribute("handle")))
198 || ("timemap".equals(request.getAttribute("handle")))) {%>
199 $('html, body').animate({
200 scrollTop: $("#divResultsStart").offset().top
201 }, 1500);
203 <%}%>
206 }
207 </script>
208 <% } else { %>
209 <script type="text/javascript">
210 function initialize() {
211 <%
212 if (query != "" || selFormat != "" || handle != "") {
213 %>
214 $('html, body').animate({
215 scrollTop: $("#divResultsStart").offset().top
216 }, 1000);
217 <%}%>
218 }
219 </script>
220 <%}%>
222 <!-- jQuery start -->
223 <link type="text/css" href="style-menu.css" rel="stylesheet" />
224 <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
225 <script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script>
226 <script type="text/javascript">
227 $(function () {
228 // Accordion
229 $("#accordion").accordion({
230 header: "h3",
231 fillSpace: true,
232 navigation: true,
233 collapsible: true
234 });
235 //hover states on the static widgets
236 $('#dialog_link, ul#icons li').hover(
237 function () {
238 $(this).addClass('ui-state-hover');
239 },
240 function () {
241 $(this).removeClass('ui-state-hover');
242 }
243 );
244 });
245 </script>
246 <style type="text/css">
247 /*demo page css*/
248 body{ font: 90% "Trebuchet MS", sans-serif; margin: 50px;}
249 .container { height:410px; width:165px;}
250 .demoHeaders { margin-top: 1em;}
251 #dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
252 #dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
253 ul#icons {margin: 0; padding: 0;}
254 ul#icons li {margin: 1px; position: relative; padding: 1px 0; cursor: pointer; float: left; list-style: none;}
255 ul#icons span.ui-icon {float: left; margin: 0 1px;}
256 </style>
258 <script type="text/javascript">
260 var tm;
261 $(function () {
262 var myOptions = {
263 zoom: 11,
264 mapTypeId: google.maps.MapTypeId.ROADMAP,
265 zoomControl: true,
266 scrollwheel: true
268 };
270 var map = new google.maps.Map(document.getElementById("map"), myOptions);
271 tm = TimeMap.init({
272 // Id of map div element (required)
273 mapId: "map",
274 timelineId: "timeline", // Id of timeline div element (required)
275 options: {
276 eventIconPath: "images/"
277 },
278 datasets: [
279 {
280 title: "Visualization of timestamps",
281 theme: "red",
282 type: "kml", // Data to be loaded in KML - must be a local URL
283 options: {
284 url: <% if(request.getAttribute("pathToKML") != null){
285 out.println("\""+request.getAttribute("pathToKML")+"\"");
286 }%> // KML file to load
287 }
288 }
289 ],
290 bandInfo: [
291 {
292 width: "85%",
293 intervalUnit: Timeline.DateTime.DAY,
294 intervalPixels: 210
295 },
296 {
297 width: "15%",
298 intervalUnit: Timeline.DateTime.WEEK,
299 intervalPixels: 150,
300 showEventText: false,
301 trackHeight: 0.2,
302 trackGap: 0.2
303 }
304 ]
305 });
308 });
311 </script>
314 <link href="js/timemap/examples.css" type="text/css" rel="stylesheet"/>
315 <style>
316 div#timelinecontainer{ height: 310px; }
317 div#mapcontainer{ height: 600px; }
318 </style>
320 <!-- jQuery end -->
322 <title>Strabon Endpoint</title>
323 <!--Load the AJAX API-->
324 <script type="text/javascript" src="https://www.google.com/jsapi"></script>
325 <script type="text/javascript">
327 // Load the Visualization API and the piechart package.
328 google.load('visualization', '1.0', {'packages': ['corechart']});
330 google.setOnLoadCallback(drawChart);
332 // Set a callback to run when the Google Visualization API is loaded.
335 // Callback that creates and populates a data table,
336 // instantiates the pie chart, passes in the data and
337 // draws it.
341 function drawChart() {
343 // Create the data table.
344 var data = new google.visualization.DataTable();
345 <% if (request.getAttribute("format")!=null && request.getAttribute("response") != null) {
346 if (request.getAttribute("format").equals("CHART")) {
347 out.println(request.getAttribute("response"));
348 %>
351 chart.draw(data, options);
353 <%}}%>
354 }
355 </script>
358 </head>
359 <body topmargin="0" leftmargin="0" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" onload="initialize()">
361 <!-- include TELEIOS header and description -->
362 <%@ include file="header.html"%>
363 <!-- include TELEIOS header and description -->
365 <FORM enctype="UTF-8" accept-charset="UTF-8" method="post" action="Query">
366 <INPUT type=hidden name="view" value="HTML"/>
368 <table border="0" width="100%">
369 <tr>
370 <td width="90" valign="top">
371 <table border="0" cellspacing="0" cellpadding="0" width="165">
372 <tr><td id="twidth">
373 <div class="container">
374 <div id="accordion">
375 <%
377 Iterator <StrabonBeanWrapperConfiguration> entryListIterator = strabonWrapper.getEntries().iterator();
378 boolean first = true;
379 String hash = "";
380 while(entryListIterator.hasNext())
381 {
382 StrabonBeanWrapperConfiguration entry = entryListIterator.next();
384 if (entry.isHeader()) {
385 if (!first) {
386 %>
387 </div></div>
388 <%
389 } else {
390 first = false;
391 }
393 String label=entry.getLabel();
394 String style = "", href = "";
395 hash = new Integer(Math.abs(label.hashCode())).toString();
396 href="href=\"#"+hash+"\"";
397 %>
398 <div><h3><a <%=style%> <%=href%>><%=label%></a></h3><div>
399 <%
400 } else if (entry.isBean()) {
401 String label=entry.getLabel();
402 String bean=entry.getBean();
403 if(bean.equals("browse.jsp") || bean.equals("ChangeConnection"))
404 continue;
405 String style = "", href = "";
406 hash = new Integer(Math.abs(label.hashCode()*bean.hashCode())).toString();
407 href = "\"" +bean + "#"+ hash+"\"";
408 style = "class=\"navText\"";
409 %>
410 <b>&middot;</b>&nbsp;<a class="linkText" href=<%=href%>><%=label%></a><br/>
411 <%
412 } else {
413 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)+"\"";
414 String title="\""+entry.getTitle()+"\"";
415 String label=entry.getLabel();
416 %>
417 <b>&middot;</b>&nbsp;<a class="linkText" href=<%=href%> title=<%=title%>><%=label%></a><br/>
418 <%
420 }
421 }
422 %>
423 </div>
424 </div>
425 </td>
426 </tr>
427 <!--
428 <tr><td width="90" class="style4"><a href="describe.jsp" class="navText">Describe</a></td></tr>
429 <tr><td width="90" class="style4"><a href="store.jsp" class="navText" title="Store triples">Store</a></td></tr>
430 -->
431 </table>
432 </td>
433 <td width="*" valign="top" >
434 <table cellspacing="5">
435 <%if (request.getAttribute("info") != null) { %>
436 <!-- Info Message -->
437 <TR><TD colspan=2>
438 <CENTER><P><%=request.getAttribute("info") %></P></CENTER>
439 </TD></TR>
440 <!-- Info Message -->
441 <%}%>
442 <tr>
443 <td id="output" colspan=2>
444 <div style="font-size:13px">
445 You must be logged in to perform update queries, or run in localhost.
446 </div>
447 </td>
448 </tr>
449 <tr>
450 <td id="output" style="width: 150px">stSPARQL Query:</td>
451 <td id="output"><textarea name="query" title="pose your query/update here" rows="20" cols="100"><%=query%></textarea></td>
452 </tr>
453 <tr>
454 <td id="output">Output Format:</td>
455 <td id="output">
456 <select name="format" title="select one of the following output format types">
457 <%
458 for (String format : Common.registeredQueryResultsFormatNames) {%>
459 <OPTION value="<%=format%>"<%=format.equals(selFormat) ? "selected":""%>><%=format%></OPTION>
460 <%}%>
461 </select>
462 </td>
463 </tr>
464 <tr>
465 <td id="output">View Result:</td>
466 <td id="output">
467 <SELECT name="handle" title="select how you would like to view the result">
468 <OPTION value="plain"<%= ("plain".equals(handle)) ? "selected":""%>>Plain</OPTION>
469 <OPTION value="download"<%= ("download".equals(handle)) ? "selected":""%>>Download</OPTION>
470 <OPTION value="map"<%= ("map".equals(handle)) ? "selected":""%>>On a map</OPTION>
471 <OPTION value="map_local"<%= ("map_local".equals(handle)) ? "selected":""%>>On a map (localhost)</OPTION>
472 <OPTION value="timemap"<%= ("timemap".equals(handle)) ? "selected":""%>>On a timemap</OPTION>
473 </SELECT>
474 </td>
475 </tr>
477 <tr>
478 <td id="output">Map Bounds:</td>
479 <td id="output">
480 <textarea readonly id='bounds' rows="1" cols="100"></textarea>
481 </td>
482 </tr>
484 <tr>
485 <td colspan=2 id="output"><br/><center>
486 <input type="submit" title="execute query" value="Query" name="submit" style="width: 350px" />
487 <input type="submit" title="execute update" value="Update" name="submit" style="width: 350px"/></center><br/></td>
488 </tr>
492 <% if (request.getAttribute("error") != null) {%>
493 <!-- Error Message -->
494 <TR>
495 <TD id="output">Result: </TD><TD id="output"><%=request.getAttribute("error") %></TD>
496 </TR>
497 <!-- Error Message -->
498 <%}%>
499 </table></td></tr></table><br/><br/>
500 </form>
501 <a name="#results">&nbsp;</a>
502 <div id="divResultsStart"></div>
503 <!-- Response -->
504 <% if(request.getAttribute("format") == null || !request.getAttribute("format").equals("CHART")){
505 if (request.getAttribute("response") != null) {
506 if (Common.getHTMLFormat().equals(request.getParameter("format"))) {%>
507 <%=request.getAttribute("response")%>
508 <%} else { %>
509 <PRE><%=request.getAttribute("response") %></PRE>
510 <%}%>
511 <%}}%>
512 <!-- Response -->
513 <% if (request.getAttribute("pathToKML") != null && request.getAttribute("handle").toString().contains("timemap")) { %>
514 <div id="timemap">
515 <div id="timelinecontainer">
516 <div id="timeline"></div>
517 </div>
518 <div id="mapcontainer">
519 <div id="map"></div>
520 </div>
521 </div>
522 <%} else {%>
523 <div id="map"></div>
524 <%} %>
525 <div id="divResultsEnd" style="height: 1px; width: 1px"></div>
526 <div id="chart_div"></div>
527 </body>
528 </html>