Strabon

view endpoint/WebContent/query.jsp @ 1191:98aae21ffe72

same
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Mon Jul 08 01:05:31 2013 +0300 (2013-07-08)
parents a5340fe30e7f
children 9fbbd9a8d724
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.Iterator"%>
9 <%@page import="org.openrdf.query.TupleQueryResult"%>
10 <%@page import="org.openrdf.query.BindingSet"%>
11 <jsp:directive.page import="eu.earthobservatory.org.StrabonEndpoint.Common"/>
12 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
13 <html>
14 <head>
15 <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
16 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
17 <script type="text/javascript" src="js/more_link.js"></script>
18 <link rel="stylesheet" href="style.css" type="text/css" />
19 <script type="text/javascript">
20 function toggleMe(a) {
21 var e = document.getElementById(a);
22 if (!e) {
23 return true;
24 }
25 if (e.style.display == "none") {
26 e.style.display = "block";
27 } else {
28 e.style.display = "none";
29 }
30 return true;
31 }
32 </script>
33 <script>
34 $(document).ready(function() {
35 var showChar = 100;
36 var ellipsestext = "...";
37 var moretext = "more";
38 var lesstext = "less";
39 $('.more').each(function() {
40 var content = $(this).html();
42 if(content.length > showChar) {
44 var c = content.substr(0, showChar);
45 var h = content.substr(showChar-1, content.length - showChar);
47 var html = c + '<span class="moreelipses">'+ellipsestext+'</span>&nbsp;<span class="morecontent"><span>' + h + '</span>&nbsp;&nbsp;<a href="" class="morelink">'+moretext+'</a></span>';
49 $(this).html(html);
50 }
52 });
54 $(".morelink").click(function(){
55 if($(this).hasClass("less")) {
56 $(this).removeClass("less");
57 $(this).html(moretext);
58 } else {
59 $(this).addClass("less");
60 $(this).html(lesstext);
61 }
62 $(this).parent().prev().toggle();
63 $(this).prev().toggle();
64 return false;
65 });
66 });
67 </script>
68 <%
69 // get the reference to StrabonBeanWrapper
70 StrabonBeanWrapper strabonWrapper;
71 String label1= "placeholder";
72 String label2= "placeholder";
73 TupleQueryResult result = null;
75 ServletContext context;
76 context = getServletContext();
77 WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context);
78 strabonWrapper=(StrabonBeanWrapper) applicationContext.getBean("strabonBean");
80 // get query parameter or attribute (the attribute comes from ConnectionBean)
81 String query = strabonWrapper.getPrefixes();
82 if (request.getParameter("query") != null) {
83 query = request.getParameter("query");
85 } else if (request.getAttribute("query") != null) {
86 query = (String) request.getAttribute("query");
88 }
90 if ("null".equals(query)) {
91 query = "";
92 }
94 // get format parameter or attribute (the attribute comes from ConnectionBean)
95 String selFormat = "HTML";
96 if (request.getParameter("format") != null) {
97 selFormat = request.getParameter("format");
99 } else if (request.getAttribute("format") != null) {
100 selFormat = (String) request.getAttribute("format");
102 }
104 // get handle parameter or attribute (the attribute comes from ConnectionBean)
105 String handle = "";
106 if (request.getParameter("handle") != null) {
107 handle = request.getParameter("handle");
109 } else if (request.getAttribute("handle") != null) {
110 handle = (String) request.getAttribute("handle");
112 }
114 if (request.getAttribute("pathToKML") != null) {
115 if ("map_local".equals(request.getAttribute("handle"))) {
116 %>
117 <script type="text/javascript" src="js/geoxml3-kmz.js"></script>
118 <script type="text/javascript" src="js/ProjectedOverlay.js"></script>
119 <%
120 }
121 %>
122 <link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
123 <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
124 <script type="text/javascript">
125 function initialize() {
126 var myOptions = {
127 zoom: 11,
128 mapTypeId: google.maps.MapTypeId.ROADMAP
129 };
131 // get KML filename
132 var kml = '<%=request.getAttribute("pathToKML")%>';
134 // create map
135 var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
136 <% if (request.getAttribute("pathToKML") == null) {%>
137 // center at Brahames
138 map.setCenter(new google.maps.LatLng(37.92253, 23.72275));
139 <%}%>
141 <%if ("map_local".equals(request.getAttribute("handle"))) {%>
142 // display using geoxml3
143 var myParser = new geoXML3.parser({map: map});
144 myParser.parse(kml);
146 <%} else {%>
147 var ctaLayer = new google.maps.KmlLayer(kml);
148 ctaLayer.setMap(map);
149 <%}%>
151 <%if ("map".equals(request.getAttribute("handle")) || "map_local".equals(request.getAttribute("handle"))) {%>
152 $('html, body').animate({
153 scrollTop: $("#divResultsStart").offset().top
154 }, 1500);
155 <%}%>
156 }
157 </script>
158 <% } else { %>
159 <script type="text/javascript">
160 function initialize() {
161 <%
162 if (query != "" || selFormat != "" || handle != "") {
163 %>
164 $('html, body').animate({
165 scrollTop: $("#divResultsStart").offset().top
166 }, 1000);
167 <%}%>
168 }
169 </script>
170 <%}%>
172 <!-- jQuery start -->
173 <link type="text/css" href="style-menu.css" rel="stylesheet" />
174 <script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>
175 <script type="text/javascript" src="js/jquery-ui-1.8.23.custom.min.js"></script>
176 <script type="text/javascript">
177 $(function(){
178 // Accordion
179 $("#accordion").accordion({
180 header: "h3",
181 fillSpace: true,
182 navigation: true,
183 collapsible: true
184 });
185 //hover states on the static widgets
186 $('#dialog_link, ul#icons li').hover(
187 function() { $(this).addClass('ui-state-hover'); },
188 function() { $(this).removeClass('ui-state-hover'); }
189 );
190 });
191 </script>
192 <style type="text/css">
193 /*demo page css*/
194 body{ font: 90% "Trebuchet MS", sans-serif; margin: 50px;}
195 .container { height:410px; width:165px;}
196 .demoHeaders { margin-top: 1em;}
197 #dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
198 #dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
199 ul#icons {margin: 0; padding: 0;}
200 ul#icons li {margin: 1px; position: relative; padding: 1px 0; cursor: pointer; float: left; list-style: none;}
201 ul#icons span.ui-icon {float: left; margin: 0 1px;}
202 </style>
203 <!-- jQuery end -->
205 <title>TELEIOS: Strabon Endpoint</title>
206 <!--Load the AJAX API-->
207 <script type="text/javascript" src="https://www.google.com/jsapi"></script>
208 <script type="text/javascript">
210 // Load the Visualization API and the piechart package.
211 google.load('visualization', '1.0', {'packages':['corechart']});
213 // Set a callback to run when the Google Visualization API is loaded.
215 google.setOnLoadCallback(drawChart);
217 // Callback that creates and populates a data table,
218 // instantiates the pie chart, passes in the data and
219 // draws it.
223 function drawChart() {
225 <% if (request.getAttribute("response") != null) {
226 if (request.getParameter("format").equals("CHART")) {
227 StrabonBeanWrapper sw = (StrabonBeanWrapper) request.getAttribute("response");
228 result = sw.getResult();
229 label1 = result.getBindingNames().get(0).toString();
230 label2 = result.getBindingNames().get(1).toString();%>
232 // Create the data table.
233 var data = new google.visualization.DataTable();
236 data.addColumn('string', <%=label1%>.);
237 data.addColumn('number', <%=label2%>);
239 <%
240 while(result.hasNext()){
241 BindingSet bindings = result.next();
242 %> data.addRow('string', <%=bindings.getValue(label1).toString()%>);
243 data.addRow('number', <%=Integer.parseInt(bindings.getValue(label2).toString())%>);
244 <% } %>
245 // Set chart options
246 var options = {'title':'Displaying results in chart',
247 'width':400,
248 'height':300};
250 // Instantiate and draw our chart, passing in some options.
251 var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
252 chart.draw(data, options);
254 <%}}%>
255 }
256 </script>
257 </head>
258 <body topmargin="0" leftmargin="0" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" onload="initialize()">
260 <!-- include TELEIOS header and description -->
261 <%@ include file="teleios-header.html"%>
262 <!-- include TELEIOS header and description -->
264 <FORM enctype="UTF-8" accept-charset="UTF-8" method="post" action="Query">
265 <INPUT type=hidden name="view" value="HTML"/>
267 <table border="0" width="100%">
268 <tr>
269 <td width="90" valign="top">
270 <table border="0" cellspacing="0" cellpadding="0" width="165">
271 <tr><td id="twidth">
272 <div class="container">
273 <div id="accordion">
274 <%
276 Iterator <StrabonBeanWrapperConfiguration> entryListIterator = strabonWrapper.getEntries().iterator();
277 boolean first = true;
278 String hash = "";
279 while(entryListIterator.hasNext())
280 {
281 StrabonBeanWrapperConfiguration entry = entryListIterator.next();
283 if (entry.isHeader()) {
284 if (!first) {
285 %>
286 </div></div>
287 <%
288 } else {
289 first = false;
290 }
292 String label=entry.getLabel();
293 String style = "", href = "";
294 hash = new Integer(Math.abs(label.hashCode())).toString();
295 href="href=\"#"+hash+"\"";
296 %>
297 <div><h3><a <%=style%> <%=href%>><%=label%></a></h3><div>
298 <%
299 } else if (entry.isBean()) {
300 String label=entry.getLabel();
301 String bean=entry.getBean();
302 if(bean.equals("browse.jsp") || bean.equals("ChangeConnection"))
303 continue;
304 String style = "", href = "";
305 hash = new Integer(Math.abs(label.hashCode()*bean.hashCode())).toString();
306 href = "\"" +bean + "#"+ hash+"\"";
307 style = "class=\"navText\"";
308 %>
309 <b>&middot;</b>&nbsp;<a class="linkText" href=<%=href%>><%=label%></a><br/>
310 <%
311 } else {
312 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)+"\"";
313 String title="\""+entry.getTitle()+"\"";
314 String label=entry.getLabel();
315 %>
316 <b>&middot;</b>&nbsp;<a class="linkText" href=<%=href%> title=<%=title%>><%=label%></a><br/>
317 <%
319 }
320 }
321 %>
322 </div>
323 </div>
324 </td>
325 </tr>
326 <!--
327 <tr><td width="90" class="style4"><a href="describe.jsp" class="navText">Describe</a></td></tr>
328 <tr><td width="90" class="style4"><a href="store.jsp" class="navText" title="Store triples">Store</a></td></tr>
329 -->
330 </table>
331 </td>
332 <td width="*" valign="top" >
333 <table cellspacing="5">
334 <%if (request.getAttribute("info") != null) { %>
335 <!-- Info Message -->
336 <TR><TD colspan=2>
337 <CENTER><P><%=request.getAttribute("info") %></P></CENTER>
338 </TD></TR>
339 <!-- Info Message -->
340 <%}%>
341 <tr>
342 <td id="output" colspan=2>
343 <div style="font-size:13px">
344 You must be logged in to perform update queries.
345 </div>
346 </td>
347 </tr>
348 <tr>
349 <td id="output" style="width: 150px">stSPARQL Query:</td>
350 <td id="output"><textarea name="query" title="pose your query/update here" rows="20" cols="100"><%=query%></textarea></td>
351 </tr>
352 <tr>
353 <td id="output">Output Format:</td>
354 <td id="output">
355 <select name="format" title="select one of the following output format types">
356 <%
357 for (String format : Common.registeredQueryResultsFormatNames) {%>
358 <OPTION value="<%=format%>"<%=format.equals(selFormat) ? "selected":""%>><%=format%></OPTION>
359 <%}%>
360 </select>
361 </td>
362 </tr>
363 <tr>
364 <td id="output">View Result:</td>
365 <td id="output">
366 <SELECT name="handle" title="select how you would like to view the result">
367 <OPTION value="plain"<%= ("plain".equals(handle)) ? "selected":""%>>Plain</OPTION>
368 <OPTION value="download"<%= ("download".equals(handle)) ? "selected":""%>>Download</OPTION>
369 <OPTION value="map"<%= ("map".equals(handle)) ? "selected":""%>>On a map</OPTION>
370 <OPTION value="map_local"<%= ("map_local".equals(handle)) ? "selected":""%>>On a map (localhost)</OPTION>
371 </SELECT>
372 </td>
373 </tr>
375 <tr>
376 <td colspan=2 id="output"><br/><center>
377 <input type="submit" title="execute query" value="Query" name="submit" style="width: 350px" />
378 <input type="submit" title="execute update" value="Update" name="submit" style="width: 350px"/></center><br/></td>
379 </tr>
381 <% if (request.getAttribute("error") != null) {%>
382 <!-- Error Message -->
383 <TR>
384 <TD id="output">Result: </TD><TD id="output"><%=request.getAttribute("error") %></TD>
385 </TR>
386 <!-- Error Message -->
387 <%}%>
388 </table></td></tr></table><br/><br/>
389 </form>
390 <a name="#results">&nbsp;</a>
391 <div id="divResultsStart"></div>
392 <!-- Response -->
393 <% if (request.getAttribute("response") != null) {
394 if (Common.getHTMLFormat().equals(request.getParameter("format"))) {%>
395 <%=request.getAttribute("response")%>
396 <%} else { %>
397 <PRE><%=request.getAttribute("response") %></PRE>
398 <%}%>
399 <%}%>
400 <!-- Response -->
401 <% if (request.getAttribute("pathToKML") != null) { %>
402 <div id="map_canvas"></div>
403 <%}%>
404 <div id="divResultsEnd" style="height: 1px; width 1px"></div>
405 </body>
406 </html>