Strabon

changeset 1442:025b64f6f1fa

adresses bug #75: now GeoJSON correctly prints a datatype literal value, instead of always printing it as a string
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu Oct 30 15:37:40 2014 +0200 (2014-10-30)
parents 54679bf9f89b
children 077efe72e238
files resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java
line diff
     1.1 --- a/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java	Thu Oct 30 15:36:00 2014 +0200
     1.2 +++ b/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java	Thu Oct 30 15:37:40 2014 +0200
     1.3 @@ -13,6 +13,7 @@
     1.4  import java.io.OutputStream;
     1.5  import java.nio.charset.Charset;
     1.6  import java.util.ArrayList;
     1.7 +import java.util.Calendar;
     1.8  import java.util.List;
     1.9  
    1.10  import org.geotools.data.simple.SimpleFeatureCollection;
    1.11 @@ -24,9 +25,8 @@
    1.12  import org.opengis.feature.simple.SimpleFeature;
    1.13  import org.opengis.feature.simple.SimpleFeatureType;
    1.14  import org.openrdf.model.Literal;
    1.15 +import org.openrdf.model.URI;
    1.16  import org.openrdf.model.Value;
    1.17 -import org.openrdf.model.impl.LiteralImpl;
    1.18 -import org.openrdf.model.impl.URIImpl;
    1.19  import org.openrdf.query.Binding;
    1.20  import org.openrdf.query.BindingSet;
    1.21  import org.openrdf.query.TupleQueryResultHandlerException;
    1.22 @@ -215,6 +215,7 @@
    1.23  					
    1.24  					properties.add(binding.getName());
    1.25  					values.add(value);
    1.26 +					System.out.println(value.getClass());
    1.27  				}
    1.28  			}
    1.29  			
    1.30 @@ -224,7 +225,32 @@
    1.31  				
    1.32  				// add the properties
    1.33  				for (int p = 0; p < properties.size(); p++) {
    1.34 -					sftb.add(properties.get(p), String.class);
    1.35 +					Value val = values.get(p);
    1.36 +					
    1.37 +					if (val instanceof Literal) {
    1.38 +						Literal lit = (Literal) val;
    1.39 +						URI datatype = lit.getDatatype();
    1.40 +						
    1.41 +						if (XMLGSDatatypeUtil.isNumericDatatype(datatype)) {
    1.42 +							System.out.println("is number");
    1.43 +							sftb.add(properties.get(p), Number.class);
    1.44 +							
    1.45 +						} else if (XMLGSDatatypeUtil.isCalendarDatatype(datatype)) {
    1.46 +							System.out.println("is calendar");
    1.47 +							sftb.add(properties.get(p), Calendar.class);
    1.48 +							
    1.49 +						} else if (XMLGSDatatypeUtil.isBooleanDatatype(datatype)) {
    1.50 +							System.out.println("is boolean");
    1.51 +							sftb.add(properties.get(p), Boolean.class);
    1.52 +							
    1.53 +						} else { // fallback to String
    1.54 +							sftb.add(properties.get(p), String.class);	
    1.55 +						}
    1.56 +						
    1.57 +					} else { // fallback to String
    1.58 +						sftb.add(properties.get(p), String.class);
    1.59 +					}
    1.60 +					
    1.61  				}
    1.62  				
    1.63  				SimpleFeatureType featureType = sftb.buildFeatureType();
    1.64 @@ -235,7 +261,7 @@
    1.65  				
    1.66  				// add the values to the builder of the feature
    1.67  				for (int v = 0; v < values.size(); v++) {
    1.68 -					featureBuilder.add(values.get(v));
    1.69 +					featureBuilder.add(values.get(v).stringValue());
    1.70  				}
    1.71  				
    1.72  				SimpleFeature feature = featureBuilder.buildFeature(null);