Strabon
changeset 132:6945f58b1619
Added geojson support. more tests will follow
author | Manos Karpathiotakis <mk@di.uoa.gr> |
---|---|
date | Tue May 08 17:36:10 2012 +0300 (2012-05-08) |
parents | 6b85aec0ed58 |
children | abb14d6fd936 |
files | generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java pom.xml runtime/pom.xml runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java |
line diff
1.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Tue May 08 12:03:17 2012 +0300 1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/evaluation/GeneralDBEvaluation.java Tue May 08 17:36:10 2012 +0300 1.3 @@ -247,7 +247,7 @@ 1.4 @Override 1.5 public Value evaluate(FunctionCall fc, BindingSet bindings) throws ValueExprEvaluationException, QueryEvaluationException 1.6 { 1.7 - // System.out.println("FunctionCall placeholder"); 1.8 + System.out.println("FunctionCall placeholder"); 1.9 1.10 if(fc.getParentNode() instanceof Avg) 1.11 {
2.1 --- a/pom.xml Tue May 08 12:03:17 2012 +0300 2.2 +++ b/pom.xml Tue May 08 17:36:10 2012 +0300 2.3 @@ -29,7 +29,7 @@ 2.4 </modules> 2.5 2.6 <properties> 2.7 - <eu.earthobservatory.version>3.1.9-SNAPSHOT</eu.earthobservatory.version> 2.8 + <eu.earthobservatory.version>3.1.9-SNAPSHOT</eu.earthobservatory.version> 2.9 <sesame.version>2.6.3</sesame.version> 2.10 <aduna.appbase.version>3.5.0</aduna.appbase.version> 2.11 <slf4j.version>1.6.1</slf4j.version> 2.12 @@ -243,6 +243,12 @@ 2.13 2.14 <!-- GeoTools --> 2.15 <dependency> 2.16 + <groupId>org.geotools</groupId> 2.17 + <artifactId>gt-geojson</artifactId> 2.18 + <version>${geotools.version}</version> 2.19 + </dependency> 2.20 + 2.21 + <dependency> 2.22 <groupId>org.geotools.xsd</groupId> 2.23 <artifactId>gt-xsd-kml</artifactId> 2.24 <version>${geotools.version}</version>
3.1 --- a/runtime/pom.xml Tue May 08 12:03:17 2012 +0300 3.2 +++ b/runtime/pom.xml Tue May 08 17:36:10 2012 +0300 3.3 @@ -1,4 +1,5 @@ 3.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"> 3.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3.6 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3.7 3.8 <modelVersion>4.0.0</modelVersion> 3.9 3.10 @@ -12,29 +13,29 @@ 3.11 3.12 <name>Strabon: Runtime</name> 3.13 <description>Runtime dependencies for Strabon</description> 3.14 - <packaging>jar</packaging> 3.15 - 3.16 + <packaging>jar</packaging> 3.17 + 3.18 <dependencies> 3.19 <dependency> 3.20 <groupId>org.openrdf.sesame</groupId> 3.21 <artifactId>sesame-queryresultio-sparqlxml-spatial</artifactId> 3.22 </dependency> 3.23 - 3.24 + 3.25 <dependency> 3.26 <groupId>org.openrdf.sesame</groupId> 3.27 <artifactId>sesame-sail-postgis</artifactId> 3.28 </dependency> 3.29 - 3.30 + 3.31 <dependency> 3.32 <groupId>org.openrdf.sesame</groupId> 3.33 <artifactId>sesame-sail-monetdb</artifactId> 3.34 </dependency> 3.35 - 3.36 + 3.37 <dependency> 3.38 <groupId>org.openrdf.sesame</groupId> 3.39 <artifactId>sesame-sail-generaldb</artifactId> 3.40 </dependency> 3.41 - 3.42 + 3.43 <dependency> 3.44 <groupId>org.openrdf.sesame</groupId> 3.45 <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 3.46 @@ -47,14 +48,14 @@ 3.47 3.48 <dependency> 3.49 <groupId>org.openrdf.sesame</groupId> 3.50 - <artifactId>sesame-queryalgebra-evaluation</artifactId> 3.51 + <artifactId>sesame-queryalgebra-evaluation</artifactId> 3.52 </dependency> 3.53 3.54 <dependency> 3.55 <groupId>org.openrdf.sesame</groupId> 3.56 <artifactId>sesame-queryparser-api</artifactId> 3.57 </dependency> 3.58 - 3.59 + 3.60 <dependency> 3.61 <groupId>org.openrdf.sesame</groupId> 3.62 <artifactId>sesame-queryparser-sparql</artifactId> 3.63 @@ -74,12 +75,12 @@ 3.64 <groupId>org.openrdf.sesame</groupId> 3.65 <artifactId>sesame-query</artifactId> 3.66 </dependency> 3.67 - 3.68 + 3.69 <dependency> 3.70 <groupId>org.openrdf.sesame</groupId> 3.71 <artifactId>sesame-sail-rdbms</artifactId> 3.72 </dependency> 3.73 - 3.74 + 3.75 <dependency> 3.76 <groupId>org.openrdf.sesame</groupId> 3.77 <artifactId>sesame-repository-sail</artifactId> 3.78 @@ -87,199 +88,200 @@ 3.79 3.80 <!-- rio API --> 3.81 <dependency> 3.82 - <groupId>org.openrdf.sesame</groupId> 3.83 - <artifactId>sesame-rio-rdfxml</artifactId> 3.84 + <groupId>org.openrdf.sesame</groupId> 3.85 + <artifactId>sesame-rio-rdfxml</artifactId> 3.86 </dependency> 3.87 3.88 <dependency> 3.89 - <groupId>org.openrdf.sesame</groupId> 3.90 - <artifactId>sesame-rio-ntriples</artifactId> 3.91 + <groupId>org.openrdf.sesame</groupId> 3.92 + <artifactId>sesame-rio-ntriples</artifactId> 3.93 </dependency> 3.94 3.95 <dependency> 3.96 - <groupId>org.openrdf.sesame</groupId> 3.97 - <artifactId>sesame-rio-turtle</artifactId> 3.98 + <groupId>org.openrdf.sesame</groupId> 3.99 + <artifactId>sesame-rio-turtle</artifactId> 3.100 </dependency> 3.101 3.102 <dependency> 3.103 - <groupId>org.openrdf.sesame</groupId> 3.104 - <artifactId>sesame-rio-trig</artifactId> 3.105 + <groupId>org.openrdf.sesame</groupId> 3.106 + <artifactId>sesame-rio-trig</artifactId> 3.107 </dependency> 3.108 - 3.109 + 3.110 <dependency> 3.111 - <groupId>org.openrdf.sesame</groupId> 3.112 - <artifactId>sesame-rio-trix</artifactId> 3.113 + <groupId>org.openrdf.sesame</groupId> 3.114 + <artifactId>sesame-rio-trix</artifactId> 3.115 </dependency> 3.116 - 3.117 + 3.118 <dependency> 3.119 - <groupId>org.openrdf.sesame</groupId> 3.120 - <artifactId>sesame-rio-n3</artifactId> 3.121 + <groupId>org.openrdf.sesame</groupId> 3.122 + <artifactId>sesame-rio-n3</artifactId> 3.123 </dependency> 3.124 - 3.125 + 3.126 <dependency> 3.127 - <groupId>org.openrdf.sesame</groupId> 3.128 - <artifactId>sesame-rio-binary</artifactId> 3.129 + <groupId>org.openrdf.sesame</groupId> 3.130 + <artifactId>sesame-rio-binary</artifactId> 3.131 </dependency> 3.132 <!-- rio API --> 3.133 3.134 <!-- GeoTools --> 3.135 - <dependency> 3.136 - <groupId>org.geotools.xsd</groupId> 3.137 - <artifactId>gt-xsd-kml</artifactId> 3.138 - </dependency> 3.139 + <dependency> 3.140 + <groupId>org.geotools</groupId> 3.141 + <artifactId>gt-geojson</artifactId> 3.142 + </dependency> 3.143 3.144 - <dependency> 3.145 - <groupId>org.geotools</groupId> 3.146 - <artifactId>gt-xml</artifactId> 3.147 - </dependency> 3.148 + <dependency> 3.149 + <groupId>org.geotools.xsd</groupId> 3.150 + <artifactId>gt-xsd-kml</artifactId> 3.151 + </dependency> 3.152 3.153 - <dependency> 3.154 - <groupId>org.geotools</groupId> 3.155 - <artifactId>gt-epsg-hsql</artifactId> 3.156 - </dependency> 3.157 - 3.158 - <dependency> 3.159 - <groupId>org.geotools</groupId> 3.160 - <artifactId>gt-shapefile</artifactId> 3.161 - </dependency> 3.162 - 3.163 - <dependency> 3.164 - <groupId>org.geotools</groupId> 3.165 - <artifactId>gt-opengis</artifactId> 3.166 - </dependency> 3.167 + <dependency> 3.168 + <groupId>org.geotools</groupId> 3.169 + <artifactId>gt-xml</artifactId> 3.170 + </dependency> 3.171 3.172 - <!-- Aduna Appbase --> 3.173 - <dependency> 3.174 - <groupId>info.aduna.appbase</groupId> 3.175 - <artifactId>aduna-appbase</artifactId> 3.176 - <type>pom</type> 3.177 - </dependency> 3.178 + <dependency> 3.179 + <groupId>org.geotools</groupId> 3.180 + <artifactId>gt-epsg-hsql</artifactId> 3.181 + </dependency> 3.182 3.183 - <!-- Aduna Commons --> 3.184 - <!-- Note: other Aduna Commons dependencies are imported from appbase --> 3.185 - <dependency> 3.186 - <groupId>info.aduna.commons</groupId> 3.187 - <artifactId>aduna-commons-collections</artifactId> 3.188 - </dependency> 3.189 - <dependency> 3.190 - <groupId>info.aduna.commons</groupId> 3.191 - <artifactId>aduna-commons-concurrent</artifactId> 3.192 - </dependency> 3.193 - <dependency> 3.194 - <groupId>info.aduna.commons</groupId> 3.195 - <artifactId>aduna-commons-i18n</artifactId> 3.196 - </dependency> 3.197 - <dependency> 3.198 - <groupId>info.aduna.commons</groupId> 3.199 - <artifactId>aduna-commons-iteration</artifactId> 3.200 - </dependency> 3.201 - <dependency> 3.202 - <groupId>info.aduna.commons</groupId> 3.203 - <artifactId>aduna-commons-net-http-server-embedded</artifactId> 3.204 - </dependency> 3.205 + <dependency> 3.206 + <groupId>org.geotools</groupId> 3.207 + <artifactId>gt-shapefile</artifactId> 3.208 + </dependency> 3.209 3.210 - <!-- Apache Commons --> 3.211 - <dependency> 3.212 - <groupId>commons-cli</groupId> 3.213 - <artifactId>commons-cli</artifactId> 3.214 - </dependency> 3.215 - <dependency> 3.216 - <groupId>commons-dbcp</groupId> 3.217 - <artifactId>commons-dbcp</artifactId> 3.218 - </dependency> 3.219 - <dependency> 3.220 - <groupId>commons-fileupload</groupId> 3.221 - <artifactId>commons-fileupload</artifactId> 3.222 - </dependency> 3.223 - <dependency> 3.224 - <groupId>commons-io</groupId> 3.225 - <artifactId>commons-io</artifactId> 3.226 - <!-- this is the version that is specified as an optional dependency for fileupload --> 3.227 - </dependency> 3.228 - <dependency> 3.229 - <groupId>commons-httpclient</groupId> 3.230 - <artifactId>commons-httpclient</artifactId> 3.231 - <exclusions> 3.232 - <exclusion> 3.233 - <groupId>commons-logging</groupId> 3.234 - <artifactId>commons-logging</artifactId> 3.235 - </exclusion> 3.236 - <exclusion> 3.237 - <!-- httpclient includes older codec --> 3.238 - <groupId>commons-codec</groupId> 3.239 - <artifactId>commons-codec</artifactId> 3.240 - </exclusion> 3.241 - </exclusions> 3.242 - </dependency> 3.243 - <dependency> 3.244 - <groupId>commons-codec</groupId> 3.245 - <artifactId>commons-codec</artifactId> 3.246 - <scope>runtime</scope> 3.247 - </dependency> 3.248 + <dependency> 3.249 + <groupId>org.geotools</groupId> 3.250 + <artifactId>gt-opengis</artifactId> 3.251 + </dependency> 3.252 3.253 - <!-- Spring framework --> 3.254 - <dependency> 3.255 - <groupId>org.springframework</groupId> 3.256 - <artifactId>spring-aop</artifactId> 3.257 - <exclusions> 3.258 - <exclusion> 3.259 - <groupId>commons-logging</groupId> 3.260 - <artifactId>commons-logging</artifactId> 3.261 - </exclusion> 3.262 - </exclusions> 3.263 - </dependency> 3.264 + <!-- Aduna Appbase --> 3.265 + <dependency> 3.266 + <groupId>info.aduna.appbase</groupId> 3.267 + <artifactId>aduna-appbase</artifactId> 3.268 + <type>pom</type> 3.269 + </dependency> 3.270 3.271 - <!-- Compliance tests --> 3.272 - <dependency> 3.273 - <groupId>edu.lehigh.swat.bench</groupId> 3.274 - <artifactId>uba</artifactId> 3.275 - </dependency> 3.276 - <dependency> 3.277 - <groupId>edu.lehigh.swat.bench</groupId> 3.278 - <artifactId>ubt</artifactId> 3.279 - </dependency> 3.280 + <!-- Aduna Commons --> 3.281 + <!-- Note: other Aduna Commons dependencies are imported from appbase --> 3.282 + <dependency> 3.283 + <groupId>info.aduna.commons</groupId> 3.284 + <artifactId>aduna-commons-collections</artifactId> 3.285 + </dependency> 3.286 + <dependency> 3.287 + <groupId>info.aduna.commons</groupId> 3.288 + <artifactId>aduna-commons-concurrent</artifactId> 3.289 + </dependency> 3.290 + <dependency> 3.291 + <groupId>info.aduna.commons</groupId> 3.292 + <artifactId>aduna-commons-i18n</artifactId> 3.293 + </dependency> 3.294 + <dependency> 3.295 + <groupId>info.aduna.commons</groupId> 3.296 + <artifactId>aduna-commons-iteration</artifactId> 3.297 + </dependency> 3.298 + <dependency> 3.299 + <groupId>info.aduna.commons</groupId> 3.300 + <artifactId>aduna-commons-net-http-server-embedded</artifactId> 3.301 + </dependency> 3.302 3.303 - <!-- JDBC Drivers --> 3.304 + <!-- Apache Commons --> 3.305 + <dependency> 3.306 + <groupId>commons-cli</groupId> 3.307 + <artifactId>commons-cli</artifactId> 3.308 + </dependency> 3.309 + <dependency> 3.310 + <groupId>commons-dbcp</groupId> 3.311 + <artifactId>commons-dbcp</artifactId> 3.312 + </dependency> 3.313 + <dependency> 3.314 + <groupId>commons-fileupload</groupId> 3.315 + <artifactId>commons-fileupload</artifactId> 3.316 + </dependency> 3.317 + <dependency> 3.318 + <groupId>commons-io</groupId> 3.319 + <artifactId>commons-io</artifactId> 3.320 + <!-- this is the version that is specified as an optional dependency for 3.321 + fileupload --> 3.322 + </dependency> 3.323 + <dependency> 3.324 + <groupId>commons-httpclient</groupId> 3.325 + <artifactId>commons-httpclient</artifactId> 3.326 + <exclusions> 3.327 + <exclusion> 3.328 + <groupId>commons-logging</groupId> 3.329 + <artifactId>commons-logging</artifactId> 3.330 + </exclusion> 3.331 + <exclusion> 3.332 + <!-- httpclient includes older codec --> 3.333 + <groupId>commons-codec</groupId> 3.334 + <artifactId>commons-codec</artifactId> 3.335 + </exclusion> 3.336 + </exclusions> 3.337 + </dependency> 3.338 + <dependency> 3.339 + <groupId>commons-codec</groupId> 3.340 + <artifactId>commons-codec</artifactId> 3.341 + <scope>runtime</scope> 3.342 + </dependency> 3.343 3.344 - <dependency> 3.345 - <groupId>postgresql</groupId> 3.346 - <artifactId>postgresql</artifactId> 3.347 - </dependency> 3.348 + <!-- Spring framework --> 3.349 + <dependency> 3.350 + <groupId>org.springframework</groupId> 3.351 + <artifactId>spring-aop</artifactId> 3.352 + <exclusions> 3.353 + <exclusion> 3.354 + <groupId>commons-logging</groupId> 3.355 + <artifactId>commons-logging</artifactId> 3.356 + </exclusion> 3.357 + </exclusions> 3.358 + </dependency> 3.359 3.360 - <dependency> 3.361 - <groupId>mysql</groupId> 3.362 - <artifactId>mysql-connector-java</artifactId> 3.363 - </dependency> 3.364 + <!-- Compliance tests --> 3.365 + <dependency> 3.366 + <groupId>edu.lehigh.swat.bench</groupId> 3.367 + <artifactId>uba</artifactId> 3.368 + </dependency> 3.369 + <dependency> 3.370 + <groupId>edu.lehigh.swat.bench</groupId> 3.371 + <artifactId>ubt</artifactId> 3.372 + </dependency> 3.373 3.374 - <!-- various --> 3.375 - <dependency> 3.376 - <groupId>cglib</groupId> 3.377 - <artifactId>cglib</artifactId> 3.378 - </dependency> 3.379 - 3.380 - <!-- Testing: JUnit --> 3.381 - <dependency> 3.382 - <groupId>junit</groupId> 3.383 - <artifactId>junit</artifactId> 3.384 - <scope>test</scope> 3.385 - </dependency> 3.386 + <!-- JDBC Drivers --> 3.387 3.388 - <dependency> 3.389 - <groupId>monetdb</groupId> 3.390 - <artifactId>jdbcclient</artifactId> 3.391 - <version>3.4.0</version> 3.392 - </dependency> 3.393 + <dependency> 3.394 + <groupId>postgresql</groupId> 3.395 + <artifactId>postgresql</artifactId> 3.396 + </dependency> 3.397 3.398 - <!-- 3.399 - <dependency> 3.400 - <groupId>net.sf</groupId> 3.401 - <artifactId>log4jdbc3</artifactId> 3.402 - <version>1.2beta2</version> 3.403 - </dependency> 3.404 - --> 3.405 + <dependency> 3.406 + <groupId>mysql</groupId> 3.407 + <artifactId>mysql-connector-java</artifactId> 3.408 + </dependency> 3.409 + 3.410 + <!-- various --> 3.411 + <dependency> 3.412 + <groupId>cglib</groupId> 3.413 + <artifactId>cglib</artifactId> 3.414 + </dependency> 3.415 + 3.416 + <!-- Testing: JUnit --> 3.417 + <dependency> 3.418 + <groupId>junit</groupId> 3.419 + <artifactId>junit</artifactId> 3.420 + <scope>test</scope> 3.421 + </dependency> 3.422 + 3.423 + <dependency> 3.424 + <groupId>monetdb</groupId> 3.425 + <artifactId>jdbcclient</artifactId> 3.426 + <version>3.4.0</version> 3.427 + </dependency> 3.428 + 3.429 + <!-- <dependency> <groupId>net.sf</groupId> <artifactId>log4jdbc3</artifactId> 3.430 + <version>1.2beta2</version> </dependency> --> 3.431 </dependencies> 3.432 3.433 -<build> 3.434 + <build> 3.435 <pluginManagement> 3.436 <plugins> 3.437 <!-- FIXME: version 2.2-beta-2 causes a lot problems -->
4.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Tue May 08 12:03:17 2012 +0300 4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Tue May 08 17:36:10 2012 +0300 4.3 @@ -2,7 +2,6 @@ 4.4 4.5 import java.io.DataOutputStream; 4.6 import java.io.File; 4.7 -import java.io.FileInputStream; 4.8 import java.io.FileNotFoundException; 4.9 import java.io.FileOutputStream; 4.10 import java.io.IOException; 4.11 @@ -21,9 +20,21 @@ 4.12 import javax.xml.namespace.QName; 4.13 4.14 import org.apache.commons.io.output.ByteArrayOutputStream; 4.15 +import org.geotools.data.simple.SimpleFeatureCollection; 4.16 +import org.geotools.feature.FeatureCollections; 4.17 +import org.geotools.feature.simple.SimpleFeatureBuilder; 4.18 +import org.geotools.feature.simple.SimpleFeatureTypeBuilder; 4.19 +import org.geotools.geojson.feature.FeatureJSON; 4.20 import org.geotools.kml.KML; 4.21 import org.geotools.kml.KMLConfiguration; 4.22 +import org.geotools.referencing.CRS; 4.23 import org.geotools.xml.Encoder; 4.24 +import org.opengis.feature.simple.SimpleFeature; 4.25 +import org.opengis.feature.simple.SimpleFeatureType; 4.26 +import org.opengis.referencing.FactoryException; 4.27 +import org.opengis.referencing.NoSuchAuthorityCodeException; 4.28 +import org.opengis.referencing.crs.CoordinateReferenceSystem; 4.29 +import org.opengis.referencing.operation.MathTransform; 4.30 import org.openrdf.model.URI; 4.31 import org.openrdf.model.Value; 4.32 import org.openrdf.model.ValueFactory; 4.33 @@ -38,6 +49,7 @@ 4.34 import org.openrdf.query.TupleQueryResultHandlerException; 4.35 import org.openrdf.query.Update; 4.36 import org.openrdf.query.UpdateExecutionException; 4.37 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 4.38 import org.openrdf.query.resultio.sparqlxml.stSPARQLResultsXMLWriter; 4.39 import org.openrdf.repository.RepositoryException; 4.40 import org.openrdf.repository.sail.SailRepository; 4.41 @@ -48,9 +60,10 @@ 4.42 import org.openrdf.rio.RDFParseException; 4.43 import org.openrdf.rio.RDFParser; 4.44 import org.openrdf.rio.Rio; 4.45 -import org.openrdf.rio.ntriples.NTriplesParser; 4.46 import org.openrdf.rio.ntriples.NTriplesWriter; 4.47 +import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 4.48 import org.openrdf.sail.helpers.SailBase; 4.49 +import org.openrdf.sail.rdbms.model.RdbmsLiteral; 4.50 4.51 import com.vividsolutions.jts.geom.Geometry; 4.52 import com.vividsolutions.jts.geom.GeometryCollection; 4.53 @@ -65,6 +78,7 @@ 4.54 import com.vividsolutions.jts.io.ParseException; 4.55 import com.vividsolutions.jts.io.WKTReader; 4.56 4.57 + 4.58 public abstract class Strabon { 4.59 4.60 /** 4.61 @@ -82,14 +96,14 @@ 4.62 } 4.63 4.64 public Strabon(String databaseName, String user, String password, int port, String serverName, boolean checkForLockTable) 4.65 - throws SQLException, ClassNotFoundException 4.66 - { 4.67 + throws SQLException, ClassNotFoundException 4.68 + { 4.69 if (checkForLockTable == true) { 4.70 checkAndDeleteLock(databaseName, user, password, port, serverName); 4.71 } 4.72 - 4.73 + 4.74 initiate(databaseName, user, password, port, serverName); 4.75 - } 4.76 + } 4.77 4.78 4.79 protected abstract void initiate(String databaseName, String user, String password, int port, String serverName) ; 4.80 @@ -102,16 +116,16 @@ 4.81 System.setProperty("org.geotools.referencing.forceXY", "true"); 4.82 //our repository 4.83 repo1 = new SailRepository(db_store); 4.84 - 4.85 + 4.86 try { 4.87 repo1.initialize(); 4.88 } catch (RepositoryException e) { 4.89 - 4.90 + 4.91 e.printStackTrace(); 4.92 } 4.93 4.94 System.out.println("Clearing Successful"); 4.95 - 4.96 + 4.97 try { 4.98 con1 = repo1.getConnection(); 4.99 } catch (RepositoryException e) { 4.100 @@ -122,7 +136,7 @@ 4.101 4.102 4.103 protected abstract void checkAndDeleteLock(String databaseName, String user, String password, int port, String serverName) 4.104 - throws SQLException, ClassNotFoundException ; 4.105 + throws SQLException, ClassNotFoundException ; 4.106 4.107 public SailRepositoryConnection getSailRepoConnection() { 4.108 return con1; 4.109 @@ -139,53 +153,53 @@ 4.110 System.out.println("Closing..."); 4.111 4.112 4.113 - 4.114 - try { 4.115 - con1.commit(); 4.116 - con1.close(); 4.117 - repo1.shutDown(); 4.118 - } catch (RepositoryException e) { 4.119 - 4.120 - e.printStackTrace(); 4.121 - } 4.122 + 4.123 + try { 4.124 + con1.commit(); 4.125 + con1.close(); 4.126 + repo1.shutDown(); 4.127 + } catch (RepositoryException e) { 4.128 + 4.129 + e.printStackTrace(); 4.130 + } 4.131 } 4.132 4.133 public Object query(String queryString) 4.134 - throws MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException 4.135 - { 4.136 + throws MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException 4.137 + { 4.138 return query(queryString, "", this.getSailRepoConnection()); 4.139 - } 4.140 + } 4.141 4.142 public Object query(String queryString, String resultsFormat) 4.143 throws MalformedQueryException , QueryEvaluationException, IOException, TupleQueryResultHandlerException 4.144 - { 4.145 + { 4.146 return query (queryString, resultsFormat, this.getSailRepoConnection()); 4.147 - } 4.148 - 4.149 + } 4.150 + 4.151 public Object query(String queryString, SailRepositoryConnection con) 4.152 - throws MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException 4.153 - { 4.154 + throws MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException 4.155 + { 4.156 return query(queryString, "", con); 4.157 - } 4.158 - 4.159 + } 4.160 + 4.161 public Object query(String queryString, String resultsFormat, SailRepositoryConnection con) 4.162 - throws MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException 4.163 + throws MalformedQueryException, QueryEvaluationException, IOException, TupleQueryResultHandlerException 4.164 4.165 - { 4.166 + { 4.167 TupleQuery tupleQuery = null; 4.168 try { 4.169 tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString); 4.170 } catch (RepositoryException e) { 4.171 - 4.172 + 4.173 e.printStackTrace(); 4.174 } 4.175 //System.out.println("Placemark0"); 4.176 //System.out.println("\n\n\nGot query - new2: " + queryString + "\n\n\n"); 4.177 - 4.178 + 4.179 ArrayList<String> ret = new ArrayList<String>(); 4.180 - 4.181 + 4.182 ByteArrayOutputStream retStream = new ByteArrayOutputStream(); 4.183 -// DataOutputStream out = new DataOutputStream(retStream); 4.184 + // DataOutputStream out = new DataOutputStream(retStream); 4.185 OutputStreamWriter writeOut = new OutputStreamWriter(retStream,"UTF-8"); 4.186 if ( resultsFormat.equalsIgnoreCase("EXP") ) { 4.187 long results = 0; 4.188 @@ -196,29 +210,29 @@ 4.189 results++; 4.190 } 4.191 long t3 = System.nanoTime(); 4.192 - 4.193 + 4.194 return new long[]{t2-t1, t3-t2, t3-t1,results}; 4.195 } else if ( resultsFormat.equalsIgnoreCase("") ) { 4.196 TupleQueryResult result = null; 4.197 - //System.out.println("About to evaluate: "); 4.198 - result = tupleQuery.evaluate(); 4.199 - 4.200 + //System.out.println("About to evaluate: "); 4.201 + result = tupleQuery.evaluate(); 4.202 + 4.203 //System.out.println("-------------------------------------------"); 4.204 //System.out.println("- RESULTS -"); 4.205 //System.out.println("-------------------------------------------"); 4.206 - 4.207 - 4.208 - while (result.hasNext()) { 4.209 - 4.210 - BindingSet bindingSet = result.next(); 4.211 -// try { 4.212 - System.out.println(bindingSet.toString()); 4.213 - ret.add(bindingSet.toString()); 4.214 -// } catch (NullPointerException e) { 4.215 -// System.err.println("Null pointer"); 4.216 -// } 4.217 - } 4.218 - 4.219 + 4.220 + 4.221 + while (result.hasNext()) { 4.222 + 4.223 + BindingSet bindingSet = result.next(); 4.224 + // try { 4.225 + System.out.println(bindingSet.toString()); 4.226 + ret.add(bindingSet.toString()); 4.227 + // } catch (NullPointerException e) { 4.228 + // System.err.println("Null pointer"); 4.229 + // } 4.230 + } 4.231 + 4.232 //System.out.println("-------------------------------------------"); 4.233 System.out.flush(); 4.234 return ret; 4.235 @@ -227,17 +241,196 @@ 4.236 System.out.println("Serializing results (XML)"); 4.237 tupleQuery.evaluate(new stSPARQLResultsXMLWriter(retStream)); 4.238 } 4.239 + else if (resultsFormat.equalsIgnoreCase("GeoJSON")) { 4.240 + 4.241 + DataOutputStream dos = new DataOutputStream(retStream); 4.242 + 4.243 + TupleQueryResult result = null; 4.244 + try 4.245 + { 4.246 + result = tupleQuery.evaluate(); 4.247 + } 4.248 + catch (QueryEvaluationException e1) 4.249 + { 4.250 + e1.printStackTrace(); 4.251 + } 4.252 + 4.253 + int resultsCounter = 0; 4.254 + 4.255 + //Setting a Feature Collection 4.256 + SimpleFeatureCollection sfCollection = FeatureCollections.newCollection("geomOutput"); 4.257 + 4.258 + int spatialBindingsNo=0; 4.259 + 4.260 + //May not need that much - still initializing it 4.261 + String[] spatialBindings = new String[result.getBindingNames().size()]; 4.262 + SimpleFeatureTypeBuilder[] tb = new SimpleFeatureTypeBuilder[result.getBindingNames().size()]; 4.263 + 4.264 + for(int i=0;i<result.getBindingNames().size();i++) 4.265 + { 4.266 + tb[i] = new SimpleFeatureTypeBuilder(); 4.267 + } 4.268 + 4.269 + BindingSet bindingSet; 4.270 + if(result.hasNext()) 4.271 + { 4.272 + //Sneak Peek to obtain info on which bindings are spatial 4.273 + bindingSet = result.next(); 4.274 + boolean spatial = false; 4.275 + for(String bindingName : bindingSet.getBindingNames()) 4.276 + { 4.277 + Value val = bindingSet.getValue(bindingName); 4.278 + 4.279 + if(val instanceof RdbmsLiteral) 4.280 + { 4.281 + if(((RdbmsLiteral) val).getDatatype()!=null) 4.282 + { 4.283 + if(((RdbmsLiteral) val).getDatatype().toString().equals(StrabonPolyhedron.ogcGeometry)) 4.284 + { 4.285 + spatial = true; 4.286 + } 4.287 + } 4.288 + } 4.289 + 4.290 + if(val instanceof GeneralDBPolyhedron) 4.291 + { 4.292 + spatial = true; 4.293 + 4.294 + } 4.295 + 4.296 + if(spatial) 4.297 + { 4.298 + spatial = false; 4.299 + spatialBindings[spatialBindingsNo] = bindingName; 4.300 + spatialBindingsNo++; 4.301 + } 4.302 + } 4.303 + 4.304 + } 4.305 + else 4.306 + { 4.307 + return retStream.toString(); //empty 4.308 + } 4.309 + 4.310 + boolean firstLineParsed = false; 4.311 + 4.312 + do 4.313 + { 4.314 + if(firstLineParsed) 4.315 + { 4.316 + bindingSet = result.next(); 4.317 + } 4.318 + 4.319 + firstLineParsed = true; 4.320 + 4.321 + //How many features will occur from a single result? --> spatialBindingsNo 4.322 + for(int i=0; i<spatialBindingsNo;i++) 4.323 + { 4.324 + tb[i].setName("Feature_"+(++resultsCounter)); 4.325 + 4.326 + //Every time a featureType is built, the builder is nullified!! 4.327 + //Can't avoid re-iterating... 4.328 + for(String otherBinding : bindingSet.getBindingNames()) 4.329 + { 4.330 + if(!otherBinding.equals(spatialBindings[i])) 4.331 + { 4.332 + tb[i].add(otherBinding,String.class); 4.333 + } 4.334 + } 4.335 + 4.336 + 4.337 + int SRID=4326; 4.338 + Geometry geom = null; 4.339 + Value unparsedGeometry = bindingSet.getValue(spatialBindings[i]); 4.340 + //Regardless of our geometry's input, we need its SRID 4.341 + if(unparsedGeometry instanceof GeneralDBPolyhedron) 4.342 + { 4.343 + geom = ((GeneralDBPolyhedron) unparsedGeometry).getPolyhedron().getGeometry(); 4.344 + SRID = ((GeneralDBPolyhedron) unparsedGeometry).getPolyhedron().getGeometry().getSRID(); 4.345 + } 4.346 + else //RdbmsLiteral 4.347 + //TODO GML support to be added 4.348 + { 4.349 + String unparsedWKT = ((RdbmsLiteral)unparsedGeometry).getLabel(); 4.350 + try { 4.351 + int pos = unparsedWKT.indexOf(";"); 4.352 + if(pos!=-1) 4.353 + { 4.354 + geom = new WKTReader().read(unparsedWKT.substring(0,pos)); 4.355 + int whereToCut = unparsedWKT.lastIndexOf('/'); 4.356 + SRID = Integer.parseInt(unparsedWKT.substring(whereToCut+1)); 4.357 + } 4.358 + else 4.359 + { 4.360 + geom = new WKTReader().read(unparsedWKT); 4.361 + SRID=4326; 4.362 + } 4.363 + 4.364 + } 4.365 + catch (ParseException e) 4.366 + { 4.367 + System.out.println("Faults detected in spatial literal representation"); 4.368 + e.printStackTrace(); 4.369 + } 4.370 + } 4.371 + 4.372 + CoordinateReferenceSystem geomCRS = null; 4.373 + try { 4.374 + geomCRS = CRS.decode("EPSG:"+SRID); 4.375 + } catch (NoSuchAuthorityCodeException e) { 4.376 + System.out.println("Error decoding returned geometry's SRID"); 4.377 + e.printStackTrace(); 4.378 + } catch (FactoryException e) { 4.379 + e.printStackTrace(); 4.380 + } 4.381 + 4.382 + tb[i].setCRS(geomCRS); 4.383 + tb[i].setSRS("EPSG:"+SRID); 4.384 + tb[i].add("geometry",Geometry.class); 4.385 + 4.386 + SimpleFeatureType featureType = tb[i].buildFeatureType(); 4.387 + SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); 4.388 + 4.389 + for(String otherBinding : bindingSet.getBindingNames()) 4.390 + { 4.391 + if(!otherBinding.equals(spatialBindings[i])) 4.392 + { 4.393 + featureBuilder.add(bindingSet.getValue(otherBinding)); 4.394 + } 4.395 + } 4.396 + 4.397 + featureBuilder.add(geom); 4.398 + 4.399 + 4.400 + SimpleFeature feature = featureBuilder.buildFeature(null); 4.401 + sfCollection.add(feature); 4.402 + 4.403 +// FeatureJSON fjson22 = new FeatureJSON(); 4.404 +// fjson22.setEncodeFeatureCRS(true); 4.405 +// fjson22.writeFeatureCollection(sfCollection, dos); 4.406 +// System.out.println(retStream.toString()); 4.407 + } 4.408 + 4.409 + } 4.410 + while((result.hasNext())); 4.411 + 4.412 + FeatureJSON fjson = new FeatureJSON(); 4.413 + fjson.setEncodeFeatureCRS(true); 4.414 + fjson.writeFeatureCollection(sfCollection, dos); 4.415 + System.out.println(retStream.toString()); 4.416 + 4.417 + } 4.418 else if ( resultsFormat.equalsIgnoreCase("KMZ") ) { 4.419 //GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null); 4.420 GeometryFactory gf = new GeometryFactory(new PrecisionModel(),4326); 4.421 WKTReader reader = new WKTReader(gf); 4.422 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 4.423 - 4.424 + 4.425 DataOutputStream dos = new DataOutputStream(baos); 4.426 - 4.427 + 4.428 //used to construct the entire kml document 4.429 StringBuilder sb = new StringBuilder(); 4.430 - 4.431 + 4.432 TupleQueryResult result = null; 4.433 try { 4.434 result = tupleQuery.evaluate(); 4.435 @@ -248,7 +441,7 @@ 4.436 //System.out.println("-------------------------------------------"); 4.437 //System.out.println("- RESULTS -"); 4.438 //System.out.println("-------------------------------------------"); 4.439 - 4.440 + 4.441 int resultCounter = 0; 4.442 try { 4.443 while (result.hasNext()) { 4.444 @@ -261,17 +454,17 @@ 4.445 { 4.446 String unparsed = bindingSet.getBinding(bindingName).getValue().toString(); 4.447 String corrResult = unparsed.substring(1,unparsed.length()-1); 4.448 - 4.449 + 4.450 try { 4.451 Geometry geom = reader.read(corrResult); 4.452 geom.setSRID(4326); 4.453 //geom.setSRID(32630); 4.454 - 4.455 + 4.456 //CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:32630"); 4.457 //CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326"); 4.458 - 4.459 + 4.460 //MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true); 4.461 - 4.462 + 4.463 //geom = JTS.transform(geom, transform); 4.464 //geom.geometryChanged(); 4.465 geometryCounter++; 4.466 @@ -296,25 +489,25 @@ 4.467 else if(geom instanceof MultiLineString) 4.468 { 4.469 geometryType = KML.MultiGeometry; 4.470 - 4.471 + 4.472 } 4.473 else if(geom instanceof MultiPolygon) 4.474 { 4.475 geometryType = KML.MultiGeometry; 4.476 - 4.477 + 4.478 } 4.479 else if(geom instanceof GeometryCollection) 4.480 { 4.481 geometryType = KML.MultiGeometry; 4.482 - 4.483 + 4.484 } 4.485 else //TODO exception should be thrown here --> Specialize it 4.486 { 4.487 //System.out.println("Wrong Handling--> "+geometryType.toString()); 4.488 throw new Exception("Wrong Handling--> "+geom.toString()); 4.489 - 4.490 + 4.491 } 4.492 - 4.493 + 4.494 //Encoding to KML 4.495 Encoder encoder = new Encoder(new KMLConfiguration()); 4.496 encoder.setIndenting(true); 4.497 @@ -324,14 +517,14 @@ 4.498 corrResult = baos.toString(); 4.499 //removing the xml header 4.500 corrResult = corrResult.substring(38); 4.501 - 4.502 + 4.503 //Constructing each individual element 4.504 sb.append("\n<Placemark>"); 4.505 corrResult = corrResult.replaceAll("xmlns:kml=\"http://earth.google.com/kml/2.1\"","").replaceAll("kml:",""); 4.506 sb.append("\n<name> Geometry"+resultCounter+"_"+geometryCounter+"</name>"); 4.507 sb.append("\n<description>"); 4.508 //Time to fill the description 4.509 - 4.510 + 4.511 if(bindingNames.size() > 1) 4.512 { 4.513 //Creating Row1 --> names 4.514 @@ -346,14 +539,14 @@ 4.515 } 4.516 } 4.517 sb.append("</tr>"); 4.518 - 4.519 + 4.520 sb.append("<tr>"); 4.521 for(String otherBinding: bindingNames) 4.522 { 4.523 if(!otherBinding.equals(bindingName)) 4.524 { 4.525 sb.append("<td>"); 4.526 - 4.527 + 4.528 String bindingValue = bindingSet.getBinding(otherBinding).getValue().toString(); 4.529 sb.append(bindingValue); 4.530 sb.append("</td>"); 4.531 @@ -366,13 +559,13 @@ 4.532 sb.append("mantalakia"); 4.533 } 4.534 sb.append("</description>"); 4.535 - 4.536 + 4.537 sb.append(corrResult); 4.538 sb.append("\n</Placemark>\n"); 4.539 - 4.540 + 4.541 //emptying the buffer 4.542 baos.reset(); 4.543 - 4.544 + 4.545 } catch (ParseException e) { 4.546 //Den prokeitai gia WKT 4.547 //System.out.println(bindingSet.toString()); 4.548 @@ -380,7 +573,7 @@ 4.549 } catch (Exception e) { 4.550 e.printStackTrace(); 4.551 } 4.552 - 4.553 + 4.554 //Start populating KML here 4.555 } 4.556 // System.out.println(bindingSet.toString()); 4.557 @@ -396,62 +589,62 @@ 4.558 // TODO Auto-generated catch block 4.559 e.printStackTrace(); 4.560 } 4.561 - 4.562 + 4.563 //Finishing the structure of the kml document 4.564 sb.insert(0,"<?xml version=\"1.0\" encoding=\"UTF-8\"?> <kml xmlns=\"http://www.opengis.net/kml/2.2\"> <Folder>"); 4.565 sb.append("</Folder></kml>"); 4.566 - 4.567 + 4.568 //System.out.println(sb.toString()); 4.569 //System.out.println(baos.toString()); 4.570 - 4.571 + 4.572 // StringBuilder sb = new StringBuilder(); 4.573 // sb.append(baos.toString().replaceAll("<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>","")); 4.574 // sb.insert(0, "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <kml xmlns=\"http://www.opengis.net/kml/2.2\">" + 4.575 // "<kml:Placemark xmlns:kml=\"http://www.opengis.net/kml/2.2\">"); 4.576 // sb.append("</kml:Placemark></kml>"); 4.577 - 4.578 - 4.579 + 4.580 + 4.581 //System.out.println("*******************************"); 4.582 //sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 4.583 //System.out.println(sb.toString()); 4.584 - 4.585 + 4.586 //System.out.println(sb.toString()); 4.587 - 4.588 + 4.589 //XXX Probably not needed after all 4.590 // DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 4.591 // DocumentBuilder builder = factory.newDocumentBuilder(); 4.592 // StringReader sr = new StringReader(sb.toString()); 4.593 // Document document = builder.parse(new InputSource(sr)); 4.594 - 4.595 - 4.596 + 4.597 + 4.598 //System.out.println("-------------------------------------------"); 4.599 System.out.flush(); 4.600 - 4.601 + 4.602 try { 4.603 //String cstr = new String("aa", "UTF8"); 4.604 String newString = new String(sb.toString().getBytes(), Charset.availableCharsets().get("UTF-8")); 4.605 writeOut.write(newString); 4.606 //out.writeBytes(newString); 4.607 - 4.608 -// out.writeBytes(sb.toString()); 4.609 - 4.610 + 4.611 + // out.writeBytes(sb.toString()); 4.612 + 4.613 } catch (IOException e) { 4.614 // TODO Auto-generated catch block 4.615 e.printStackTrace(); 4.616 } 4.617 - 4.618 + 4.619 } 4.620 else if ( resultsFormat.equalsIgnoreCase("KML") ) { 4.621 //GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null); 4.622 GeometryFactory gf = new GeometryFactory(new PrecisionModel(),4326); 4.623 WKTReader reader = new WKTReader(gf); 4.624 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 4.625 - 4.626 + 4.627 DataOutputStream dos = new DataOutputStream(baos); 4.628 - 4.629 + 4.630 //used to construct the entire kml document 4.631 StringBuilder sb = new StringBuilder(); 4.632 - 4.633 + 4.634 TupleQueryResult result = null; 4.635 try { 4.636 result = tupleQuery.evaluate(); 4.637 @@ -462,7 +655,7 @@ 4.638 //System.out.println("-------------------------------------------"); 4.639 //System.out.println("- RESULTS -"); 4.640 //System.out.println("-------------------------------------------"); 4.641 - 4.642 + 4.643 int resultCounter = 0; 4.644 try { 4.645 while (result.hasNext()) { 4.646 @@ -475,19 +668,19 @@ 4.647 { 4.648 String unparsed = bindingSet.getBinding(bindingName).getValue().toString(); 4.649 String corrResult = unparsed.substring(1,unparsed.length()-1); 4.650 - 4.651 + 4.652 try { 4.653 Geometry geom = reader.read(corrResult); 4.654 //Integer s = new Integer(4326); 4.655 //geom.setSRID(4326); 4.656 - 4.657 + 4.658 //geom.setSRID(32630); 4.659 - 4.660 + 4.661 //CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:32630"); 4.662 //CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326"); 4.663 - 4.664 + 4.665 //MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true); 4.666 - 4.667 + 4.668 //geom = JTS.transform(geom, transform); 4.669 //geom.geometryChanged(); 4.670 geometryCounter++; 4.671 @@ -512,25 +705,25 @@ 4.672 else if(geom instanceof MultiLineString) 4.673 { 4.674 geometryType = KML.MultiGeometry; 4.675 - 4.676 + 4.677 } 4.678 else if(geom instanceof MultiPolygon) 4.679 { 4.680 geometryType = KML.MultiGeometry; 4.681 - 4.682 + 4.683 } 4.684 else if(geom instanceof GeometryCollection) 4.685 { 4.686 geometryType = KML.MultiGeometry; 4.687 - 4.688 + 4.689 } 4.690 else //TODO exception should be thrown here --> Specialize it 4.691 { 4.692 //System.out.println("Wrong Handling--> "+geometryType.toString()); 4.693 throw new Exception("Wrong Handling--> "+geom.toString()); 4.694 - 4.695 + 4.696 } 4.697 - 4.698 + 4.699 //Encoding to KML 4.700 Encoder encoder = new Encoder(new KMLConfiguration()); 4.701 encoder.setIndenting(true); 4.702 @@ -540,14 +733,14 @@ 4.703 corrResult = baos.toString(); 4.704 //removing the xml header 4.705 corrResult = corrResult.substring(38); 4.706 - 4.707 + 4.708 //Constructing each individual element 4.709 sb.append("\n<Placemark>"); 4.710 corrResult = corrResult.replaceAll("xmlns:kml=\"http://earth.google.com/kml/2.1\"","").replaceAll("kml:",""); 4.711 sb.append("\n<name> Geometry"+resultCounter+"_"+geometryCounter+"</name>"); 4.712 sb.append("\n<description>"); 4.713 //Time to fill the description 4.714 - 4.715 + 4.716 if(bindingNames.size() > 1) 4.717 { 4.718 //Creating Row1 --> names 4.719 @@ -562,14 +755,14 @@ 4.720 } 4.721 } 4.722 sb.append("</tr>"); 4.723 - 4.724 + 4.725 sb.append("<tr>"); 4.726 for(String otherBinding: bindingNames) 4.727 { 4.728 if(!otherBinding.equals(bindingName)) 4.729 { 4.730 sb.append("<td>"); 4.731 - 4.732 + 4.733 String bindingValue = bindingSet.getBinding(otherBinding).getValue().toString(); 4.734 sb.append(bindingValue); 4.735 sb.append("</td>"); 4.736 @@ -582,13 +775,13 @@ 4.737 sb.append("mantalakia"); 4.738 } 4.739 sb.append("</description>"); 4.740 - 4.741 + 4.742 sb.append(corrResult); 4.743 sb.append("\n</Placemark>\n"); 4.744 - 4.745 + 4.746 //emptying the buffer 4.747 baos.reset(); 4.748 - 4.749 + 4.750 } catch (ParseException e) { 4.751 //Den prokeitai gia WKT 4.752 //System.out.println(bindingSet.toString()); 4.753 @@ -596,7 +789,7 @@ 4.754 } catch (Exception e) { 4.755 e.printStackTrace(); 4.756 } 4.757 - 4.758 + 4.759 //Start populating KML here 4.760 } 4.761 // System.out.println(bindingSet.toString()); 4.762 @@ -612,45 +805,45 @@ 4.763 // TODO Auto-generated catch block 4.764 e.printStackTrace(); 4.765 } 4.766 - 4.767 + 4.768 //Finishing the structure of the kml document 4.769 sb.insert(0,"<?xml version=\"1.0\" encoding=\"UTF-8\"?> <kml xmlns=\"http://www.opengis.net/kml/2.2\"> <Folder>"); 4.770 sb.append("</Folder></kml>"); 4.771 - 4.772 + 4.773 //System.out.println(sb.toString()); 4.774 //System.out.println(baos.toString()); 4.775 - 4.776 + 4.777 // StringBuilder sb = new StringBuilder(); 4.778 // sb.append(baos.toString().replaceAll("<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>","")); 4.779 // sb.insert(0, "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <kml xmlns=\"http://www.opengis.net/kml/2.2\">" + 4.780 // "<kml:Placemark xmlns:kml=\"http://www.opengis.net/kml/2.2\">"); 4.781 // sb.append("</kml:Placemark></kml>"); 4.782 - 4.783 - 4.784 + 4.785 + 4.786 //System.out.println("*******************************"); 4.787 //sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 4.788 //System.out.println(sb.toString()); 4.789 - 4.790 + 4.791 //System.out.println(sb.toString()); 4.792 - 4.793 + 4.794 //XXX Probably not needed after all 4.795 // DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 4.796 // DocumentBuilder builder = factory.newDocumentBuilder(); 4.797 // StringReader sr = new StringReader(sb.toString()); 4.798 // Document document = builder.parse(new InputSource(sr)); 4.799 - 4.800 - 4.801 + 4.802 + 4.803 //System.out.println("-------------------------------------------"); 4.804 System.out.flush(); 4.805 - 4.806 + 4.807 try { 4.808 //String cstr = new String("aa", "UTF8"); 4.809 String newString = new String(sb.toString().getBytes(), Charset.availableCharsets().get("UTF-8")); 4.810 writeOut.write(newString); 4.811 //out.writeBytes(newString); 4.812 - 4.813 -// out.writeBytes(sb.toString()); 4.814 - 4.815 + 4.816 + // out.writeBytes(sb.toString()); 4.817 + 4.818 } catch (IOException e) { 4.819 // TODO Auto-generated catch block 4.820 e.printStackTrace(); 4.821 @@ -668,7 +861,7 @@ 4.822 // out.writeBytes("</th>"); 4.823 // } 4.824 /////////////////////////////// 4.825 - 4.826 + 4.827 //System.out.println("Placemark2!!"); 4.828 //Remove IF in case it is considered redundant -> added to test Registry.war 4.829 if(result.hasNext()) 4.830 @@ -712,38 +905,38 @@ 4.831 } 4.832 } 4.833 else { 4.834 -// System.exit(-1);// throw new InvalidDatasetFormatFault(); // TODO 4.835 + // System.exit(-1);// throw new InvalidDatasetFormatFault(); // TODO 4.836 System.out.println("No Such Format Available!!"); 4.837 return null; 4.838 } 4.839 - 4.840 + 4.841 try { 4.842 -// baos.flush(); 4.843 + // baos.flush(); 4.844 writeOut.flush(); 4.845 retStream.flush(); 4.846 } catch (IOException e) { 4.847 // TODO Auto-generated catch block 4.848 e.printStackTrace(); 4.849 } 4.850 - 4.851 + 4.852 // Print results. 4.853 //System.out.println(retStream.toString()); 4.854 4.855 //return ret; 4.856 return retStream.toString(); 4.857 - } 4.858 + } 4.859 4.860 public void update(String updateString, SailRepositoryConnection con) throws MalformedQueryException 4.861 4.862 { 4.863 Update update = null; 4.864 - 4.865 + 4.866 try { 4.867 update = con.prepareUpdate(QueryLanguage.SPARQL, updateString); 4.868 } catch (RepositoryException e) { 4.869 e.printStackTrace(); 4.870 } 4.871 - 4.872 + 4.873 System.out.println("Placemark0"); 4.874 System.out.println("\n\n\nGot query: " + updateString + "\n\n\n"); 4.875 4.876 @@ -762,13 +955,13 @@ 4.877 private void store(File file, String baseURI, RDFFormat format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault { 4.878 con1.add(file, baseURI, format); 4.879 } 4.880 - 4.881 + 4.882 public void storeInRepo(Object src, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault, RDFHandlerException 4.883 { 4.884 System.out.println("generaldb.Strabon.store in repo"); 4.885 storeInRepo(src, null, null, format); 4.886 } 4.887 - 4.888 + 4.889 public void storeInRepo(Object src, String baseURI, String context, String format) throws RDFParseException, RepositoryException, IOException,InvalidDatasetFormatFault, RDFHandlerException 4.890 { 4.891 RDFFormat realFormat = null; 4.892 @@ -827,7 +1020,7 @@ 4.893 e.printStackTrace(); 4.894 } 4.895 } 4.896 - 4.897 + 4.898 private void storeFile(File file, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException, RDFHandlerException 4.899 { 4.900 System.out.println("File : " + file.getName()); 4.901 @@ -852,7 +1045,7 @@ 4.902 con1.add(file, baseURI, format, context); 4.903 } 4.904 con1.add(georeader, "", RDFFormat.NTRIPLES); 4.905 - 4.906 + 4.907 } 4.908 4.909 private void storeURL(URL url, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException, RDFHandlerException 4.910 @@ -872,7 +1065,7 @@ 4.911 System.out.println("These are the extra triples:"+ handler.getTriples().toString()); 4.912 StringReader georeader= new StringReader(handler.getTriples().toString()); 4.913 handler.endRDF(); 4.914 - 4.915 + 4.916 if (context == null) { 4.917 System.out.println("[3]"); 4.918 con1.add(url, baseURI, format); 4.919 @@ -882,7 +1075,7 @@ 4.920 } 4.921 con1.add(georeader, "", RDFFormat.NTRIPLES); 4.922 } 4.923 - 4.924 + 4.925 private void storeString(String text, String baseURI, URI context, RDFFormat format) throws RDFParseException, RepositoryException, IOException, RDFHandlerException 4.926 { 4.927 if (baseURI == null) 4.928 @@ -896,7 +1089,7 @@ 4.929 StringReader reader = new StringReader(text); 4.930 RDFParser parser = Rio.createParser(format); 4.931 GeosparqlRDFHandlerBase handler = new GeosparqlRDFHandlerBase(); 4.932 - 4.933 + 4.934 handler.startRDF(); 4.935 parser.setRDFHandler(handler); 4.936 parser.parse(reader, ""); 4.937 @@ -904,7 +1097,7 @@ 4.938 StringReader georeader= new StringReader(handler.getTriples().toString()); 4.939 handler.endRDF(); 4.940 4.941 - 4.942 + 4.943 if (context == null) { 4.944 System.out.println("[5]"); 4.945 con1.add(reader, baseURI, format); 4.946 @@ -921,13 +1114,13 @@ 4.947 public void describe(String describeString, SailRepositoryConnection con, String outFile) throws MalformedQueryException 4.948 { 4.949 GraphQuery graphQuery = null; 4.950 - 4.951 + 4.952 try { 4.953 graphQuery = con.prepareGraphQuery(QueryLanguage.SPARQL, describeString); 4.954 } catch (RepositoryException e) { 4.955 e.printStackTrace(); 4.956 } 4.957 - 4.958 + 4.959 System.out.println("Placemark0"); 4.960 System.out.println("\n\n\nGot query: " + describeString + "\n\n\n"); 4.961