Strabon

changeset 1237:32c838570030

extended KMLWriter so that when a timestamp is present in the result set, along with a geometry, its value is written enclosed in a "timestamp" "when" tag.
author Konstantina Bereta <Konstantina.Bereta@di.uoa.gr>
date Mon Jul 29 15:23:59 2013 +0300 (2013-07-29)
parents 7dc5f2a42690
children 981b55a32ec8
files resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java
line diff
     1.1 --- a/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Thu Jul 18 19:54:45 2013 +0300
     1.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Mon Jul 29 15:23:59 2013 +0300
     1.3 @@ -15,6 +15,7 @@
     1.4  import javax.xml.bind.JAXBException;
     1.5  import javax.xml.namespace.QName;
     1.6  
     1.7 +import org.apache.xerces.xni.grammars.XMLGrammarDescription;
     1.8  import org.geotools.kml.KML;
     1.9  import org.geotools.kml.KMLConfiguration;
    1.10  import org.geotools.xml.Encoder;
    1.11 @@ -61,6 +62,11 @@
    1.12  	private static final String NAMESPACE 			= "http://www.opengis.net/kml/2.2";
    1.13  	private static final String RESULT_SET_TAG 		= "Folder";
    1.14  	private static final String PLACEMARK_TAG 		= "Placemark";
    1.15 +	private static final String TIMESTAMP_TAG 		= "TimeStamp";
    1.16 +	private static final String TIMESPAN_TAG 		= "TimeSpan";
    1.17 +	private static final String BEGIN_TAG 		= "begin";
    1.18 +	private static final String END_TAG 		= "end";
    1.19 +	private static final String WHEN_TAG 		= "when";
    1.20  	private static final String NAME_TAG 			= "name";
    1.21  	private static final String DESC_TAG 			= "description";
    1.22  	private static final String EXT_DATA_TAG 		= "ExtendedData";
    1.23 @@ -92,6 +98,13 @@
    1.24  	private Boolean hasGeometry;
    1.25  
    1.26  	/**
    1.27 +	 * True if results have at least one temporal element.
    1.28 +	 * This element can be either an instant (xsd:dateTime value) or a period (strdf:period)
    1.29 +	 */
    1.30 +	private Boolean hasTimestamp;
    1.31 +    
    1.32 +	private Boolean hasTimespan;
    1.33 +	/**
    1.34  	 * The JTS wrapper
    1.35  	 */
    1.36  	private JTSWrapper jts;
    1.37 @@ -175,11 +188,23 @@
    1.38  		try {
    1.39  			// true if there are bindings that do not correspond to geometries
    1.40  			boolean hasDesc = false;
    1.41 +			String timeValue;
    1.42  			
    1.43  			Hashtable<String, String> extData = new Hashtable<String, String>();
    1.44  
    1.45 +
    1.46  			// write placemark tag
    1.47  			xmlWriter.startTag(PLACEMARK_TAG);
    1.48 +			for (Binding binding : bindingSet) {
    1.49 +
    1.50 +				Literal literal = (Literal) binding.getValue();
    1.51 +				if(XMLGSDatatypeUtil.isCalendarDatatype(literal.getDatatype())){
    1.52 +					hasTimestamp = true;
    1.53 +					xmlWriter.startTag(TIMESTAMP_TAG);
    1.54 +					xmlWriter.textElement(WHEN_TAG, literal.getLabel());
    1.55 +					xmlWriter.endTag(TIMESTAMP_TAG);
    1.56 +				}
    1.57 +			}
    1.58  			xmlWriter.textElement(NAME_TAG, "Result" + nresults);
    1.59  			
    1.60  			// parse binding set
    1.61 @@ -198,6 +223,7 @@
    1.62  					xmlWriter.unescapedText(getKML(value));
    1.63  					
    1.64  				} else { // URI, BlankNode, or Literal other than spatial literal
    1.65 +					
    1.66  					if (logger.isDebugEnabled()) {
    1.67  						logger.debug("[Strabon.KMLWriter] Found URI/BlankNode/Literal ({}): {}", value.getClass(), value);
    1.68  					}
    1.69 @@ -253,10 +279,10 @@
    1.70  				}
    1.71  				xmlWriter.endTag(EXT_DATA_TAG);
    1.72  			}
    1.73 -			
    1.74 +		
    1.75  			// end Placemark
    1.76  			xmlWriter.endTag(PLACEMARK_TAG);
    1.77 -			
    1.78 +		
    1.79  			// clear description string builders
    1.80  			descHeader.setLength(0);
    1.81  			descData.setLength(0);