Strabon

changeset 543:f7e99907a8f1

Now the HTML writer generates proper HTML code for tables. Strabon Endpoint displays an HTML table instead of the code for HTML tables.
Fixes Ticket #14: http://bug.strabon.di.uoa.gr/ticket/14
author Babis Nikolaou <charnik@di.uoa.gr>
date Fri Sep 14 13:28:45 2012 +0300 (2012-09-14)
parents 4f97fb6389a5
children 4ae6d7c860a5
files endpoint/WebContent/query.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java resultio/src/main/java/org/openrdf/query/resultio/sparqlhtml/stSPARQLResultsHTMLWriter.java
line diff
     1.1 --- a/endpoint/WebContent/query.jsp	Fri Sep 14 13:03:24 2012 +0300
     1.2 +++ b/endpoint/WebContent/query.jsp	Fri Sep 14 13:28:45 2012 +0300
     1.3 @@ -133,11 +133,15 @@
     1.4  <%}%>
     1.5  </table></td></tr></table><br/><br/>
     1.6  </form>
     1.7 -<% if (request.getAttribute("response") != null) {%>
     1.8  	<!-- Response -->
     1.9 +<% if (request.getAttribute("response") != null) {
    1.10 +	if (Common.getHTMLFormat().equals(request.getParameter("format"))) {%>
    1.11 +		<%=request.getAttribute("response")%>
    1.12 +	<%} else { %>
    1.13  	<PRE><%=request.getAttribute("response") %></PRE>
    1.14 +	<%}%>
    1.15 +<%}%>
    1.16  	<!-- Response -->
    1.17 -<%}%>
    1.18  <% if (request.getAttribute("pathToKML") != null) { %>
    1.19  	<div id="map_canvas"></div>
    1.20  <%}%>
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java	Fri Sep 14 13:03:24 2012 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java	Fri Sep 14 13:28:45 2012 +0300
     2.3 @@ -69,4 +69,8 @@
     2.4  			}
     2.5  		}
     2.6  	}
     2.7 +	
     2.8 +	public static final String getHTMLFormat() {
     2.9 +		return stSPARQLQueryResultFormat.HTML.getName();
    2.10 +	}
    2.11  }
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Fri Sep 14 13:03:24 2012 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Fri Sep 14 13:28:45 2012 +0300
     3.3 @@ -275,7 +275,11 @@
     3.4  					
     3.5  					try {
     3.6  						strabonWrapper.query(query, format, bos);
     3.7 -						request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString()));
     3.8 +						if (format.equals(Common.getHTMLFormat())) {
     3.9 +							request.setAttribute(RESPONSE, bos.toString());
    3.10 +						} else {
    3.11 +							request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString()));
    3.12 +						}
    3.13  						
    3.14  					} catch (Exception e) {
    3.15  						logger.error("[StrabonEndpoint.QueryBean] Error during querying.", e);
     4.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlhtml/stSPARQLResultsHTMLWriter.java	Fri Sep 14 13:03:24 2012 +0300
     4.2 +++ b/resultio/src/main/java/org/openrdf/query/resultio/sparqlhtml/stSPARQLResultsHTMLWriter.java	Fri Sep 14 13:28:45 2012 +0300
     4.3 @@ -2,7 +2,6 @@
     4.4  
     4.5  import java.io.IOException;
     4.6  import java.io.OutputStream;
     4.7 -import java.util.LinkedList;
     4.8  import java.util.List;
     4.9  
    4.10  import org.openrdf.model.BNode;
    4.11 @@ -20,6 +19,7 @@
    4.12   */
    4.13  public class stSPARQLResultsHTMLWriter implements TupleQueryResultWriter {
    4.14  
    4.15 +	public static final String TABLE			= "TABLE";
    4.16  	public static final String TABLE_ROW_TAG	= "TR";
    4.17  	public static final String TABLE_HEADER_TAG = "TH";
    4.18  	public static final String TABLE_DATA_TAG	= "TD";
    4.19 @@ -51,6 +51,9 @@
    4.20  			// keep the order of binding names
    4.21  			this.bindingNames = bindingNames;
    4.22  			
    4.23 +			// write start of table
    4.24 +			xmlWriter.startTag(TABLE);
    4.25 +			
    4.26  			// write Table header containing the bindings
    4.27  			xmlWriter.startTag(TABLE_ROW_TAG);
    4.28  			for (String bindingName: bindingNames) {
    4.29 @@ -67,6 +70,10 @@
    4.30  	@Override
    4.31  	public void endQueryResult() throws TupleQueryResultHandlerException {
    4.32  		try {
    4.33 +			
    4.34 +			// write end of table
    4.35 +			xmlWriter.endTag(TABLE);
    4.36 +						
    4.37  			// needed to flush data
    4.38  			xmlWriter.endDocument();
    4.39