Strabon

changeset 469:bbfa0a46c19d

describe functionality - output format remains to be if/elsed.. i think
author pico
date Thu Jul 19 23:30:09 2012 +0300 (2012-07-19)
parents c38041bfcb3d
children 920ebd41a1a3
files endpoint/WebContent/WEB-INF/beans.xml endpoint/WebContent/store.jsp endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.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	Wed Jul 18 18:51:27 2012 +0300
     1.2 +++ b/endpoint/WebContent/WEB-INF/beans.xml	Thu Jul 19 23:30:09 2012 +0300
     1.3 @@ -18,7 +18,7 @@
     1.4  
     1.5          <constructor-arg type="java.lang.String" >
     1.6              <!-- Database name -->
     1.7 -            <value>endpoint</value>
     1.8 +            <value>DLRstrabonv5</value>
     1.9          </constructor-arg>
    1.10  
    1.11          <constructor-arg type="java.lang.String" >
    1.12 @@ -28,7 +28,7 @@
    1.13  
    1.14          <constructor-arg type="java.lang.String" >
    1.15              <!-- Password -->
    1.16 -	    <value>postgres</value>
    1.17 +	    <value>brun1s86</value>
    1.18          </constructor-arg>
    1.19  
    1.20          <constructor-arg type="int" >
     2.1 --- a/endpoint/WebContent/store.jsp	Wed Jul 18 18:51:27 2012 +0300
     2.2 +++ b/endpoint/WebContent/store.jsp	Thu Jul 19 23:30:09 2012 +0300
     2.3 @@ -44,6 +44,7 @@
     2.4  	<td width="90" valign="top" bgcolor="#dfe8f0"> 
     2.5  		<TABLE border="0" cellspacing="0" cellpadding="0" width="165" id="navigation">
     2.6  			<tr><td width="90" class="style4"><a href="Query" class="navText">Query</a></td></tr> 
     2.7 +                        <tr><td width=\"90\" class=\"style4\"><a href=\"Describe\" class=\"navText\">Describe</a></td></tr>
     2.8  			<tr><td width="90" class="style4"><a href="javascript:history.go(0)" class="navText">Clear</a></td></tr> 
     2.9  		</TABLE>
    2.10  	</td>
    2.11 @@ -127,4 +128,4 @@
    2.12  </FORM>
    2.13  <br/><br/><br/><br/><br/>
    2.14  </BODY>
    2.15 -</HTML>
    2.16 \ No newline at end of file
    2.17 +</HTML>
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java	Wed Jul 18 18:51:27 2012 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/DescribeBean.java	Thu Jul 19 23:30:09 2012 +0300
     3.3 @@ -1,8 +1,23 @@
     3.4  package eu.earthobservatory.org.StrabonEndpoint;
     3.5  
     3.6 +import java.io.BufferedWriter;
     3.7 +import java.io.File;
     3.8 +import java.io.FileOutputStream;
     3.9 +import java.io.FileWriter;
    3.10  import java.io.IOException;
    3.11 -import java.net.MalformedURLException;
    3.12 -import java.util.ArrayList;
    3.13 +import java.io.PrintWriter;
    3.14 +import java.io.UnsupportedEncodingException;
    3.15 +import java.math.BigInteger;
    3.16 +import java.net.URLDecoder;
    3.17 +import java.net.URLEncoder;
    3.18 +import java.security.SecureRandom;
    3.19 +import java.util.Date;
    3.20 +import java.util.HashMap;
    3.21 +import java.util.Iterator;
    3.22 +import java.util.List;
    3.23 +import java.util.Map;
    3.24 +import java.util.zip.ZipEntry;
    3.25 +import java.util.zip.ZipOutputStream;
    3.26  
    3.27  import javax.servlet.ServletConfig;
    3.28  import javax.servlet.ServletContext;
    3.29 @@ -11,14 +26,19 @@
    3.30  import javax.servlet.http.HttpServletRequest;
    3.31  import javax.servlet.http.HttpServletResponse;
    3.32  
    3.33 -import org.openrdf.rio.RDFFormat;
    3.34 -import org.openrdf.rio.RDFParseException;
    3.35 +import org.apache.commons.io.FileUtils;
    3.36 +import org.openrdf.query.MalformedQueryException;
    3.37 +import org.openrdf.query.QueryEvaluationException;
    3.38 +import org.openrdf.query.TupleQueryResultHandlerException;
    3.39 +import org.openrdf.repository.RepositoryException;
    3.40  import org.slf4j.Logger;
    3.41  import org.slf4j.LoggerFactory;
    3.42  import org.springframework.web.context.WebApplicationContext;
    3.43  import org.springframework.web.context.support.WebApplicationContextUtils;
    3.44  
    3.45 -import java.io.PrintWriter;
    3.46 +import eu.earthobservatory.org.StrabonEndpoint.StrabonBeanWrapper.Entry;
    3.47 +import eu.earthobservatory.org.StrabonEndpoint.ResponseMessages;
    3.48 +import eu.earthobservatory.runtime.generaldb.Strabon;
    3.49  
    3.50  
    3.51  public class DescribeBean extends HttpServlet{
    3.52 @@ -33,67 +53,344 @@
    3.53  	*/
    3.54  	private StrabonBeanWrapper strabonWrapper;
    3.55  
    3.56 -        @Override
    3.57 -	public void init(ServletConfig servletConfig) throws ServletException {
    3.58 -		super.init(servletConfig);
    3.59 -		
    3.60 -		// get strabon wrapper
    3.61 -		ServletContext context = getServletContext();
    3.62 -		WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context);
    3.63 -		
    3.64 -		strabonWrapper = (StrabonBeanWrapper) applicationContext.getBean("strabonBean");
    3.65 -	}
    3.66 -
    3.67 -        @Override
    3.68 +    @Override
    3.69  	public void doGet(HttpServletRequest request, HttpServletResponse response)
    3.70  	throws ServletException, IOException 
    3.71  	{
    3.72  		doPost(request, response);
    3.73  	}
    3.74  
    3.75 -        @Override
    3.76 +    @Override
    3.77  	public void doPost(HttpServletRequest request, HttpServletResponse response)
    3.78  	throws ServletException, IOException
    3.79  	{
    3.80 +		final class DataHive{
    3.81 +			private String format;
    3.82 +			private String SPARQLQuery;
    3.83 +			private String errorMessage;
    3.84  
    3.85 -        	PrintWriter out = response.getWriter();
    3.86 -                out.println("Build a form or sth?");
    3.87 -        	out.flush();
    3.88 -        /*
    3.89 -        String[] args = NULL;
    3.90 +			DataHive(){
    3.91 +				this.format = null;
    3.92 +				this.SPARQLQuery = null;
    3.93 +				this.errorMessage = null;				
    3.94 +			}
    3.95  
    3.96 -	if (args.length < 7) {
    3.97 - 		out.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> <OUTPUT>");
    3.98 - 		out.println(" where <HOST> is the postgis database host to connect to");
    3.99 - 		out.println(" <PORT> is the port to connect to on the database host");
   3.100 - 		out.println(" <DATABASE> is the spatially enabled postgis database that Strabon will use as a backend, ");
   3.101 - 		out.println(" <USERNAME> is the username to use when connecting to the database ");
   3.102 - 		out.println(" <PASSWORD> is the password to use when connecting to the database");
   3.103 - 		out.println(" <QUERY> is the stSPARQL query to evaluate.");
   3.104 - 		out.println(" <OUTPUT> is the output file.");
   3.105 - 		System.exit(0);
   3.106 +			public String getSPARQLQuery() {
   3.107 +				return SPARQLQuery;
   3.108 +			}
   3.109 +
   3.110 +			public void setSPARQLQuery(String sPARQLQuery) {
   3.111 +				SPARQLQuery = sPARQLQuery;
   3.112 +			}
   3.113 +
   3.114 +			public String getFormat() {
   3.115 +				return format;
   3.116 +			}
   3.117 +
   3.118 +			public void setFormat(String fFormat) {
   3.119 +				format = fFormat;
   3.120 +			}
   3.121 +
   3.122 +			public String getErrorMessage() {
   3.123 +				return errorMessage;
   3.124 +			}
   3.125 +
   3.126 +			public void setErrorMessage(String error) {
   3.127 +				this.errorMessage = error;
   3.128 +			}
   3.129 +			
   3.130 +			public String toString() {
   3.131 +				return "Format: " + (this.format != null ? this.format : " NULL") + 
   3.132 +						", SPARQLQuery: " + (this.SPARQLQuery != null ? this.SPARQLQuery : " NULL") + 
   3.133 +						", errormessage: " + (this.errorMessage != null ? this.errorMessage : " NULL") + ".";
   3.134 + 			}
   3.135  		}
   3.136 -        else{
   3.137 +		
   3.138 +		request.setCharacterEncoding("UTF-8");
   3.139  
   3.140 -	String host = args[0];
   3.141 -	Integer port = new Integer(args[1]);
   3.142 -	String db = args[2];
   3.143 -	String user = args[3];
   3.144 -	String passwd = args[4];
   3.145 -	String queryString = args[5];
   3.146 -	String outFile = args[6];
   3.147 -        }
   3.148 +		DataHive hive = new DataHive(); 
   3.149  
   3.150 -	Strabon strabon = null;
   3.151 -	try {
   3.152 -  		strabon = new Strabon(db, user, passwd, port, host, true);
   3.153 -  		strabon.describe(queryString, strabon.getSailRepoConnection(), outFile);
   3.154 -	} catch (Exception e) {
   3.155 -		logger.error("[Strabon.DescribeOp] Error during execution of DESCRIBE query.", e);
   3.156 -	} finally {
   3.157 -		if (strabon != null) {
   3.158 -			strabon.close();
   3.159 +		String query = request.getParameter("SPARQLQuery");
   3.160 +		String q = (query == null) ? null : URLDecoder.decode(request.getParameter("SPARQLQuery"), "UTF-8");
   3.161 +
   3.162 +		if (query == null) {
   3.163 +	               query = request.getParameter("describe");
   3.164 +	               q = (query == null) ? null : URLDecoder.decode(request.getParameter("describe"), "UTF-8");
   3.165  		}
   3.166 -	}*/
   3.167 +			
   3.168 +		hive.setSPARQLQuery(q);
   3.169 +
   3.170 +		String reqFormat = (request.getParameter("format") == null) ? "" : request.getParameter("format");
   3.171 +		String reqAccept = (request.getHeader("accept") == null) ? "" : request.getHeader("accept");
   3.172 +		String reqFuncionality = (request.getParameter("submit") == null) ? "" : request.getParameter("submit");
   3.173 +		
   3.174 +
   3.175 +		if ((reqFormat == "") && (reqAccept == "")) {
   3.176 +			hive.setFormat("HTML");
   3.177 +			response.setContentType("text/html; charset=UTF-8");
   3.178 +			
   3.179 +	    } else if (reqAccept.contains("application/vnd.ms-excel")) {
   3.180 +		    response.setContentType("application/vnd.ms-excel");
   3.181 +		    hive.setFormat("Spreadsheet");		
   3.182 +	    } else if (reqAccept.contains("application/sparql-results+xml")) {
   3.183 +		    response.setContentType("application/sparql-results+xml");
   3.184 +		    hive.setFormat("XML");		
   3.185 +	    } else if (reqAccept.contains("application/sparql-results+json")) {
   3.186 +		    response.setContentType("application/sparql-results+json");
   3.187 +		    hive.setFormat("JSON");		
   3.188 +	    } else if (reqAccept.contains("application/javascript")) {
   3.189 +		    response.setContentType("application/javascript");
   3.190 +		    hive.setFormat("Javascript");		
   3.191 +	    } else if (reqAccept.contains("text/plain")) {
   3.192 +		    response.setContentType("text/plain");
   3.193 +		    hive.setFormat("NTriples");		
   3.194 +	    } else if (reqAccept.contains("application/rdf+xml")) {
   3.195 +		    response.setContentType("application/rdf+xml");
   3.196 +		    hive.setFormat("RDF/XML");		
   3.197 +	    } else if (reqAccept.contains("text/csv")) {
   3.198 +		    response.setContentType("text/csv");
   3.199 +		    hive.setFormat("CSV");		
   3.200 +	    } else if (reqAccept.contains("text/tab-separated-values")) {
   3.201 +		    response.setContentType("text/tab-separated-values");
   3.202 +		    hive.setFormat("TSV");		
   3.203 +	    }
   3.204 +		
   3.205 +
   3.206 +		PrintWriter out = response.getWriter();
   3.207 +                out.flush();
   3.208 +
   3.209 +
   3.210 +			appendHTML1a(out, "");
   3.211 +
   3.212 +			appendHTMLQ(out, strabonWrapper);
   3.213 +
   3.214 +			appendHTML1b(out);
   3.215 +
   3.216 +			if (hive.getSPARQLQuery() != null)
   3.217 +				out.write(hive.getSPARQLQuery());
   3.218 +
   3.219 +			appendHTML2(out, hive.getFormat());
   3.220 +
   3.221 +			String answer = "";
   3.222 +			if (hive.getSPARQLQuery() != null) {
   3.223 +				StringBuilder errorMessage = new StringBuilder ();
   3.224 +				answer = evaluateQuery(strabonWrapper, hive.getFormat(), reqFuncionality, hive.getSPARQLQuery(), errorMessage);
   3.225 +				hive.setErrorMessage(errorMessage.toString());
   3.226 +				if (hive.getErrorMessage() != null) {
   3.227 +					appendHTML3(out, hive.getErrorMessage());
   3.228 +				}
   3.229 +			}
   3.230 +
   3.231 +			out.append("</table></td></tr></table>");
   3.232 +			if (!answer.equals("")) {
   3.233 +				out.println("<style type=\"text/css\">");
   3.234 +				out.println("table.result    {border:1px solid #777777;}");
   3.235 +				out.println("table.result tr {border:1px dashed grey;}");
   3.236 +				out.println("table.result th {background-color:grey;color:black;}");
   3.237 +				out.println("</style>");
   3.238 +				out.println("<table class=\"result\">");
   3.239 +				out.append(answer);
   3.240 +				out.append("</table>");
   3.241 +			}
   3.242 +			appendHTML4(out);
   3.243 +			appendHTML5(out);
   3.244 +		}
   3.245 +	
   3.246 +
   3.247 +			
   3.248 +    @Override
   3.249 +	public void init(ServletConfig servletConfig) throws ServletException {
   3.250 +		super.init(servletConfig);
   3.251 +
   3.252 +		// get StrabonWrapper
   3.253 +		ServletContext context = getServletContext();
   3.254 +		WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context);
   3.255 +
   3.256 +		strabonWrapper = (StrabonBeanWrapper) applicationContext.getBean("strabonBean");
   3.257  	}
   3.258 -} 
   3.259 +
   3.260 +	public String evaluateQuery(StrabonBeanWrapper strabonWrapper, String resultFormat, String reqFunctionality, String SPARQLQuery, StringBuilder errorMessage) {		
   3.261 +		String answer = "";
   3.262 +
   3.263 +		try {
   3.264 +			if (SPARQLQuery == null) {
   3.265 +				answer = "";
   3.266 +			} else {
   3.267 +				answer = (String) strabonWrapper.describe(SPARQLQuery, resultFormat);
   3.268 +			}
   3.269 +		} catch (Exception e) {
   3.270 +			logger.error("[StrabonEndpoint.DescribeBean] Error during describing.", e);
   3.271 +			errorMessage.append(e.getMessage());
   3.272 +		}
   3.273 +
   3.274 +		return answer;		
   3.275 +	}
   3.276 +
   3.277 +	protected static void appendHTML1a(PrintWriter out, String pathToKML) {
   3.278 +		out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">");
   3.279 +		out.println("<html>");
   3.280 +		out.println("<head>");
   3.281 +		out.println("<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\" />");
   3.282 +		out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");		
   3.283 +		out.println("<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\" /> ");
   3.284 +		out.println("<style type=\"text/css\"> ");
   3.285 +		out.println("<!--");
   3.286 +		out.println(".style3 {font-size: 15px}");
   3.287 +		out.println(".style4 {font-size: 12px}");
   3.288 +		out.println(".style5 {font-size: 15px;font-weight: bold;}");
   3.289 +		out.println(".style6 {color: #FF0000}");
   3.290 +		out.println(".style7 {font-size: 14px}");
   3.291 +		out.println(" .hidden { visibility: hidden }");
   3.292 +		out.println("-->");
   3.293 +		out.println("</style> ");
   3.294 +		out.println("<title>TELEIOS: Strabon Endpoint</title>");
   3.295 +		out.println("</head>");
   3.296 +		out.println("<body topmargin=\"0\" leftmargin=\"0\" link=\"#FFFFFF\" vlink=\"#FFFFFF\" alink=\"#FFFFFF\" onload=\"initialize()\">");
   3.297 +		out.println("  <TABLE width=\"100%\" BORDER=0 CELLPADDING=0 CELLSPACING=0>");
   3.298 +		out.println("    <TR>");
   3.299 +		out.println("		");
   3.300 +		out.println("      <TD height=\"16\" background=\"images/pixi_white.gif\"><img src=\"images/pixi_white.gif\" width=\"16\" height=\"16\"></TD>");
   3.301 +		out.println("	</TR>");
   3.302 +		out.println("	<TR>");
   3.303 +		out.println("      <TD height=\"1\"></TD>");
   3.304 +		out.println("	</TR>		");
   3.305 +		out.println("	<TR>");
   3.306 +		out.println("      <TD height=\"60\" background=\"images/nav2_bg.gif\"> ");
   3.307 +		out.println("        <table width=\"100%\" border=\"0\">");
   3.308 +		out.println("         <tr>");
   3.309 +		out.println("            <td width=\"1\"><img src=\"images/nav2_bg.gif\" width=\"1\" height=\"60\"></td>");
   3.310 +		out.println("            <td valign=\"top\" width=\"80px\"><img border=\"0\" src=\"images/teleios_logo.png\" /></td>");
   3.311 +		out.println("            <td valign=\"top\" align=\"left\">");
   3.312 +		out.println("            <span class=\"logo\"> &nbsp stSPARQL Endpoint</span><br><span class=\"style4\"></span></td>");
   3.313 +		out.println("          </tr>");
   3.314 +		out.println("        </table> </TD>");
   3.315 +		out.println("	</TR>");
   3.316 +		out.println("	<TR>");
   3.317 +		out.println("      <TD height=\"50\" id=\"intro\">");
   3.318 +		out.println("On this page you can execute stSPARQL queries against the Strabon backend. " +
   3.319 +				"The dataset is based on  the following ontologies: " +
   3.320 +				"<a href=\"http://harmonisa.uni-klu.ac.at/content/land-use-land-cover-ontologies\" > Corine Land Cover </a>, " +
   3.321 +				"<a > Greek Administrative Geography(Kallikratis), </a>" +
   3.322 +				"<a href=\"http://labs.mondeca.com/dataset/lov/details/vocabulary_lgdo.html\" > Linked Geodata </a> " +
   3.323 +				" and <a href=\"http://www.geonames.org/search.html?q=ontology&country=\" >  geonames </a>." +
   3.324 +				"We also use the <a href=\"images/graph.png\">NOA ontology</a> we developed for the <a href=\"http://www.space.noa.gr/ \">NOA </a> use case of the European FP7 project " +
   3.325 +				"<a href=\"http://www.earthobservatory.eu/\" >TELEIOS </a>. ") ;
   3.326 +		out.println("<a onclick=\"return toggleMe('par')\" />(More) </a> <br>");
   3.327 +		out.println(" <p id=\"par\"> In this context NOA has been developing a real-time fire hotspot detection service for effectively monitoring a " +
   3.328 +				"fire-front. The technique is based on the use of acquisitions originating from the SEVIRI (Spinning Enhanced Visible and " +
   3.329 +				"Infrared Imager) sensor, on top of MSG-1 (Meteosat Second Generation satellite, renamed to Meteosat-8) and MSG-2 (renamed to " +
   3.330 +				"Meteosat-9) satellite platforms. Since 2007, NOA operates an MSG/SEVIRI acquisition station, and has been systematically archiving" +
   3.331 +				" raw satellite images on a 5 and 15 minutes basis, the respective temporal resolutions of MSG-1 and MSG-2. The acquired data are then annotated " +
   3.332 +				"using the stRDF model and can be queried using the stSPARQL query language. </p>  ");
   3.333 +		out.println("On the left sidebar, some example stSPARQL queries are provided. The NOA use case is described in more detail in the VLDB application paper " +
   3.334 +				"<a href=\"\"> here. </a> ");
   3.335 +		out.println("      </TD>");
   3.336 +		out.println("	</TR>");
   3.337 +		out.println("</TABLE>");
   3.338 +		out.println("<form " +
   3.339 +				"enctype=\"UTF-8\" " +
   3.340 +				"accept-charset=\"UTF-8\" "+
   3.341 +				"method=\"post\"" +
   3.342 +				">");
   3.343 +
   3.344 +		out.println("<table border=\"0\" width=\"100%\"><tr> ");
   3.345 +		out.println("<td width=\"90\" valign=\"top\" bgcolor=\"#dfe8f0\"> ");
   3.346 +		out.println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"165\" id=\"navigation\"> ");
   3.347 +		out.println("<tr><td width=\"90\" class=\"style4\"><a href=\"Query\" class=\"navText\">Query</a></td></tr> ");
   3.348 +                out.println("<tr><td width=\"90\" class=\"style4\"><a href=\"Describe\" class=\"navText\">Describe</a></td></tr> ");
   3.349 +	}
   3.350 +
   3.351 +	protected static void appendHTML1b(PrintWriter out) {	
   3.352 +		out.println("<tr><td width=\"90\" class=\"style4\"><a href=\"store.jsp\" class=\"navText\" title=\"Store triples\">Store</a></td></tr> ");;
   3.353 +		out.println("<tr><td width=\"90\" class=\"style4\"><a href=\"javascript:history.go(0)\" class=\"navText\" title=\"Clear editor\">Clear</a></td></tr> ");
   3.354 +		out.println("</table>");
   3.355 +		out.println("</td>");
   3.356 +		out.println("<td width=\"*\" valign=\"top\" >"); 
   3.357 +
   3.358 +		out.println("<table cellspacing=\"5\">");
   3.359 +		out.println("<tr>");
   3.360 +		out.println("<td id=\"output\" \">stSPARQL Query:</td>");
   3.361 +		out.println("<td id=\"output\" \"><textarea name=\"SPARQLQuery\" title=\"pose your query/update here\" rows=\"15\" cols=\"100\">");
   3.362 +	}
   3.363 +
   3.364 +	protected static void appendHTML2(PrintWriter out, String format) {
   3.365 +		out.println("</textarea></td>");
   3.366 +		out.println("</tr>");
   3.367 +		out.println("<tr>");
   3.368 +
   3.369 +		out.println("<td id=\"output\";\"><center>Output Format:<br/><select name=\"format\" title=\"select one of the following output format types\">");
   3.370 +		
   3.371 +		Map<String, String> selections = new HashMap<String, String>();
   3.372 +		selections.put("HTML", "HTML");
   3.373 +		selections.put("Spreadsheet", "Spreadsheet");
   3.374 +		selections.put("XML", "XML");
   3.375 +		selections.put("JSON", "JSON");
   3.376 +		selections.put("Javascript", "Javascript");
   3.377 +		selections.put("NTriples", "NTriples");
   3.378 +		selections.put("RDF/XML", "RDF/XML");
   3.379 +		selections.put("CSV", "CSV");
   3.380 +                selections.put("TSV", "TSV");
   3.381 +		
   3.382 +		Iterator <String> it = selections.keySet().iterator();
   3.383 +		
   3.384 +		while (it.hasNext()) {
   3.385 +			String key = it.next();
   3.386 +			String value = selections.get(key);
   3.387 +			out.print("<option ");
   3.388 +			if (key.equalsIgnoreCase(format))
   3.389 +				out.print("selected");
   3.390 +			
   3.391 +			out.println(" value=\"" + key + "\">" + value + "</option>");
   3.392 +		}
   3.393 +		
   3.394 +		out.println("</select></center></td>");
   3.395 +		out.println("<td colspan=2 \"><br/><center><input type=\"submit\" title=\"execute query\" value=\"Describe\" name=\"submit\" /></center><br/></td>");
   3.396 +		out.println("</tr>");
   3.397 +	}
   3.398 +
   3.399 +	protected static void appendHTML3(PrintWriter out, String errorMessage) {
   3.400 +		out.println("<tr>");
   3.401 +		out.println("<td id=\"output\" \">Result: </td>");
   3.402 +		out.println("<td id=\"output\" \">");
   3.403 +		out.println(errorMessage);
   3.404 +		out.println("</td>");
   3.405 +		out.println("</tr>");
   3.406 +	}
   3.407 +
   3.408 +	protected static void appendHTML4(PrintWriter out) {
   3.409 +		out.println("<br/><br/>");
   3.410 +		out.println("</form>");
   3.411 +	}
   3.412 +
   3.413 +	protected static void appendHTML5(PrintWriter out) {
   3.414 +		out.println("</body>");
   3.415 +		out.println("</html>");
   3.416 +	}
   3.417 +
   3.418 +	protected static void appendHTMLQ(PrintWriter out, StrabonBeanWrapper strabonWrapper) throws UnsupportedEncodingException {
   3.419 +		out.println("<tr><td id=\"twidth\">");
   3.420 +		List<Entry> entries = strabonWrapper.getEntries();
   3.421 +		Iterator<Entry> it = entries.iterator();
   3.422 +		while (it.hasNext()) {
   3.423 +			Entry entry = it.next();
   3.424 +			out.println(createLink(entry));
   3.425 +		}
   3.426 +		out.println("</td></tr> ");
   3.427 +	}
   3.428 +	
   3.429 +	private static String createLink(Entry entry) throws UnsupportedEncodingException {
   3.430 +		StringBuffer buf = new StringBuffer(1024);
   3.431 +		buf.append("<a href=\"");
   3.432 +		buf.append(entry.getBean());
   3.433 +		buf.append("?SPARQLQuery=");
   3.434 +		buf.append(URLEncoder.encode(entry.getStatement(), "UTF-8"));
   3.435 +		buf.append("&format=");
   3.436 +		buf.append(entry.getFormat()+"\"");
   3.437 +		buf.append("title="+"\""+entry.getTitle());
   3.438 +		buf.append("\">&nbsp;&middot;&nbsp;");
   3.439 +		buf.append(entry.getLabel());
   3.440 +		buf.append("</a><br/>");
   3.441 +		
   3.442 +		return buf.toString();
   3.443 +	}
   3.444 +}
     4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed Jul 18 18:51:27 2012 +0300
     4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Thu Jul 19 23:30:09 2012 +0300
     4.3 @@ -539,6 +539,7 @@
     4.4  		out.println("<td width=\"90\" valign=\"top\" bgcolor=\"#dfe8f0\"> ");
     4.5  		out.println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"165\" id=\"navigation\"> ");
     4.6  		out.println("<tr><td width=\"90\" class=\"style4\"><a href=\"Query\" class=\"navText\">Query</a></td></tr> ");
     4.7 +                out.println("<tr><td width=\"90\" class=\"style4\"><a href=\"Describe\" class=\"navText\">Describe</a></td></tr> ");
     4.8  	}
     4.9  
    4.10  	protected static void appendHTML1b(PrintWriter out) {	
     5.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Wed Jul 18 18:51:27 2012 +0300
     5.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Thu Jul 19 23:30:09 2012 +0300
     5.3 @@ -214,6 +214,21 @@
     5.4  		
     5.5  		return answer.toString();
     5.6  	}
     5.7 +	
     5.8 +	public String describe(String queryString, String answerFormatStrabon)
     5.9 +	throws MalformedQueryException, RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException, ClassNotFoundException {
    5.10 +		logger.info("[StrabonEndpoint] Received SELECT query.");
    5.11 +		if ((this.strabon == null) && (!init())) {
    5.12 +			throw new RepositoryException("Could not connect to Strabon.");
    5.13 +		} 
    5.14 +
    5.15 +		ByteArrayOutputStream answer = new ByteArrayOutputStream();
    5.16 +		
    5.17 +		strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), answer);
    5.18 +		
    5.19 +		return answer.toString();
    5.20 +	}
    5.21 +
    5.22  
    5.23  	public Object update(String updateString, String answerFormatStrabon) 
    5.24  	throws MalformedQueryException, RepositoryException, QueryEvaluationException,