Strabon

changeset 330:26fe4bcae66a

integrated Format enumeration type into Strabon. From now on, there are no String references to output formats, except for the command line.
author Babis Nikolaou <charnik@di.uoa.gr>
date Fri Jun 22 20:21:18 2012 +0300 (2012-06-22)
parents a449fcf2e56c
children f9c40e79fe8b
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java resultio/src/main/java/org/openrdf/query/resultio/sparqlxml/Format.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryDir.java runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryDir.java runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Fri Jun 22 19:56:58 2012 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java	Fri Jun 22 20:21:18 2012 +0300
     1.3 @@ -12,6 +12,7 @@
     1.4  import org.openrdf.query.MalformedQueryException;
     1.5  import org.openrdf.query.QueryEvaluationException;
     1.6  import org.openrdf.query.TupleQueryResultHandlerException;
     1.7 +import org.openrdf.query.resultio.sparqlxml.Format;
     1.8  import org.openrdf.repository.RepositoryException;
     1.9  import org.openrdf.repository.sail.SailRepositoryConnection;
    1.10  import org.openrdf.rio.RDFFormat;
    1.11 @@ -189,7 +190,7 @@
    1.12  
    1.13  		ByteArrayOutputStream answer = new ByteArrayOutputStream();
    1.14  		
    1.15 -		strabon.query(queryString, answerFormatStrabon, strabon.getSailRepoConnection(), answer);
    1.16 +		strabon.query(queryString, Format.fromString(answerFormatStrabon), strabon.getSailRepoConnection(), answer);
    1.17  		
    1.18  		return answer.toString();
    1.19  	}
     2.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlxml/Format.java	Fri Jun 22 19:56:58 2012 +0300
     2.2 +++ b/resultio/src/main/java/org/openrdf/query/resultio/sparqlxml/Format.java	Fri Jun 22 20:21:18 2012 +0300
     2.3 @@ -45,7 +45,12 @@
     2.4  	/**
     2.5  	 * HTML format
     2.6  	 */
     2.7 -	HTML("HTML");
     2.8 +	HTML("HTML"),
     2.9 +	
    2.10 +	/**
    2.11 +	 * Invalid format.
    2.12 +	 */
    2.13 +	INVALID("INVALID");
    2.14  	
    2.15  	/**
    2.16  	 * The string representation of this format
    2.17 @@ -60,7 +65,9 @@
    2.18  	
    2.19  	static { // initialize map from constant name to enum constant
    2.20  		for (Format format : values()) {
    2.21 +			// add both upper- and lower-case versions of the format 
    2.22  			stringToEnum.put(format.toString(), format);
    2.23 +			stringToEnum.put(format.toString().toLowerCase(), format);
    2.24  		}
    2.25  	}
    2.26  	
    2.27 @@ -79,12 +86,12 @@
    2.28  	}
    2.29  	
    2.30  	/**
    2.31 -	 * Returns a Format enum given a language string.
    2.32 +	 * Returns a Format enum given a format string.
    2.33  	 * 
    2.34  	 * @param lang
    2.35  	 * @return
    2.36  	 */
    2.37 -	public static Format fromString(String lang) {
    2.38 -		return stringToEnum.get(lang);
    2.39 +	public static Format fromString(String format) {
    2.40 +		return (stringToEnum.get(format) == null) ? INVALID:stringToEnum.get(format);
    2.41  	}
    2.42  }
     3.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Jun 22 19:56:58 2012 +0300
     3.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Fri Jun 22 20:21:18 2012 +0300
     3.3 @@ -44,6 +44,7 @@
     3.4  import org.openrdf.query.Update;
     3.5  import org.openrdf.query.UpdateExecutionException;
     3.6  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
     3.7 +import org.openrdf.query.resultio.sparqlxml.Format;
     3.8  import org.openrdf.query.resultio.sparqlxml.stSPARQLResultsKMLWriter;
     3.9  import org.openrdf.query.resultio.sparqlxml.stSPARQLResultsXMLWriter;
    3.10  import org.openrdf.repository.RepositoryException;
    3.11 @@ -187,10 +188,10 @@
    3.12  
    3.13  	public Object query(String queryString, OutputStream out)
    3.14  	throws  MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException {
    3.15 -		return query(queryString, "", this.getSailRepoConnection(), out);	
    3.16 +		return query(queryString, Format.DEFAULT, this.getSailRepoConnection(), out);	
    3.17  	}
    3.18  
    3.19 -	public Object query(String queryString, String resultsFormat, OutputStream out)
    3.20 +	public Object query(String queryString, Format resultsFormat, OutputStream out)
    3.21  	throws  MalformedQueryException , QueryEvaluationException, IOException, TupleQueryResultHandlerException {
    3.22  		return query(queryString, resultsFormat, this.getSailRepoConnection(), out);
    3.23  	}
    3.24 @@ -218,7 +219,7 @@
    3.25  		return ret;	
    3.26  	}
    3.27  
    3.28 -	public Object query(String queryString, String resultsFormat, SailRepositoryConnection con, OutputStream out)
    3.29 +	public Object query(String queryString, Format resultsFormat, SailRepositoryConnection con, OutputStream out)
    3.30  	throws MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException {
    3.31  		boolean status = true;
    3.32  		
    3.33 @@ -238,289 +239,301 @@
    3.34  			logger.error("[Strabon.query] Error in preparing tuple query.", e);
    3.35  			status = false;
    3.36  		}
    3.37 +		
    3.38 +		TupleQueryResult result = null;
    3.39 +		
    3.40 +		switch (resultsFormat) {
    3.41 +			case DEFAULT:
    3.42 +				
    3.43 +				result = tupleQuery.evaluate();
    3.44 +				while (result.hasNext()) {
    3.45 +					BindingSet bindingSet = result.next();
    3.46 +					
    3.47 +					writeString(out, bindingSet.toString());
    3.48 +					writeString(out, NEWLINE);
    3.49 +				}
    3.50  
    3.51 -		if (FORMAT_EXP.equalsIgnoreCase(resultsFormat)) {
    3.52 -			long results = 0;
    3.53 -			
    3.54 -			long t1 = System.nanoTime();
    3.55 -			TupleQueryResult result = tupleQuery.evaluate();
    3.56 -			long t2 = System.nanoTime();
    3.57 -			
    3.58 -			while (result.hasNext()) {
    3.59 -				results++;
    3.60 -			}
    3.61 -			
    3.62 -			long t3 = System.nanoTime();
    3.63 +				break;
    3.64 +				
    3.65 +			case EXP:
    3.66 +				long results = 0;
    3.67 +				
    3.68 +				long t1 = System.nanoTime();
    3.69 +				result = tupleQuery.evaluate();
    3.70 +				long t2 = System.nanoTime();
    3.71 +				
    3.72 +				while (result.hasNext()) {
    3.73 +					results++;
    3.74 +				}
    3.75 +				
    3.76 +				long t3 = System.nanoTime();
    3.77 +	
    3.78 +				//return new long[]{t2-t1, t3-t2, t3-t1, results};
    3.79 +				break;
    3.80 +				
    3.81 +			case XML:
    3.82 +				if (logger.isDebugEnabled()) {
    3.83 +					logger.debug("Serializing results (XML)");
    3.84 +				}
    3.85 +				
    3.86 +				tupleQuery.evaluate(new stSPARQLResultsXMLWriter(out));
    3.87 +				break;
    3.88 +				
    3.89 +			case KML:
    3.90 +				if (logger.isDebugEnabled()) {
    3.91 +					logger.debug("Serializing results (KML)");
    3.92 +				}
    3.93  
    3.94 -			//return new long[]{t2-t1, t3-t2, t3-t1, results};
    3.95 -			
    3.96 -		} else if (FORMAT_DEFAULT.equalsIgnoreCase(resultsFormat)) {
    3.97 -			
    3.98 -			TupleQueryResult result = null;
    3.99 -			result = tupleQuery.evaluate();
   3.100 +				tupleQuery.evaluate(new stSPARQLResultsKMLWriter(out));
   3.101 +				
   3.102 +				break;
   3.103 +				
   3.104 +			case KMZ:
   3.105 +				// create a zip entry
   3.106 +				ZipEntry entry = new ZipEntry("sparql_results.kml");
   3.107 +				
   3.108 +				// create a zip stream on standard output
   3.109 +				ZipOutputStream kmzout = new ZipOutputStream(out);
   3.110 +				
   3.111 +				// add the zip entry in it
   3.112 +				kmzout.putNextEntry(entry);
   3.113 +				
   3.114 +				// pass the zip stream for evaluation
   3.115 +				tupleQuery.evaluate(new stSPARQLResultsKMLWriter(kmzout));
   3.116  
   3.117 -			while (result.hasNext()) {
   3.118 -				BindingSet bindingSet = result.next();
   3.119 +				// close the zip entry
   3.120 +				kmzout.closeEntry();
   3.121  				
   3.122 -				writeString(out, bindingSet.toString());
   3.123 +				// close the zip stream
   3.124 +				kmzout.close();
   3.125 +				break;
   3.126 +				
   3.127 +			case GEOJSON:
   3.128 +
   3.129 +				DataOutputStream dos = new DataOutputStream(out);
   3.130 +	
   3.131 +				try {
   3.132 +					result = tupleQuery.evaluate();
   3.133 +					
   3.134 +				} catch (QueryEvaluationException e) {
   3.135 +					logger.error("[Strabon.query] Error during query evaluation.", e);
   3.136 +					status = false;
   3.137 +					
   3.138 +					return status;
   3.139 +				}
   3.140 +	
   3.141 +				int resultsCounter = 0;
   3.142 +	
   3.143 +				//Setting a Feature Collection
   3.144 +				SimpleFeatureCollection sfCollection = FeatureCollections.newCollection("geomOutput");
   3.145 +	
   3.146 +				int spatialBindingsNo=0;
   3.147 +	
   3.148 +				//May not need that much - still initializing it
   3.149 +				String[] spatialBindings = new String[result.getBindingNames().size()];
   3.150 +				SimpleFeatureTypeBuilder[] tb = new SimpleFeatureTypeBuilder[result.getBindingNames().size()];
   3.151 +	
   3.152 +				for(int i=0;i<result.getBindingNames().size();i++)
   3.153 +				{
   3.154 +					tb[i] = new SimpleFeatureTypeBuilder(); 
   3.155 +				}
   3.156 +	
   3.157 +				BindingSet bindingSet;
   3.158 +				if(result.hasNext())
   3.159 +				{
   3.160 +					//Sneak Peek to obtain info on which bindings are spatial
   3.161 +					bindingSet = result.next();
   3.162 +					boolean spatial = false;
   3.163 +					for(String bindingName : bindingSet.getBindingNames())
   3.164 +					{
   3.165 +						Value val = bindingSet.getValue(bindingName);
   3.166 +	
   3.167 +						if(val instanceof RdbmsLiteral)
   3.168 +						{
   3.169 +							if(((RdbmsLiteral) val).getDatatype()!=null)
   3.170 +							{
   3.171 +								if(((RdbmsLiteral) val).getDatatype().toString().equals(StrabonPolyhedron.ogcGeometry))
   3.172 +								{
   3.173 +									spatial = true;
   3.174 +								}
   3.175 +							}
   3.176 +						}
   3.177 +	
   3.178 +						if(val instanceof GeneralDBPolyhedron)
   3.179 +						{
   3.180 +							spatial = true;
   3.181 +	
   3.182 +						}
   3.183 +	
   3.184 +						if(spatial)
   3.185 +						{
   3.186 +							spatial = false;
   3.187 +							spatialBindings[spatialBindingsNo] = bindingName;
   3.188 +							spatialBindingsNo++;
   3.189 +						}
   3.190 +					}
   3.191 +	
   3.192 +				} else {
   3.193 +					return status;//empty
   3.194 +				}
   3.195 +	
   3.196 +				boolean firstLineParsed = false;
   3.197 +	
   3.198 +				do {
   3.199 +					if(firstLineParsed)
   3.200 +					{
   3.201 +						bindingSet = result.next();
   3.202 +					}
   3.203 +	
   3.204 +					firstLineParsed = true;
   3.205 +	
   3.206 +					//How many features will occur from a single result? --> spatialBindingsNo
   3.207 +					for(int i=0; i<spatialBindingsNo;i++)
   3.208 +					{
   3.209 +						tb[i].setName("Feature_"+(++resultsCounter));
   3.210 +	
   3.211 +						//Every time a featureType is built, the builder is nullified!!
   3.212 +						//Can't avoid re-iterating...
   3.213 +						for(String otherBinding : bindingSet.getBindingNames())
   3.214 +						{
   3.215 +							if(!otherBinding.equals(spatialBindings[i]))
   3.216 +							{
   3.217 +								tb[i].add(otherBinding,String.class);
   3.218 +							}
   3.219 +						}
   3.220 +	
   3.221 +	
   3.222 +						int SRID=4326;
   3.223 +						Geometry geom = null;
   3.224 +						Value unparsedGeometry = bindingSet.getValue(spatialBindings[i]);
   3.225 +						//Regardless of our geometry's input, we need its SRID
   3.226 +						if(unparsedGeometry instanceof GeneralDBPolyhedron)
   3.227 +						{
   3.228 +							geom = ((GeneralDBPolyhedron) unparsedGeometry).getPolyhedron().getGeometry();
   3.229 +							SRID = ((GeneralDBPolyhedron) unparsedGeometry).getPolyhedron().getGeometry().getSRID();
   3.230 +						}
   3.231 +						else //RdbmsLiteral
   3.232 +							//TODO GML support to be added
   3.233 +						{
   3.234 +							String unparsedWKT = ((RdbmsLiteral)unparsedGeometry).getLabel();
   3.235 +							try {
   3.236 +								int pos = unparsedWKT.indexOf(";");
   3.237 +								if(pos!=-1)
   3.238 +								{
   3.239 +									geom = new WKTReader().read(unparsedWKT.substring(0,pos));
   3.240 +									int whereToCut = unparsedWKT.lastIndexOf('/');
   3.241 +									SRID = Integer.parseInt(unparsedWKT.substring(whereToCut+1));
   3.242 +								}
   3.243 +								else
   3.244 +								{
   3.245 +									geom = new WKTReader().read(unparsedWKT);
   3.246 +									SRID=4326;
   3.247 +								}
   3.248 +	
   3.249 +							} 
   3.250 +							catch (ParseException e) {
   3.251 +								logger.error("[Strabon.query] Faults detected in spatial literal representation.", e);
   3.252 +								status = false;
   3.253 +							}
   3.254 +						}
   3.255 +	
   3.256 +						CoordinateReferenceSystem geomCRS = null;
   3.257 +						try {
   3.258 +							geomCRS = CRS.decode("EPSG:"+SRID);
   3.259 +							
   3.260 +						} catch (NoSuchAuthorityCodeException e) {
   3.261 +							logger.error("[Strabon.query] Error decoding returned geometry's SRID", e);
   3.262 +							status = false;
   3.263 +							
   3.264 +							return status;
   3.265 +						} catch (FactoryException e) {
   3.266 +							logger.error("[Strabon.query]", e);
   3.267 +							status = false;
   3.268 +							
   3.269 +							return status;
   3.270 +						}
   3.271 +	
   3.272 +						tb[i].setCRS(geomCRS);
   3.273 +						tb[i].setSRS("EPSG:" + SRID);
   3.274 +						tb[i].add("geometry", Geometry.class);
   3.275 +	
   3.276 +						SimpleFeatureType featureType = tb[i].buildFeatureType();
   3.277 +						SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
   3.278 +	
   3.279 +						for(String otherBinding : bindingSet.getBindingNames())
   3.280 +						{
   3.281 +							if(!otherBinding.equals(spatialBindings[i]))
   3.282 +							{
   3.283 +								featureBuilder.add(bindingSet.getValue(otherBinding));
   3.284 +							}
   3.285 +						}
   3.286 +	
   3.287 +						featureBuilder.add(geom);
   3.288 +	
   3.289 +	
   3.290 +						SimpleFeature feature = featureBuilder.buildFeature(null);
   3.291 +						sfCollection.add(feature);
   3.292 +					}
   3.293 +	
   3.294 +				}
   3.295 +				
   3.296 +				while((result.hasNext()));
   3.297 +	
   3.298 +				FeatureJSON fjson = new FeatureJSON();
   3.299 +				fjson.setEncodeFeatureCRS(true);
   3.300 +				fjson.writeFeatureCollection(sfCollection, dos);
   3.301  				writeString(out, NEWLINE);
   3.302 -			}
   3.303 -			
   3.304 -		} else if (FORMAT_XML.equalsIgnoreCase(resultsFormat)) {
   3.305 -			if (logger.isDebugEnabled()) {
   3.306 -				logger.debug("Serializing results (XML)");
   3.307 -			}
   3.308 -			
   3.309 -			tupleQuery.evaluate(new stSPARQLResultsXMLWriter(out));
   3.310 -			
   3.311 -		} else if (FORMAT_KML.equalsIgnoreCase(resultsFormat)) {
   3.312 -			if (logger.isDebugEnabled()) {
   3.313 -				logger.debug("Serializing results (KML/KMZ)");
   3.314 -			}
   3.315 +				
   3.316 +				break;
   3.317  
   3.318 -			tupleQuery.evaluate(new stSPARQLResultsKMLWriter(out));
   3.319 -			
   3.320 -		} else if (FORMAT_KMZ.equalsIgnoreCase(resultsFormat)) {
   3.321 -			// create a zip entry
   3.322 -			ZipEntry entry = new ZipEntry("sparql_results.kml");
   3.323 -			
   3.324 -			// create a zip stream on standard output
   3.325 -			ZipOutputStream kmzout = new ZipOutputStream(out);
   3.326 -			
   3.327 -			// add the zip entry in it
   3.328 -			kmzout.putNextEntry(entry);
   3.329 -			
   3.330 -			// pass the zip stream for evaluation
   3.331 -			tupleQuery.evaluate(new stSPARQLResultsKMLWriter(kmzout));
   3.332 -
   3.333 -			// close the zip entry
   3.334 -			kmzout.closeEntry();
   3.335 -			
   3.336 -			// close the zip stream
   3.337 -			kmzout.close();
   3.338 -			
   3.339 -		} else if (FORMAT_GEOJSON.equalsIgnoreCase(resultsFormat)) {
   3.340 -
   3.341 -			DataOutputStream dos = new DataOutputStream(out);
   3.342 -
   3.343 -			TupleQueryResult result = null;
   3.344 -			try {
   3.345 +			case HTML:
   3.346 +		
   3.347  				result = tupleQuery.evaluate();
   3.348  				
   3.349 -			} catch (QueryEvaluationException e) {
   3.350 -				logger.error("[Strabon.query] Error during query evaluation.", e);
   3.351 -				status = false;
   3.352 -				
   3.353 -				return status;
   3.354 -			}
   3.355 -
   3.356 -			int resultsCounter = 0;
   3.357 -
   3.358 -			//Setting a Feature Collection
   3.359 -			SimpleFeatureCollection sfCollection = FeatureCollections.newCollection("geomOutput");
   3.360 -
   3.361 -			int spatialBindingsNo=0;
   3.362 -
   3.363 -			//May not need that much - still initializing it
   3.364 -			String[] spatialBindings = new String[result.getBindingNames().size()];
   3.365 -			SimpleFeatureTypeBuilder[] tb = new SimpleFeatureTypeBuilder[result.getBindingNames().size()];
   3.366 -
   3.367 -			for(int i=0;i<result.getBindingNames().size();i++)
   3.368 -			{
   3.369 -				tb[i] = new SimpleFeatureTypeBuilder(); 
   3.370 -			}
   3.371 -
   3.372 -			BindingSet bindingSet;
   3.373 -			if(result.hasNext())
   3.374 -			{
   3.375 -				//Sneak Peek to obtain info on which bindings are spatial
   3.376 -				bindingSet = result.next();
   3.377 -				boolean spatial = false;
   3.378 -				for(String bindingName : bindingSet.getBindingNames())
   3.379 -				{
   3.380 -					Value val = bindingSet.getValue(bindingName);
   3.381 -
   3.382 -					if(val instanceof RdbmsLiteral)
   3.383 -					{
   3.384 -						if(((RdbmsLiteral) val).getDatatype()!=null)
   3.385 -						{
   3.386 -							if(((RdbmsLiteral) val).getDatatype().toString().equals(StrabonPolyhedron.ogcGeometry))
   3.387 -							{
   3.388 -								spatial = true;
   3.389 -							}
   3.390 +				if (result.hasNext()) {
   3.391 +					BindingSet set = result.next();
   3.392 +					Set<String> bindingNames = set.getBindingNames();			
   3.393 +					writeString(out, "<tr>");
   3.394 +					for (String bindingName: bindingNames) {
   3.395 +						writeString(out, "<th>");
   3.396 +						writeString(out, bindingName);
   3.397 +						writeString(out, "</th>");
   3.398 +					}
   3.399 +					
   3.400 +					writeString(out, "</tr>");
   3.401 +					writeString(out, "<tr>");
   3.402 +	
   3.403 +					for (String bindingName: bindingNames) {
   3.404 +						writeString(out, "<td>");
   3.405 +						writeString(out, set.getValue(bindingName).stringValue());
   3.406 +						writeString(out, "</td>");
   3.407 +					}
   3.408 +					writeString(out, "</tr>");
   3.409 +	
   3.410 +	
   3.411 +					while (result.hasNext()) {
   3.412 +						writeString(out, "<tr>");
   3.413 +						BindingSet bindingSet1 = result.next();
   3.414 +	
   3.415 +						for (String bindingName: bindingNames) {
   3.416 +							writeString(out, "<td>");
   3.417 +							Binding binding = bindingSet1.getBinding(bindingName); 
   3.418 +							if (binding != null) {
   3.419 +								Value val = binding.getValue();
   3.420 +								writeString(out, val.stringValue());
   3.421 +							}					
   3.422 +							writeString(out, "</td>");
   3.423  						}
   3.424 +	
   3.425 +						writeString(out, "</tr>");
   3.426  					}
   3.427 -
   3.428 -					if(val instanceof GeneralDBPolyhedron)
   3.429 -					{
   3.430 -						spatial = true;
   3.431 -
   3.432 -					}
   3.433 -
   3.434 -					if(spatial)
   3.435 -					{
   3.436 -						spatial = false;
   3.437 -						spatialBindings[spatialBindingsNo] = bindingName;
   3.438 -						spatialBindingsNo++;
   3.439 -					}
   3.440 -				}
   3.441 -
   3.442 -			} else {
   3.443 -				return status;//empty
   3.444 -			}
   3.445 -
   3.446 -			boolean firstLineParsed = false;
   3.447 -
   3.448 -			do {
   3.449 -				if(firstLineParsed)
   3.450 -				{
   3.451 -					bindingSet = result.next();
   3.452 -				}
   3.453 -
   3.454 -				firstLineParsed = true;
   3.455 -
   3.456 -				//How many features will occur from a single result? --> spatialBindingsNo
   3.457 -				for(int i=0; i<spatialBindingsNo;i++)
   3.458 -				{
   3.459 -					tb[i].setName("Feature_"+(++resultsCounter));
   3.460 -
   3.461 -					//Every time a featureType is built, the builder is nullified!!
   3.462 -					//Can't avoid re-iterating...
   3.463 -					for(String otherBinding : bindingSet.getBindingNames())
   3.464 -					{
   3.465 -						if(!otherBinding.equals(spatialBindings[i]))
   3.466 -						{
   3.467 -							tb[i].add(otherBinding,String.class);
   3.468 -						}
   3.469 -					}
   3.470 -
   3.471 -
   3.472 -					int SRID=4326;
   3.473 -					Geometry geom = null;
   3.474 -					Value unparsedGeometry = bindingSet.getValue(spatialBindings[i]);
   3.475 -					//Regardless of our geometry's input, we need its SRID
   3.476 -					if(unparsedGeometry instanceof GeneralDBPolyhedron)
   3.477 -					{
   3.478 -						geom = ((GeneralDBPolyhedron) unparsedGeometry).getPolyhedron().getGeometry();
   3.479 -						SRID = ((GeneralDBPolyhedron) unparsedGeometry).getPolyhedron().getGeometry().getSRID();
   3.480 -					}
   3.481 -					else //RdbmsLiteral
   3.482 -						//TODO GML support to be added
   3.483 -					{
   3.484 -						String unparsedWKT = ((RdbmsLiteral)unparsedGeometry).getLabel();
   3.485 -						try {
   3.486 -							int pos = unparsedWKT.indexOf(";");
   3.487 -							if(pos!=-1)
   3.488 -							{
   3.489 -								geom = new WKTReader().read(unparsedWKT.substring(0,pos));
   3.490 -								int whereToCut = unparsedWKT.lastIndexOf('/');
   3.491 -								SRID = Integer.parseInt(unparsedWKT.substring(whereToCut+1));
   3.492 -							}
   3.493 -							else
   3.494 -							{
   3.495 -								geom = new WKTReader().read(unparsedWKT);
   3.496 -								SRID=4326;
   3.497 -							}
   3.498 -
   3.499 -						} 
   3.500 -						catch (ParseException e) {
   3.501 -							logger.error("[Strabon.query] Faults detected in spatial literal representation.", e);
   3.502 -							status = false;
   3.503 -						}
   3.504 -					}
   3.505 -
   3.506 -					CoordinateReferenceSystem geomCRS = null;
   3.507 -					try {
   3.508 -						geomCRS = CRS.decode("EPSG:"+SRID);
   3.509 -						
   3.510 -					} catch (NoSuchAuthorityCodeException e) {
   3.511 -						logger.error("[Strabon.query] Error decoding returned geometry's SRID", e);
   3.512 -						status = false;
   3.513 -						
   3.514 -						return status;
   3.515 -					} catch (FactoryException e) {
   3.516 -						logger.error("[Strabon.query]", e);
   3.517 -						status = false;
   3.518 -						
   3.519 -						return status;
   3.520 -					}
   3.521 -
   3.522 -					tb[i].setCRS(geomCRS);
   3.523 -					tb[i].setSRS("EPSG:" + SRID);
   3.524 -					tb[i].add("geometry", Geometry.class);
   3.525 -
   3.526 -					SimpleFeatureType featureType = tb[i].buildFeatureType();
   3.527 -					SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType);
   3.528 -
   3.529 -					for(String otherBinding : bindingSet.getBindingNames())
   3.530 -					{
   3.531 -						if(!otherBinding.equals(spatialBindings[i]))
   3.532 -						{
   3.533 -							featureBuilder.add(bindingSet.getValue(otherBinding));
   3.534 -						}
   3.535 -					}
   3.536 -
   3.537 -					featureBuilder.add(geom);
   3.538 -
   3.539 -
   3.540 -					SimpleFeature feature = featureBuilder.buildFeature(null);
   3.541 -					sfCollection.add(feature);
   3.542 -				}
   3.543 -
   3.544 -			}
   3.545 -			
   3.546 -			while((result.hasNext()));
   3.547 -
   3.548 -			FeatureJSON fjson = new FeatureJSON();
   3.549 -			fjson.setEncodeFeatureCRS(true);
   3.550 -			fjson.writeFeatureCollection(sfCollection, dos);
   3.551 -			writeString(out, NEWLINE);
   3.552 -
   3.553 -		} else if(FORMAT_HTML.equalsIgnoreCase(resultsFormat)) {
   3.554 -			TupleQueryResult result = tupleQuery.evaluate();
   3.555 -			
   3.556 -			if (result.hasNext()) {
   3.557 -				BindingSet set = result.next();
   3.558 -				Set<String> bindingNames = set.getBindingNames();			
   3.559 -				writeString(out, "<tr>");
   3.560 -				for (String bindingName: bindingNames) {
   3.561 -					writeString(out, "<th>");
   3.562 -					writeString(out, bindingName);
   3.563 -					writeString(out, "</th>");
   3.564 +					writeString(out, NEWLINE);
   3.565  				}
   3.566  				
   3.567 -				writeString(out, "</tr>");
   3.568 -				writeString(out, "<tr>");
   3.569 -
   3.570 -				for (String bindingName: bindingNames) {
   3.571 -					writeString(out, "<td>");
   3.572 -					writeString(out, set.getValue(bindingName).stringValue());
   3.573 -					writeString(out, "</td>");
   3.574 -				}
   3.575 -				writeString(out, "</tr>");
   3.576 -
   3.577 -
   3.578 -				while (result.hasNext()) {
   3.579 -					writeString(out, "<tr>");
   3.580 -					BindingSet bindingSet = result.next();
   3.581 -
   3.582 -					for (String bindingName: bindingNames) {
   3.583 -						writeString(out, "<td>");
   3.584 -						Binding binding = bindingSet.getBinding(bindingName); 
   3.585 -						if (binding != null) {
   3.586 -							Value val = binding.getValue();
   3.587 -							writeString(out, val.stringValue());
   3.588 -						}					
   3.589 -						writeString(out, "</td>");
   3.590 -					}
   3.591 -
   3.592 -					writeString(out, "</tr>");
   3.593 -				}
   3.594 -				writeString(out, NEWLINE);
   3.595 -			}
   3.596 +				break;
   3.597  			
   3.598 -		} else {
   3.599 -			logger.warn("[Strabon.query] No such format available \"" + resultsFormat + "\".");
   3.600 +		default:
   3.601 +			logger.warn("[Strabon.query] Invalid format.");
   3.602  			status = false;
   3.603  		}
   3.604  
     4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryDir.java	Fri Jun 22 19:56:58 2012 +0300
     4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryDir.java	Fri Jun 22 20:21:18 2012 +0300
     4.3 @@ -6,6 +6,7 @@
     4.4  import java.io.FilenameFilter;
     4.5  import java.io.IOException;
     4.6  
     4.7 +import org.openrdf.query.resultio.sparqlxml.Format;
     4.8  import org.slf4j.Logger;
     4.9  import org.slf4j.LoggerFactory;
    4.10  
    4.11 @@ -62,7 +63,7 @@
    4.12  					String filename = children[i];
    4.13  					try {
    4.14  						String queryString = readFile(path + System.getProperty("file.separator") + filename);
    4.15 -						strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection(), System.out);
    4.16 +						strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out);
    4.17  						
    4.18  					} catch (IOException e) {
    4.19  						logger.error("[Strabon.QueryDir] IOException while reading " + filename, e);
     5.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java	Fri Jun 22 19:56:58 2012 +0300
     5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java	Fri Jun 22 20:21:18 2012 +0300
     5.3 @@ -1,5 +1,6 @@
     5.4  package eu.earthobservatory.runtime.monetdb;
     5.5  
     5.6 +import org.openrdf.query.resultio.sparqlxml.Format;
     5.7  import org.slf4j.Logger;
     5.8  import org.slf4j.LoggerFactory;
     5.9  
    5.10 @@ -39,7 +40,7 @@
    5.11  		Strabon strabon = null;
    5.12  		try {
    5.13  			strabon = new Strabon(db, user, passwd, port, host, true);
    5.14 -			strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection(), System.out);
    5.15 +			strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out);
    5.16  			
    5.17  		} catch (Exception e) {
    5.18  			logger.error("[Strabon.QueryOp] Error during execution of SPARQL query.", e);
     6.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryDir.java	Fri Jun 22 19:56:58 2012 +0300
     6.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryDir.java	Fri Jun 22 20:21:18 2012 +0300
     6.3 @@ -6,6 +6,7 @@
     6.4  import java.io.FilenameFilter;
     6.5  import java.io.IOException;
     6.6  
     6.7 +import org.openrdf.query.resultio.sparqlxml.Format;
     6.8  import org.slf4j.Logger;
     6.9  import org.slf4j.LoggerFactory;
    6.10  
    6.11 @@ -64,7 +65,7 @@
    6.12  						logger.info("[Strabon.QueryDir] Evaluating query from '" + path + System.getProperty("file.separator") + filename  +"'.");
    6.13  						String queryString = readFile(path + System.getProperty("file.separator") + filename);
    6.14  						logger.info("[Strabon.QueryDir] Evaluating stSPARQL query: \n"+queryString+"\n");
    6.15 -						strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection(), System.out);
    6.16 +						strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out);
    6.17  						
    6.18  					} catch (IOException e) {
    6.19  						logger.error("[Strabon.QueryDir] IOException while reading " + filename, e);
     7.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java	Fri Jun 22 19:56:58 2012 +0300
     7.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java	Fri Jun 22 20:21:18 2012 +0300
     7.3 @@ -1,5 +1,6 @@
     7.4  package eu.earthobservatory.runtime.postgis;
     7.5  
     7.6 +import org.openrdf.query.resultio.sparqlxml.Format;
     7.7  import org.slf4j.Logger;
     7.8  import org.slf4j.LoggerFactory;
     7.9  
    7.10 @@ -40,7 +41,7 @@
    7.11  		Strabon strabon = null;
    7.12  		try {
    7.13  			strabon = new Strabon(db, user, passwd, port, host, true);
    7.14 -			strabon.query(queryString, resultsFormat, strabon.getSailRepoConnection(), System.out);
    7.15 +			strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out);
    7.16  			
    7.17  		} catch (Exception e) {
    7.18  			logger.error("[Strabon.QueryOp] Error during execution of SPARQL query.", e);