Strabon
changeset 688:9a4bb8e81273
split queryresultio-spatial into submodules (one for API that provides the stSPARQLQueryResultFormat and one for each writer implementation, e.g., XML, HTML, etc.)
Renamed resultio to resultio-spatial.
Renamed endpoint-client artifact to strabon-endpoint-client.
Moved org.openrdf.resultio.Format to eu.earthobservatory.utils.
Renamed and moved org.openrdf.resultio.stSPARQLQueryResultWriter to eu.earthobservatory.utils.stSPARQLQueryResultToFormatAdapter. This is a factory class for stSPARQLQueryResults.
NOTICE: You should import the whole Strabon project into Eclipse to work with this commit
Renamed resultio to resultio-spatial.
Renamed endpoint-client artifact to strabon-endpoint-client.
Moved org.openrdf.resultio.Format to eu.earthobservatory.utils.
Renamed and moved org.openrdf.resultio.stSPARQLQueryResultWriter to eu.earthobservatory.utils.stSPARQLQueryResultToFormatAdapter. This is a factory class for stSPARQLQueryResults.
NOTICE: You should import the whole Strabon project into Eclipse to work with this commit
line diff
1.1 --- a/ChangeLog Mon Nov 05 20:40:17 2012 +0200 1.2 +++ b/ChangeLog Tue Nov 06 19:24:43 2012 +0200 1.3 @@ -2,6 +2,11 @@ 1.4 1.5 * Version 3.2.5 released. 1.6 1.7 + * Implemented a Java client for Strabon Endpoint. The client should be 1.8 + used only with endpoint versions >=3.2.5. The implementation may be 1.9 + found int the `endpoint-client' submodule of maven. Currently, only 1.10 + querying of Strabon Endpoints is supported. 1.11 + 1.12 * Added support for requesting the capabilities of Strabon Endpoint 1.13 (fixes Bug #20 <http://bug.strabon.di.uoa.gr/ticket/20>). See 1.14 changesets f840796400bf and ?<TBC>? for specific details and how you
2.1 --- a/endpoint-client/pom.xml Mon Nov 05 20:40:17 2012 +0200 2.2 +++ b/endpoint-client/pom.xml Tue Nov 06 19:24:43 2012 +0200 2.3 @@ -8,7 +8,7 @@ 2.4 <version>3.2.5-SNAPSHOT</version> 2.5 </parent> 2.6 2.7 - <artifactId>endpoint-client</artifactId> 2.8 + <artifactId>strabon-endpoint-client</artifactId> 2.9 2.10 <name>Strabon: Endpoint client</name> 2.11 <description>A java client for Strabon endpoint</description> 2.12 @@ -17,53 +17,18 @@ 2.13 <dependencies> 2.14 <dependency> 2.15 <groupId>org.openrdf.sesame</groupId> 2.16 - <artifactId>sesame-queryresultio-spatial</artifactId> 2.17 - </dependency> 2.18 - <!-- 2.19 - <dependency> 2.20 - <groupId>org.openrdf.sesame</groupId> 2.21 - <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 2.22 + <artifactId>sesame-rio-api</artifactId> 2.23 </dependency> 2.24 <dependency> 2.25 <groupId>org.openrdf.sesame</groupId> 2.26 - <artifactId>sesame-queryalgebra-evaluation</artifactId> 2.27 + <artifactId>sesame-queryresultio-spatial-api</artifactId> 2.28 </dependency> 2.29 + <!-- 2.30 <dependency> 2.31 <groupId>org.openrdf.sesame</groupId> 2.32 - <artifactId>sesame-rio-rdfxml</artifactId> 2.33 + <artifactId>sesame-queryresultio-spatial-api</artifactId> 2.34 </dependency> 2.35 - 2.36 - <dependency> 2.37 - <groupId>org.openrdf.sesame</groupId> 2.38 - <artifactId>sesame-rio-ntriples</artifactId> 2.39 - </dependency> 2.40 - 2.41 - <dependency> 2.42 - <groupId>org.openrdf.sesame</groupId> 2.43 - <artifactId>sesame-rio-turtle</artifactId> 2.44 - </dependency> 2.45 - 2.46 - <dependency> 2.47 - <groupId>org.openrdf.sesame</groupId> 2.48 - <artifactId>sesame-rio-trig</artifactId> 2.49 - </dependency> 2.50 - 2.51 - <dependency> 2.52 - <groupId>org.openrdf.sesame</groupId> 2.53 - <artifactId>sesame-rio-trix</artifactId> 2.54 - </dependency> 2.55 - 2.56 - <dependency> 2.57 - <groupId>org.openrdf.sesame</groupId> 2.58 - <artifactId>sesame-rio-n3</artifactId> 2.59 - </dependency> 2.60 - 2.61 - <dependency> 2.62 - <groupId>org.openrdf.sesame</groupId> 2.63 - <artifactId>sesame-rio-binary</artifactId> 2.64 - </dependency> 2.65 ---> 2.66 - 2.67 + --> 2.68 <dependency> 2.69 <groupId>commons-httpclient</groupId> 2.70 <artifactId>commons-httpclient</artifactId>
3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java Mon Nov 05 20:40:17 2012 +0200 3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/StrabonBeanWrapper.java Tue Nov 06 19:24:43 2012 +0200 3.3 @@ -9,6 +9,8 @@ 3.4 */ 3.5 package eu.earthobservatory.org.StrabonEndpoint; 3.6 3.7 +import eu.earthobservatory.utils.Format; 3.8 + 3.9 import java.io.IOException; 3.10 import java.io.OutputStream; 3.11 import java.io.StringReader; 3.12 @@ -23,7 +25,6 @@ 3.13 import org.openrdf.query.MalformedQueryException; 3.14 import org.openrdf.query.QueryEvaluationException; 3.15 import org.openrdf.query.TupleQueryResultHandlerException; 3.16 -import org.openrdf.query.resultio.Format; 3.17 import org.openrdf.repository.RepositoryException; 3.18 import org.openrdf.repository.sail.SailRepositoryConnection; 3.19 import org.openrdf.rio.RDFFormat;
4.1 --- a/evaluation/pom.xml Mon Nov 05 20:40:17 2012 +0200 4.2 +++ b/evaluation/pom.xml Tue Nov 06 19:24:43 2012 +0200 4.3 @@ -10,7 +10,7 @@ 4.4 4.5 <groupId>org.openrdf.sesame</groupId> 4.6 <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 4.7 - <name>OpenRDF Sesame: Query algebra - evaluation -spatial</name> 4.8 + <name>OpenRDF Sesame: Query algebra - evaluation - spatial</name> 4.9 <description>Spatial Extension Functions - stSPARQL </description> 4.10 <packaging>jar</packaging> 4.11
5.1 --- a/pom.xml Mon Nov 05 20:40:17 2012 +0200 5.2 +++ b/pom.xml Tue Nov 06 19:24:43 2012 +0200 5.3 @@ -24,13 +24,13 @@ 5.4 <module>postgis</module> 5.5 <module>monetdb</module> 5.6 <module>generaldb</module> 5.7 - <module>resultio</module> 5.8 + <module>resultio-spatial</module> 5.9 <module>endpoint</module> 5.10 <module>endpoint-client</module> 5.11 </modules> 5.12 5.13 <properties> 5.14 - <eu.earthobservatory.version>3.2.5-SNAPSHOT</eu.earthobservatory.version> 5.15 + <eu.earthobservatory.version>3.2.5-SNAPSHOT</eu.earthobservatory.version> 5.16 <sesame.version>2.6.3</sesame.version> 5.17 <aduna.appbase.version>3.5.0</aduna.appbase.version> 5.18 <!--slf4j.version>1.5.8</slf4j.version--> 5.19 @@ -54,11 +54,57 @@ 5.20 <version>${eu.earthobservatory.version}</version> 5.21 </dependency> 5.22 5.23 + 5.24 + <!-- queryresultio-spatial dependencies--> 5.25 <dependency> 5.26 <groupId>org.openrdf.sesame</groupId> 5.27 - <artifactId>sesame-queryresultio-spatial</artifactId> 5.28 + <artifactId>sesame-queryresultio-spatial-api</artifactId> 5.29 <version>${eu.earthobservatory.version}</version> 5.30 </dependency> 5.31 + <dependency> 5.32 + <groupId>org.openrdf.sesame</groupId> 5.33 + <artifactId>sesame-queryresultio-spatial-sparqlgeojson</artifactId> 5.34 + <version>${eu.earthobservatory.version}</version> 5.35 + </dependency> 5.36 + <dependency> 5.37 + <groupId>org.openrdf.sesame</groupId> 5.38 + <artifactId>sesame-queryresultio-spatial-sparqlhtml</artifactId> 5.39 + <version>${eu.earthobservatory.version}</version> 5.40 + </dependency> 5.41 + <dependency> 5.42 + <groupId>org.openrdf.sesame</groupId> 5.43 + <artifactId>sesame-queryresultio-spatial-sparqlkml</artifactId> 5.44 + <version>${eu.earthobservatory.version}</version> 5.45 + </dependency> 5.46 + <dependency> 5.47 + <groupId>org.openrdf.sesame</groupId> 5.48 + <artifactId>sesame-queryresultio-spatial-sparqlxml</artifactId> 5.49 + <version>${eu.earthobservatory.version}</version> 5.50 + </dependency> 5.51 + <dependency> 5.52 + <groupId>org.openrdf.sesame</groupId> 5.53 + <artifactId>sesame-queryresultio-spatial-text</artifactId> 5.54 + <version>${eu.earthobservatory.version}</version> 5.55 + </dependency> 5.56 + <!-- queryresultio-spatial dependencies--> 5.57 + 5.58 + <!-- sesame queryresultio dependencies --> 5.59 + <dependency> 5.60 + <groupId>org.openrdf.sesame</groupId> 5.61 + <artifactId>sesame-queryresultio-api</artifactId> 5.62 + <version>${sesame.version}</version> 5.63 + </dependency> 5.64 + <dependency> 5.65 + <groupId>org.openrdf.sesame</groupId> 5.66 + <artifactId>sesame-queryresultio-sparqlxml</artifactId> 5.67 + <version>${sesame.version}</version> 5.68 + </dependency> 5.69 + <dependency> 5.70 + <groupId>org.openrdf.sesame</groupId> 5.71 + <artifactId>sesame-queryresultio-text</artifactId> 5.72 + <version>${sesame.version}</version> 5.73 + </dependency> 5.74 + <!-- sesame queryresultio dependencies --> 5.75 5.76 <dependency> 5.77 <groupId>org.openrdf.sesame</groupId> 5.78 @@ -210,6 +256,11 @@ 5.79 <!-- RIO --> 5.80 <dependency> 5.81 <groupId>org.openrdf.sesame</groupId> 5.82 + <artifactId>sesame-rio-api</artifactId> 5.83 + <version>${sesame.version}</version> 5.84 + </dependency> 5.85 + <dependency> 5.86 + <groupId>org.openrdf.sesame</groupId> 5.87 <artifactId>sesame-rio-rdfxml</artifactId> 5.88 <version>${sesame.version}</version> 5.89 </dependency> 5.90 @@ -496,16 +547,16 @@ 5.91 <version>2.2</version> 5.92 </dependency> 5.93 5.94 -<dependency> 5.95 - <groupId>org.jvnet.ogc</groupId> 5.96 - <artifactId>ogc-tools-gml-jts</artifactId> 5.97 - <version>1.0.2</version> 5.98 -</dependency> 5.99 -<dependency> 5.100 - <groupId>com.sun.xml.bind</groupId> 5.101 - <artifactId>jaxb-impl</artifactId> 5.102 - <version>2.1.1</version> 5.103 -</dependency> 5.104 + <dependency> 5.105 + <groupId>org.jvnet.ogc</groupId> 5.106 + <artifactId>ogc-tools-gml-jts</artifactId> 5.107 + <version>1.0.2</version> 5.108 + </dependency> 5.109 + <dependency> 5.110 + <groupId>com.sun.xml.bind</groupId> 5.111 + <artifactId>jaxb-impl</artifactId> 5.112 + <version>2.1.1</version> 5.113 + </dependency> 5.114 5.115 <dependency> 5.116 <groupId>javax</groupId>
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/resultio-spatial/api/pom.xml Tue Nov 06 19:24:43 2012 +0200 6.3 @@ -0,0 +1,22 @@ 6.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 6.5 + 6.6 + <modelVersion>4.0.0</modelVersion> 6.7 + 6.8 + <parent> 6.9 + <groupId>org.openrdf.sesame</groupId> 6.10 + <artifactId>sesame-queryresultio-spatial</artifactId> 6.11 + <version>3.2.5-SNAPSHOT</version> 6.12 + </parent> 6.13 + 6.14 + <artifactId>sesame-queryresultio-spatial-api</artifactId> 6.15 + 6.16 + <name>OpenRDF Sesame: Spatial Query result IO - API</name> 6.17 + <description>Spatial Query result IO API</description> 6.18 + 6.19 + <dependencies> 6.20 + <dependency> 6.21 + <groupId>org.openrdf.sesame</groupId> 6.22 + <artifactId>sesame-queryresultio-api</artifactId> 6.23 + </dependency> 6.24 + </dependencies> 6.25 +</project>
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java Tue Nov 06 19:24:43 2012 +0200 7.3 @@ -0,0 +1,143 @@ 7.4 +/** 7.5 + * This Source Code Form is subject to the terms of the Mozilla Public 7.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 7.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7.8 + * 7.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 7.10 + * 7.11 + * http://www.strabon.di.uoa.gr/ 7.12 + */ 7.13 +package org.openrdf.query.resultio; 7.14 + 7.15 +import java.nio.charset.Charset; 7.16 +import java.util.ArrayList; 7.17 +import java.util.Arrays; 7.18 +import java.util.Collection; 7.19 +import java.util.List; 7.20 + 7.21 +/** 7.22 + * Represents the concept of an tuple query result serialization format for 7.23 + * stSPARQL/GeoSPARQL. Tuple query result formats are identified by a 7.24 + * {@link #getName() name} and can have one or more associated MIME types, 7.25 + * zero or more associated file extensions and can specify a (default) 7.26 + * character encoding. 7.27 + * 7.28 + * In contrast to formats mentioned in class {@link #TupleQueryResultFormat}, 7.29 + * stSPARQL/GeoSPARQL formats do not adhere to any specification for SPARQL 7.30 + * except for those that are extension of the respective formats in class 7.31 + * {@link #TupleQueryResultFormat}, such as TSV. 7.32 + * For example, the projected variables in a stSPARQL/GeoSPARQL query are 7.33 + * not included in the beginning of these formats. Instead, they are provided 7.34 + * as an additional description for a feature (e.g., a tuple query result with 7.35 + * a projected variable corresponding to a geometry). 7.36 + * 7.37 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 7.38 + * 7.39 + */ 7.40 +public class stSPARQLQueryResultFormat extends TupleQueryResultFormat { 7.41 + 7.42 + /** 7.43 + * XML format (extension of {@link TupleQueryResultFormat#SPARQL} format to include geometries) 7.44 + */ 7.45 + public static final stSPARQLQueryResultFormat XML = new stSPARQLQueryResultFormat("XML", 7.46 + Arrays.asList("application/sparql-results+xml", "application/xml"), Charset.forName("UTF-8"), Arrays.asList("xml")); 7.47 + 7.48 + /** 7.49 + * KML format (see http://www.opengeospatial.org/standards/kml/) 7.50 + */ 7.51 + public static final stSPARQLQueryResultFormat KML = new stSPARQLQueryResultFormat("KML", 7.52 + Arrays.asList("application/vnd.google-earth.kml+xml", "application/kml"), Charset.forName("UTF-8"), Arrays.asList("kml")); 7.53 + 7.54 + /** 7.55 + * KMZ format (a zipped KML content) 7.56 + */ 7.57 + public static final stSPARQLQueryResultFormat KMZ = new stSPARQLQueryResultFormat("KMZ", 7.58 + Arrays.asList("application/vnd.google-earth.kmz", "application/kmz"), Charset.forName("UTF-8"), Arrays.asList("kmz")); 7.59 + 7.60 + /** 7.61 + * GeoJSON format (see http://www.geojson.org/geojson-spec.html) 7.62 + */ 7.63 + public static final stSPARQLQueryResultFormat GEOJSON = new stSPARQLQueryResultFormat("GeoJSON", 7.64 + Arrays.asList("application/json", "application/geojson"), Charset.forName("UTF-8"), Arrays.asList("json")); 7.65 + 7.66 + /** 7.67 + * Tab separated value format (extension of {@link TupleQueryResultFormat#TSV} format to include geometries) 7.68 + */ 7.69 + public static final stSPARQLQueryResultFormat TSV = new stSPARQLQueryResultFormat("TSV", 7.70 + Arrays.asList("text/tab-separated-values"), Charset.forName("UTF-8"), Arrays.asList("tsv")); 7.71 + 7.72 + /** 7.73 + * HTML format (encoded as an HTML table, without the <tt><TABLE></tt> tag) 7.74 + */ 7.75 + public static final stSPARQLQueryResultFormat HTML = new stSPARQLQueryResultFormat("HTML", 7.76 + Arrays.asList("text/html"), Charset.forName("UTF-8"), Arrays.asList("html", "htm")); 7.77 + 7.78 + /** 7.79 + * The available stSPARQLQuery Result Formats 7.80 + */ 7.81 + private static final List<stSPARQLQueryResultFormat> VALUES = new ArrayList<stSPARQLQueryResultFormat>(6); 7.82 + 7.83 + // registers stSPARQL/GeoSPARQL formats 7.84 + static { 7.85 + register(XML); 7.86 + register(KML); 7.87 + register(KMZ); 7.88 + register(GEOJSON); 7.89 + register(TSV); 7.90 + register(HTML); 7.91 + } 7.92 + 7.93 + /** 7.94 + * Register the specified stSPARQLQueryResultFormat. 7.95 + * 7.96 + * @param format 7.97 + */ 7.98 + public static void register(stSPARQLQueryResultFormat format) { 7.99 + TupleQueryResultFormat.register(format); 7.100 + VALUES.add(format); 7.101 + } 7.102 + 7.103 + /** 7.104 + * Gets the stSPARQLQueryResultFormat given its name. 7.105 + * 7.106 + * @param formatName 7.107 + * @return 7.108 + */ 7.109 + public static stSPARQLQueryResultFormat valueOf(String formatName) { 7.110 + for (TupleQueryResultFormat format : values()) { 7.111 + if (format instanceof stSPARQLQueryResultFormat && 7.112 + format.getName().equalsIgnoreCase(formatName)) { 7.113 + return (stSPARQLQueryResultFormat) format; 7.114 + } 7.115 + } 7.116 + 7.117 + return null; 7.118 + } 7.119 + 7.120 + /** 7.121 + * Returns all known/registered tuple query result formats. 7.122 + */ 7.123 + public static Collection<TupleQueryResultFormat> values() { 7.124 + return TupleQueryResultFormat.values(); 7.125 + } 7.126 + 7.127 + public static stSPARQLQueryResultFormat forMIMEType(String mimeType) { 7.128 + return forMIMEType(mimeType, null); 7.129 + } 7.130 + 7.131 + public static stSPARQLQueryResultFormat forMIMEType(String mimeType, stSPARQLQueryResultFormat fallback) { 7.132 + return matchMIMEType(mimeType, VALUES, fallback); 7.133 + } 7.134 + 7.135 + public stSPARQLQueryResultFormat(String name, String mimeType, String fileExt) { 7.136 + super(name, mimeType, fileExt); 7.137 + } 7.138 + 7.139 + public stSPARQLQueryResultFormat(String name, String mimeType, Charset charset, String fileExt) { 7.140 + super(name, mimeType, charset, fileExt); 7.141 + } 7.142 + 7.143 + public stSPARQLQueryResultFormat(String name, Collection<String> mimeTypes, Charset charset, Collection<String> fileExtensions) { 7.144 + super(name, mimeTypes, charset, fileExtensions); 7.145 + } 7.146 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultParser.java Tue Nov 06 19:24:43 2012 +0200 8.3 @@ -0,0 +1,64 @@ 8.4 +/** 8.5 + * This Source Code Form is subject to the terms of the Mozilla Public 8.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 8.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8.8 + * 8.9 + * Copyright (C) 2012, Pyravlos Team 8.10 + * 8.11 + * http://www.strabon.di.uoa.gr/ 8.12 + */ 8.13 +package org.openrdf.query.resultio; 8.14 + 8.15 +import java.io.IOException; 8.16 +import java.io.InputStream; 8.17 + 8.18 +import org.openrdf.model.ValueFactory; 8.19 +import org.openrdf.query.TupleQueryResultHandler; 8.20 +import org.openrdf.query.TupleQueryResultHandlerException; 8.21 + 8.22 +/** 8.23 + * A general interface for stSPARQL tuple query result parsers. 8.24 + * 8.25 + * @see {@link TupleQueryResultParser} 8.26 + * 8.27 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 8.28 + */ 8.29 +public interface stSPARQLQueryResultParser { 8.30 + 8.31 + /** 8.32 + * Gets the query result format that this parser can parse. 8.33 + */ 8.34 + public stSPARQLQueryResultFormat getTupleQueryResultFormat(); 8.35 + 8.36 + /** 8.37 + * Sets the ValueFactory that the parser will use to create Value objects for 8.38 + * the parsed query result. 8.39 + * 8.40 + * @param valueFactory 8.41 + * The value factory that the parser should use. 8.42 + */ 8.43 + public void setValueFactory(ValueFactory valueFactory); 8.44 + 8.45 + /** 8.46 + * Sets the TupleQueryResultHandler that will handle the parsed query result 8.47 + * data. 8.48 + */ 8.49 + public void setTupleQueryResultHandler(TupleQueryResultHandler handler); 8.50 + 8.51 + /** 8.52 + * Parses the data from the supplied InputStream. 8.53 + * 8.54 + * @param in 8.55 + * The InputStream from which to read the data. 8.56 + * @throws IOException 8.57 + * If an I/O error occurred while data was read from the InputStream. 8.58 + * @throws QueryResultParseException 8.59 + * If the parser has encountered an unrecoverable parse error. 8.60 + * @throws TupleQueryResultHandlerException 8.61 + * If the configured query result handler has encountered an 8.62 + * unrecoverable error. 8.63 + */ 8.64 + public void parse(InputStream in) 8.65 + throws IOException, QueryResultParseException, TupleQueryResultHandlerException; 8.66 + 8.67 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultParserBase.java Tue Nov 06 19:24:43 2012 +0200 9.3 @@ -0,0 +1,71 @@ 9.4 +/** 9.5 + * This Source Code Form is subject to the terms of the Mozilla Public 9.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 9.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9.8 + * 9.9 + * Copyright (C) 2012, Pyravlos Team 9.10 + * 9.11 + * http://www.strabon.di.uoa.gr/ 9.12 + */ 9.13 +package org.openrdf.query.resultio; 9.14 + 9.15 +import org.openrdf.model.ValueFactory; 9.16 +import org.openrdf.model.impl.ValueFactoryImpl; 9.17 +import org.openrdf.query.TupleQueryResultHandler; 9.18 + 9.19 +/** 9.20 + * Base class for {@link stSPARQLQueryResultParser}s offering common functionality for 9.21 + * query result parsers. 9.22 + * 9.23 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 9.24 + * 9.25 + */ 9.26 +public abstract class stSPARQLQueryResultParserBase implements stSPARQLQueryResultParser { 9.27 + 9.28 + /*-----------* 9.29 + * Variables * 9.30 + *-----------*/ 9.31 + 9.32 + /** 9.33 + * The ValueFactory to use for creating RDF model objects. 9.34 + */ 9.35 + protected ValueFactory valueFactory; 9.36 + 9.37 + /** 9.38 + * The TupleQueryResultHandler that will handle the parsed query results. 9.39 + */ 9.40 + protected TupleQueryResultHandler handler; 9.41 + 9.42 + /*--------------* 9.43 + * Constructors * 9.44 + *--------------*/ 9.45 + 9.46 + /** 9.47 + * Creates a new parser base that, by default, will use an instance of 9.48 + * {@link ValueFactoryImpl} to create Value objects. 9.49 + */ 9.50 + public stSPARQLQueryResultParserBase() { 9.51 + this(new ValueFactoryImpl()); 9.52 + } 9.53 + 9.54 + /** 9.55 + * Creates a new parser base that will use the supplied ValueFactory to 9.56 + * create Value objects. 9.57 + */ 9.58 + public stSPARQLQueryResultParserBase(ValueFactory valueFactory) { 9.59 + setValueFactory(valueFactory); 9.60 + } 9.61 + 9.62 + /*---------* 9.63 + * Methods * 9.64 + *---------*/ 9.65 + 9.66 + public void setValueFactory(ValueFactory valueFactory) { 9.67 + this.valueFactory = valueFactory; 9.68 + } 9.69 + 9.70 + public void setTupleQueryResultHandler(TupleQueryResultHandler handler) { 9.71 + this.handler = handler; 9.72 + } 9.73 + 9.74 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultParserFactory.java Tue Nov 06 19:24:43 2012 +0200 10.3 @@ -0,0 +1,32 @@ 10.4 +/** 10.5 + * This Source Code Form is subject to the terms of the Mozilla Public 10.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 10.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 10.8 + * 10.9 + * Copyright (C) 2012, Pyravlos Team 10.10 + * 10.11 + * http://www.strabon.di.uoa.gr/ 10.12 + */ 10.13 +package org.openrdf.query.resultio; 10.14 + 10.15 +/** 10.16 + * A stSPARQLQueryResultParserFactory returns {@link stSPARQLQueryResultParser}s for 10.17 + * a specific tuple query result format. 10.18 + * 10.19 + * @see {@link TupleQueryResultParserFactory} 10.20 + * 10.21 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 10.22 + * 10.23 + */ 10.24 +public interface stSPARQLQueryResultParserFactory { 10.25 + /** 10.26 + * Returns the tuple query result format for this factory. 10.27 + */ 10.28 + public stSPARQLQueryResultFormat getTupleQueryResultFormat(); 10.29 + 10.30 + /** 10.31 + * Returns a TupleQueryResultParser instance. 10.32 + */ 10.33 + public stSPARQLQueryResultParser getParser(); 10.34 + 10.35 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultParserRegistry.java Tue Nov 06 19:24:43 2012 +0200 11.3 @@ -0,0 +1,47 @@ 11.4 +/** 11.5 + * This Source Code Form is subject to the terms of the Mozilla Public 11.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 11.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 11.8 + * 11.9 + * Copyright (C) 2012, Pyravlos Team 11.10 + * 11.11 + * http://www.strabon.di.uoa.gr/ 11.12 + */ 11.13 +package org.openrdf.query.resultio; 11.14 + 11.15 +import info.aduna.lang.service.FileFormatServiceRegistry; 11.16 + 11.17 +/** 11.18 + * A registry that keeps track of the available 11.19 + * {@link stSPARQLQueryResultParserFactory}s. 11.20 + * 11.21 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 11.22 + * 11.23 + */ 11.24 +public class stSPARQLQueryResultParserRegistry extends FileFormatServiceRegistry<stSPARQLQueryResultFormat, stSPARQLQueryResultParserFactory> { 11.25 + 11.26 + private static stSPARQLQueryResultParserRegistry defaultRegistry; 11.27 + 11.28 + /** 11.29 + * Gets the default stSPARQLQueryResultParserRegistry. 11.30 + * 11.31 + * @return The default registry. 11.32 + */ 11.33 + public static synchronized stSPARQLQueryResultParserRegistry getInstance() { 11.34 + if (defaultRegistry == null) { 11.35 + defaultRegistry = new stSPARQLQueryResultParserRegistry(); 11.36 + } 11.37 + 11.38 + return defaultRegistry; 11.39 + } 11.40 + 11.41 + public stSPARQLQueryResultParserRegistry() { 11.42 + super(stSPARQLQueryResultParserFactory.class); 11.43 + } 11.44 + 11.45 + @Override 11.46 + protected stSPARQLQueryResultFormat getKey(stSPARQLQueryResultParserFactory factory) { 11.47 + return factory.getTupleQueryResultFormat(); 11.48 + } 11.49 + 11.50 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultWriter.java Tue Nov 06 19:24:43 2012 +0200 12.3 @@ -0,0 +1,26 @@ 12.4 +/** 12.5 + * This Source Code Form is subject to the terms of the Mozilla Public 12.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 12.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 12.8 + * 12.9 + * Copyright (C) 2012, Pyravlos Team 12.10 + * 12.11 + * http://www.strabon.di.uoa.gr/ 12.12 + */ 12.13 +package org.openrdf.query.resultio; 12.14 + 12.15 +import org.openrdf.query.TupleQueryResultHandler; 12.16 + 12.17 +/** 12.18 + * The interface of objects that writer query results in a specific query result 12.19 + * format. 12.20 + * 12.21 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 12.22 + */ 12.23 +public interface stSPARQLQueryResultWriter extends TupleQueryResultHandler { 12.24 + 12.25 + /** 12.26 + * Gets the query result format that this writer uses. 12.27 + */ 12.28 + public stSPARQLQueryResultFormat getTupleQueryResultFormat(); 12.29 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultWriterFactory.java Tue Nov 06 19:24:43 2012 +0200 13.3 @@ -0,0 +1,38 @@ 13.4 +/** 13.5 + * This Source Code Form is subject to the terms of the Mozilla Public 13.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 13.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13.8 + * 13.9 + * Copyright (C) 2012, Pyravlos Team 13.10 + * 13.11 + * http://www.strabon.di.uoa.gr/ 13.12 + */ 13.13 +package org.openrdf.query.resultio; 13.14 + 13.15 +import java.io.OutputStream; 13.16 + 13.17 +/** 13.18 + * Returns {@link stSPARQLQueryResultWriter}s for a specific tuple query result 13.19 + * format. 13.20 + * 13.21 + * @see {@link TupleQueryResultWriterFactory} 13.22 + * 13.23 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 13.24 + */ 13.25 +public interface stSPARQLQueryResultWriterFactory { 13.26 + 13.27 + /** 13.28 + * Returns the tuple query result format for this factory. 13.29 + */ 13.30 + public stSPARQLQueryResultFormat getTupleQueryResultFormat(); 13.31 + 13.32 + /** 13.33 + * Returns a stSPARQLQueryResultWriter instance that will write to the supplied 13.34 + * output stream. 13.35 + * 13.36 + * @param out 13.37 + * The OutputStream to write the result to. 13.38 + */ 13.39 + public stSPARQLQueryResultWriter getWriter(OutputStream out); 13.40 + 13.41 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultWriterRegistry.java Tue Nov 06 19:24:43 2012 +0200 14.3 @@ -0,0 +1,47 @@ 14.4 +/** 14.5 + * This Source Code Form is subject to the terms of the Mozilla Public 14.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 14.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 14.8 + * 14.9 + * Copyright (C) 2012, Pyravlos Team 14.10 + * 14.11 + * http://www.strabon.di.uoa.gr/ 14.12 + */ 14.13 +package org.openrdf.query.resultio; 14.14 + 14.15 +import info.aduna.lang.service.FileFormatServiceRegistry; 14.16 + 14.17 +/** 14.18 + * A registry that keeps track of the available 14.19 + * {@link stSPARQLQueryResultWriterFactory}s. 14.20 + * 14.21 + * @see {@link TupleQueryResultWriterRegistry} 14.22 + * 14.23 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 14.24 + */ 14.25 +public class stSPARQLQueryResultWriterRegistry extends FileFormatServiceRegistry<stSPARQLQueryResultFormat, stSPARQLQueryResultWriterFactory> { 14.26 + 14.27 + private static stSPARQLQueryResultWriterRegistry defaultRegistry; 14.28 + 14.29 + /** 14.30 + * Gets the default stSPARQLQueryResultWriterRegistry. 14.31 + * 14.32 + * @return The default registry. 14.33 + */ 14.34 + public static synchronized stSPARQLQueryResultWriterRegistry getInstance() { 14.35 + if (defaultRegistry == null) { 14.36 + defaultRegistry = new stSPARQLQueryResultWriterRegistry(); 14.37 + } 14.38 + 14.39 + return defaultRegistry; 14.40 + } 14.41 + 14.42 + public stSPARQLQueryResultWriterRegistry() { 14.43 + super(stSPARQLQueryResultWriterFactory.class); 14.44 + } 14.45 + 14.46 + @Override 14.47 + protected stSPARQLQueryResultFormat getKey(stSPARQLQueryResultWriterFactory factory) { 14.48 + return factory.getTupleQueryResultFormat(); 14.49 + } 14.50 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/resultio-spatial/pom.xml Tue Nov 06 19:24:43 2012 +0200 15.3 @@ -0,0 +1,119 @@ 15.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 15.5 + 15.6 + <modelVersion>4.0.0</modelVersion> 15.7 + 15.8 + <parent> 15.9 + <groupId>eu.earthobservatory</groupId> 15.10 + <artifactId>strabon</artifactId> 15.11 + <version>3.2.5-SNAPSHOT</version> 15.12 + </parent> 15.13 + 15.14 + <groupId>org.openrdf.sesame</groupId> 15.15 + <artifactId>sesame-queryresultio-spatial</artifactId> 15.16 + <name>OpenRDF Sesame: Spatial Query result IO</name> 15.17 + <description>Minimal spatial extensions of Query result parser and writer implementation for the SPARQL Query Results Format.</description> 15.18 + <packaging>pom</packaging> 15.19 + 15.20 + <modules> 15.21 + <module>api</module> 15.22 + <module>sparqlgeojson</module> 15.23 + <module>sparqlhtml</module> 15.24 + <module>sparqlkml</module> 15.25 + <module>sparqlxml</module> 15.26 + <module>text</module> 15.27 + </modules> 15.28 + 15.29 + <!-- 15.30 + <dependencies> 15.31 + <dependency> 15.32 + <groupId>org.openrdf.sesame</groupId> 15.33 + <artifactId>sesame-sail-generaldb</artifactId> 15.34 + </dependency> 15.35 + 15.36 + <dependency> 15.37 + <groupId>org.openrdf.sesame</groupId> 15.38 + <artifactId>sesame-queryresultio-sparqlxml</artifactId> 15.39 + <version>${sesame.version}</version> 15.40 + </dependency> 15.41 + 15.42 + <dependency> 15.43 + <groupId>org.openrdf.sesame</groupId> 15.44 + <artifactId>sesame-queryresultio-sparqljson</artifactId> 15.45 + <version>${sesame.version}</version> 15.46 + </dependency> 15.47 + 15.48 + <dependency> 15.49 + <groupId>org.openrdf.sesame</groupId> 15.50 + <artifactId>sesame-queryresultio-text</artifactId> 15.51 + <version>${sesame.version}</version> 15.52 + </dependency> 15.53 + 15.54 + <dependency> 15.55 + <groupId>org.openrdf.sesame</groupId> 15.56 + <artifactId>sesame-queryalgebra-model</artifactId> 15.57 + </dependency> 15.58 + 15.59 + <dependency> 15.60 + <groupId>org.openrdf.sesame</groupId> 15.61 + <artifactId>sesame-model</artifactId> 15.62 + </dependency> 15.63 + 15.64 + <dependency> 15.65 + <groupId>org.openrdf.sesame</groupId> 15.66 + <artifactId>sesame-query</artifactId> 15.67 + </dependency> 15.68 + 15.69 + <dependency> 15.70 + <groupId>org.openrdf.sesame</groupId> 15.71 + <artifactId>sesame-repository-sparql</artifactId> 15.72 + </dependency> 15.73 + 15.74 + <dependency> 15.75 + <groupId>org.slf4j</groupId> 15.76 + <artifactId>slf4j-log4j12</artifactId> 15.77 + </dependency> 15.78 + 15.79 + <dependency> 15.80 + <groupId>junit</groupId> 15.81 + <artifactId>junit</artifactId> 15.82 + </dependency> 15.83 + 15.84 + <dependency> 15.85 + <groupId>org.geotools</groupId> 15.86 + <artifactId>gt-geojson</artifactId> 15.87 + </dependency> 15.88 + 15.89 + <dependency> 15.90 + <groupId>org.geotools.xsd</groupId> 15.91 + <artifactId>gt-xsd-kml</artifactId> 15.92 + </dependency> 15.93 + 15.94 + <dependency> 15.95 + <groupId>org.geotools</groupId> 15.96 + <artifactId>gt-xml</artifactId> 15.97 + </dependency> 15.98 + 15.99 + <dependency> 15.100 + <groupId>org.geotools</groupId> 15.101 + <artifactId>gt-epsg-hsql</artifactId> 15.102 + </dependency> 15.103 + 15.104 + <dependency> 15.105 + <groupId>org.geotools</groupId> 15.106 + <artifactId>gt-shapefile</artifactId> 15.107 + </dependency> 15.108 + 15.109 + <dependency> 15.110 + <groupId>org.geotools</groupId> 15.111 + <artifactId>gt-opengis</artifactId> 15.112 + </dependency> 15.113 + <dependency> 15.114 + <groupId>com.vividsolutions</groupId> 15.115 + <artifactId>jts</artifactId> 15.116 + <type>jar</type> 15.117 + <scope>compile</scope> 15.118 + </dependency> 15.119 + </dependencies> 15.120 + --> 15.121 +</project> 15.122 +
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/resultio-spatial/sparqlgeojson/pom.xml Tue Nov 06 19:24:43 2012 +0200 16.3 @@ -0,0 +1,76 @@ 16.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 16.5 + 16.6 + <modelVersion>4.0.0</modelVersion> 16.7 + 16.8 + <parent> 16.9 + <groupId>org.openrdf.sesame</groupId> 16.10 + <artifactId>sesame-queryresultio-spatial</artifactId> 16.11 + <version>3.2.5-SNAPSHOT</version> 16.12 + </parent> 16.13 + 16.14 + <artifactId>sesame-queryresultio-spatial-sparqlgeojson</artifactId> 16.15 + 16.16 + <name>OpenRDF Sesame: Spatial Query result IO - GeoJSON</name> 16.17 + <description>Spatial Query result IO API</description> 16.18 + 16.19 + <dependencies> 16.20 + 16.21 + <dependency> <!-- TO BE REMOVED --> 16.22 + <groupId>org.openrdf.sesame</groupId> 16.23 + <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 16.24 + </dependency> 16.25 + <dependency> <!-- TO BE REMOVED ? --> 16.26 + <groupId>org.openrdf.sesame</groupId> 16.27 + <artifactId>sesame-sail-generaldb</artifactId> 16.28 + </dependency> 16.29 + 16.30 + <dependency> 16.31 + <groupId>org.openrdf.sesame</groupId> 16.32 + <artifactId>sesame-queryresultio-spatial-api</artifactId> 16.33 + </dependency> 16.34 + 16.35 + <dependency> 16.36 + <groupId>org.slf4j</groupId> 16.37 + <artifactId>slf4j-log4j12</artifactId> 16.38 + </dependency> 16.39 + 16.40 + <dependency> 16.41 + <groupId>junit</groupId> 16.42 + <artifactId>junit</artifactId> 16.43 + <scope>test</scope> 16.44 + </dependency> 16.45 + 16.46 + <dependency> 16.47 + <groupId>org.geotools</groupId> 16.48 + <artifactId>gt-geojson</artifactId> 16.49 + </dependency> 16.50 + 16.51 + 16.52 + <dependency> 16.53 + <groupId>org.geotools</groupId> 16.54 + <artifactId>gt-xml</artifactId> 16.55 + </dependency> 16.56 + 16.57 + <dependency> 16.58 + <groupId>org.geotools</groupId> 16.59 + <artifactId>gt-epsg-hsql</artifactId> 16.60 + </dependency> 16.61 + 16.62 + <dependency> 16.63 + <groupId>org.geotools</groupId> 16.64 + <artifactId>gt-shapefile</artifactId> 16.65 + </dependency> 16.66 + 16.67 + <dependency> 16.68 + <groupId>org.geotools</groupId> 16.69 + <artifactId>gt-opengis</artifactId> 16.70 + </dependency> 16.71 + <dependency> 16.72 + <groupId>com.vividsolutions</groupId> 16.73 + <artifactId>jts</artifactId> 16.74 + <type>jar</type> 16.75 + <scope>compile</scope> 16.76 + </dependency> 16.77 + 16.78 + </dependencies> 16.79 +</project>
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java Tue Nov 06 19:24:43 2012 +0200 17.3 @@ -0,0 +1,236 @@ 17.4 +/** 17.5 + * This Source Code Form is subject to the terms of the Mozilla Public 17.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 17.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 17.8 + * 17.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 17.10 + * 17.11 + * http://www.strabon.di.uoa.gr/ 17.12 + */ 17.13 +package org.openrdf.query.resultio.sparqlgeojson; 17.14 + 17.15 +import java.io.IOException; 17.16 +import java.io.OutputStream; 17.17 +import java.nio.charset.Charset; 17.18 +import java.util.ArrayList; 17.19 +import java.util.List; 17.20 + 17.21 +import org.geotools.data.simple.SimpleFeatureCollection; 17.22 +import org.geotools.feature.FeatureCollections; 17.23 +import org.geotools.feature.simple.SimpleFeatureBuilder; 17.24 +import org.geotools.feature.simple.SimpleFeatureTypeBuilder; 17.25 +import org.geotools.geojson.feature.FeatureJSON; 17.26 +import org.geotools.referencing.CRS; 17.27 +import org.opengis.feature.simple.SimpleFeature; 17.28 +import org.opengis.feature.simple.SimpleFeatureType; 17.29 +import org.openrdf.model.Literal; 17.30 +import org.openrdf.model.Value; 17.31 +import org.openrdf.query.Binding; 17.32 +import org.openrdf.query.BindingSet; 17.33 +import org.openrdf.query.TupleQueryResultHandlerException; 17.34 +import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; 17.35 +import org.openrdf.query.algebra.evaluation.util.JTSWrapper; 17.36 +import org.openrdf.query.resultio.TupleQueryResultFormat; 17.37 +import org.openrdf.query.resultio.TupleQueryResultWriter; 17.38 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 17.39 +import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 17.40 +import org.openrdf.sail.generaldb.model.XMLGSDatatypeUtil; 17.41 +import org.slf4j.Logger; 17.42 +import org.slf4j.LoggerFactory; 17.43 + 17.44 +import com.vividsolutions.jts.geom.Geometry; 17.45 + 17.46 +/** 17.47 + * A TupleQueryResultWriter that writes query results in the <a 17.48 + * href="http://www.geojson.org/geojson-spec.html/">GeoJSON Format</a>. 17.49 + * 17.50 + * @author Manos Karpathiotakis <mk@di.uoa.gr> 17.51 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 17.52 + */ 17.53 +public class stSPARQLResultsGeoJSONWriter implements TupleQueryResultWriter { 17.54 + 17.55 + private static final Logger logger = LoggerFactory.getLogger(org.openrdf.query.resultio.sparqlgeojson.stSPARQLResultsGeoJSONWriter.class); 17.56 + 17.57 + /** 17.58 + * The underlying output stream to write 17.59 + */ 17.60 + private OutputStream out; 17.61 + 17.62 + /** 17.63 + * Set a Feature Collection 17.64 + */ 17.65 + private SimpleFeatureCollection sfCollection; 17.66 + 17.67 + /** 17.68 + * The wrapper of JTS library 17.69 + */ 17.70 + private JTSWrapper jts; 17.71 + 17.72 + /** 17.73 + * Keep track of the number of results 17.74 + */ 17.75 + private int nresults; 17.76 + 17.77 + /** 17.78 + * The class to use for serializing to GeoJSON 17.79 + */ 17.80 + private FeatureJSON fjson; 17.81 + 17.82 + /** 17.83 + * Keep track of the number of features 17.84 + */ 17.85 + private int nfeatures; 17.86 + 17.87 + public stSPARQLResultsGeoJSONWriter(OutputStream out) { 17.88 + this.out = out; 17.89 + 17.90 + // set the feature collection 17.91 + sfCollection = FeatureCollections.newCollection("geomOutput"); 17.92 + 17.93 + // get the instance of JTSWrapper 17.94 + jts = JTSWrapper.getInstance(); 17.95 + 17.96 + // initialize results/features 17.97 + nresults = 0; 17.98 + nfeatures = 0; 17.99 + } 17.100 + 17.101 + @Override 17.102 + public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException { 17.103 + fjson = new FeatureJSON(); 17.104 + fjson.setEncodeFeatureCRS(true); 17.105 + } 17.106 + 17.107 + @Override 17.108 + public void endQueryResult() throws TupleQueryResultHandlerException { 17.109 + try { 17.110 + fjson.writeFeatureCollection(sfCollection, out); 17.111 + out.write("\n".getBytes(Charset.defaultCharset())); 17.112 + 17.113 + // write a warning when there are no features in the answer 17.114 + if (nfeatures < nresults) { 17.115 + logger.warn("[Strabon.GeoJSONWriter] No spatial binding found in the result, hence the result is empty eventhough query evaluation produced {} results. GeoJSON requires that at least one binding maps to a geometry.", nresults); 17.116 + 17.117 + } 17.118 + } catch (IOException e) { 17.119 + throw new TupleQueryResultHandlerException(e); 17.120 + } 17.121 + } 17.122 + 17.123 + @Override 17.124 + public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException { 17.125 + try { 17.126 + nresults++; 17.127 + 17.128 + // list keeping binding names that are not binded to geometries 17.129 + ArrayList<String> properties = new ArrayList<String>(); 17.130 + 17.131 + // list keeping values for binding names 17.132 + ArrayList<Value> values = new ArrayList<Value>(); 17.133 + 17.134 + // list keeping the features of the result 17.135 + ArrayList<SimpleFeatureTypeBuilder> features = new ArrayList<SimpleFeatureTypeBuilder>(); 17.136 + 17.137 + // list keeping the geometries of features 17.138 + ArrayList<Geometry> geometries = new ArrayList<Geometry>(); 17.139 + 17.140 + // parse binding set 17.141 + for (Binding binding : bindingSet) { 17.142 + Value value = binding.getValue(); 17.143 + 17.144 + if (XMLGSDatatypeUtil.isGeometryValue(value)) { 17.145 + // it's a spatial value 17.146 + if (logger.isDebugEnabled()) { 17.147 + logger.debug("[Strabon.GeoJSON] Found geometry: {}", value); 17.148 + } 17.149 + 17.150 + nfeatures++; 17.151 + 17.152 + // we need the geometry and the SRID 17.153 + Geometry geom = null; 17.154 + int srid = -1; 17.155 + 17.156 + if (value instanceof GeneralDBPolyhedron) { 17.157 + GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) value; 17.158 + 17.159 + geom = dbpolyhedron.getPolyhedron().getGeometry(); 17.160 + srid = dbpolyhedron.getPolyhedron().getGeometry().getSRID(); 17.161 + 17.162 + } else { // spatial literal WKT or GML 17.163 + // get the textual representation of the geometry (WKT or GML) 17.164 + String geoText = value.stringValue(); 17.165 + 17.166 + if (XMLGSDatatypeUtil.isWKTLiteral((Literal) value)) {// WKT 17.167 + // get its geometry 17.168 + geom = jts.WKTread(WKTHelper.getWithoutSRID(geoText)); 17.169 + 17.170 + // get its SRID 17.171 + srid = WKTHelper.getSRID(geoText); 17.172 + 17.173 + } else { // GML 17.174 + // get its geometry 17.175 + geom = jts.GMLread(geoText); 17.176 + 17.177 + // get its SRID 17.178 + srid = geom.getSRID(); 17.179 + 17.180 + } 17.181 + } 17.182 + 17.183 + SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder(); 17.184 + sftb.setName("Feature_" + nresults + "_" + nfeatures); 17.185 + sftb.setCRS(CRS.decode("EPSG:" + srid)); 17.186 + sftb.setSRS("EPSG:" + srid); 17.187 + sftb.add("geometry", Geometry.class); 17.188 + 17.189 + // add the feature in the list of features 17.190 + features.add(sftb); 17.191 + 17.192 + // add the geometry of the feature in the list of geometries 17.193 + geometries.add(geom); 17.194 + 17.195 + } else { // URI, BlankNode, or Literal other than geometry 17.196 + if (logger.isDebugEnabled()) { 17.197 + logger.debug("[Strabon.GeoJSON] Found resource: {}", value); 17.198 + } 17.199 + 17.200 + properties.add(binding.getName()); 17.201 + values.add(value); 17.202 + } 17.203 + } 17.204 + 17.205 + // construct the feature of the result 17.206 + for (int i = 0; i < features.size(); i++) { 17.207 + SimpleFeatureTypeBuilder sftb = features.get(i); 17.208 + 17.209 + // add the properties 17.210 + for (int p = 0; p < properties.size(); p++) { 17.211 + sftb.add(properties.get(p), String.class); 17.212 + } 17.213 + 17.214 + SimpleFeatureType featureType = sftb.buildFeatureType(); 17.215 + SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); 17.216 + 17.217 + // add the geometry to the builder of the feature 17.218 + featureBuilder.add(geometries.get(i)); 17.219 + 17.220 + // add the values to the builder of the feature 17.221 + for (int v = 0; v < values.size(); v++) { 17.222 + featureBuilder.add(values.get(v)); 17.223 + } 17.224 + 17.225 + SimpleFeature feature = featureBuilder.buildFeature(null); 17.226 + sfCollection.add(feature); 17.227 + } 17.228 + 17.229 + } catch (Exception e) { 17.230 + throw new TupleQueryResultHandlerException(e); 17.231 + } 17.232 + 17.233 + } 17.234 + 17.235 + @Override 17.236 + public TupleQueryResultFormat getTupleQueryResultFormat() { 17.237 + return stSPARQLQueryResultFormat.GEOJSON; 17.238 + } 17.239 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriterFactory.java Tue Nov 06 19:24:43 2012 +0200 18.3 @@ -0,0 +1,35 @@ 18.4 +/** 18.5 + * This Source Code Form is subject to the terms of the Mozilla Public 18.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 18.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 18.8 + * 18.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 18.10 + * 18.11 + * http://www.strabon.di.uoa.gr/ 18.12 + */ 18.13 +package org.openrdf.query.resultio.sparqlgeojson; 18.14 + 18.15 +import java.io.OutputStream; 18.16 + 18.17 +import org.openrdf.query.resultio.TupleQueryResultFormat; 18.18 +import org.openrdf.query.resultio.TupleQueryResultWriter; 18.19 +import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 18.20 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 18.21 + 18.22 +/** 18.23 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 18.24 + * 18.25 + */ 18.26 +public class stSPARQLResultsGeoJSONWriterFactory implements TupleQueryResultWriterFactory { 18.27 + 18.28 + @Override 18.29 + public TupleQueryResultFormat getTupleQueryResultFormat() { 18.30 + return stSPARQLQueryResultFormat.GEOJSON; 18.31 + } 18.32 + 18.33 + @Override 18.34 + public TupleQueryResultWriter getWriter(OutputStream out) { 18.35 + return new stSPARQLResultsGeoJSONWriter(out); 18.36 + } 18.37 + 18.38 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/resultio-spatial/sparqlhtml/pom.xml Tue Nov 06 19:24:43 2012 +0200 19.3 @@ -0,0 +1,59 @@ 19.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 19.5 + 19.6 + <modelVersion>4.0.0</modelVersion> 19.7 + 19.8 + <parent> 19.9 + <groupId>org.openrdf.sesame</groupId> 19.10 + <artifactId>sesame-queryresultio-spatial</artifactId> 19.11 + <version>3.2.5-SNAPSHOT</version> 19.12 + </parent> 19.13 + 19.14 + <artifactId>sesame-queryresultio-spatial-sparqlhtml</artifactId> 19.15 + 19.16 + <name>OpenRDF Sesame: Spatial Query result IO - HTML</name> 19.17 + <description>Spatial Query result IO API</description> 19.18 + 19.19 + <dependencies> 19.20 + <dependency> 19.21 + <groupId>org.openrdf.sesame</groupId> 19.22 + <artifactId>sesame-queryresultio-spatial-api</artifactId> 19.23 + </dependency> 19.24 + <dependency> 19.25 + <groupId>org.openrdf.sesame</groupId> 19.26 + <artifactId>sesame-queryresultio-spatial-sparqlxml</artifactId> 19.27 + </dependency> 19.28 + <dependency> <!-- TO BE REMOVED --> 19.29 + <groupId>org.openrdf.sesame</groupId> 19.30 + <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 19.31 + </dependency> 19.32 + 19.33 + <dependency> 19.34 + <groupId>org.slf4j</groupId> 19.35 + <artifactId>slf4j-log4j12</artifactId> 19.36 + </dependency> 19.37 + 19.38 + <dependency> 19.39 + <groupId>junit</groupId> 19.40 + <artifactId>junit</artifactId> 19.41 + <scope>test</scope> 19.42 + </dependency> 19.43 + <!-- 19.44 + <dependency> 19.45 + <groupId>org.openrdf.sesame</groupId> 19.46 + <artifactId>sesame-model</artifactId> 19.47 + </dependency> 19.48 + <dependency> 19.49 + <groupId>org.openrdf.sesame</groupId> 19.50 + <artifactId>sesame-query</artifactId> 19.51 + </dependency> 19.52 + <dependency> 19.53 + <groupId>org.openrdf.sesame</groupId> 19.54 + <artifactId>sesame-rio-api</artifactId> 19.55 + </dependency> 19.56 + <dependency> 19.57 + <groupId>org.openrdf.sesame</groupId> 19.58 + <artifactId>sesame-util</artifactId> 19.59 + </dependency> 19.60 + --> 19.61 + </dependencies> 19.62 +</project>
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/resultio-spatial/sparqlhtml/src/main/java/org/openrdf/query/resultio/sparqlhtml/stSPARQLResultsHTMLWriter.java Tue Nov 06 19:24:43 2012 +0200 20.3 @@ -0,0 +1,170 @@ 20.4 +/** 20.5 + * This Source Code Form is subject to the terms of the Mozilla Public 20.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 20.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 20.8 + * 20.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 20.10 + * 20.11 + * http://www.strabon.di.uoa.gr/ 20.12 + */ 20.13 +package org.openrdf.query.resultio.sparqlhtml; 20.14 + 20.15 +import java.io.IOException; 20.16 +import java.io.OutputStream; 20.17 +import java.net.URLEncoder; 20.18 +import java.util.List; 20.19 + 20.20 +import org.openrdf.model.BNode; 20.21 +import org.openrdf.query.Binding; 20.22 +import org.openrdf.query.BindingSet; 20.23 +import org.openrdf.query.TupleQueryResultHandlerException; 20.24 +import org.openrdf.query.resultio.TupleQueryResultFormat; 20.25 +import org.openrdf.query.resultio.TupleQueryResultWriter; 20.26 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 20.27 +import org.openrdf.query.resultio.sparqlxml.stSPARQLXMLWriter; 20.28 +import org.openrdf.model.Value; 20.29 +import org.openrdf.model.URI; 20.30 + 20.31 +/** 20.32 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 20.33 + * 20.34 + */ 20.35 +public class stSPARQLResultsHTMLWriter implements TupleQueryResultWriter { 20.36 + 20.37 + public static final String TABLE = "TABLE"; 20.38 + public static final String TABLE_ROW_TAG = "TR"; 20.39 + public static final String TABLE_HEADER_TAG = "TH"; 20.40 + public static final String TABLE_DATA_TAG = "TD"; 20.41 + public static final String LINK = "A"; 20.42 + public static final String LINK_REF = "HREF"; 20.43 + public static final String STYLE = "class"; 20.44 + public static final String ID = "id"; 20.45 + public static final String LINK_ID = "uri"; 20.46 + public static final String TABLE_HEADER_CLASS = "query_results_header"; 20.47 + public static final String TABLE_DATA_CLASS = "query_results_data"; 20.48 + public static final String TABLE_CLASS = "query_results_table"; 20.49 + public static final String MORE_LINK = "comment more"; 20.50 + 20.51 + /** 20.52 + * The underlying XML formatter. 20.53 + */ 20.54 + private stSPARQLXMLWriter xmlWriter; 20.55 + 20.56 + /** 20.57 + * The ordered list of binding names of the result. 20.58 + */ 20.59 + private List<String> bindingNames; 20.60 + 20.61 + public stSPARQLResultsHTMLWriter(OutputStream out) { 20.62 + this(new stSPARQLXMLWriter(out)); 20.63 + } 20.64 + 20.65 + public stSPARQLResultsHTMLWriter(stSPARQLXMLWriter writer) { 20.66 + xmlWriter = writer; 20.67 + xmlWriter.setPrettyPrint(true); 20.68 + } 20.69 + 20.70 + @Override 20.71 + public void startQueryResult(List<String> bindingNames) 20.72 + throws TupleQueryResultHandlerException { 20.73 + 20.74 + try { 20.75 + // keep the order of binding names 20.76 + this.bindingNames = bindingNames; 20.77 + // set style for table 20.78 + xmlWriter.setAttribute(STYLE, TABLE_CLASS); 20.79 + // write start of table 20.80 + xmlWriter.startTag(TABLE); 20.81 + // write Table header containing the bindings 20.82 + xmlWriter.startTag(TABLE_ROW_TAG); 20.83 + for (String bindingName: bindingNames) { 20.84 + // set style for header 20.85 + xmlWriter.setAttribute(STYLE, TABLE_HEADER_CLASS); 20.86 + xmlWriter.textElement(TABLE_HEADER_TAG, bindingName); 20.87 + } 20.88 + 20.89 + xmlWriter.endTag(TABLE_ROW_TAG); 20.90 + } catch (IOException e) { 20.91 + throw new TupleQueryResultHandlerException(e); 20.92 + } 20.93 + 20.94 + } 20.95 + 20.96 + @Override 20.97 + public void endQueryResult() throws TupleQueryResultHandlerException { 20.98 + try { 20.99 + 20.100 + // write end of table 20.101 + xmlWriter.endTag(TABLE); 20.102 + 20.103 + // needed to flush data 20.104 + xmlWriter.endDocument(); 20.105 + 20.106 + } catch (IOException e) { 20.107 + throw new TupleQueryResultHandlerException(e); 20.108 + } 20.109 + } 20.110 + 20.111 + @Override 20.112 + public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException { 20.113 + try { 20.114 + StringBuilder value = new StringBuilder(); 20.115 + Value boundValue = null; 20.116 + 20.117 + xmlWriter.startTag(TABLE_ROW_TAG); 20.118 + for (String bindingName : bindingNames) { 20.119 + Binding binding = bindingSet.getBinding(bindingName); 20.120 + if(binding != null) 20.121 + { 20.122 + boundValue = binding.getValue(); 20.123 + value.append(boundValue.stringValue()); 20.124 + 20.125 + if(boundValue instanceof BNode) { 20.126 + value.insert(0, "_:"); 20.127 + } 20.128 + 20.129 + // If the value is a uri, make it link 20.130 + if(boundValue instanceof URI) 20.131 + { 20.132 + xmlWriter.setAttribute(STYLE, TABLE_DATA_CLASS); 20.133 + xmlWriter.startTag(TABLE_DATA_TAG); 20.134 + 20.135 + // select all the triples that contain the boundValue 20.136 + String query= "select * " + 20.137 + "where " + 20.138 + "{ " + 20.139 + "?subject ?predicate ?object . "+ 20.140 + "FILTER((?subject = <"+ boundValue.toString()+ ">) || "+ 20.141 + "(?predicate = <"+ boundValue.toString()+ ">) || "+ 20.142 + "(?object = <"+ boundValue.toString()+ ">)) " + 20.143 + "}"; 20.144 + 20.145 + String href = "Browse?view=HTML&query="+URLEncoder.encode(query, "UTF-8")+"&format=HTML&resource="+boundValue.toString(); 20.146 + xmlWriter.setAttribute(LINK_REF, href); 20.147 + xmlWriter.startTag(LINK); 20.148 + xmlWriter.text(boundValue.toString()); 20.149 + xmlWriter.endTag(LINK); 20.150 + } 20.151 + else 20.152 + { 20.153 + xmlWriter.setAttribute(STYLE, TABLE_DATA_CLASS+" "+MORE_LINK); 20.154 + xmlWriter.startTag(TABLE_DATA_TAG); 20.155 + xmlWriter.text(boundValue.toString()); 20.156 + } 20.157 + xmlWriter.endTag(TABLE_DATA_TAG); 20.158 + } 20.159 + value.setLength(0); 20.160 + } 20.161 + xmlWriter.endTag(TABLE_ROW_TAG); 20.162 + 20.163 + } catch (IOException e) { 20.164 + throw new TupleQueryResultHandlerException(e); 20.165 + } 20.166 + } 20.167 + 20.168 + @Override 20.169 + public TupleQueryResultFormat getTupleQueryResultFormat() { 20.170 + return stSPARQLQueryResultFormat.HTML; 20.171 + } 20.172 + 20.173 +} 20.174 \ No newline at end of file
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/resultio-spatial/sparqlhtml/src/main/java/org/openrdf/query/resultio/sparqlhtml/stSPARQLResultsHTMLWriterFactory.java Tue Nov 06 19:24:43 2012 +0200 21.3 @@ -0,0 +1,35 @@ 21.4 +/** 21.5 + * This Source Code Form is subject to the terms of the Mozilla Public 21.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 21.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 21.8 + * 21.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 21.10 + * 21.11 + * http://www.strabon.di.uoa.gr/ 21.12 + */ 21.13 +package org.openrdf.query.resultio.sparqlhtml; 21.14 + 21.15 +import java.io.OutputStream; 21.16 + 21.17 +import org.openrdf.query.resultio.TupleQueryResultFormat; 21.18 +import org.openrdf.query.resultio.TupleQueryResultWriter; 21.19 +import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 21.20 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 21.21 + 21.22 +/** 21.23 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 21.24 + * 21.25 + */ 21.26 +public class stSPARQLResultsHTMLWriterFactory implements TupleQueryResultWriterFactory { 21.27 + 21.28 + @Override 21.29 + public TupleQueryResultFormat getTupleQueryResultFormat() { 21.30 + return stSPARQLQueryResultFormat.HTML; 21.31 + } 21.32 + 21.33 + @Override 21.34 + public TupleQueryResultWriter getWriter(OutputStream out) { 21.35 + return new stSPARQLResultsHTMLWriter(out); 21.36 + } 21.37 + 21.38 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/resultio-spatial/sparqlkml/pom.xml Tue Nov 06 19:24:43 2012 +0200 22.3 @@ -0,0 +1,69 @@ 22.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 22.5 + 22.6 + <modelVersion>4.0.0</modelVersion> 22.7 + 22.8 + <parent> 22.9 + <groupId>org.openrdf.sesame</groupId> 22.10 + <artifactId>sesame-queryresultio-spatial</artifactId> 22.11 + <version>3.2.5-SNAPSHOT</version> 22.12 + </parent> 22.13 + 22.14 + <artifactId>sesame-queryresultio-spatial-sparqlkml</artifactId> 22.15 + 22.16 + <name>OpenRDF Sesame: Spatial Query result IO - KML/KMZ</name> 22.17 + <description>Spatial Query result IO API</description> 22.18 + 22.19 + <dependencies> 22.20 + <dependency> 22.21 + <groupId>org.openrdf.sesame</groupId> 22.22 + <artifactId>sesame-queryresultio-spatial-api</artifactId> 22.23 + </dependency> 22.24 + <dependency> 22.25 + <groupId>org.openrdf.sesame</groupId> 22.26 + <artifactId>sesame-queryresultio-spatial-sparqlxml</artifactId> 22.27 + </dependency> 22.28 + <dependency> 22.29 + <groupId>org.slf4j</groupId> 22.30 + <artifactId>slf4j-log4j12</artifactId> 22.31 + </dependency> 22.32 + 22.33 + <dependency> 22.34 + <groupId>junit</groupId> 22.35 + <artifactId>junit</artifactId> 22.36 + <scope>test</scope> 22.37 + </dependency> 22.38 + 22.39 + <dependency> 22.40 + <groupId>org.geotools.xsd</groupId> 22.41 + <artifactId>gt-xsd-kml</artifactId> 22.42 + </dependency> 22.43 + 22.44 + <dependency> <!-- TO BE REMOVED --> 22.45 + <groupId>org.openrdf.sesame</groupId> 22.46 + <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 22.47 + </dependency> 22.48 + <dependency> <!-- TO BE REMOVED ? --> 22.49 + <groupId>org.openrdf.sesame</groupId> 22.50 + <artifactId>sesame-sail-generaldb</artifactId> 22.51 + </dependency> 22.52 + 22.53 + <!-- 22.54 + <dependency> 22.55 + <groupId>org.openrdf.sesame</groupId> 22.56 + <artifactId>sesame-model</artifactId> 22.57 + </dependency> 22.58 + <dependency> 22.59 + <groupId>org.openrdf.sesame</groupId> 22.60 + <artifactId>sesame-query</artifactId> 22.61 + </dependency> 22.62 + <dependency> 22.63 + <groupId>org.openrdf.sesame</groupId> 22.64 + <artifactId>sesame-rio-api</artifactId> 22.65 + </dependency> 22.66 + <dependency> 22.67 + <groupId>org.openrdf.sesame</groupId> 22.68 + <artifactId>sesame-util</artifactId> 22.69 + </dependency> 22.70 + --> 22.71 + </dependencies> 22.72 +</project>
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java Tue Nov 06 19:24:43 2012 +0200 23.3 @@ -0,0 +1,522 @@ 23.4 +/** 23.5 + * This Source Code Form is subject to the terms of the Mozilla Public License, 23.6 + * v. 2.0. If a copy of the MPL was not distributed with this file, You can 23.7 + * obtain one at http://mozilla.org/MPL/2.0/. Copyright (C) 2010, 2011, 2012, 23.8 + * Pyravlos Team http://www.strabon.di.uoa.gr/ 23.9 + */ 23.10 +package org.openrdf.query.resultio.sparqlkml; 23.11 + 23.12 +import java.io.ByteArrayOutputStream; 23.13 +import java.io.IOException; 23.14 +import java.io.OutputStream; 23.15 +import java.util.ArrayList; 23.16 +import java.util.Hashtable; 23.17 +import java.util.List; 23.18 + 23.19 +import javax.xml.bind.JAXBException; 23.20 +import javax.xml.namespace.QName; 23.21 + 23.22 +import org.geotools.kml.KML; 23.23 +import org.geotools.kml.KMLConfiguration; 23.24 +import org.geotools.xml.Encoder; 23.25 +import org.openrdf.model.BNode; 23.26 +import org.openrdf.model.Literal; 23.27 +import org.openrdf.model.Value; 23.28 +import org.openrdf.query.Binding; 23.29 +import org.openrdf.query.BindingSet; 23.30 +import org.openrdf.query.TupleQueryResultHandlerException; 23.31 +import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; 23.32 +import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; 23.33 +import org.openrdf.query.algebra.evaluation.util.JTSWrapper; 23.34 +import org.openrdf.query.resultio.TupleQueryResultFormat; 23.35 +import org.openrdf.query.resultio.TupleQueryResultWriter; 23.36 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 23.37 +import org.openrdf.query.resultio.sparqlxml.stSPARQLXMLWriter; 23.38 +import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 23.39 +import org.openrdf.sail.generaldb.model.XMLGSDatatypeUtil; 23.40 +import org.slf4j.Logger; 23.41 +import org.slf4j.LoggerFactory; 23.42 + 23.43 +import com.vividsolutions.jts.geom.Geometry; 23.44 +import com.vividsolutions.jts.geom.GeometryCollection; 23.45 +import com.vividsolutions.jts.geom.LineString; 23.46 +import com.vividsolutions.jts.geom.MultiLineString; 23.47 +import com.vividsolutions.jts.geom.MultiPoint; 23.48 +import com.vividsolutions.jts.geom.MultiPolygon; 23.49 +import com.vividsolutions.jts.geom.Point; 23.50 +import com.vividsolutions.jts.geom.Polygon; 23.51 +import com.vividsolutions.jts.io.ParseException; 23.52 + 23.53 +/** 23.54 + * @author Manos Karpathiotakis <mk@di.uoa.gr> 23.55 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 23.56 + * @author Panayiotis Smeros <psmeros@di.uoa.gr> 23.57 + * 23.58 + */ 23.59 +public class stSPARQLResultsKMLWriter implements TupleQueryResultWriter { 23.60 + private static final Logger logger = LoggerFactory.getLogger(org.openrdf.query.resultio.sparqlkml.stSPARQLResultsKMLWriter.class); 23.61 + 23.62 + // KML tags/attributes 23.63 + private static final String ROOT_TAG = "kml"; 23.64 + private static final String NAMESPACE = "http://www.opengis.net/kml/2.2"; 23.65 + private static final String RESULT_SET_TAG = "Folder"; 23.66 + private static final String PLACEMARK_TAG = "Placemark"; 23.67 + private static final String NAME_TAG = "name"; 23.68 + private static final String DESC_TAG = "description"; 23.69 + private static final String STYLE_TAG = "Style"; 23.70 + private static final String STYLEMAP_TAG = "StyleMap"; 23.71 + private static final String LINESTYLE_TAG = "LineStyle"; 23.72 + private static final String POLYSTYLE_TAG = "PolyStyle"; 23.73 + private static final String EXT_DATA_TAG = "ExtendedData"; 23.74 + private static final String DATA_TAG = "Data"; 23.75 + private static final String VALUE_TAG = "value"; 23.76 + private static final String NAME_ATTR = NAME_TAG; 23.77 + 23.78 + private static final String STYLE_ID = "resultStyle"; 23.79 + private static final String TABLE_ROW_BEGIN = "<TR>"; 23.80 + private static final String TABLE_ROW_END = "</TR>"; 23.81 + private static final String TABLE_DATA_BEGIN = "<TD>"; 23.82 + private static final String TABLE_DATA_END = "</TD>"; 23.83 + private static final String NEWLINE = "\n"; 23.84 + private static final String TABLE_DESC_BEGIN = "<![CDATA[<TABLE border=\"1\">"+ NEWLINE; 23.85 + private static final String TABLE_DESC_END = "</TABLE>]]>" + NEWLINE; 23.86 + 23.87 + private static final String GEOMETRY_NAME = "Geometry"; 23.88 + private static final String MULTIGEOMETRY = "MultiGeometry"; 23.89 + 23.90 + // Styling options 23.91 + private static final int numOfStyles = 5; 23.92 + private static final String[][] styles = { 23.93 + // note that colors are encoded as "aabbggrr" strings where 23.94 + // aa=alpha (00 to ff); bb=blue (00 to ff); gg=green (00 to ff); 23.95 + // rr=red 23.96 + // (00 to ff). 23.97 + // id, line width, line color, polygon fill, mouse over line width, 23.98 + // mouse over line color mouse over polygon fill 23.99 + // {STYLE_ID + "1", "1.5", "7d0000ff", "ad0000ff", "1.5", 23.100 + // "7d0000ff", "ad0000ff"}, {STYLE_ID + "2", "1.5", "7d0000ff", 23.101 + // "ad0000ff", "1.5", "7d0000ff", "ad0000ff"}, {STYLE_ID + "3", 23.102 + // "1.5", "7d550000", "ad550000", "1.5", "7d0000ff", "ad0000ff"}, 23.103 + // {STYLE_ID + "4", "1.5", "7d005500", "ad005500", "1.5", 23.104 + // "7d0000ff", "ad0000ff"}, {STYLE_ID + "5", "1.5", "7d000055", 23.105 + // "ad000055", "1.5", "7d0000ff", "ad0000ff"}}; 23.106 + { STYLE_ID + "1", "1.5", "000000ff", "000000ff", "1.5", "000000ff", 23.107 + "000000ff" }, 23.108 + { STYLE_ID + "2", "1.5", "000000ff", "000000ff", "1.5", "000000ff", 23.109 + "000000ff" }, 23.110 + { STYLE_ID + "3", "1.5", "7d550000", "ad550000", "1.5", "7d0000ff", 23.111 + "ad0000ff" }, 23.112 + { STYLE_ID + "4", "1.5", "7d005500", "ad005500", "1.5", "7d0000ff", 23.113 + "ad0000ff" }, 23.114 + { STYLE_ID + "5", "1.5", "7dff0000", "adff0000", "1.5", "7dff0000", 23.115 + "adff0000" } }; 23.116 + 23.117 + /** 23.118 + * The underlying XML formatter. 23.119 + */ 23.120 + private stSPARQLXMLWriter xmlWriter; 23.121 + 23.122 + /** 23.123 + * The number of results seen. 23.124 + */ 23.125 + private int nresults; 23.126 + 23.127 + /** 23.128 + * The number of geometries seen. 23.129 + */ 23.130 + private int ngeometries; 23.131 + 23.132 + /** 23.133 + * The JTS wrapper 23.134 + */ 23.135 + private JTSWrapper jts; 23.136 + 23.137 + /** 23.138 + * Stream for manipulating geometries 23.139 + */ 23.140 + private ByteArrayOutputStream baos; 23.141 + 23.142 + /** 23.143 + * Description string holding the projected variables of the SPARQL query 23.144 + */ 23.145 + private StringBuilder descHeader; 23.146 + 23.147 + /** 23.148 + * Description string holding the values for the projected variables of the 23.149 + * SPARQL query 23.150 + */ 23.151 + private StringBuilder descData; 23.152 + 23.153 + /** 23.154 + * Indentation used in tags that are constructed manually 23.155 + */ 23.156 + private int depth; 23.157 + 23.158 + /** 23.159 + * Creates an stSPARQLResultsKMLWriter that encodes the SPARQL results in 23.160 + * KML. 23.161 + * 23.162 + * @param out 23.163 + */ 23.164 + public stSPARQLResultsKMLWriter(OutputStream out) { 23.165 + this(new stSPARQLXMLWriter(out)); 23.166 + } 23.167 + 23.168 + public stSPARQLResultsKMLWriter(stSPARQLXMLWriter writer) { 23.169 + xmlWriter = writer; 23.170 + xmlWriter.setPrettyPrint(true); 23.171 + depth = 4; 23.172 + jts = JTSWrapper.getInstance(); 23.173 + baos = new ByteArrayOutputStream(); 23.174 + descHeader = new StringBuilder(); 23.175 + descData = new StringBuilder(); 23.176 + nresults = 0; 23.177 + ngeometries = 0; 23.178 + } 23.179 + 23.180 + @Override 23.181 + public void startQueryResult(List<String> bindingNames) 23.182 + throws TupleQueryResultHandlerException { 23.183 + try { 23.184 + 23.185 + xmlWriter.startDocument(); 23.186 + xmlWriter.setAttribute("xmlns", NAMESPACE); 23.187 + xmlWriter.startTag(ROOT_TAG); 23.188 + xmlWriter.startTag(RESULT_SET_TAG); 23.189 + 23.190 + // add default styles 23.191 + for (String[] style : styles) { 23.192 + String id = style[0]; 23.193 + String lineWidth = style[1]; 23.194 + String lineColor = style[2]; 23.195 + String polygonFill = style[3]; 23.196 + String mouseOverLineWidth = style[4]; 23.197 + String mouseOverLineColor = style[5]; 23.198 + String mouseOverPolygonFill = style[6]; 23.199 + 23.200 + // append normal style 23.201 + xmlWriter.setAttribute("id", "normal_" + id); 23.202 + xmlWriter.startTag(STYLE_TAG); 23.203 + xmlWriter.startTag(LINESTYLE_TAG); 23.204 + xmlWriter.textElement("width", lineWidth); 23.205 + xmlWriter.textElement("color", lineColor); 23.206 + xmlWriter.endTag(LINESTYLE_TAG); 23.207 + xmlWriter.startTag(POLYSTYLE_TAG); 23.208 + xmlWriter.textElement("color", polygonFill); 23.209 + xmlWriter.endTag(POLYSTYLE_TAG); 23.210 + xmlWriter.endTag(STYLE_TAG); 23.211 + 23.212 + // append highlight style 23.213 + xmlWriter.setAttribute("id", "highlight_" + id); 23.214 + xmlWriter.startTag(STYLE_TAG); 23.215 + xmlWriter.startTag(LINESTYLE_TAG); 23.216 + xmlWriter.textElement("width", mouseOverLineWidth); 23.217 + xmlWriter.textElement("color", mouseOverLineColor); 23.218 + xmlWriter.endTag(LINESTYLE_TAG); 23.219 + xmlWriter.startTag(POLYSTYLE_TAG); 23.220 + xmlWriter.textElement("color", mouseOverPolygonFill); 23.221 + xmlWriter.endTag(POLYSTYLE_TAG); 23.222 + xmlWriter.endTag(STYLE_TAG); 23.223 + 23.224 + // define map style combining the above styles 23.225 + xmlWriter.setAttribute("id", id); 23.226 + xmlWriter.startTag(STYLEMAP_TAG); 23.227 + xmlWriter.startTag("Pair"); 23.228 + xmlWriter.textElement("key", "normal"); 23.229 + xmlWriter.textElement("styleUrl", "#normal_" + id); 23.230 + xmlWriter.endTag("Pair"); 23.231 + xmlWriter.startTag("Pair"); 23.232 + xmlWriter.textElement("key", "highlight"); 23.233 + xmlWriter.textElement("styleUrl", "#highlight_" + id); 23.234 + xmlWriter.endTag("Pair"); 23.235 + xmlWriter.endTag(STYLEMAP_TAG); 23.236 + } 23.237 + // end of default style definition 23.238 + } catch (IOException e) { 23.239 + throw new TupleQueryResultHandlerException(e); 23.240 + } 23.241 + } 23.242 + 23.243 + @Override 23.244 + public void endQueryResult() throws TupleQueryResultHandlerException { 23.245 + try { 23.246 + 23.247 + xmlWriter.endTag(RESULT_SET_TAG); 23.248 + xmlWriter.endTag(ROOT_TAG); 23.249 + xmlWriter.endDocument(); 23.250 + baos.close(); 23.251 + 23.252 + if (ngeometries < nresults) { 23.253 + logger.warn("[Strabon.KMLWriter] No spatial binding found in the result. KML requires that at least one binding maps to a geometry.", nresults); 23.254 + } 23.255 + 23.256 + } catch (IOException e) { 23.257 + throw new TupleQueryResultHandlerException(e); 23.258 + } 23.259 + } 23.260 + 23.261 + @Override 23.262 + public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException { 23.263 + try { 23.264 + int numOfGeometries = 0; 23.265 + 23.266 + // true if there are bindings that do not correspond to geometries 23.267 + boolean hasDesc = false; 23.268 + 23.269 + // increase result size 23.270 + nresults++; 23.271 + 23.272 + // create description table and header 23.273 + indent(descHeader, depth); 23.274 + descHeader.append(TABLE_DESC_BEGIN); 23.275 + indent(descHeader, depth); 23.276 + 23.277 + List<String> geometries = new ArrayList<String>(); 23.278 + Hashtable<String, String> extData = new Hashtable<String, String>(); 23.279 + 23.280 + // parse binding set 23.281 + for (Binding binding : bindingSet) { 23.282 + 23.283 + Value value = binding.getValue(); 23.284 + 23.285 + // check for geometry value 23.286 + if (XMLGSDatatypeUtil.isGeometryValue(value)) { 23.287 + numOfGeometries++; 23.288 + ngeometries++; 23.289 + if (logger.isDebugEnabled()) { 23.290 + logger.debug("[Strabon] Found geometry: {}", value); 23.291 + } 23.292 + 23.293 + geometries.add(getGeometry(value)); 23.294 + 23.295 + } else { // URI, BlankNode, or Literal other than spatial literal 23.296 + if (logger.isDebugEnabled()) { 23.297 + logger.debug("[Strabon.KMLWriter] Found URI/BlankNode/Literal ({}): {}", value.getClass(), value); 23.298 + } 23.299 + 23.300 + // mark that we found sth corresponding to the description 23.301 + hasDesc = true; 23.302 + 23.303 + // write description 23.304 + writeDesc(binding); 23.305 + 23.306 + // fill also the extended data attribute of the Placemark 23.307 + extData.put(binding.getName(), getBindingValue(binding)); 23.308 + } 23.309 + } 23.310 + 23.311 + if (numOfGeometries > 1) { 23.312 + // write each polygon in separate placemarks 23.313 + for (String geometry : geometries) { 23.314 + xmlWriter.startTag(PLACEMARK_TAG); 23.315 + xmlWriter.textElement(NAME_TAG, GEOMETRY_NAME); 23.316 + xmlWriter.textElement("styleUrl", "#"+ styles[geometries.indexOf(geometry) % (numOfStyles - 2)][0]); 23.317 + xmlWriter.startTag(MULTIGEOMETRY); 23.318 + xmlWriter.unescapedText(geometry); 23.319 + xmlWriter.endTag(MULTIGEOMETRY); 23.320 + xmlWriter.endTag(PLACEMARK_TAG); 23.321 + } 23.322 + } 23.323 + 23.324 + // also write them in the same placemarks 23.325 + xmlWriter.startTag(PLACEMARK_TAG); 23.326 + xmlWriter.textElement(NAME_TAG, GEOMETRY_NAME); 23.327 + xmlWriter.textElement("styleUrl", "#" + styles[(numOfStyles - 1)][0]); 23.328 + xmlWriter.startTag(MULTIGEOMETRY); 23.329 + 23.330 + for (String geometry : geometries) { 23.331 + xmlWriter.unescapedText(geometry); 23.332 + } 23.333 + 23.334 + xmlWriter.endTag(MULTIGEOMETRY); 23.335 + 23.336 + // we have found and constructed a description for this result. 23.337 + // Write it down. 23.338 + if (hasDesc) { 23.339 + // end the placeholder for the description data 23.340 + indent(descData, depth); 23.341 + 23.342 + // append to the table header the actual content from 23.343 + // the bindings 23.344 + descHeader.append(descData); 23.345 + 23.346 + // close the table for the description 23.347 + descHeader.append(NEWLINE); 23.348 + indent(descHeader, depth); 23.349 + descHeader.append(TABLE_DESC_END); 23.350 + 23.351 + // begin the "description" tag 23.352 + xmlWriter.startTag(DESC_TAG); 23.353 + 23.354 + // write the actual description 23.355 + xmlWriter.unescapedText(descHeader.toString()); 23.356 + 23.357 + // end the "description" tag 23.358 + xmlWriter.endTag(DESC_TAG); 23.359 + } 23.360 + 23.361 + // add the extended data 23.362 + if (extData.size() > 0) { 23.363 + xmlWriter.startTag(EXT_DATA_TAG); 23.364 + for (String key : extData.keySet()) { 23.365 + xmlWriter.setAttribute(NAME_ATTR, key); 23.366 + xmlWriter.startTag(DATA_TAG); 23.367 + xmlWriter.textElement(VALUE_TAG, extData.get(key)); 23.368 + xmlWriter.endTag(DATA_TAG); 23.369 + } 23.370 + xmlWriter.endTag(EXT_DATA_TAG); 23.371 + } 23.372 + 23.373 + // end Placemark 23.374 + xmlWriter.endTag(PLACEMARK_TAG); 23.375 + 23.376 + // clear description string builders 23.377 + descHeader.setLength(0); 23.378 + descData.setLength(0); 23.379 + 23.380 + } catch (IOException e) { 23.381 + throw new TupleQueryResultHandlerException(e); 23.382 + } 23.383 + } 23.384 + 23.385 + private String getGeometry(Value value) { 23.386 + String geometry = ""; 23.387 + QName geometryType = null; 23.388 + // the underlying geometry in value 23.389 + Geometry geom = null; 23.390 + // the underlying SRID of the geometry 23.391 + int srid = -1; 23.392 + // get the KML encoder 23.393 + Encoder encoder = null; 23.394 + try { 23.395 + encoder = new Encoder(new KMLConfiguration()); 23.396 + encoder.setIndenting(true); 23.397 + if (value instanceof GeneralDBPolyhedron) { 23.398 + GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) value; 23.399 + geom = dbpolyhedron.getPolyhedron().getGeometry(); 23.400 + srid = dbpolyhedron.getPolyhedron().getGeometry().getSRID(); 23.401 + } else { // spatial literal 23.402 + Literal spatial = (Literal) value; 23.403 + String geomRep = spatial.stringValue(); 23.404 + if (XMLGSDatatypeUtil.isWKTLiteral(spatial)) { // WKT 23.405 + geom = jts.WKTread(WKTHelper.getWithoutSRID(geomRep)); 23.406 + srid = WKTHelper.getSRID(geomRep); 23.407 + } else { // GML 23.408 + geom = jts.GMLread(geomRep); 23.409 + srid = geom.getSRID(); 23.410 + } 23.411 + } 23.412 + // transform the geometry to {@link GeoConstants#defaultSRID} 23.413 + geom = jts.transform(geom, srid, GeoConstants.defaultSRID); 23.414 + if (geom instanceof Point) { 23.415 + geometryType = KML.Point; 23.416 + } else if (geom instanceof Polygon) { 23.417 + geometryType = KML.Polygon; 23.418 + } else if (geom instanceof LineString) { 23.419 + geometryType = KML.LineString; 23.420 + } else if (geom instanceof MultiPoint) { 23.421 + geometryType = KML.MultiGeometry; 23.422 + } else if (geom instanceof MultiLineString) { 23.423 + geometryType = KML.MultiGeometry; 23.424 + } else if (geom instanceof MultiPolygon) { 23.425 + geometryType = KML.MultiGeometry; 23.426 + } else if (geom instanceof GeometryCollection) { 23.427 + geometryType = KML.MultiGeometry; 23.428 + } 23.429 + if (geometryType == null) { 23.430 + logger.warn("[Strabon.KMLWriter] Found unknown geometry type."); 23.431 + 23.432 + } else { 23.433 + encoder.encode(geom, geometryType, baos); 23.434 + geometry = baos.toString().substring(38).replaceAll(" xmlns:kml=\"http://earth.google.com/kml/2.1\"", "").replaceAll("kml:", ""); 23.435 + 23.436 + if (geometryType == KML.MultiGeometry) { 23.437 + geometry = geometry.substring(geometry.indexOf("<MultiGeometry>") + 15, geometry.indexOf("</MultiGeometry>")); 23.438 + } 23.439 + 23.440 + /* 23.441 + * if(geom instanceof Point) { geometry = 23.442 + * geometry.substring(geometry.indexOf("<Point>"), 23.443 + * geometry.indexOf("</Point>") + 8); } else if(geom instanceof 23.444 + * Polygon) { geometry = 23.445 + * geometry.substring(geometry.indexOf("<Polygon>"), 23.446 + * geometry.indexOf("</Polygon>") + 10); } else if(geom 23.447 + * instanceof LineString) { geometry = 23.448 + * geometry.substring(geometry.indexOf("<LineString>"), 23.449 + * geometry.indexOf("</LineString>") + 13); } else if(geom 23.450 + * instanceof MultiPoint) { geometry = 23.451 + * geometry.substring(geometry.indexOf("<MultiPoint>"), 23.452 + * geometry.indexOf("</MultiPoint>") + 13); } else if(geom 23.453 + * instanceof MultiLineString) { geometry = 23.454 + * geometry.substring(geometry.indexOf("<MultiLineString>"), 23.455 + * geometry.indexOf("</MultiLineString>") + 18); } else if(geom 23.456 + * instanceof MultiPolygon) { geometry = 23.457 + * geometry.substring(geometry.indexOf("<MultiPolygon>"), 23.458 + * geometry.indexOf("</MultiPolygon>") + 15); } else if(geom 23.459 + * instanceof GeometryCollection) { geometry = 23.460 + * geometry.substring(geometry.indexOf("<GeometryCollection>"), 23.461 + * geometry.indexOf("</GeometryCollection>") + 21); } 23.462 + */ 23.463 + baos.reset(); 23.464 + } 23.465 + } catch (ParseException e) { 23.466 + logger.error("[Strabon.KMLWriter] Parse error exception of geometry: {}", e.getMessage()); 23.467 + 23.468 + } catch (IOException e) { 23.469 + logger.error("[Strabon.KMLWriter] IOException during KML encoding of geometry: {}", e.getMessage()); 23.470 + 23.471 + } catch (JAXBException e) { 23.472 + logger.error("[Strabon.KMLWriter] Exception during GML parsing: {}", e.getMessage()); 23.473 + } 23.474 + 23.475 + return geometry; 23.476 + } 23.477 + 23.478 + /** 23.479 + * Adds to the description table information for a binding. 23.480 + * 23.481 + * @param binding 23.482 + */ 23.483 + private void writeDesc(Binding binding) { 23.484 + descData.append(NEWLINE); 23.485 + indent(descData, depth + 1); 23.486 + descData.append(TABLE_ROW_BEGIN); 23.487 + descData.append(TABLE_DATA_BEGIN); 23.488 + descData.append(binding.getName()); 23.489 + descData.append(TABLE_DATA_END); 23.490 + descData.append(TABLE_DATA_BEGIN); 23.491 + if (binding.getValue() instanceof BNode) { 23.492 + descData.append("_:"); 23.493 + } 23.494 + descData.append(binding.getValue().stringValue()); 23.495 + descData.append(TABLE_DATA_END); 23.496 + descData.append(TABLE_ROW_END); 23.497 + } 23.498 + 23.499 + private String getBindingValue(Binding binding) { 23.500 + String val = binding.getValue().stringValue(); 23.501 + if (binding.getValue() instanceof BNode) { 23.502 + val = "_:" + val; 23.503 + } 23.504 + 23.505 + return val; 23.506 + } 23.507 + 23.508 + @Override 23.509 + public TupleQueryResultFormat getTupleQueryResultFormat() { 23.510 + return stSPARQLQueryResultFormat.KML; 23.511 + } 23.512 + 23.513 + /** 23.514 + * Adds indentation to the given string builder according to the specified 23.515 + * depth. 23.516 + * 23.517 + * @param sb 23.518 + * @param depth 23.519 + */ 23.520 + private void indent(StringBuilder sb, int depth) { 23.521 + for (int i = 0; i < depth; i++) { 23.522 + sb.append(xmlWriter.getIndentString()); 23.523 + } 23.524 + } 23.525 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriterFactory.java Tue Nov 06 19:24:43 2012 +0200 24.3 @@ -0,0 +1,35 @@ 24.4 +/** 24.5 + * This Source Code Form is subject to the terms of the Mozilla Public 24.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 24.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 24.8 + * 24.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 24.10 + * 24.11 + * http://www.strabon.di.uoa.gr/ 24.12 + */ 24.13 +package org.openrdf.query.resultio.sparqlkml; 24.14 + 24.15 +import java.io.OutputStream; 24.16 + 24.17 +import org.openrdf.query.resultio.TupleQueryResultFormat; 24.18 +import org.openrdf.query.resultio.TupleQueryResultWriter; 24.19 +import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 24.20 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 24.21 + 24.22 +/** 24.23 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 24.24 + * 24.25 + */ 24.26 +public class stSPARQLResultsKMLWriterFactory implements TupleQueryResultWriterFactory { 24.27 + 24.28 + @Override 24.29 + public TupleQueryResultFormat getTupleQueryResultFormat() { 24.30 + return stSPARQLQueryResultFormat.KML; 24.31 + } 24.32 + 24.33 + @Override 24.34 + public TupleQueryResultWriter getWriter(OutputStream out) { 24.35 + return new stSPARQLResultsKMLWriter(out); 24.36 + } 24.37 + 24.38 +}
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMZWriter.java Tue Nov 06 19:24:43 2012 +0200 25.3 @@ -0,0 +1,106 @@ 25.4 +/** 25.5 + * This Source Code Form is subject to the terms of the Mozilla Public 25.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 25.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 25.8 + * 25.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 25.10 + * 25.11 + * http://www.strabon.di.uoa.gr/ 25.12 + */ 25.13 +package org.openrdf.query.resultio.sparqlkml; 25.14 + 25.15 +import java.io.IOException; 25.16 +import java.io.OutputStream; 25.17 +import java.util.List; 25.18 +import java.util.zip.ZipEntry; 25.19 +import java.util.zip.ZipOutputStream; 25.20 + 25.21 +import org.openrdf.query.BindingSet; 25.22 +import org.openrdf.query.TupleQueryResultHandlerException; 25.23 +import org.openrdf.query.resultio.TupleQueryResultFormat; 25.24 +import org.openrdf.query.resultio.TupleQueryResultWriter; 25.25 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 25.26 +import org.openrdf.query.resultio.sparqlkml.stSPARQLResultsKMLWriter; 25.27 + 25.28 +/** 25.29 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 25.30 + * 25.31 + */ 25.32 +public class stSPARQLResultsKMZWriter implements TupleQueryResultWriter { 25.33 + 25.34 + /** 25.35 + * The name of the KML file that shall be zipped 25.36 + * (by convention corresponds to "doc") 25.37 + */ 25.38 + private static final String ZIP_ENTRY_FILENAME = "doc.kml"; 25.39 + 25.40 + /** 25.41 + * After all a KMZ file is a zipped KML one 25.42 + */ 25.43 + private stSPARQLResultsKMLWriter kmlWriter; 25.44 + 25.45 + /** 25.46 + * The zipped output stream to wrap the original one 25.47 + */ 25.48 + private ZipOutputStream kmzout; 25.49 + 25.50 + /** 25.51 + * The zip entry 25.52 + */ 25.53 + private ZipEntry entry; 25.54 + 25.55 + public stSPARQLResultsKMZWriter(OutputStream out) { 25.56 + // create a zip stream on the given output stream 25.57 + kmzout = new ZipOutputStream(out); 25.58 + 25.59 + // initialize the KMLWriter with that stream instead passing the original 25.60 + kmlWriter = new stSPARQLResultsKMLWriter(kmzout); 25.61 + } 25.62 + 25.63 + @Override 25.64 + public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException { 25.65 + try { 25.66 + // create a zip entry 25.67 + entry = new ZipEntry(ZIP_ENTRY_FILENAME); 25.68 + 25.69 + // add the zip entry in it 25.70 + kmzout.putNextEntry(entry); 25.71 + 25.72 + // now pass execution to KMLWriter 25.73 + kmlWriter.startQueryResult(bindingNames); 25.74 + 25.75 + } catch (IOException e) { 25.76 + throw new TupleQueryResultHandlerException(e); 25.77 + } 25.78 + } 25.79 + 25.80 + @Override 25.81 + public void endQueryResult() throws TupleQueryResultHandlerException { 25.82 + 25.83 + try { 25.84 + // pass execution to KMLWriter 25.85 + kmlWriter.endQueryResult(); 25.86 + 25.87 + // close the zip entry 25.88 + kmzout.closeEntry(); 25.89 + 25.90 + // close the zip stream 25.91 + kmzout.close(); 25.92 + 25.93 + } catch (IOException e) { 25.94 + throw new TupleQueryResultHandlerException(e); 25.95 + } 25.96 + } 25.97 + 25.98 + @Override 25.99 + public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException { 25.100 + // pass execution to KMLWriter 25.101 + kmlWriter.handleSolution(bindingSet); 25.102 + } 25.103 + 25.104 + @Override 25.105 + public TupleQueryResultFormat getTupleQueryResultFormat() { 25.106 + return stSPARQLQueryResultFormat.KMZ; 25.107 + } 25.108 + 25.109 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMZWriterFactory.java Tue Nov 06 19:24:43 2012 +0200 26.3 @@ -0,0 +1,35 @@ 26.4 +/** 26.5 + * This Source Code Form is subject to the terms of the Mozilla Public 26.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 26.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 26.8 + * 26.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 26.10 + * 26.11 + * http://www.strabon.di.uoa.gr/ 26.12 + */ 26.13 +package org.openrdf.query.resultio.sparqlkml; 26.14 + 26.15 +import java.io.OutputStream; 26.16 + 26.17 +import org.openrdf.query.resultio.TupleQueryResultFormat; 26.18 +import org.openrdf.query.resultio.TupleQueryResultWriter; 26.19 +import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 26.20 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 26.21 + 26.22 +/** 26.23 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 26.24 + * 26.25 + */ 26.26 +public class stSPARQLResultsKMZWriterFactory implements TupleQueryResultWriterFactory { 26.27 + 26.28 + @Override 26.29 + public TupleQueryResultFormat getTupleQueryResultFormat() { 26.30 + return stSPARQLQueryResultFormat.KMZ; 26.31 + } 26.32 + 26.33 + @Override 26.34 + public TupleQueryResultWriter getWriter(OutputStream out) { 26.35 + return new stSPARQLResultsKMZWriter(out); 26.36 + } 26.37 + 26.38 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/resultio-spatial/sparqlxml/pom.xml Tue Nov 06 19:24:43 2012 +0200 27.3 @@ -0,0 +1,59 @@ 27.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 27.5 + 27.6 + <modelVersion>4.0.0</modelVersion> 27.7 + 27.8 + <parent> 27.9 + <groupId>org.openrdf.sesame</groupId> 27.10 + <artifactId>sesame-queryresultio-spatial</artifactId> 27.11 + <version>3.2.5-SNAPSHOT</version> 27.12 + </parent> 27.13 + 27.14 + <artifactId>sesame-queryresultio-spatial-sparqlxml</artifactId> 27.15 + 27.16 + <name>OpenRDF Sesame: Spatial Query result IO - XML</name> 27.17 + <description>Spatial Query result IO API</description> 27.18 + 27.19 + <dependencies> 27.20 + <dependency> 27.21 + <groupId>org.openrdf.sesame</groupId> 27.22 + <artifactId>sesame-queryresultio-spatial-api</artifactId> 27.23 + </dependency> 27.24 + <dependency> 27.25 + <groupId>org.openrdf.sesame</groupId> 27.26 + <artifactId>sesame-queryresultio-sparqlxml</artifactId> 27.27 + </dependency> 27.28 + <dependency> <!-- TO BE REMOVED --> 27.29 + <groupId>org.openrdf.sesame</groupId> 27.30 + <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 27.31 + </dependency> 27.32 + 27.33 + <dependency> 27.34 + <groupId>org.slf4j</groupId> 27.35 + <artifactId>slf4j-log4j12</artifactId> 27.36 + </dependency> 27.37 + 27.38 + <dependency> 27.39 + <groupId>junit</groupId> 27.40 + <artifactId>junit</artifactId> 27.41 + <scope>test</scope> 27.42 + </dependency> 27.43 + <!-- 27.44 + <dependency> 27.45 + <groupId>org.openrdf.sesame</groupId> 27.46 + <artifactId>sesame-model</artifactId> 27.47 + </dependency> 27.48 + <dependency> 27.49 + <groupId>org.openrdf.sesame</groupId> 27.50 + <artifactId>sesame-query</artifactId> 27.51 + </dependency> 27.52 + <dependency> 27.53 + <groupId>org.openrdf.sesame</groupId> 27.54 + <artifactId>sesame-rio-api</artifactId> 27.55 + </dependency> 27.56 + <dependency> 27.57 + <groupId>org.openrdf.sesame</groupId> 27.58 + <artifactId>sesame-util</artifactId> 27.59 + </dependency> 27.60 + --> 27.61 + </dependencies> 27.62 +</project>
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/resultio-spatial/sparqlxml/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLResultsXMLWriter.java Tue Nov 06 19:24:43 2012 +0200 28.3 @@ -0,0 +1,190 @@ 28.4 +/* 28.5 + * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007. 28.6 + * 28.7 + * Licensed under the Aduna BSD-style license. 28.8 + */ 28.9 +package org.openrdf.query.resultio.sparqlxml; 28.10 + 28.11 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.BINDING_NAME_ATT; 28.12 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.BINDING_TAG; 28.13 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.BNODE_TAG; 28.14 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.HEAD_TAG; 28.15 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.LITERAL_DATATYPE_ATT; 28.16 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.LITERAL_LANG_ATT; 28.17 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.LITERAL_TAG; 28.18 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.NAMESPACE; 28.19 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.RESULT_SET_TAG; 28.20 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.RESULT_TAG; 28.21 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.ROOT_TAG; 28.22 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.URI_TAG; 28.23 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.VAR_NAME_ATT; 28.24 +import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.VAR_TAG; 28.25 +import info.aduna.xml.XMLWriter; 28.26 + 28.27 +import java.io.IOException; 28.28 +import java.io.OutputStream; 28.29 +import java.util.List; 28.30 + 28.31 +import org.openrdf.model.BNode; 28.32 +import org.openrdf.model.Literal; 28.33 +import org.openrdf.model.URI; 28.34 +import org.openrdf.model.Value; 28.35 +import org.openrdf.model.impl.LiteralImpl; 28.36 +import org.openrdf.model.impl.URIImpl; 28.37 +import org.openrdf.query.Binding; 28.38 +import org.openrdf.query.BindingSet; 28.39 +import org.openrdf.query.TupleQueryResultHandlerException; 28.40 +import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; 28.41 +import org.openrdf.query.resultio.TupleQueryResultFormat; 28.42 +import org.openrdf.query.resultio.TupleQueryResultWriter; 28.43 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 28.44 + 28.45 +/** 28.46 + * A {@link TupleQueryResultWriter} that writes tuple query results in the <a 28.47 + * href="http://www.w3.org/TR/rdf-sparql-XMLres/">SPARQL Query Results XML 28.48 + * Format</a>. 28.49 + * 28.50 + * @author Manos Karpathiotakis <mk@di.uoa.gr> 28.51 + */ 28.52 +public class stSPARQLResultsXMLWriter implements TupleQueryResultWriter { 28.53 + 28.54 + /*-----------* 28.55 + * Variables * 28.56 + *-----------*/ 28.57 + 28.58 + /** 28.59 + * XMLWriter to write XML to. 28.60 + */ 28.61 + private XMLWriter xmlWriter; 28.62 + 28.63 + /*--------------* 28.64 + * Constructors * 28.65 + *--------------*/ 28.66 + 28.67 + public stSPARQLResultsXMLWriter(OutputStream out) { 28.68 + this(new XMLWriter(out)); 28.69 + } 28.70 + 28.71 + public stSPARQLResultsXMLWriter(XMLWriter xmlWriter) { 28.72 + this.xmlWriter = xmlWriter; 28.73 + this.xmlWriter.setPrettyPrint(true); 28.74 + } 28.75 + 28.76 + public final TupleQueryResultFormat getTupleQueryResultFormat() { 28.77 + return stSPARQLQueryResultFormat.XML; 28.78 + } 28.79 + 28.80 + /** 28.81 + * Enables/disables addition of indentation characters and newlines in the 28.82 + * XML document. By default, pretty-printing is set to <tt>true</tt>. If 28.83 + * set to <tt>false</tt>, no indentation and newlines are added to the XML 28.84 + * document. This method has to be used before writing starts (that is, 28.85 + * before {@link #startQueryResult(List)} is called). 28.86 + */ 28.87 + public void setPrettyPrint(boolean prettyPrint) { 28.88 + xmlWriter.setPrettyPrint(prettyPrint); 28.89 + } 28.90 + 28.91 + public void startQueryResult(List<String> bindingNames) 28.92 + throws TupleQueryResultHandlerException 28.93 + { 28.94 + try { 28.95 + xmlWriter.startDocument(); 28.96 + 28.97 + xmlWriter.setAttribute("xmlns", NAMESPACE); 28.98 + xmlWriter.startTag(ROOT_TAG); 28.99 + 28.100 + // Write header 28.101 + xmlWriter.startTag(HEAD_TAG); 28.102 + for (String name : bindingNames) { 28.103 + xmlWriter.setAttribute(VAR_NAME_ATT, name); 28.104 + xmlWriter.emptyElement(VAR_TAG); 28.105 + } 28.106 + xmlWriter.endTag(HEAD_TAG); 28.107 + 28.108 + // Write start of results 28.109 + xmlWriter.startTag(RESULT_SET_TAG); 28.110 + } 28.111 + catch (IOException e) { 28.112 + throw new TupleQueryResultHandlerException(e); 28.113 + } 28.114 + } 28.115 + 28.116 + public void endQueryResult() 28.117 + throws TupleQueryResultHandlerException 28.118 + { 28.119 + try { 28.120 + xmlWriter.endTag(RESULT_SET_TAG); 28.121 + xmlWriter.endTag(ROOT_TAG); 28.122 + 28.123 + xmlWriter.endDocument(); 28.124 + } 28.125 + catch (IOException e) { 28.126 + throw new TupleQueryResultHandlerException(e); 28.127 + } 28.128 + } 28.129 + 28.130 + public void handleSolution(BindingSet bindingSet) 28.131 + throws TupleQueryResultHandlerException 28.132 + { 28.133 + try { 28.134 + xmlWriter.startTag(RESULT_TAG); 28.135 + 28.136 + for (Binding binding : bindingSet) { 28.137 + xmlWriter.setAttribute(BINDING_NAME_ATT, binding.getName()); 28.138 + xmlWriter.startTag(BINDING_TAG); 28.139 + 28.140 + writeValue(binding.getValue()); 28.141 + 28.142 + xmlWriter.endTag(BINDING_TAG); 28.143 + } 28.144 + 28.145 + xmlWriter.endTag(RESULT_TAG); 28.146 + } 28.147 + catch (IOException e) { 28.148 + throw new TupleQueryResultHandlerException(e); 28.149 + } 28.150 + } 28.151 + 28.152 + private void writeValue(Value value) throws IOException { 28.153 + if (value instanceof URI) { 28.154 + writeURI((URI) value); 28.155 + } else if (value instanceof BNode) { 28.156 + writeBNode((BNode) value); 28.157 + } else if (value instanceof Literal) { 28.158 + writeLiteral((Literal) value); 28.159 + } 28.160 + else { // spatial literal 28.161 + // else if (value instanceof RdbmsPolyhedron) 28.162 + URI datatype = new URIImpl(GeoConstants.WKT); 28.163 + Literal literal = new LiteralImpl(value.stringValue(), datatype); 28.164 + writeLiteral(literal); 28.165 + } 28.166 + } 28.167 + 28.168 + private void writeURI(URI uri) 28.169 + throws IOException 28.170 + { 28.171 + xmlWriter.textElement(URI_TAG, uri.toString()); 28.172 + } 28.173 + 28.174 + private void writeBNode(BNode bNode) 28.175 + throws IOException 28.176 + { 28.177 + xmlWriter.textElement(BNODE_TAG, bNode.getID()); 28.178 + } 28.179 + 28.180 + private void writeLiteral(Literal literal) 28.181 + throws IOException 28.182 + { 28.183 + if (literal.getLanguage() != null) { 28.184 + xmlWriter.setAttribute(LITERAL_LANG_ATT, literal.getLanguage()); 28.185 + } 28.186 + else if (literal.getDatatype() != null) { 28.187 + URI datatype = literal.getDatatype(); 28.188 + xmlWriter.setAttribute(LITERAL_DATATYPE_ATT, datatype.toString()); 28.189 + } 28.190 + 28.191 + xmlWriter.textElement(LITERAL_TAG, literal.getLabel()); 28.192 + } 28.193 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/resultio-spatial/sparqlxml/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLResultsXMLWriterFactory.java Tue Nov 06 19:24:43 2012 +0200 29.3 @@ -0,0 +1,35 @@ 29.4 +/** 29.5 + * This Source Code Form is subject to the terms of the Mozilla Public 29.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 29.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 29.8 + * 29.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 29.10 + * 29.11 + * http://www.strabon.di.uoa.gr/ 29.12 + */ 29.13 +package org.openrdf.query.resultio.sparqlxml; 29.14 + 29.15 +import java.io.OutputStream; 29.16 + 29.17 +import org.openrdf.query.resultio.TupleQueryResultFormat; 29.18 +import org.openrdf.query.resultio.TupleQueryResultWriter; 29.19 +import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 29.20 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 29.21 + 29.22 +/** 29.23 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 29.24 + * 29.25 + */ 29.26 +public class stSPARQLResultsXMLWriterFactory implements TupleQueryResultWriterFactory { 29.27 + 29.28 + @Override 29.29 + public TupleQueryResultFormat getTupleQueryResultFormat() { 29.30 + return stSPARQLQueryResultFormat.XML; 29.31 + } 29.32 + 29.33 + @Override 29.34 + public TupleQueryResultWriter getWriter(OutputStream out) { 29.35 + return new stSPARQLResultsXMLWriter(out); 29.36 + } 29.37 + 29.38 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/resultio-spatial/sparqlxml/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLXMLWriter.java Tue Nov 06 19:24:43 2012 +0200 30.3 @@ -0,0 +1,55 @@ 30.4 +/** 30.5 + * This Source Code Form is subject to the terms of the Mozilla Public 30.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 30.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 30.8 + * 30.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 30.10 + * 30.11 + * http://www.strabon.di.uoa.gr/ 30.12 + */ 30.13 +package org.openrdf.query.resultio.sparqlxml; 30.14 + 30.15 +import java.io.IOException; 30.16 +import java.io.OutputStream; 30.17 +import java.io.UnsupportedEncodingException; 30.18 +import java.io.Writer; 30.19 + 30.20 +import info.aduna.xml.XMLWriter; 30.21 + 30.22 +/** 30.23 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 30.24 + * 30.25 + */ 30.26 +public class stSPARQLXMLWriter extends XMLWriter { 30.27 + 30.28 + /** 30.29 + * @param writer 30.30 + */ 30.31 + public stSPARQLXMLWriter(Writer writer) { 30.32 + super(writer); 30.33 + } 30.34 + 30.35 + /** 30.36 + * @param outputStream 30.37 + */ 30.38 + public stSPARQLXMLWriter(OutputStream outputStream) { 30.39 + super(outputStream); 30.40 + } 30.41 + 30.42 + /** 30.43 + * @param outputStream 30.44 + * @param charEncoding 30.45 + * @throws UnsupportedEncodingException 30.46 + */ 30.47 + public stSPARQLXMLWriter(OutputStream outputStream, String charEncoding) throws UnsupportedEncodingException { 30.48 + super(outputStream, charEncoding); 30.49 + } 30.50 + 30.51 + /** 30.52 + * Like XMLWriter.text(String text) but without escaping the string. 30.53 + */ 30.54 + public void unescapedText(String text) throws IOException { 30.55 + _write(text); 30.56 + } 30.57 + 30.58 +}
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/resultio-spatial/text/pom.xml Tue Nov 06 19:24:43 2012 +0200 31.3 @@ -0,0 +1,63 @@ 31.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 31.5 + 31.6 + <modelVersion>4.0.0</modelVersion> 31.7 + 31.8 + <parent> 31.9 + <groupId>org.openrdf.sesame</groupId> 31.10 + <artifactId>sesame-queryresultio-spatial</artifactId> 31.11 + <version>3.2.5-SNAPSHOT</version> 31.12 + </parent> 31.13 + 31.14 + <artifactId>sesame-queryresultio-spatial-text</artifactId> 31.15 + 31.16 + <name>OpenRDF Sesame: Spatial Query result IO - Text</name> 31.17 + <description>Spatial Query result IO API</description> 31.18 + 31.19 + <dependencies> 31.20 + <dependency> 31.21 + <groupId>org.openrdf.sesame</groupId> 31.22 + <artifactId>sesame-queryresultio-spatial-api</artifactId> 31.23 + </dependency> 31.24 + <dependency> <!-- TO BE REMOVED --> 31.25 + <groupId>org.openrdf.sesame</groupId> 31.26 + <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 31.27 + </dependency> 31.28 + <dependency> <!-- TO BE REMOVED ? --> 31.29 + <groupId>org.openrdf.sesame</groupId> 31.30 + <artifactId>sesame-sail-generaldb</artifactId> 31.31 + </dependency> 31.32 + <dependency> 31.33 + <groupId>org.openrdf.sesame</groupId> 31.34 + <artifactId>sesame-queryresultio-text</artifactId> 31.35 + </dependency> 31.36 + 31.37 + <dependency> 31.38 + <groupId>org.slf4j</groupId> 31.39 + <artifactId>slf4j-log4j12</artifactId> 31.40 + </dependency> 31.41 + 31.42 + <dependency> 31.43 + <groupId>junit</groupId> 31.44 + <artifactId>junit</artifactId> 31.45 + <scope>test</scope> 31.46 + </dependency> 31.47 +<!-- 31.48 + <dependency> 31.49 + <groupId>org.openrdf.sesame</groupId> 31.50 + <artifactId>sesame-model</artifactId> 31.51 + </dependency> 31.52 + <dependency> 31.53 + <groupId>org.openrdf.sesame</groupId> 31.54 + <artifactId>sesame-query</artifactId> 31.55 + </dependency> 31.56 + <dependency> 31.57 + <groupId>org.openrdf.sesame</groupId> 31.58 + <artifactId>sesame-rio-api</artifactId> 31.59 + </dependency> 31.60 + <dependency> 31.61 + <groupId>org.openrdf.sesame</groupId> 31.62 + <artifactId>sesame-util</artifactId> 31.63 + </dependency> 31.64 +--> 31.65 + </dependencies> 31.66 +</project>
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/resultio-spatial/text/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java Tue Nov 06 19:24:43 2012 +0200 32.3 @@ -0,0 +1,43 @@ 32.4 +/** 32.5 + * This Source Code Form is subject to the terms of the Mozilla Public 32.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 32.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 32.8 + * 32.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 32.10 + * 32.11 + * http://www.strabon.di.uoa.gr/ 32.12 + */ 32.13 +package org.openrdf.query.resultio.text; 32.14 + 32.15 +import java.io.IOException; 32.16 +import java.io.OutputStream; 32.17 + 32.18 +import org.openrdf.model.Value; 32.19 +import org.openrdf.model.impl.LiteralImpl; 32.20 +import org.openrdf.query.resultio.text.tsv.SPARQLResultsTSVWriter; 32.21 +import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 32.22 + 32.23 +/** 32.24 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 32.25 + * 32.26 + */ 32.27 +public class stSPARQLResultsTSVWriter extends SPARQLResultsTSVWriter { 32.28 + 32.29 + public stSPARQLResultsTSVWriter(OutputStream out) { 32.30 + super(out); 32.31 + } 32.32 + 32.33 + @Override 32.34 + protected void writeValue(Value val) throws IOException { 32.35 + if (val instanceof GeneralDBPolyhedron) { 32.36 + // catch the spatial case and create a new literal 32.37 + // constructing a new literal is the only way if we want to reuse the {@link #writeValue(Value)} method 32.38 + GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) val; 32.39 + val = new LiteralImpl(dbpolyhedron.getPolyhedronStringRep(), dbpolyhedron.getDatatype()); 32.40 + } 32.41 + 32.42 + // write value 32.43 + super.writeValue(val); 32.44 + 32.45 + } 32.46 +}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/resultio-spatial/text/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriterFactory.java Tue Nov 06 19:24:43 2012 +0200 33.3 @@ -0,0 +1,35 @@ 33.4 +/** 33.5 + * This Source Code Form is subject to the terms of the Mozilla Public 33.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 33.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 33.8 + * 33.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 33.10 + * 33.11 + * http://www.strabon.di.uoa.gr/ 33.12 + */ 33.13 +package org.openrdf.query.resultio.text; 33.14 + 33.15 +import java.io.OutputStream; 33.16 + 33.17 +import org.openrdf.query.resultio.TupleQueryResultFormat; 33.18 +import org.openrdf.query.resultio.TupleQueryResultWriter; 33.19 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 33.20 +import org.openrdf.query.resultio.text.tsv.SPARQLResultsTSVWriterFactory; 33.21 + 33.22 +/** 33.23 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 33.24 + * 33.25 + */ 33.26 +public class stSPARQLResultsTSVWriterFactory extends SPARQLResultsTSVWriterFactory { 33.27 + 33.28 + @Override 33.29 + public TupleQueryResultFormat getTupleQueryResultFormat() { 33.30 + return stSPARQLQueryResultFormat.TSV; 33.31 + } 33.32 + 33.33 + @Override 33.34 + public TupleQueryResultWriter getWriter(OutputStream out) { 33.35 + return new stSPARQLResultsTSVWriter(out); 33.36 + } 33.37 + 33.38 +}
34.1 --- a/resultio/pom.xml Mon Nov 05 20:40:17 2012 +0200 34.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 34.3 @@ -1,115 +0,0 @@ 34.4 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 34.5 - 34.6 - <modelVersion>4.0.0</modelVersion> 34.7 - 34.8 - <parent> 34.9 - <groupId>eu.earthobservatory</groupId> 34.10 - <artifactId>strabon</artifactId> 34.11 - <version>3.2.5-SNAPSHOT</version> 34.12 - </parent> 34.13 - 34.14 - <groupId>org.openrdf.sesame</groupId> 34.15 - <artifactId>sesame-queryresultio-spatial</artifactId> 34.16 - <name>OpenRDF Sesame: Query result IO - Spatial</name> 34.17 - <description>Minimal spatial extensions of Query result parser and writer implementation for the SPARQL Query Results Format.</description> 34.18 - <packaging>jar</packaging> 34.19 - 34.20 - <dependencies> 34.21 - 34.22 - <dependency> 34.23 - <groupId>org.openrdf.sesame</groupId> 34.24 - <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 34.25 - </dependency> 34.26 - 34.27 - <dependency> 34.28 - <groupId>org.openrdf.sesame</groupId> 34.29 - <artifactId>sesame-sail-generaldb</artifactId> 34.30 - </dependency> 34.31 - 34.32 - <dependency> 34.33 - <groupId>org.openrdf.sesame</groupId> 34.34 - <artifactId>sesame-queryresultio-sparqlxml</artifactId> 34.35 - <version>${sesame.version}</version> 34.36 - </dependency> 34.37 - 34.38 - <dependency> 34.39 - <groupId>org.openrdf.sesame</groupId> 34.40 - <artifactId>sesame-queryresultio-sparqljson</artifactId> 34.41 - <version>${sesame.version}</version> 34.42 - </dependency> 34.43 - 34.44 - <dependency> 34.45 - <groupId>org.openrdf.sesame</groupId> 34.46 - <artifactId>sesame-queryresultio-text</artifactId> 34.47 - <version>${sesame.version}</version> 34.48 - </dependency> 34.49 - 34.50 - <dependency> 34.51 - <groupId>org.openrdf.sesame</groupId> 34.52 - <artifactId>sesame-queryalgebra-model</artifactId> 34.53 - </dependency> 34.54 - 34.55 - <dependency> 34.56 - <groupId>org.openrdf.sesame</groupId> 34.57 - <artifactId>sesame-model</artifactId> 34.58 - </dependency> 34.59 - 34.60 - <dependency> 34.61 - <groupId>org.openrdf.sesame</groupId> 34.62 - <artifactId>sesame-query</artifactId> 34.63 - </dependency> 34.64 - 34.65 - <dependency> 34.66 - <groupId>org.openrdf.sesame</groupId> 34.67 - <artifactId>sesame-repository-sparql</artifactId> 34.68 - </dependency> 34.69 - 34.70 - <dependency> 34.71 - <groupId>org.slf4j</groupId> 34.72 - <artifactId>slf4j-log4j12</artifactId> 34.73 - </dependency> 34.74 - 34.75 - <dependency> 34.76 - <groupId>junit</groupId> 34.77 - <artifactId>junit</artifactId> 34.78 - </dependency> 34.79 - 34.80 - <!-- GeoTools --> 34.81 - <dependency> 34.82 - <groupId>org.geotools</groupId> 34.83 - <artifactId>gt-geojson</artifactId> 34.84 - </dependency> 34.85 - 34.86 - <dependency> 34.87 - <groupId>org.geotools.xsd</groupId> 34.88 - <artifactId>gt-xsd-kml</artifactId> 34.89 - </dependency> 34.90 - 34.91 - <dependency> 34.92 - <groupId>org.geotools</groupId> 34.93 - <artifactId>gt-xml</artifactId> 34.94 - </dependency> 34.95 - 34.96 - <dependency> 34.97 - <groupId>org.geotools</groupId> 34.98 - <artifactId>gt-epsg-hsql</artifactId> 34.99 - </dependency> 34.100 - 34.101 - <dependency> 34.102 - <groupId>org.geotools</groupId> 34.103 - <artifactId>gt-shapefile</artifactId> 34.104 - </dependency> 34.105 - 34.106 - <dependency> 34.107 - <groupId>org.geotools</groupId> 34.108 - <artifactId>gt-opengis</artifactId> 34.109 - </dependency> 34.110 - <dependency> 34.111 - <groupId>com.vividsolutions</groupId> 34.112 - <artifactId>jts</artifactId> 34.113 - <type>jar</type> 34.114 - <scope>compile</scope> 34.115 - </dependency> 34.116 - </dependencies> 34.117 -</project> 34.118 -
35.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/Format.java Mon Nov 05 20:40:17 2012 +0200 35.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 35.3 @@ -1,111 +0,0 @@ 35.4 -/** 35.5 - * This Source Code Form is subject to the terms of the Mozilla Public 35.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 35.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 35.8 - * 35.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 35.10 - * 35.11 - * http://www.strabon.di.uoa.gr/ 35.12 - */ 35.13 -package org.openrdf.query.resultio; 35.14 - 35.15 -import java.util.HashMap; 35.16 -import java.util.Map; 35.17 - 35.18 -/** 35.19 - * This enumeration type represents the available formats 35.20 - * for the results of the evaluation of a SPARQL query. 35.21 - * 35.22 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 35.23 - * 35.24 - */ 35.25 -public enum Format { 35.26 - 35.27 - /** 35.28 - * Default format 35.29 - */ 35.30 - DEFAULT(""), 35.31 - 35.32 - /** 35.33 - * XML format 35.34 - */ 35.35 - XML("XML"), 35.36 - 35.37 - /** 35.38 - * KML format 35.39 - */ 35.40 - KML("KML"), 35.41 - 35.42 - /** 35.43 - * KMZ format (compressed KML) 35.44 - */ 35.45 - KMZ("KMZ"), 35.46 - 35.47 - /** 35.48 - * GeoJSON format 35.49 - */ 35.50 - GEOJSON("GeoJSON"), 35.51 - 35.52 - /** 35.53 - * Format for experiments 35.54 - */ 35.55 - EXP("EXP"), 35.56 - 35.57 - /** 35.58 - * HTML format 35.59 - */ 35.60 - HTML("HTML"), 35.61 - 35.62 - /** 35.63 - * TSV (tab-separated values) format 35.64 - */ 35.65 - TSV("TSV"), 35.66 - 35.67 - /** 35.68 - * Invalid format. 35.69 - */ 35.70 - INVALID("INVALID"); 35.71 - 35.72 - /** 35.73 - * The string representation of this format 35.74 - */ 35.75 - private String name; 35.76 - 35.77 - /** 35.78 - * Map a string constant to a Format 35.79 - */ 35.80 - private static final Map<String, Format> stringToEnum = new HashMap<String, Format>(); 35.81 - 35.82 - 35.83 - static { // initialize map from constant name to enum constant 35.84 - for (Format format : values()) { 35.85 - // add both upper- and lower-case versions of the format 35.86 - stringToEnum.put(format.toString(), format); 35.87 - stringToEnum.put(format.toString().toLowerCase(), format); 35.88 - } 35.89 - } 35.90 - 35.91 - /** 35.92 - * Format constructor. 35.93 - * 35.94 - * @param name 35.95 - */ 35.96 - Format(String name) { 35.97 - this.name = name; 35.98 - } 35.99 - 35.100 - @Override 35.101 - public String toString() { 35.102 - return name; 35.103 - } 35.104 - 35.105 - /** 35.106 - * Returns a Format enum given a format string. 35.107 - * 35.108 - * @param lang 35.109 - * @return 35.110 - */ 35.111 - public static Format fromString(String format) { 35.112 - return (stringToEnum.get(format) == null) ? INVALID:stringToEnum.get(format); 35.113 - } 35.114 -}
36.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java Mon Nov 05 20:40:17 2012 +0200 36.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 36.3 @@ -1,236 +0,0 @@ 36.4 -/** 36.5 - * This Source Code Form is subject to the terms of the Mozilla Public 36.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 36.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 36.8 - * 36.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 36.10 - * 36.11 - * http://www.strabon.di.uoa.gr/ 36.12 - */ 36.13 -package org.openrdf.query.resultio.sparqlgeojson; 36.14 - 36.15 -import java.io.IOException; 36.16 -import java.io.OutputStream; 36.17 -import java.nio.charset.Charset; 36.18 -import java.util.ArrayList; 36.19 -import java.util.List; 36.20 - 36.21 -import org.geotools.data.simple.SimpleFeatureCollection; 36.22 -import org.geotools.feature.FeatureCollections; 36.23 -import org.geotools.feature.simple.SimpleFeatureBuilder; 36.24 -import org.geotools.feature.simple.SimpleFeatureTypeBuilder; 36.25 -import org.geotools.geojson.feature.FeatureJSON; 36.26 -import org.geotools.referencing.CRS; 36.27 -import org.opengis.feature.simple.SimpleFeature; 36.28 -import org.opengis.feature.simple.SimpleFeatureType; 36.29 -import org.openrdf.model.Literal; 36.30 -import org.openrdf.model.Value; 36.31 -import org.openrdf.query.Binding; 36.32 -import org.openrdf.query.BindingSet; 36.33 -import org.openrdf.query.TupleQueryResultHandlerException; 36.34 -import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; 36.35 -import org.openrdf.query.algebra.evaluation.util.JTSWrapper; 36.36 -import org.openrdf.query.resultio.TupleQueryResultFormat; 36.37 -import org.openrdf.query.resultio.TupleQueryResultWriter; 36.38 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 36.39 -import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 36.40 -import org.openrdf.sail.generaldb.model.XMLGSDatatypeUtil; 36.41 -import org.slf4j.Logger; 36.42 -import org.slf4j.LoggerFactory; 36.43 - 36.44 -import com.vividsolutions.jts.geom.Geometry; 36.45 - 36.46 -/** 36.47 - * A TupleQueryResultWriter that writes query results in the <a 36.48 - * href="http://www.geojson.org/geojson-spec.html/">GeoJSON Format</a>. 36.49 - * 36.50 - * @author Manos Karpathiotakis <mk@di.uoa.gr> 36.51 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 36.52 - */ 36.53 -public class stSPARQLResultsGeoJSONWriter implements TupleQueryResultWriter { 36.54 - 36.55 - private static final Logger logger = LoggerFactory.getLogger(org.openrdf.query.resultio.sparqlgeojson.stSPARQLResultsGeoJSONWriter.class); 36.56 - 36.57 - /** 36.58 - * The underlying output stream to write 36.59 - */ 36.60 - private OutputStream out; 36.61 - 36.62 - /** 36.63 - * Set a Feature Collection 36.64 - */ 36.65 - private SimpleFeatureCollection sfCollection; 36.66 - 36.67 - /** 36.68 - * The wrapper of JTS library 36.69 - */ 36.70 - private JTSWrapper jts; 36.71 - 36.72 - /** 36.73 - * Keep track of the number of results 36.74 - */ 36.75 - private int nresults; 36.76 - 36.77 - /** 36.78 - * The class to use for serializing to GeoJSON 36.79 - */ 36.80 - private FeatureJSON fjson; 36.81 - 36.82 - /** 36.83 - * Keep track of the number of features 36.84 - */ 36.85 - private int nfeatures; 36.86 - 36.87 - public stSPARQLResultsGeoJSONWriter(OutputStream out) { 36.88 - this.out = out; 36.89 - 36.90 - // set the feature collection 36.91 - sfCollection = FeatureCollections.newCollection("geomOutput"); 36.92 - 36.93 - // get the instance of JTSWrapper 36.94 - jts = JTSWrapper.getInstance(); 36.95 - 36.96 - // initialize results/features 36.97 - nresults = 0; 36.98 - nfeatures = 0; 36.99 - } 36.100 - 36.101 - @Override 36.102 - public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException { 36.103 - fjson = new FeatureJSON(); 36.104 - fjson.setEncodeFeatureCRS(true); 36.105 - } 36.106 - 36.107 - @Override 36.108 - public void endQueryResult() throws TupleQueryResultHandlerException { 36.109 - try { 36.110 - fjson.writeFeatureCollection(sfCollection, out); 36.111 - out.write("\n".getBytes(Charset.defaultCharset())); 36.112 - 36.113 - // write a warning when there are no features in the answer 36.114 - if (nfeatures < nresults) { 36.115 - logger.warn("[Strabon.GeoJSONWriter] No spatial binding found in the result, hence the result is empty eventhough query evaluation produced {} results. GeoJSON requires that at least one binding maps to a geometry.", nresults); 36.116 - 36.117 - } 36.118 - } catch (IOException e) { 36.119 - throw new TupleQueryResultHandlerException(e); 36.120 - } 36.121 - } 36.122 - 36.123 - @Override 36.124 - public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException { 36.125 - try { 36.126 - nresults++; 36.127 - 36.128 - // list keeping binding names that are not binded to geometries 36.129 - ArrayList<String> properties = new ArrayList<String>(); 36.130 - 36.131 - // list keeping values for binding names 36.132 - ArrayList<Value> values = new ArrayList<Value>(); 36.133 - 36.134 - // list keeping the features of the result 36.135 - ArrayList<SimpleFeatureTypeBuilder> features = new ArrayList<SimpleFeatureTypeBuilder>(); 36.136 - 36.137 - // list keeping the geometries of features 36.138 - ArrayList<Geometry> geometries = new ArrayList<Geometry>(); 36.139 - 36.140 - // parse binding set 36.141 - for (Binding binding : bindingSet) { 36.142 - Value value = binding.getValue(); 36.143 - 36.144 - if (XMLGSDatatypeUtil.isGeometryValue(value)) { 36.145 - // it's a spatial value 36.146 - if (logger.isDebugEnabled()) { 36.147 - logger.debug("[Strabon.GeoJSON] Found geometry: {}", value); 36.148 - } 36.149 - 36.150 - nfeatures++; 36.151 - 36.152 - // we need the geometry and the SRID 36.153 - Geometry geom = null; 36.154 - int srid = -1; 36.155 - 36.156 - if (value instanceof GeneralDBPolyhedron) { 36.157 - GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) value; 36.158 - 36.159 - geom = dbpolyhedron.getPolyhedron().getGeometry(); 36.160 - srid = dbpolyhedron.getPolyhedron().getGeometry().getSRID(); 36.161 - 36.162 - } else { // spatial literal WKT or GML 36.163 - // get the textual representation of the geometry (WKT or GML) 36.164 - String geoText = value.stringValue(); 36.165 - 36.166 - if (XMLGSDatatypeUtil.isWKTLiteral((Literal) value)) {// WKT 36.167 - // get its geometry 36.168 - geom = jts.WKTread(WKTHelper.getWithoutSRID(geoText)); 36.169 - 36.170 - // get its SRID 36.171 - srid = WKTHelper.getSRID(geoText); 36.172 - 36.173 - } else { // GML 36.174 - // get its geometry 36.175 - geom = jts.GMLread(geoText); 36.176 - 36.177 - // get its SRID 36.178 - srid = geom.getSRID(); 36.179 - 36.180 - } 36.181 - } 36.182 - 36.183 - SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder(); 36.184 - sftb.setName("Feature_" + nresults + "_" + nfeatures); 36.185 - sftb.setCRS(CRS.decode("EPSG:" + srid)); 36.186 - sftb.setSRS("EPSG:" + srid); 36.187 - sftb.add("geometry", Geometry.class); 36.188 - 36.189 - // add the feature in the list of features 36.190 - features.add(sftb); 36.191 - 36.192 - // add the geometry of the feature in the list of geometries 36.193 - geometries.add(geom); 36.194 - 36.195 - } else { // URI, BlankNode, or Literal other than geometry 36.196 - if (logger.isDebugEnabled()) { 36.197 - logger.debug("[Strabon.GeoJSON] Found resource: {}", value); 36.198 - } 36.199 - 36.200 - properties.add(binding.getName()); 36.201 - values.add(value); 36.202 - } 36.203 - } 36.204 - 36.205 - // construct the feature of the result 36.206 - for (int i = 0; i < features.size(); i++) { 36.207 - SimpleFeatureTypeBuilder sftb = features.get(i); 36.208 - 36.209 - // add the properties 36.210 - for (int p = 0; p < properties.size(); p++) { 36.211 - sftb.add(properties.get(p), String.class); 36.212 - } 36.213 - 36.214 - SimpleFeatureType featureType = sftb.buildFeatureType(); 36.215 - SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); 36.216 - 36.217 - // add the geometry to the builder of the feature 36.218 - featureBuilder.add(geometries.get(i)); 36.219 - 36.220 - // add the values to the builder of the feature 36.221 - for (int v = 0; v < values.size(); v++) { 36.222 - featureBuilder.add(values.get(v)); 36.223 - } 36.224 - 36.225 - SimpleFeature feature = featureBuilder.buildFeature(null); 36.226 - sfCollection.add(feature); 36.227 - } 36.228 - 36.229 - } catch (Exception e) { 36.230 - throw new TupleQueryResultHandlerException(e); 36.231 - } 36.232 - 36.233 - } 36.234 - 36.235 - @Override 36.236 - public TupleQueryResultFormat getTupleQueryResultFormat() { 36.237 - return stSPARQLQueryResultFormat.GEOJSON; 36.238 - } 36.239 -}
37.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriterFactory.java Mon Nov 05 20:40:17 2012 +0200 37.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 37.3 @@ -1,35 +0,0 @@ 37.4 -/** 37.5 - * This Source Code Form is subject to the terms of the Mozilla Public 37.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 37.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 37.8 - * 37.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 37.10 - * 37.11 - * http://www.strabon.di.uoa.gr/ 37.12 - */ 37.13 -package org.openrdf.query.resultio.sparqlgeojson; 37.14 - 37.15 -import java.io.OutputStream; 37.16 - 37.17 -import org.openrdf.query.resultio.TupleQueryResultFormat; 37.18 -import org.openrdf.query.resultio.TupleQueryResultWriter; 37.19 -import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 37.20 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 37.21 - 37.22 -/** 37.23 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 37.24 - * 37.25 - */ 37.26 -public class stSPARQLResultsGeoJSONWriterFactory implements TupleQueryResultWriterFactory { 37.27 - 37.28 - @Override 37.29 - public TupleQueryResultFormat getTupleQueryResultFormat() { 37.30 - return stSPARQLQueryResultFormat.GEOJSON; 37.31 - } 37.32 - 37.33 - @Override 37.34 - public TupleQueryResultWriter getWriter(OutputStream out) { 37.35 - return new stSPARQLResultsGeoJSONWriter(out); 37.36 - } 37.37 - 37.38 -}
38.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlhtml/stSPARQLResultsHTMLWriter.java Mon Nov 05 20:40:17 2012 +0200 38.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 38.3 @@ -1,170 +0,0 @@ 38.4 -/** 38.5 - * This Source Code Form is subject to the terms of the Mozilla Public 38.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 38.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 38.8 - * 38.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 38.10 - * 38.11 - * http://www.strabon.di.uoa.gr/ 38.12 - */ 38.13 -package org.openrdf.query.resultio.sparqlhtml; 38.14 - 38.15 -import java.io.IOException; 38.16 -import java.io.OutputStream; 38.17 -import java.net.URLEncoder; 38.18 -import java.util.List; 38.19 - 38.20 -import org.openrdf.model.BNode; 38.21 -import org.openrdf.query.Binding; 38.22 -import org.openrdf.query.BindingSet; 38.23 -import org.openrdf.query.TupleQueryResultHandlerException; 38.24 -import org.openrdf.query.resultio.TupleQueryResultFormat; 38.25 -import org.openrdf.query.resultio.TupleQueryResultWriter; 38.26 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 38.27 -import org.openrdf.query.resultio.sparqlxml.stSPARQLXMLWriter; 38.28 -import org.openrdf.model.Value; 38.29 -import org.openrdf.model.URI; 38.30 - 38.31 -/** 38.32 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 38.33 - * 38.34 - */ 38.35 -public class stSPARQLResultsHTMLWriter implements TupleQueryResultWriter { 38.36 - 38.37 - public static final String TABLE = "TABLE"; 38.38 - public static final String TABLE_ROW_TAG = "TR"; 38.39 - public static final String TABLE_HEADER_TAG = "TH"; 38.40 - public static final String TABLE_DATA_TAG = "TD"; 38.41 - public static final String LINK = "A"; 38.42 - public static final String LINK_REF = "HREF"; 38.43 - public static final String STYLE = "class"; 38.44 - public static final String ID = "id"; 38.45 - public static final String LINK_ID = "uri"; 38.46 - public static final String TABLE_HEADER_CLASS = "query_results_header"; 38.47 - public static final String TABLE_DATA_CLASS = "query_results_data"; 38.48 - public static final String TABLE_CLASS = "query_results_table"; 38.49 - public static final String MORE_LINK = "comment more"; 38.50 - 38.51 - /** 38.52 - * The underlying XML formatter. 38.53 - */ 38.54 - private stSPARQLXMLWriter xmlWriter; 38.55 - 38.56 - /** 38.57 - * The ordered list of binding names of the result. 38.58 - */ 38.59 - private List<String> bindingNames; 38.60 - 38.61 - public stSPARQLResultsHTMLWriter(OutputStream out) { 38.62 - this(new stSPARQLXMLWriter(out)); 38.63 - } 38.64 - 38.65 - public stSPARQLResultsHTMLWriter(stSPARQLXMLWriter writer) { 38.66 - xmlWriter = writer; 38.67 - xmlWriter.setPrettyPrint(true); 38.68 - } 38.69 - 38.70 - @Override 38.71 - public void startQueryResult(List<String> bindingNames) 38.72 - throws TupleQueryResultHandlerException { 38.73 - 38.74 - try { 38.75 - // keep the order of binding names 38.76 - this.bindingNames = bindingNames; 38.77 - // set style for table 38.78 - xmlWriter.setAttribute(STYLE, TABLE_CLASS); 38.79 - // write start of table 38.80 - xmlWriter.startTag(TABLE); 38.81 - // write Table header containing the bindings 38.82 - xmlWriter.startTag(TABLE_ROW_TAG); 38.83 - for (String bindingName: bindingNames) { 38.84 - // set style for header 38.85 - xmlWriter.setAttribute(STYLE, TABLE_HEADER_CLASS); 38.86 - xmlWriter.textElement(TABLE_HEADER_TAG, bindingName); 38.87 - } 38.88 - 38.89 - xmlWriter.endTag(TABLE_ROW_TAG); 38.90 - } catch (IOException e) { 38.91 - throw new TupleQueryResultHandlerException(e); 38.92 - } 38.93 - 38.94 - } 38.95 - 38.96 - @Override 38.97 - public void endQueryResult() throws TupleQueryResultHandlerException { 38.98 - try { 38.99 - 38.100 - // write end of table 38.101 - xmlWriter.endTag(TABLE); 38.102 - 38.103 - // needed to flush data 38.104 - xmlWriter.endDocument(); 38.105 - 38.106 - } catch (IOException e) { 38.107 - throw new TupleQueryResultHandlerException(e); 38.108 - } 38.109 - } 38.110 - 38.111 - @Override 38.112 - public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException { 38.113 - try { 38.114 - StringBuilder value = new StringBuilder(); 38.115 - Value boundValue = null; 38.116 - 38.117 - xmlWriter.startTag(TABLE_ROW_TAG); 38.118 - for (String bindingName : bindingNames) { 38.119 - Binding binding = bindingSet.getBinding(bindingName); 38.120 - if(binding != null) 38.121 - { 38.122 - boundValue = binding.getValue(); 38.123 - value.append(boundValue.stringValue()); 38.124 - 38.125 - if(boundValue instanceof BNode) { 38.126 - value.insert(0, "_:"); 38.127 - } 38.128 - 38.129 - // If the value is a uri, make it link 38.130 - if(boundValue instanceof URI) 38.131 - { 38.132 - xmlWriter.setAttribute(STYLE, TABLE_DATA_CLASS); 38.133 - xmlWriter.startTag(TABLE_DATA_TAG); 38.134 - 38.135 - // select all the triples that contain the boundValue 38.136 - String query= "select * " + 38.137 - "where " + 38.138 - "{ " + 38.139 - "?subject ?predicate ?object . "+ 38.140 - "FILTER((?subject = <"+ boundValue.toString()+ ">) || "+ 38.141 - "(?predicate = <"+ boundValue.toString()+ ">) || "+ 38.142 - "(?object = <"+ boundValue.toString()+ ">)) " + 38.143 - "}"; 38.144 - 38.145 - String href = "Browse?view=HTML&query="+URLEncoder.encode(query, "UTF-8")+"&format=HTML&resource="+boundValue.toString(); 38.146 - xmlWriter.setAttribute(LINK_REF, href); 38.147 - xmlWriter.startTag(LINK); 38.148 - xmlWriter.text(boundValue.toString()); 38.149 - xmlWriter.endTag(LINK); 38.150 - } 38.151 - else 38.152 - { 38.153 - xmlWriter.setAttribute(STYLE, TABLE_DATA_CLASS+" "+MORE_LINK); 38.154 - xmlWriter.startTag(TABLE_DATA_TAG); 38.155 - xmlWriter.text(boundValue.toString()); 38.156 - } 38.157 - xmlWriter.endTag(TABLE_DATA_TAG); 38.158 - } 38.159 - value.setLength(0); 38.160 - } 38.161 - xmlWriter.endTag(TABLE_ROW_TAG); 38.162 - 38.163 - } catch (IOException e) { 38.164 - throw new TupleQueryResultHandlerException(e); 38.165 - } 38.166 - } 38.167 - 38.168 - @Override 38.169 - public TupleQueryResultFormat getTupleQueryResultFormat() { 38.170 - return stSPARQLQueryResultFormat.HTML; 38.171 - } 38.172 - 38.173 -} 38.174 \ No newline at end of file
39.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlhtml/stSPARQLResultsHTMLWriterFactory.java Mon Nov 05 20:40:17 2012 +0200 39.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 39.3 @@ -1,35 +0,0 @@ 39.4 -/** 39.5 - * This Source Code Form is subject to the terms of the Mozilla Public 39.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 39.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 39.8 - * 39.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 39.10 - * 39.11 - * http://www.strabon.di.uoa.gr/ 39.12 - */ 39.13 -package org.openrdf.query.resultio.sparqlhtml; 39.14 - 39.15 -import java.io.OutputStream; 39.16 - 39.17 -import org.openrdf.query.resultio.TupleQueryResultFormat; 39.18 -import org.openrdf.query.resultio.TupleQueryResultWriter; 39.19 -import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 39.20 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 39.21 - 39.22 -/** 39.23 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 39.24 - * 39.25 - */ 39.26 -public class stSPARQLResultsHTMLWriterFactory implements TupleQueryResultWriterFactory { 39.27 - 39.28 - @Override 39.29 - public TupleQueryResultFormat getTupleQueryResultFormat() { 39.30 - return stSPARQLQueryResultFormat.HTML; 39.31 - } 39.32 - 39.33 - @Override 39.34 - public TupleQueryResultWriter getWriter(OutputStream out) { 39.35 - return new stSPARQLResultsHTMLWriter(out); 39.36 - } 39.37 - 39.38 -}
40.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java Mon Nov 05 20:40:17 2012 +0200 40.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 40.3 @@ -1,522 +0,0 @@ 40.4 -/** 40.5 - * This Source Code Form is subject to the terms of the Mozilla Public License, 40.6 - * v. 2.0. If a copy of the MPL was not distributed with this file, You can 40.7 - * obtain one at http://mozilla.org/MPL/2.0/. Copyright (C) 2010, 2011, 2012, 40.8 - * Pyravlos Team http://www.strabon.di.uoa.gr/ 40.9 - */ 40.10 -package org.openrdf.query.resultio.sparqlkml; 40.11 - 40.12 -import java.io.ByteArrayOutputStream; 40.13 -import java.io.IOException; 40.14 -import java.io.OutputStream; 40.15 -import java.util.ArrayList; 40.16 -import java.util.Hashtable; 40.17 -import java.util.List; 40.18 - 40.19 -import javax.xml.bind.JAXBException; 40.20 -import javax.xml.namespace.QName; 40.21 - 40.22 -import org.geotools.kml.KML; 40.23 -import org.geotools.kml.KMLConfiguration; 40.24 -import org.geotools.xml.Encoder; 40.25 -import org.openrdf.model.BNode; 40.26 -import org.openrdf.model.Literal; 40.27 -import org.openrdf.model.Value; 40.28 -import org.openrdf.query.Binding; 40.29 -import org.openrdf.query.BindingSet; 40.30 -import org.openrdf.query.TupleQueryResultHandlerException; 40.31 -import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; 40.32 -import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; 40.33 -import org.openrdf.query.algebra.evaluation.util.JTSWrapper; 40.34 -import org.openrdf.query.resultio.TupleQueryResultFormat; 40.35 -import org.openrdf.query.resultio.TupleQueryResultWriter; 40.36 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 40.37 -import org.openrdf.query.resultio.sparqlxml.stSPARQLXMLWriter; 40.38 -import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 40.39 -import org.openrdf.sail.generaldb.model.XMLGSDatatypeUtil; 40.40 -import org.slf4j.Logger; 40.41 -import org.slf4j.LoggerFactory; 40.42 - 40.43 -import com.vividsolutions.jts.geom.Geometry; 40.44 -import com.vividsolutions.jts.geom.GeometryCollection; 40.45 -import com.vividsolutions.jts.geom.LineString; 40.46 -import com.vividsolutions.jts.geom.MultiLineString; 40.47 -import com.vividsolutions.jts.geom.MultiPoint; 40.48 -import com.vividsolutions.jts.geom.MultiPolygon; 40.49 -import com.vividsolutions.jts.geom.Point; 40.50 -import com.vividsolutions.jts.geom.Polygon; 40.51 -import com.vividsolutions.jts.io.ParseException; 40.52 - 40.53 -/** 40.54 - * @author Manos Karpathiotakis <mk@di.uoa.gr> 40.55 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 40.56 - * @author Panayiotis Smeros <psmeros@di.uoa.gr> 40.57 - * 40.58 - */ 40.59 -public class stSPARQLResultsKMLWriter implements TupleQueryResultWriter { 40.60 - private static final Logger logger = LoggerFactory.getLogger(org.openrdf.query.resultio.sparqlkml.stSPARQLResultsKMLWriter.class); 40.61 - 40.62 - // KML tags/attributes 40.63 - private static final String ROOT_TAG = "kml"; 40.64 - private static final String NAMESPACE = "http://www.opengis.net/kml/2.2"; 40.65 - private static final String RESULT_SET_TAG = "Folder"; 40.66 - private static final String PLACEMARK_TAG = "Placemark"; 40.67 - private static final String NAME_TAG = "name"; 40.68 - private static final String DESC_TAG = "description"; 40.69 - private static final String STYLE_TAG = "Style"; 40.70 - private static final String STYLEMAP_TAG = "StyleMap"; 40.71 - private static final String LINESTYLE_TAG = "LineStyle"; 40.72 - private static final String POLYSTYLE_TAG = "PolyStyle"; 40.73 - private static final String EXT_DATA_TAG = "ExtendedData"; 40.74 - private static final String DATA_TAG = "Data"; 40.75 - private static final String VALUE_TAG = "value"; 40.76 - private static final String NAME_ATTR = NAME_TAG; 40.77 - 40.78 - private static final String STYLE_ID = "resultStyle"; 40.79 - private static final String TABLE_ROW_BEGIN = "<TR>"; 40.80 - private static final String TABLE_ROW_END = "</TR>"; 40.81 - private static final String TABLE_DATA_BEGIN = "<TD>"; 40.82 - private static final String TABLE_DATA_END = "</TD>"; 40.83 - private static final String NEWLINE = "\n"; 40.84 - private static final String TABLE_DESC_BEGIN = "<![CDATA[<TABLE border=\"1\">"+ NEWLINE; 40.85 - private static final String TABLE_DESC_END = "</TABLE>]]>" + NEWLINE; 40.86 - 40.87 - private static final String GEOMETRY_NAME = "Geometry"; 40.88 - private static final String MULTIGEOMETRY = "MultiGeometry"; 40.89 - 40.90 - // Styling options 40.91 - private static final int numOfStyles = 5; 40.92 - private static final String[][] styles = { 40.93 - // note that colors are encoded as "aabbggrr" strings where 40.94 - // aa=alpha (00 to ff); bb=blue (00 to ff); gg=green (00 to ff); 40.95 - // rr=red 40.96 - // (00 to ff). 40.97 - // id, line width, line color, polygon fill, mouse over line width, 40.98 - // mouse over line color mouse over polygon fill 40.99 - // {STYLE_ID + "1", "1.5", "7d0000ff", "ad0000ff", "1.5", 40.100 - // "7d0000ff", "ad0000ff"}, {STYLE_ID + "2", "1.5", "7d0000ff", 40.101 - // "ad0000ff", "1.5", "7d0000ff", "ad0000ff"}, {STYLE_ID + "3", 40.102 - // "1.5", "7d550000", "ad550000", "1.5", "7d0000ff", "ad0000ff"}, 40.103 - // {STYLE_ID + "4", "1.5", "7d005500", "ad005500", "1.5", 40.104 - // "7d0000ff", "ad0000ff"}, {STYLE_ID + "5", "1.5", "7d000055", 40.105 - // "ad000055", "1.5", "7d0000ff", "ad0000ff"}}; 40.106 - { STYLE_ID + "1", "1.5", "000000ff", "000000ff", "1.5", "000000ff", 40.107 - "000000ff" }, 40.108 - { STYLE_ID + "2", "1.5", "000000ff", "000000ff", "1.5", "000000ff", 40.109 - "000000ff" }, 40.110 - { STYLE_ID + "3", "1.5", "7d550000", "ad550000", "1.5", "7d0000ff", 40.111 - "ad0000ff" }, 40.112 - { STYLE_ID + "4", "1.5", "7d005500", "ad005500", "1.5", "7d0000ff", 40.113 - "ad0000ff" }, 40.114 - { STYLE_ID + "5", "1.5", "7dff0000", "adff0000", "1.5", "7dff0000", 40.115 - "adff0000" } }; 40.116 - 40.117 - /** 40.118 - * The underlying XML formatter. 40.119 - */ 40.120 - private stSPARQLXMLWriter xmlWriter; 40.121 - 40.122 - /** 40.123 - * The number of results seen. 40.124 - */ 40.125 - private int nresults; 40.126 - 40.127 - /** 40.128 - * The number of geometries seen. 40.129 - */ 40.130 - private int ngeometries; 40.131 - 40.132 - /** 40.133 - * The JTS wrapper 40.134 - */ 40.135 - private JTSWrapper jts; 40.136 - 40.137 - /** 40.138 - * Stream for manipulating geometries 40.139 - */ 40.140 - private ByteArrayOutputStream baos; 40.141 - 40.142 - /** 40.143 - * Description string holding the projected variables of the SPARQL query 40.144 - */ 40.145 - private StringBuilder descHeader; 40.146 - 40.147 - /** 40.148 - * Description string holding the values for the projected variables of the 40.149 - * SPARQL query 40.150 - */ 40.151 - private StringBuilder descData; 40.152 - 40.153 - /** 40.154 - * Indentation used in tags that are constructed manually 40.155 - */ 40.156 - private int depth; 40.157 - 40.158 - /** 40.159 - * Creates an stSPARQLResultsKMLWriter that encodes the SPARQL results in 40.160 - * KML. 40.161 - * 40.162 - * @param out 40.163 - */ 40.164 - public stSPARQLResultsKMLWriter(OutputStream out) { 40.165 - this(new stSPARQLXMLWriter(out)); 40.166 - } 40.167 - 40.168 - public stSPARQLResultsKMLWriter(stSPARQLXMLWriter writer) { 40.169 - xmlWriter = writer; 40.170 - xmlWriter.setPrettyPrint(true); 40.171 - depth = 4; 40.172 - jts = JTSWrapper.getInstance(); 40.173 - baos = new ByteArrayOutputStream(); 40.174 - descHeader = new StringBuilder(); 40.175 - descData = new StringBuilder(); 40.176 - nresults = 0; 40.177 - ngeometries = 0; 40.178 - } 40.179 - 40.180 - @Override 40.181 - public void startQueryResult(List<String> bindingNames) 40.182 - throws TupleQueryResultHandlerException { 40.183 - try { 40.184 - 40.185 - xmlWriter.startDocument(); 40.186 - xmlWriter.setAttribute("xmlns", NAMESPACE); 40.187 - xmlWriter.startTag(ROOT_TAG); 40.188 - xmlWriter.startTag(RESULT_SET_TAG); 40.189 - 40.190 - // add default styles 40.191 - for (String[] style : styles) { 40.192 - String id = style[0]; 40.193 - String lineWidth = style[1]; 40.194 - String lineColor = style[2]; 40.195 - String polygonFill = style[3]; 40.196 - String mouseOverLineWidth = style[4]; 40.197 - String mouseOverLineColor = style[5]; 40.198 - String mouseOverPolygonFill = style[6]; 40.199 - 40.200 - // append normal style 40.201 - xmlWriter.setAttribute("id", "normal_" + id); 40.202 - xmlWriter.startTag(STYLE_TAG); 40.203 - xmlWriter.startTag(LINESTYLE_TAG); 40.204 - xmlWriter.textElement("width", lineWidth); 40.205 - xmlWriter.textElement("color", lineColor); 40.206 - xmlWriter.endTag(LINESTYLE_TAG); 40.207 - xmlWriter.startTag(POLYSTYLE_TAG); 40.208 - xmlWriter.textElement("color", polygonFill); 40.209 - xmlWriter.endTag(POLYSTYLE_TAG); 40.210 - xmlWriter.endTag(STYLE_TAG); 40.211 - 40.212 - // append highlight style 40.213 - xmlWriter.setAttribute("id", "highlight_" + id); 40.214 - xmlWriter.startTag(STYLE_TAG); 40.215 - xmlWriter.startTag(LINESTYLE_TAG); 40.216 - xmlWriter.textElement("width", mouseOverLineWidth); 40.217 - xmlWriter.textElement("color", mouseOverLineColor); 40.218 - xmlWriter.endTag(LINESTYLE_TAG); 40.219 - xmlWriter.startTag(POLYSTYLE_TAG); 40.220 - xmlWriter.textElement("color", mouseOverPolygonFill); 40.221 - xmlWriter.endTag(POLYSTYLE_TAG); 40.222 - xmlWriter.endTag(STYLE_TAG); 40.223 - 40.224 - // define map style combining the above styles 40.225 - xmlWriter.setAttribute("id", id); 40.226 - xmlWriter.startTag(STYLEMAP_TAG); 40.227 - xmlWriter.startTag("Pair"); 40.228 - xmlWriter.textElement("key", "normal"); 40.229 - xmlWriter.textElement("styleUrl", "#normal_" + id); 40.230 - xmlWriter.endTag("Pair"); 40.231 - xmlWriter.startTag("Pair"); 40.232 - xmlWriter.textElement("key", "highlight"); 40.233 - xmlWriter.textElement("styleUrl", "#highlight_" + id); 40.234 - xmlWriter.endTag("Pair"); 40.235 - xmlWriter.endTag(STYLEMAP_TAG); 40.236 - } 40.237 - // end of default style definition 40.238 - } catch (IOException e) { 40.239 - throw new TupleQueryResultHandlerException(e); 40.240 - } 40.241 - } 40.242 - 40.243 - @Override 40.244 - public void endQueryResult() throws TupleQueryResultHandlerException { 40.245 - try { 40.246 - 40.247 - xmlWriter.endTag(RESULT_SET_TAG); 40.248 - xmlWriter.endTag(ROOT_TAG); 40.249 - xmlWriter.endDocument(); 40.250 - baos.close(); 40.251 - 40.252 - if (ngeometries < nresults) { 40.253 - logger.warn("[Strabon.KMLWriter] No spatial binding found in the result. KML requires that at least one binding maps to a geometry.", nresults); 40.254 - } 40.255 - 40.256 - } catch (IOException e) { 40.257 - throw new TupleQueryResultHandlerException(e); 40.258 - } 40.259 - } 40.260 - 40.261 - @Override 40.262 - public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException { 40.263 - try { 40.264 - int numOfGeometries = 0; 40.265 - 40.266 - // true if there are bindings that do not correspond to geometries 40.267 - boolean hasDesc = false; 40.268 - 40.269 - // increase result size 40.270 - nresults++; 40.271 - 40.272 - // create description table and header 40.273 - indent(descHeader, depth); 40.274 - descHeader.append(TABLE_DESC_BEGIN); 40.275 - indent(descHeader, depth); 40.276 - 40.277 - List<String> geometries = new ArrayList<String>(); 40.278 - Hashtable<String, String> extData = new Hashtable<String, String>(); 40.279 - 40.280 - // parse binding set 40.281 - for (Binding binding : bindingSet) { 40.282 - 40.283 - Value value = binding.getValue(); 40.284 - 40.285 - // check for geometry value 40.286 - if (XMLGSDatatypeUtil.isGeometryValue(value)) { 40.287 - numOfGeometries++; 40.288 - ngeometries++; 40.289 - if (logger.isDebugEnabled()) { 40.290 - logger.debug("[Strabon] Found geometry: {}", value); 40.291 - } 40.292 - 40.293 - geometries.add(getGeometry(value)); 40.294 - 40.295 - } else { // URI, BlankNode, or Literal other than spatial literal 40.296 - if (logger.isDebugEnabled()) { 40.297 - logger.debug("[Strabon.KMLWriter] Found URI/BlankNode/Literal ({}): {}", value.getClass(), value); 40.298 - } 40.299 - 40.300 - // mark that we found sth corresponding to the description 40.301 - hasDesc = true; 40.302 - 40.303 - // write description 40.304 - writeDesc(binding); 40.305 - 40.306 - // fill also the extended data attribute of the Placemark 40.307 - extData.put(binding.getName(), getBindingValue(binding)); 40.308 - } 40.309 - } 40.310 - 40.311 - if (numOfGeometries > 1) { 40.312 - // write each polygon in separate placemarks 40.313 - for (String geometry : geometries) { 40.314 - xmlWriter.startTag(PLACEMARK_TAG); 40.315 - xmlWriter.textElement(NAME_TAG, GEOMETRY_NAME); 40.316 - xmlWriter.textElement("styleUrl", "#"+ styles[geometries.indexOf(geometry) % (numOfStyles - 2)][0]); 40.317 - xmlWriter.startTag(MULTIGEOMETRY); 40.318 - xmlWriter.unescapedText(geometry); 40.319 - xmlWriter.endTag(MULTIGEOMETRY); 40.320 - xmlWriter.endTag(PLACEMARK_TAG); 40.321 - } 40.322 - } 40.323 - 40.324 - // also write them in the same placemarks 40.325 - xmlWriter.startTag(PLACEMARK_TAG); 40.326 - xmlWriter.textElement(NAME_TAG, GEOMETRY_NAME); 40.327 - xmlWriter.textElement("styleUrl", "#" + styles[(numOfStyles - 1)][0]); 40.328 - xmlWriter.startTag(MULTIGEOMETRY); 40.329 - 40.330 - for (String geometry : geometries) { 40.331 - xmlWriter.unescapedText(geometry); 40.332 - } 40.333 - 40.334 - xmlWriter.endTag(MULTIGEOMETRY); 40.335 - 40.336 - // we have found and constructed a description for this result. 40.337 - // Write it down. 40.338 - if (hasDesc) { 40.339 - // end the placeholder for the description data 40.340 - indent(descData, depth); 40.341 - 40.342 - // append to the table header the actual content from 40.343 - // the bindings 40.344 - descHeader.append(descData); 40.345 - 40.346 - // close the table for the description 40.347 - descHeader.append(NEWLINE); 40.348 - indent(descHeader, depth); 40.349 - descHeader.append(TABLE_DESC_END); 40.350 - 40.351 - // begin the "description" tag 40.352 - xmlWriter.startTag(DESC_TAG); 40.353 - 40.354 - // write the actual description 40.355 - xmlWriter.unescapedText(descHeader.toString()); 40.356 - 40.357 - // end the "description" tag 40.358 - xmlWriter.endTag(DESC_TAG); 40.359 - } 40.360 - 40.361 - // add the extended data 40.362 - if (extData.size() > 0) { 40.363 - xmlWriter.startTag(EXT_DATA_TAG); 40.364 - for (String key : extData.keySet()) { 40.365 - xmlWriter.setAttribute(NAME_ATTR, key); 40.366 - xmlWriter.startTag(DATA_TAG); 40.367 - xmlWriter.textElement(VALUE_TAG, extData.get(key)); 40.368 - xmlWriter.endTag(DATA_TAG); 40.369 - } 40.370 - xmlWriter.endTag(EXT_DATA_TAG); 40.371 - } 40.372 - 40.373 - // end Placemark 40.374 - xmlWriter.endTag(PLACEMARK_TAG); 40.375 - 40.376 - // clear description string builders 40.377 - descHeader.setLength(0); 40.378 - descData.setLength(0); 40.379 - 40.380 - } catch (IOException e) { 40.381 - throw new TupleQueryResultHandlerException(e); 40.382 - } 40.383 - } 40.384 - 40.385 - private String getGeometry(Value value) { 40.386 - String geometry = ""; 40.387 - QName geometryType = null; 40.388 - // the underlying geometry in value 40.389 - Geometry geom = null; 40.390 - // the underlying SRID of the geometry 40.391 - int srid = -1; 40.392 - // get the KML encoder 40.393 - Encoder encoder = null; 40.394 - try { 40.395 - encoder = new Encoder(new KMLConfiguration()); 40.396 - encoder.setIndenting(true); 40.397 - if (value instanceof GeneralDBPolyhedron) { 40.398 - GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) value; 40.399 - geom = dbpolyhedron.getPolyhedron().getGeometry(); 40.400 - srid = dbpolyhedron.getPolyhedron().getGeometry().getSRID(); 40.401 - } else { // spatial literal 40.402 - Literal spatial = (Literal) value; 40.403 - String geomRep = spatial.stringValue(); 40.404 - if (XMLGSDatatypeUtil.isWKTLiteral(spatial)) { // WKT 40.405 - geom = jts.WKTread(WKTHelper.getWithoutSRID(geomRep)); 40.406 - srid = WKTHelper.getSRID(geomRep); 40.407 - } else { // GML 40.408 - geom = jts.GMLread(geomRep); 40.409 - srid = geom.getSRID(); 40.410 - } 40.411 - } 40.412 - // transform the geometry to {@link GeoConstants#defaultSRID} 40.413 - geom = jts.transform(geom, srid, GeoConstants.defaultSRID); 40.414 - if (geom instanceof Point) { 40.415 - geometryType = KML.Point; 40.416 - } else if (geom instanceof Polygon) { 40.417 - geometryType = KML.Polygon; 40.418 - } else if (geom instanceof LineString) { 40.419 - geometryType = KML.LineString; 40.420 - } else if (geom instanceof MultiPoint) { 40.421 - geometryType = KML.MultiGeometry; 40.422 - } else if (geom instanceof MultiLineString) { 40.423 - geometryType = KML.MultiGeometry; 40.424 - } else if (geom instanceof MultiPolygon) { 40.425 - geometryType = KML.MultiGeometry; 40.426 - } else if (geom instanceof GeometryCollection) { 40.427 - geometryType = KML.MultiGeometry; 40.428 - } 40.429 - if (geometryType == null) { 40.430 - logger.warn("[Strabon.KMLWriter] Found unknown geometry type."); 40.431 - 40.432 - } else { 40.433 - encoder.encode(geom, geometryType, baos); 40.434 - geometry = baos.toString().substring(38).replaceAll(" xmlns:kml=\"http://earth.google.com/kml/2.1\"", "").replaceAll("kml:", ""); 40.435 - 40.436 - if (geometryType == KML.MultiGeometry) { 40.437 - geometry = geometry.substring(geometry.indexOf("<MultiGeometry>") + 15, geometry.indexOf("</MultiGeometry>")); 40.438 - } 40.439 - 40.440 - /* 40.441 - * if(geom instanceof Point) { geometry = 40.442 - * geometry.substring(geometry.indexOf("<Point>"), 40.443 - * geometry.indexOf("</Point>") + 8); } else if(geom instanceof 40.444 - * Polygon) { geometry = 40.445 - * geometry.substring(geometry.indexOf("<Polygon>"), 40.446 - * geometry.indexOf("</Polygon>") + 10); } else if(geom 40.447 - * instanceof LineString) { geometry = 40.448 - * geometry.substring(geometry.indexOf("<LineString>"), 40.449 - * geometry.indexOf("</LineString>") + 13); } else if(geom 40.450 - * instanceof MultiPoint) { geometry = 40.451 - * geometry.substring(geometry.indexOf("<MultiPoint>"), 40.452 - * geometry.indexOf("</MultiPoint>") + 13); } else if(geom 40.453 - * instanceof MultiLineString) { geometry = 40.454 - * geometry.substring(geometry.indexOf("<MultiLineString>"), 40.455 - * geometry.indexOf("</MultiLineString>") + 18); } else if(geom 40.456 - * instanceof MultiPolygon) { geometry = 40.457 - * geometry.substring(geometry.indexOf("<MultiPolygon>"), 40.458 - * geometry.indexOf("</MultiPolygon>") + 15); } else if(geom 40.459 - * instanceof GeometryCollection) { geometry = 40.460 - * geometry.substring(geometry.indexOf("<GeometryCollection>"), 40.461 - * geometry.indexOf("</GeometryCollection>") + 21); } 40.462 - */ 40.463 - baos.reset(); 40.464 - } 40.465 - } catch (ParseException e) { 40.466 - logger.error("[Strabon.KMLWriter] Parse error exception of geometry: {}", e.getMessage()); 40.467 - 40.468 - } catch (IOException e) { 40.469 - logger.error("[Strabon.KMLWriter] IOException during KML encoding of geometry: {}", e.getMessage()); 40.470 - 40.471 - } catch (JAXBException e) { 40.472 - logger.error("[Strabon.KMLWriter] Exception during GML parsing: {}", e.getMessage()); 40.473 - } 40.474 - 40.475 - return geometry; 40.476 - } 40.477 - 40.478 - /** 40.479 - * Adds to the description table information for a binding. 40.480 - * 40.481 - * @param binding 40.482 - */ 40.483 - private void writeDesc(Binding binding) { 40.484 - descData.append(NEWLINE); 40.485 - indent(descData, depth + 1); 40.486 - descData.append(TABLE_ROW_BEGIN); 40.487 - descData.append(TABLE_DATA_BEGIN); 40.488 - descData.append(binding.getName()); 40.489 - descData.append(TABLE_DATA_END); 40.490 - descData.append(TABLE_DATA_BEGIN); 40.491 - if (binding.getValue() instanceof BNode) { 40.492 - descData.append("_:"); 40.493 - } 40.494 - descData.append(binding.getValue().stringValue()); 40.495 - descData.append(TABLE_DATA_END); 40.496 - descData.append(TABLE_ROW_END); 40.497 - } 40.498 - 40.499 - private String getBindingValue(Binding binding) { 40.500 - String val = binding.getValue().stringValue(); 40.501 - if (binding.getValue() instanceof BNode) { 40.502 - val = "_:" + val; 40.503 - } 40.504 - 40.505 - return val; 40.506 - } 40.507 - 40.508 - @Override 40.509 - public TupleQueryResultFormat getTupleQueryResultFormat() { 40.510 - return stSPARQLQueryResultFormat.KML; 40.511 - } 40.512 - 40.513 - /** 40.514 - * Adds indentation to the given string builder according to the specified 40.515 - * depth. 40.516 - * 40.517 - * @param sb 40.518 - * @param depth 40.519 - */ 40.520 - private void indent(StringBuilder sb, int depth) { 40.521 - for (int i = 0; i < depth; i++) { 40.522 - sb.append(xmlWriter.getIndentString()); 40.523 - } 40.524 - } 40.525 -}
41.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriterFactory.java Mon Nov 05 20:40:17 2012 +0200 41.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 41.3 @@ -1,35 +0,0 @@ 41.4 -/** 41.5 - * This Source Code Form is subject to the terms of the Mozilla Public 41.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 41.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 41.8 - * 41.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 41.10 - * 41.11 - * http://www.strabon.di.uoa.gr/ 41.12 - */ 41.13 -package org.openrdf.query.resultio.sparqlkml; 41.14 - 41.15 -import java.io.OutputStream; 41.16 - 41.17 -import org.openrdf.query.resultio.TupleQueryResultFormat; 41.18 -import org.openrdf.query.resultio.TupleQueryResultWriter; 41.19 -import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 41.20 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 41.21 - 41.22 -/** 41.23 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 41.24 - * 41.25 - */ 41.26 -public class stSPARQLResultsKMLWriterFactory implements TupleQueryResultWriterFactory { 41.27 - 41.28 - @Override 41.29 - public TupleQueryResultFormat getTupleQueryResultFormat() { 41.30 - return stSPARQLQueryResultFormat.KML; 41.31 - } 41.32 - 41.33 - @Override 41.34 - public TupleQueryResultWriter getWriter(OutputStream out) { 41.35 - return new stSPARQLResultsKMLWriter(out); 41.36 - } 41.37 - 41.38 -}
42.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMZWriter.java Mon Nov 05 20:40:17 2012 +0200 42.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 42.3 @@ -1,106 +0,0 @@ 42.4 -/** 42.5 - * This Source Code Form is subject to the terms of the Mozilla Public 42.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 42.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 42.8 - * 42.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 42.10 - * 42.11 - * http://www.strabon.di.uoa.gr/ 42.12 - */ 42.13 -package org.openrdf.query.resultio.sparqlkml; 42.14 - 42.15 -import java.io.IOException; 42.16 -import java.io.OutputStream; 42.17 -import java.util.List; 42.18 -import java.util.zip.ZipEntry; 42.19 -import java.util.zip.ZipOutputStream; 42.20 - 42.21 -import org.openrdf.query.BindingSet; 42.22 -import org.openrdf.query.TupleQueryResultHandlerException; 42.23 -import org.openrdf.query.resultio.TupleQueryResultFormat; 42.24 -import org.openrdf.query.resultio.TupleQueryResultWriter; 42.25 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 42.26 -import org.openrdf.query.resultio.sparqlkml.stSPARQLResultsKMLWriter; 42.27 - 42.28 -/** 42.29 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 42.30 - * 42.31 - */ 42.32 -public class stSPARQLResultsKMZWriter implements TupleQueryResultWriter { 42.33 - 42.34 - /** 42.35 - * The name of the KML file that shall be zipped 42.36 - * (by convention corresponds to "doc") 42.37 - */ 42.38 - private static final String ZIP_ENTRY_FILENAME = "doc.kml"; 42.39 - 42.40 - /** 42.41 - * After all a KMZ file is a zipped KML one 42.42 - */ 42.43 - private stSPARQLResultsKMLWriter kmlWriter; 42.44 - 42.45 - /** 42.46 - * The zipped output stream to wrap the original one 42.47 - */ 42.48 - private ZipOutputStream kmzout; 42.49 - 42.50 - /** 42.51 - * The zip entry 42.52 - */ 42.53 - private ZipEntry entry; 42.54 - 42.55 - public stSPARQLResultsKMZWriter(OutputStream out) { 42.56 - // create a zip stream on the given output stream 42.57 - kmzout = new ZipOutputStream(out); 42.58 - 42.59 - // initialize the KMLWriter with that stream instead passing the original 42.60 - kmlWriter = new stSPARQLResultsKMLWriter(kmzout); 42.61 - } 42.62 - 42.63 - @Override 42.64 - public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException { 42.65 - try { 42.66 - // create a zip entry 42.67 - entry = new ZipEntry(ZIP_ENTRY_FILENAME); 42.68 - 42.69 - // add the zip entry in it 42.70 - kmzout.putNextEntry(entry); 42.71 - 42.72 - // now pass execution to KMLWriter 42.73 - kmlWriter.startQueryResult(bindingNames); 42.74 - 42.75 - } catch (IOException e) { 42.76 - throw new TupleQueryResultHandlerException(e); 42.77 - } 42.78 - } 42.79 - 42.80 - @Override 42.81 - public void endQueryResult() throws TupleQueryResultHandlerException { 42.82 - 42.83 - try { 42.84 - // pass execution to KMLWriter 42.85 - kmlWriter.endQueryResult(); 42.86 - 42.87 - // close the zip entry 42.88 - kmzout.closeEntry(); 42.89 - 42.90 - // close the zip stream 42.91 - kmzout.close(); 42.92 - 42.93 - } catch (IOException e) { 42.94 - throw new TupleQueryResultHandlerException(e); 42.95 - } 42.96 - } 42.97 - 42.98 - @Override 42.99 - public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException { 42.100 - // pass execution to KMLWriter 42.101 - kmlWriter.handleSolution(bindingSet); 42.102 - } 42.103 - 42.104 - @Override 42.105 - public TupleQueryResultFormat getTupleQueryResultFormat() { 42.106 - return stSPARQLQueryResultFormat.KMZ; 42.107 - } 42.108 - 42.109 -}
43.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMZWriterFactory.java Mon Nov 05 20:40:17 2012 +0200 43.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 43.3 @@ -1,35 +0,0 @@ 43.4 -/** 43.5 - * This Source Code Form is subject to the terms of the Mozilla Public 43.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 43.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 43.8 - * 43.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 43.10 - * 43.11 - * http://www.strabon.di.uoa.gr/ 43.12 - */ 43.13 -package org.openrdf.query.resultio.sparqlkml; 43.14 - 43.15 -import java.io.OutputStream; 43.16 - 43.17 -import org.openrdf.query.resultio.TupleQueryResultFormat; 43.18 -import org.openrdf.query.resultio.TupleQueryResultWriter; 43.19 -import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 43.20 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 43.21 - 43.22 -/** 43.23 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 43.24 - * 43.25 - */ 43.26 -public class stSPARQLResultsKMZWriterFactory implements TupleQueryResultWriterFactory { 43.27 - 43.28 - @Override 43.29 - public TupleQueryResultFormat getTupleQueryResultFormat() { 43.30 - return stSPARQLQueryResultFormat.KMZ; 43.31 - } 43.32 - 43.33 - @Override 43.34 - public TupleQueryResultWriter getWriter(OutputStream out) { 43.35 - return new stSPARQLResultsKMZWriter(out); 43.36 - } 43.37 - 43.38 -}
44.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLResultsXMLWriter.java Mon Nov 05 20:40:17 2012 +0200 44.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 44.3 @@ -1,190 +0,0 @@ 44.4 -/* 44.5 - * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2007. 44.6 - * 44.7 - * Licensed under the Aduna BSD-style license. 44.8 - */ 44.9 -package org.openrdf.query.resultio.sparqlxml; 44.10 - 44.11 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.BINDING_NAME_ATT; 44.12 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.BINDING_TAG; 44.13 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.BNODE_TAG; 44.14 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.HEAD_TAG; 44.15 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.LITERAL_DATATYPE_ATT; 44.16 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.LITERAL_LANG_ATT; 44.17 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.LITERAL_TAG; 44.18 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.NAMESPACE; 44.19 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.RESULT_SET_TAG; 44.20 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.RESULT_TAG; 44.21 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.ROOT_TAG; 44.22 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.URI_TAG; 44.23 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.VAR_NAME_ATT; 44.24 -import static org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLConstants.VAR_TAG; 44.25 -import info.aduna.xml.XMLWriter; 44.26 - 44.27 -import java.io.IOException; 44.28 -import java.io.OutputStream; 44.29 -import java.util.List; 44.30 - 44.31 -import org.openrdf.model.BNode; 44.32 -import org.openrdf.model.Literal; 44.33 -import org.openrdf.model.URI; 44.34 -import org.openrdf.model.Value; 44.35 -import org.openrdf.model.impl.LiteralImpl; 44.36 -import org.openrdf.model.impl.URIImpl; 44.37 -import org.openrdf.query.Binding; 44.38 -import org.openrdf.query.BindingSet; 44.39 -import org.openrdf.query.TupleQueryResultHandlerException; 44.40 -import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; 44.41 -import org.openrdf.query.resultio.TupleQueryResultFormat; 44.42 -import org.openrdf.query.resultio.TupleQueryResultWriter; 44.43 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 44.44 - 44.45 -/** 44.46 - * A {@link TupleQueryResultWriter} that writes tuple query results in the <a 44.47 - * href="http://www.w3.org/TR/rdf-sparql-XMLres/">SPARQL Query Results XML 44.48 - * Format</a>. 44.49 - * 44.50 - * @author Manos Karpathiotakis <mk@di.uoa.gr> 44.51 - */ 44.52 -public class stSPARQLResultsXMLWriter implements TupleQueryResultWriter { 44.53 - 44.54 - /*-----------* 44.55 - * Variables * 44.56 - *-----------*/ 44.57 - 44.58 - /** 44.59 - * XMLWriter to write XML to. 44.60 - */ 44.61 - private XMLWriter xmlWriter; 44.62 - 44.63 - /*--------------* 44.64 - * Constructors * 44.65 - *--------------*/ 44.66 - 44.67 - public stSPARQLResultsXMLWriter(OutputStream out) { 44.68 - this(new XMLWriter(out)); 44.69 - } 44.70 - 44.71 - public stSPARQLResultsXMLWriter(XMLWriter xmlWriter) { 44.72 - this.xmlWriter = xmlWriter; 44.73 - this.xmlWriter.setPrettyPrint(true); 44.74 - } 44.75 - 44.76 - public final TupleQueryResultFormat getTupleQueryResultFormat() { 44.77 - return stSPARQLQueryResultFormat.XML; 44.78 - } 44.79 - 44.80 - /** 44.81 - * Enables/disables addition of indentation characters and newlines in the 44.82 - * XML document. By default, pretty-printing is set to <tt>true</tt>. If 44.83 - * set to <tt>false</tt>, no indentation and newlines are added to the XML 44.84 - * document. This method has to be used before writing starts (that is, 44.85 - * before {@link #startQueryResult(List)} is called). 44.86 - */ 44.87 - public void setPrettyPrint(boolean prettyPrint) { 44.88 - xmlWriter.setPrettyPrint(prettyPrint); 44.89 - } 44.90 - 44.91 - public void startQueryResult(List<String> bindingNames) 44.92 - throws TupleQueryResultHandlerException 44.93 - { 44.94 - try { 44.95 - xmlWriter.startDocument(); 44.96 - 44.97 - xmlWriter.setAttribute("xmlns", NAMESPACE); 44.98 - xmlWriter.startTag(ROOT_TAG); 44.99 - 44.100 - // Write header 44.101 - xmlWriter.startTag(HEAD_TAG); 44.102 - for (String name : bindingNames) { 44.103 - xmlWriter.setAttribute(VAR_NAME_ATT, name); 44.104 - xmlWriter.emptyElement(VAR_TAG); 44.105 - } 44.106 - xmlWriter.endTag(HEAD_TAG); 44.107 - 44.108 - // Write start of results 44.109 - xmlWriter.startTag(RESULT_SET_TAG); 44.110 - } 44.111 - catch (IOException e) { 44.112 - throw new TupleQueryResultHandlerException(e); 44.113 - } 44.114 - } 44.115 - 44.116 - public void endQueryResult() 44.117 - throws TupleQueryResultHandlerException 44.118 - { 44.119 - try { 44.120 - xmlWriter.endTag(RESULT_SET_TAG); 44.121 - xmlWriter.endTag(ROOT_TAG); 44.122 - 44.123 - xmlWriter.endDocument(); 44.124 - } 44.125 - catch (IOException e) { 44.126 - throw new TupleQueryResultHandlerException(e); 44.127 - } 44.128 - } 44.129 - 44.130 - public void handleSolution(BindingSet bindingSet) 44.131 - throws TupleQueryResultHandlerException 44.132 - { 44.133 - try { 44.134 - xmlWriter.startTag(RESULT_TAG); 44.135 - 44.136 - for (Binding binding : bindingSet) { 44.137 - xmlWriter.setAttribute(BINDING_NAME_ATT, binding.getName()); 44.138 - xmlWriter.startTag(BINDING_TAG); 44.139 - 44.140 - writeValue(binding.getValue()); 44.141 - 44.142 - xmlWriter.endTag(BINDING_TAG); 44.143 - } 44.144 - 44.145 - xmlWriter.endTag(RESULT_TAG); 44.146 - } 44.147 - catch (IOException e) { 44.148 - throw new TupleQueryResultHandlerException(e); 44.149 - } 44.150 - } 44.151 - 44.152 - private void writeValue(Value value) throws IOException { 44.153 - if (value instanceof URI) { 44.154 - writeURI((URI) value); 44.155 - } else if (value instanceof BNode) { 44.156 - writeBNode((BNode) value); 44.157 - } else if (value instanceof Literal) { 44.158 - writeLiteral((Literal) value); 44.159 - } 44.160 - else { // spatial literal 44.161 - // else if (value instanceof RdbmsPolyhedron) 44.162 - URI datatype = new URIImpl(GeoConstants.WKT); 44.163 - Literal literal = new LiteralImpl(value.stringValue(), datatype); 44.164 - writeLiteral(literal); 44.165 - } 44.166 - } 44.167 - 44.168 - private void writeURI(URI uri) 44.169 - throws IOException 44.170 - { 44.171 - xmlWriter.textElement(URI_TAG, uri.toString()); 44.172 - } 44.173 - 44.174 - private void writeBNode(BNode bNode) 44.175 - throws IOException 44.176 - { 44.177 - xmlWriter.textElement(BNODE_TAG, bNode.getID()); 44.178 - } 44.179 - 44.180 - private void writeLiteral(Literal literal) 44.181 - throws IOException 44.182 - { 44.183 - if (literal.getLanguage() != null) { 44.184 - xmlWriter.setAttribute(LITERAL_LANG_ATT, literal.getLanguage()); 44.185 - } 44.186 - else if (literal.getDatatype() != null) { 44.187 - URI datatype = literal.getDatatype(); 44.188 - xmlWriter.setAttribute(LITERAL_DATATYPE_ATT, datatype.toString()); 44.189 - } 44.190 - 44.191 - xmlWriter.textElement(LITERAL_TAG, literal.getLabel()); 44.192 - } 44.193 -}
45.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLResultsXMLWriterFactory.java Mon Nov 05 20:40:17 2012 +0200 45.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 45.3 @@ -1,35 +0,0 @@ 45.4 -/** 45.5 - * This Source Code Form is subject to the terms of the Mozilla Public 45.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 45.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 45.8 - * 45.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 45.10 - * 45.11 - * http://www.strabon.di.uoa.gr/ 45.12 - */ 45.13 -package org.openrdf.query.resultio.sparqlxml; 45.14 - 45.15 -import java.io.OutputStream; 45.16 - 45.17 -import org.openrdf.query.resultio.TupleQueryResultFormat; 45.18 -import org.openrdf.query.resultio.TupleQueryResultWriter; 45.19 -import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 45.20 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 45.21 - 45.22 -/** 45.23 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 45.24 - * 45.25 - */ 45.26 -public class stSPARQLResultsXMLWriterFactory implements TupleQueryResultWriterFactory { 45.27 - 45.28 - @Override 45.29 - public TupleQueryResultFormat getTupleQueryResultFormat() { 45.30 - return stSPARQLQueryResultFormat.XML; 45.31 - } 45.32 - 45.33 - @Override 45.34 - public TupleQueryResultWriter getWriter(OutputStream out) { 45.35 - return new stSPARQLResultsXMLWriter(out); 45.36 - } 45.37 - 45.38 -}
46.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlxml/stSPARQLXMLWriter.java Mon Nov 05 20:40:17 2012 +0200 46.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 46.3 @@ -1,55 +0,0 @@ 46.4 -/** 46.5 - * This Source Code Form is subject to the terms of the Mozilla Public 46.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 46.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 46.8 - * 46.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 46.10 - * 46.11 - * http://www.strabon.di.uoa.gr/ 46.12 - */ 46.13 -package org.openrdf.query.resultio.sparqlxml; 46.14 - 46.15 -import java.io.IOException; 46.16 -import java.io.OutputStream; 46.17 -import java.io.UnsupportedEncodingException; 46.18 -import java.io.Writer; 46.19 - 46.20 -import info.aduna.xml.XMLWriter; 46.21 - 46.22 -/** 46.23 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 46.24 - * 46.25 - */ 46.26 -public class stSPARQLXMLWriter extends XMLWriter { 46.27 - 46.28 - /** 46.29 - * @param writer 46.30 - */ 46.31 - public stSPARQLXMLWriter(Writer writer) { 46.32 - super(writer); 46.33 - } 46.34 - 46.35 - /** 46.36 - * @param outputStream 46.37 - */ 46.38 - public stSPARQLXMLWriter(OutputStream outputStream) { 46.39 - super(outputStream); 46.40 - } 46.41 - 46.42 - /** 46.43 - * @param outputStream 46.44 - * @param charEncoding 46.45 - * @throws UnsupportedEncodingException 46.46 - */ 46.47 - public stSPARQLXMLWriter(OutputStream outputStream, String charEncoding) throws UnsupportedEncodingException { 46.48 - super(outputStream, charEncoding); 46.49 - } 46.50 - 46.51 - /** 46.52 - * Like XMLWriter.text(String text) but without escaping the string. 46.53 - */ 46.54 - public void unescapedText(String text) throws IOException { 46.55 - _write(text); 46.56 - } 46.57 - 46.58 -}
47.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java Mon Nov 05 20:40:17 2012 +0200 47.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 47.3 @@ -1,143 +0,0 @@ 47.4 -/** 47.5 - * This Source Code Form is subject to the terms of the Mozilla Public 47.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 47.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 47.8 - * 47.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 47.10 - * 47.11 - * http://www.strabon.di.uoa.gr/ 47.12 - */ 47.13 -package org.openrdf.query.resultio; 47.14 - 47.15 -import java.nio.charset.Charset; 47.16 -import java.util.ArrayList; 47.17 -import java.util.Arrays; 47.18 -import java.util.Collection; 47.19 -import java.util.List; 47.20 - 47.21 -/** 47.22 - * Represents the concept of an tuple query result serialization format for 47.23 - * stSPARQL/GeoSPARQL. Tuple query result formats are identified by a 47.24 - * {@link #getName() name} and can have one or more associated MIME types, 47.25 - * zero or more associated file extensions and can specify a (default) 47.26 - * character encoding. 47.27 - * 47.28 - * In contrast to formats mentioned in class {@link #TupleQueryResultFormat}, 47.29 - * stSPARQL/GeoSPARQL formats do not adhere to any specification for SPARQL 47.30 - * except for those that are extension of the respective formats in class 47.31 - * {@link #TupleQueryResultFormat}, such as TSV. 47.32 - * For example, the projected variables in a stSPARQL/GeoSPARQL query are 47.33 - * not included in the beginning of these formats. Instead, they are provided 47.34 - * as an additional description for a feature (e.g., a tuple query result with 47.35 - * a projected variable corresponding to a geometry). 47.36 - * 47.37 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 47.38 - * 47.39 - */ 47.40 -public class stSPARQLQueryResultFormat extends TupleQueryResultFormat { 47.41 - 47.42 - /** 47.43 - * XML format (extension of {@link TupleQueryResultFormat#SPARQL} format to include geometries) 47.44 - */ 47.45 - public static final stSPARQLQueryResultFormat XML = new stSPARQLQueryResultFormat("XML", 47.46 - Arrays.asList("application/sparql-results+xml", "application/xml"), Charset.forName("UTF-8"), Arrays.asList("xml")); 47.47 - 47.48 - /** 47.49 - * KML format (see http://www.opengeospatial.org/standards/kml/) 47.50 - */ 47.51 - public static final stSPARQLQueryResultFormat KML = new stSPARQLQueryResultFormat("KML", 47.52 - Arrays.asList("application/vnd.google-earth.kml+xml", "application/kml"), Charset.forName("UTF-8"), Arrays.asList("kml")); 47.53 - 47.54 - /** 47.55 - * KMZ format (a zipped KML content) 47.56 - */ 47.57 - public static final stSPARQLQueryResultFormat KMZ = new stSPARQLQueryResultFormat("KMZ", 47.58 - Arrays.asList("application/vnd.google-earth.kmz", "application/kmz"), Charset.forName("UTF-8"), Arrays.asList("kmz")); 47.59 - 47.60 - /** 47.61 - * GeoJSON format (see http://www.geojson.org/geojson-spec.html) 47.62 - */ 47.63 - public static final stSPARQLQueryResultFormat GEOJSON = new stSPARQLQueryResultFormat("GeoJSON", 47.64 - Arrays.asList("application/json", "application/geojson"), Charset.forName("UTF-8"), Arrays.asList("json")); 47.65 - 47.66 - /** 47.67 - * Tab separated value format (extension of {@link TupleQueryResultFormat#TSV} format to include geometries) 47.68 - */ 47.69 - public static final stSPARQLQueryResultFormat TSV = new stSPARQLQueryResultFormat("TSV", 47.70 - Arrays.asList("text/tab-separated-values"), Charset.forName("UTF-8"), Arrays.asList("tsv")); 47.71 - 47.72 - /** 47.73 - * HTML format (encoded as an HTML table, without the <tt><TABLE></tt> tag) 47.74 - */ 47.75 - public static final stSPARQLQueryResultFormat HTML = new stSPARQLQueryResultFormat("HTML", 47.76 - Arrays.asList("text/html"), Charset.forName("UTF-8"), Arrays.asList("html", "htm")); 47.77 - 47.78 - /** 47.79 - * The available stSPARQLQuery Result Formats 47.80 - */ 47.81 - private static final List<stSPARQLQueryResultFormat> VALUES = new ArrayList<stSPARQLQueryResultFormat>(6); 47.82 - 47.83 - // registers stSPARQL/GeoSPARQL formats 47.84 - static { 47.85 - register(XML); 47.86 - register(KML); 47.87 - register(KMZ); 47.88 - register(GEOJSON); 47.89 - register(TSV); 47.90 - register(HTML); 47.91 - } 47.92 - 47.93 - /** 47.94 - * Register the specified stSPARQLQueryResultFormat. 47.95 - * 47.96 - * @param format 47.97 - */ 47.98 - public static void register(stSPARQLQueryResultFormat format) { 47.99 - TupleQueryResultFormat.register(format); 47.100 - VALUES.add(format); 47.101 - } 47.102 - 47.103 - /** 47.104 - * Gets the stSPARQLQueryResultFormat given its name. 47.105 - * 47.106 - * @param formatName 47.107 - * @return 47.108 - */ 47.109 - public static stSPARQLQueryResultFormat valueOf(String formatName) { 47.110 - for (TupleQueryResultFormat format : values()) { 47.111 - if (format instanceof stSPARQLQueryResultFormat && 47.112 - format.getName().equalsIgnoreCase(formatName)) { 47.113 - return (stSPARQLQueryResultFormat) format; 47.114 - } 47.115 - } 47.116 - 47.117 - return null; 47.118 - } 47.119 - 47.120 - /** 47.121 - * Returns all known/registered tuple query result formats. 47.122 - */ 47.123 - public static Collection<TupleQueryResultFormat> values() { 47.124 - return TupleQueryResultFormat.values(); 47.125 - } 47.126 - 47.127 - public static stSPARQLQueryResultFormat forMIMEType(String mimeType) { 47.128 - return forMIMEType(mimeType, null); 47.129 - } 47.130 - 47.131 - public static stSPARQLQueryResultFormat forMIMEType(String mimeType, stSPARQLQueryResultFormat fallback) { 47.132 - return matchMIMEType(mimeType, VALUES, fallback); 47.133 - } 47.134 - 47.135 - public stSPARQLQueryResultFormat(String name, String mimeType, String fileExt) { 47.136 - super(name, mimeType, fileExt); 47.137 - } 47.138 - 47.139 - public stSPARQLQueryResultFormat(String name, String mimeType, Charset charset, String fileExt) { 47.140 - super(name, mimeType, charset, fileExt); 47.141 - } 47.142 - 47.143 - public stSPARQLQueryResultFormat(String name, Collection<String> mimeTypes, Charset charset, Collection<String> fileExtensions) { 47.144 - super(name, mimeTypes, charset, fileExtensions); 47.145 - } 47.146 -}
48.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultWriterFactory.java Mon Nov 05 20:40:17 2012 +0200 48.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 48.3 @@ -1,76 +0,0 @@ 48.4 -/** 48.5 - * This Source Code Form is subject to the terms of the Mozilla Public 48.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 48.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 48.8 - * 48.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 48.10 - * 48.11 - * http://www.strabon.di.uoa.gr/ 48.12 - */ 48.13 -package org.openrdf.query.resultio; 48.14 - 48.15 -import java.io.OutputStream; 48.16 - 48.17 -import org.openrdf.query.resultio.sparqlgeojson.stSPARQLResultsGeoJSONWriterFactory; 48.18 -import org.openrdf.query.resultio.sparqlhtml.stSPARQLResultsHTMLWriterFactory; 48.19 -import org.openrdf.query.resultio.sparqlkml.stSPARQLResultsKMZWriterFactory; 48.20 -import org.openrdf.query.resultio.sparqlkml.stSPARQLResultsKMLWriterFactory; 48.21 -import org.openrdf.query.resultio.sparqlxml.stSPARQLResultsXMLWriterFactory; 48.22 -import org.openrdf.query.resultio.text.stSPARQLResultsTSVWriterFactory; 48.23 - 48.24 -/** 48.25 - * This is a factory class for creating stSPARQLQueryResultWriter 48.26 - * instances according to a format in {@link org.openrdf.query.resultio.sparqlxml.Format}. 48.27 - * 48.28 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 48.29 - * 48.30 - */ 48.31 -public class stSPARQLQueryResultWriterFactory { 48.32 - 48.33 - private static TupleQueryResultWriterFactory html = new stSPARQLResultsHTMLWriterFactory(); 48.34 - private static TupleQueryResultWriterFactory xml = new stSPARQLResultsXMLWriterFactory(); 48.35 - private static TupleQueryResultWriterFactory kml = new stSPARQLResultsKMLWriterFactory(); 48.36 - private static TupleQueryResultWriterFactory kmz = new stSPARQLResultsKMZWriterFactory(); 48.37 - private static TupleQueryResultWriterFactory tsv = new stSPARQLResultsTSVWriterFactory(); 48.38 - private static TupleQueryResultWriterFactory geojson = new stSPARQLResultsGeoJSONWriterFactory(); 48.39 - 48.40 - public static TupleQueryResultWriter createstSPARQLQueryResultWriter(Format format, OutputStream out) { 48.41 - TupleQueryResultWriter writer = null; 48.42 - 48.43 - switch (format) { 48.44 - case DEFAULT: 48.45 - writer = tsv.getWriter(out); 48.46 - break; 48.47 - 48.48 - case XML: 48.49 - writer = xml.getWriter(out); 48.50 - break; 48.51 - 48.52 - case KML: 48.53 - writer = kml.getWriter(out); 48.54 - break; 48.55 - 48.56 - case KMZ: 48.57 - writer = kmz.getWriter(out); 48.58 - break; 48.59 - 48.60 - case GEOJSON: 48.61 - writer = geojson.getWriter(out); 48.62 - break; 48.63 - 48.64 - case EXP: 48.65 - // TODO: add 48.66 - break; 48.67 - 48.68 - case HTML: 48.69 - writer = html.getWriter(out); 48.70 - break; 48.71 - 48.72 - case TSV: 48.73 - writer = tsv.getWriter(out); 48.74 - } 48.75 - 48.76 - return writer; 48.77 - } 48.78 - 48.79 -}
49.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java Mon Nov 05 20:40:17 2012 +0200 49.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 49.3 @@ -1,43 +0,0 @@ 49.4 -/** 49.5 - * This Source Code Form is subject to the terms of the Mozilla Public 49.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 49.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 49.8 - * 49.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 49.10 - * 49.11 - * http://www.strabon.di.uoa.gr/ 49.12 - */ 49.13 -package org.openrdf.query.resultio.text; 49.14 - 49.15 -import java.io.IOException; 49.16 -import java.io.OutputStream; 49.17 - 49.18 -import org.openrdf.model.Value; 49.19 -import org.openrdf.model.impl.LiteralImpl; 49.20 -import org.openrdf.query.resultio.text.tsv.SPARQLResultsTSVWriter; 49.21 -import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 49.22 - 49.23 -/** 49.24 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 49.25 - * 49.26 - */ 49.27 -public class stSPARQLResultsTSVWriter extends SPARQLResultsTSVWriter { 49.28 - 49.29 - public stSPARQLResultsTSVWriter(OutputStream out) { 49.30 - super(out); 49.31 - } 49.32 - 49.33 - @Override 49.34 - protected void writeValue(Value val) throws IOException { 49.35 - if (val instanceof GeneralDBPolyhedron) { 49.36 - // catch the spatial case and create a new literal 49.37 - // constructing a new literal is the only way if we want to reuse the {@link #writeValue(Value)} method 49.38 - GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) val; 49.39 - val = new LiteralImpl(dbpolyhedron.getPolyhedronStringRep(), dbpolyhedron.getDatatype()); 49.40 - } 49.41 - 49.42 - // write value 49.43 - super.writeValue(val); 49.44 - 49.45 - } 49.46 -}
50.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriterFactory.java Mon Nov 05 20:40:17 2012 +0200 50.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 50.3 @@ -1,35 +0,0 @@ 50.4 -/** 50.5 - * This Source Code Form is subject to the terms of the Mozilla Public 50.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 50.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 50.8 - * 50.9 - * Copyright (C) 2010, 2011, 2012, Pyravlos Team 50.10 - * 50.11 - * http://www.strabon.di.uoa.gr/ 50.12 - */ 50.13 -package org.openrdf.query.resultio.text; 50.14 - 50.15 -import java.io.OutputStream; 50.16 - 50.17 -import org.openrdf.query.resultio.TupleQueryResultFormat; 50.18 -import org.openrdf.query.resultio.TupleQueryResultWriter; 50.19 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 50.20 -import org.openrdf.query.resultio.text.tsv.SPARQLResultsTSVWriterFactory; 50.21 - 50.22 -/** 50.23 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 50.24 - * 50.25 - */ 50.26 -public class stSPARQLResultsTSVWriterFactory extends SPARQLResultsTSVWriterFactory { 50.27 - 50.28 - @Override 50.29 - public TupleQueryResultFormat getTupleQueryResultFormat() { 50.30 - return stSPARQLQueryResultFormat.TSV; 50.31 - } 50.32 - 50.33 - @Override 50.34 - public TupleQueryResultWriter getWriter(OutputStream out) { 50.35 - return new stSPARQLResultsTSVWriter(out); 50.36 - } 50.37 - 50.38 -}
51.1 --- a/runtime/pom.xml Mon Nov 05 20:40:17 2012 +0200 51.2 +++ b/runtime/pom.xml Tue Nov 06 19:24:43 2012 +0200 51.3 @@ -22,8 +22,29 @@ 51.4 51.5 <dependency> 51.6 <groupId>org.openrdf.sesame</groupId> 51.7 - <artifactId>sesame-queryresultio-spatial</artifactId> 51.8 + <artifactId>sesame-queryresultio-spatial-api</artifactId> 51.9 </dependency> 51.10 + <dependency> 51.11 + <groupId>org.openrdf.sesame</groupId> 51.12 + <artifactId>sesame-queryresultio-spatial-sparqlgeojson</artifactId> 51.13 + </dependency> 51.14 + <dependency> 51.15 + <groupId>org.openrdf.sesame</groupId> 51.16 + <artifactId>sesame-queryresultio-spatial-sparqlkml</artifactId> 51.17 + </dependency> 51.18 + <dependency> 51.19 + <groupId>org.openrdf.sesame</groupId> 51.20 + <artifactId>sesame-queryresultio-spatial-sparqlxml</artifactId> 51.21 + </dependency> 51.22 + <dependency> 51.23 + <groupId>org.openrdf.sesame</groupId> 51.24 + <artifactId>sesame-queryresultio-spatial-sparqlhtml</artifactId> 51.25 + </dependency> 51.26 + <dependency> 51.27 + <groupId>org.openrdf.sesame</groupId> 51.28 + <artifactId>sesame-queryresultio-spatial-text</artifactId> 51.29 + </dependency> 51.30 + 51.31 51.32 <dependency> 51.33 <groupId>org.openrdf.sesame</groupId>
52.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Mon Nov 05 20:40:17 2012 +0200 52.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Tue Nov 06 19:24:43 2012 +0200 52.3 @@ -32,9 +32,7 @@ 52.4 import org.openrdf.query.TupleQueryResultHandlerException; 52.5 import org.openrdf.query.Update; 52.6 import org.openrdf.query.UpdateExecutionException; 52.7 -import org.openrdf.query.resultio.Format; 52.8 import org.openrdf.query.resultio.TupleQueryResultWriter; 52.9 -import org.openrdf.query.resultio.stSPARQLQueryResultWriterFactory; 52.10 import org.openrdf.repository.RepositoryException; 52.11 import org.openrdf.repository.sail.SailRepository; 52.12 import org.openrdf.repository.sail.SailRepositoryConnection; 52.13 @@ -47,7 +45,9 @@ 52.14 import org.slf4j.Logger; 52.15 import org.slf4j.LoggerFactory; 52.16 52.17 +import eu.earthobservatory.utils.Format; 52.18 import eu.earthobservatory.utils.RDFHandlerFactory; 52.19 +import eu.earthobservatory.utils.stSPARQLQueryResultToFormatAdapter; 52.20 52.21 public abstract class Strabon { 52.22 52.23 @@ -252,7 +252,7 @@ 52.24 52.25 default: 52.26 // get the writer for the specified format 52.27 - TupleQueryResultWriter resultWriter = stSPARQLQueryResultWriterFactory.createstSPARQLQueryResultWriter(resultsFormat, out); 52.28 + TupleQueryResultWriter resultWriter = stSPARQLQueryResultToFormatAdapter.createstSPARQLQueryResultWriter(resultsFormat, out); 52.29 52.30 // check for null format 52.31 if (resultWriter == null) {
53.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryDir.java Mon Nov 05 20:40:17 2012 +0200 53.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryDir.java Tue Nov 06 19:24:43 2012 +0200 53.3 @@ -9,13 +9,14 @@ 53.4 */ 53.5 package eu.earthobservatory.runtime.monetdb; 53.6 53.7 +import eu.earthobservatory.utils.Format; 53.8 + 53.9 import java.io.BufferedReader; 53.10 import java.io.File; 53.11 import java.io.FileReader; 53.12 import java.io.FilenameFilter; 53.13 import java.io.IOException; 53.14 53.15 -import org.openrdf.query.resultio.Format; 53.16 import org.slf4j.Logger; 53.17 import org.slf4j.LoggerFactory; 53.18
54.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java Mon Nov 05 20:40:17 2012 +0200 54.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/monetdb/QueryOp.java Tue Nov 06 19:24:43 2012 +0200 54.3 @@ -9,7 +9,8 @@ 54.4 */ 54.5 package eu.earthobservatory.runtime.monetdb; 54.6 54.7 -import org.openrdf.query.resultio.Format; 54.8 +import eu.earthobservatory.utils.Format; 54.9 + 54.10 import org.slf4j.Logger; 54.11 import org.slf4j.LoggerFactory; 54.12
55.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryDir.java Mon Nov 05 20:40:17 2012 +0200 55.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryDir.java Tue Nov 06 19:24:43 2012 +0200 55.3 @@ -9,13 +9,14 @@ 55.4 */ 55.5 package eu.earthobservatory.runtime.postgis; 55.6 55.7 +import eu.earthobservatory.utils.Format; 55.8 + 55.9 import java.io.BufferedReader; 55.10 import java.io.File; 55.11 import java.io.FileReader; 55.12 import java.io.FilenameFilter; 55.13 import java.io.IOException; 55.14 55.15 -import org.openrdf.query.resultio.Format; 55.16 import org.slf4j.Logger; 55.17 import org.slf4j.LoggerFactory; 55.18
56.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java Mon Nov 05 20:40:17 2012 +0200 56.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/postgis/QueryOp.java Tue Nov 06 19:24:43 2012 +0200 56.3 @@ -9,7 +9,8 @@ 56.4 */ 56.5 package eu.earthobservatory.runtime.postgis; 56.6 56.7 -import org.openrdf.query.resultio.Format; 56.8 +import eu.earthobservatory.utils.Format; 56.9 + 56.10 import org.slf4j.Logger; 56.11 import org.slf4j.LoggerFactory; 56.12
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 57.2 +++ b/runtime/src/main/java/eu/earthobservatory/utils/Format.java Tue Nov 06 19:24:43 2012 +0200 57.3 @@ -0,0 +1,111 @@ 57.4 +/** 57.5 + * This Source Code Form is subject to the terms of the Mozilla Public 57.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 57.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 57.8 + * 57.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 57.10 + * 57.11 + * http://www.strabon.di.uoa.gr/ 57.12 + */ 57.13 +package eu.earthobservatory.utils; 57.14 + 57.15 +import java.util.HashMap; 57.16 +import java.util.Map; 57.17 + 57.18 +/** 57.19 + * This enumeration type represents the available formats 57.20 + * for the results of the evaluation of a SPARQL query. 57.21 + * 57.22 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 57.23 + * 57.24 + */ 57.25 +public enum Format { 57.26 + 57.27 + /** 57.28 + * Default format 57.29 + */ 57.30 + DEFAULT(""), 57.31 + 57.32 + /** 57.33 + * XML format 57.34 + */ 57.35 + XML("XML"), 57.36 + 57.37 + /** 57.38 + * KML format 57.39 + */ 57.40 + KML("KML"), 57.41 + 57.42 + /** 57.43 + * KMZ format (compressed KML) 57.44 + */ 57.45 + KMZ("KMZ"), 57.46 + 57.47 + /** 57.48 + * GeoJSON format 57.49 + */ 57.50 + GEOJSON("GeoJSON"), 57.51 + 57.52 + /** 57.53 + * Format for experiments 57.54 + */ 57.55 + EXP("EXP"), 57.56 + 57.57 + /** 57.58 + * HTML format 57.59 + */ 57.60 + HTML("HTML"), 57.61 + 57.62 + /** 57.63 + * TSV (tab-separated values) format 57.64 + */ 57.65 + TSV("TSV"), 57.66 + 57.67 + /** 57.68 + * Invalid format. 57.69 + */ 57.70 + INVALID("INVALID"); 57.71 + 57.72 + /** 57.73 + * The string representation of this format 57.74 + */ 57.75 + private String name; 57.76 + 57.77 + /** 57.78 + * Map a string constant to a Format 57.79 + */ 57.80 + private static final Map<String, Format> stringToEnum = new HashMap<String, Format>(); 57.81 + 57.82 + 57.83 + static { // initialize map from constant name to enum constant 57.84 + for (Format format : values()) { 57.85 + // add both upper- and lower-case versions of the format 57.86 + stringToEnum.put(format.toString(), format); 57.87 + stringToEnum.put(format.toString().toLowerCase(), format); 57.88 + } 57.89 + } 57.90 + 57.91 + /** 57.92 + * Format constructor. 57.93 + * 57.94 + * @param name 57.95 + */ 57.96 + Format(String name) { 57.97 + this.name = name; 57.98 + } 57.99 + 57.100 + @Override 57.101 + public String toString() { 57.102 + return name; 57.103 + } 57.104 + 57.105 + /** 57.106 + * Returns a Format enum given a format string. 57.107 + * 57.108 + * @param lang 57.109 + * @return 57.110 + */ 57.111 + public static Format fromString(String format) { 57.112 + return (stringToEnum.get(format) == null) ? INVALID:stringToEnum.get(format); 57.113 + } 57.114 +}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 58.2 +++ b/runtime/src/main/java/eu/earthobservatory/utils/stSPARQLQueryResultToFormatAdapter.java Tue Nov 06 19:24:43 2012 +0200 58.3 @@ -0,0 +1,78 @@ 58.4 +/** 58.5 + * This Source Code Form is subject to the terms of the Mozilla Public 58.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 58.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 58.8 + * 58.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 58.10 + * 58.11 + * http://www.strabon.di.uoa.gr/ 58.12 + */ 58.13 +package eu.earthobservatory.utils; 58.14 + 58.15 +import java.io.OutputStream; 58.16 + 58.17 +import org.openrdf.query.resultio.TupleQueryResultWriter; 58.18 +import org.openrdf.query.resultio.TupleQueryResultWriterFactory; 58.19 +import org.openrdf.query.resultio.sparqlgeojson.stSPARQLResultsGeoJSONWriterFactory; 58.20 +import org.openrdf.query.resultio.sparqlhtml.stSPARQLResultsHTMLWriterFactory; 58.21 +import org.openrdf.query.resultio.sparqlkml.stSPARQLResultsKMLWriterFactory; 58.22 +import org.openrdf.query.resultio.sparqlkml.stSPARQLResultsKMZWriterFactory; 58.23 +import org.openrdf.query.resultio.sparqlxml.stSPARQLResultsXMLWriterFactory; 58.24 +import org.openrdf.query.resultio.text.stSPARQLResultsTSVWriterFactory; 58.25 + 58.26 +/** 58.27 + * This is a factory class for creating stSPARQLQueryResultWriter 58.28 + * instances according to a format in {@link org.openrdf.query.resultio.sparqlxml.Format}. 58.29 + * 58.30 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 58.31 + * 58.32 + */ 58.33 +public class stSPARQLQueryResultToFormatAdapter { 58.34 + 58.35 + private static TupleQueryResultWriterFactory html = new stSPARQLResultsHTMLWriterFactory(); 58.36 + private static TupleQueryResultWriterFactory xml = new stSPARQLResultsXMLWriterFactory(); 58.37 + private static TupleQueryResultWriterFactory kml = new stSPARQLResultsKMLWriterFactory(); 58.38 + private static TupleQueryResultWriterFactory kmz = new stSPARQLResultsKMZWriterFactory(); 58.39 + private static TupleQueryResultWriterFactory tsv = new stSPARQLResultsTSVWriterFactory(); 58.40 + private static TupleQueryResultWriterFactory geojson = new stSPARQLResultsGeoJSONWriterFactory(); 58.41 + 58.42 + public static TupleQueryResultWriter createstSPARQLQueryResultWriter(Format format, OutputStream out) { 58.43 + TupleQueryResultWriter writer = null; 58.44 + 58.45 + switch (format) { 58.46 + case DEFAULT: 58.47 + writer = tsv.getWriter(out); 58.48 + break; 58.49 + 58.50 + case XML: 58.51 + writer = xml.getWriter(out); 58.52 + break; 58.53 + 58.54 + case KML: 58.55 + writer = kml.getWriter(out); 58.56 + break; 58.57 + 58.58 + case KMZ: 58.59 + writer = kmz.getWriter(out); 58.60 + break; 58.61 + 58.62 + case GEOJSON: 58.63 + writer = geojson.getWriter(out); 58.64 + break; 58.65 + 58.66 + case EXP: 58.67 + // TODO: add 58.68 + break; 58.69 + 58.70 + case HTML: 58.71 + writer = html.getWriter(out); 58.72 + break; 58.73 + 58.74 + case TSV: 58.75 + writer = tsv.getWriter(out); 58.76 + } 58.77 + 58.78 + return writer; 58.79 + } 58.80 + 58.81 +}