Strabon

changeset 1011:dd7724b049de

added support of all SPARQL result types provided by Sesame (json, xml, csv, tsv, binary). To get the respective writer, just prepend the string "SPARQL/", e.g., "SPARQL/JSON". This is to ensure that we support all SPARQL result formats of the SPARQL Protocol.
author Babis Nikolaou <charnik@di.uoa.gr>
date Mon Apr 08 15:41:13 2013 +0300 (2013-04-08)
parents 34a6c207f0d3
children 4e4583f93e69
files endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SPARQLEndpoint.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/BrowseBean.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java pom.xml resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java runtime/pom.xml runtime/src/main/java/eu/earthobservatory/utils/Format.java runtime/src/main/java/eu/earthobservatory/utils/stSPARQLQueryResultToFormatAdapter.java
line diff
     1.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SPARQLEndpoint.java	Sat Apr 06 18:05:36 2013 +0300
     1.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SPARQLEndpoint.java	Mon Apr 08 15:41:13 2013 +0300
     1.3 @@ -215,7 +215,7 @@
     1.4  		SPARQLEndpoint endpoint = new SPARQLEndpoint(host, port, appName);
     1.5  		
     1.6  		try {
     1.7 -			EndpointResult result = endpoint.query(query, stSPARQLQueryResultFormat.valueOf(format));
     1.8 +			EndpointResult result = endpoint.query(query, (stSPARQLQueryResultFormat) stSPARQLQueryResultFormat.valueOf(format));
     1.9  			
    1.10  			System.out.println("Status code: " + result.getStatusCode());
    1.11  			System.out.println("Status text: " + result.getStatusText());
     2.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/BrowseBean.java	Sat Apr 06 18:05:36 2013 +0300
     2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/BrowseBean.java	Mon Apr 08 15:41:13 2013 +0300
     2.3 @@ -23,6 +23,7 @@
     2.4  import javax.servlet.http.HttpServletResponse;
     2.5  
     2.6  import org.apache.commons.lang.StringEscapeUtils;
     2.7 +import org.openrdf.query.resultio.TupleQueryResultFormat;
     2.8  import org.openrdf.query.resultio.stSPARQLQueryResultFormat;
     2.9  import org.slf4j.Logger;
    2.10  import org.slf4j.LoggerFactory;
    2.11 @@ -179,7 +180,7 @@
    2.12  		String format = request.getParameter("format");
    2.13  		
    2.14  		// get stSPARQLQueryResultFormat from given format name
    2.15 -		stSPARQLQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format);
    2.16 +		TupleQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format);
    2.17  
    2.18  		if (query == null || format == null || queryResultFormat == null) {
    2.19  			dispatcher = request.getRequestDispatcher("browse.jsp");
     3.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java	Sat Apr 06 18:05:36 2013 +0300
     3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/Common.java	Mon Apr 08 15:41:13 2013 +0300
     3.3 @@ -65,7 +65,7 @@
     3.4  	/**
     3.5  	 * Keeps the registered and available stSPARQL Query Results Formats.
     3.6  	 */
     3.7 -	public static final List<stSPARQLQueryResultFormat> registeredQueryResultsFormats = new ArrayList<stSPARQLQueryResultFormat>();
     3.8 +	public static final List<TupleQueryResultFormat> registeredQueryResultsFormats = new ArrayList<TupleQueryResultFormat>();
     3.9  	
    3.10  	/**
    3.11  	 * Keeps the name of the registered and available stSPARQL Query Results Formats.
    3.12 @@ -76,10 +76,10 @@
    3.13  	// initialize registered and available stSPARQL query results formats
    3.14  	static {
    3.15  		for (TupleQueryResultFormat format : stSPARQLQueryResultFormat.values()) {
    3.16 -			if (format instanceof stSPARQLQueryResultFormat) {
    3.17 -				registeredQueryResultsFormats.add((stSPARQLQueryResultFormat) format);
    3.18 +			//if (format instanceof stSPARQLQueryResultFormat) {
    3.19 +				registeredQueryResultsFormats.add(format);
    3.20  				registeredQueryResultsFormatNames.add(format.getName());
    3.21 -			}
    3.22 +			//}
    3.23  		}
    3.24  	}
    3.25  	
     4.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Sat Apr 06 18:05:36 2013 +0300
     4.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Mon Apr 08 15:41:13 2013 +0300
     4.3 @@ -30,6 +30,7 @@
     4.4  
     4.5  import org.apache.commons.io.FileUtils;
     4.6  import org.apache.commons.lang.StringEscapeUtils;
     4.7 +import org.openrdf.query.resultio.TupleQueryResultFormat;
     4.8  import org.openrdf.query.resultio.stSPARQLQueryResultFormat;
     4.9  import org.slf4j.Logger;
    4.10  import org.slf4j.LoggerFactory;
    4.11 @@ -221,7 +222,7 @@
    4.12  			String maxLimit = request.getParameter("maxLimit");
    4.13  			
    4.14  			// get stSPARQLQueryResultFormat from given format name
    4.15 -			stSPARQLQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format);
    4.16 +			TupleQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format);
    4.17  			
    4.18  			if (query == null || format == null || queryResultFormat == null) {
    4.19  				dispatcher = request.getRequestDispatcher("query.jsp");
     5.1 --- a/pom.xml	Sat Apr 06 18:05:36 2013 +0300
     5.2 +++ b/pom.xml	Mon Apr 08 15:41:13 2013 +0300
     5.3 @@ -214,6 +214,16 @@
     5.4  				<artifactId>sesame-queryresultio-text</artifactId>
     5.5  				<version>${sesame.version}</version>
     5.6  			</dependency>
     5.7 +			<dependency>
     5.8 +				<groupId>org.openrdf.sesame</groupId>
     5.9 +				<artifactId>sesame-queryresultio-binary</artifactId>
    5.10 +				<version>${sesame.version}</version>
    5.11 +			</dependency>
    5.12 +			<dependency>
    5.13 +				<groupId>org.openrdf.sesame</groupId>
    5.14 +				<artifactId>sesame-queryresultio-sparqljson</artifactId>
    5.15 +				<version>${sesame.version}</version>
    5.16 +			</dependency>
    5.17  		<!-- sesame queryresultio dependencies -->
    5.18  
    5.19  			<dependency>
     6.1 --- a/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java	Sat Apr 06 18:05:36 2013 +0300
     6.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java	Mon Apr 08 15:41:13 2013 +0300
     6.3 @@ -98,16 +98,16 @@
     6.4  	}
     6.5  	
     6.6  	/**
     6.7 -	 * Gets the stSPARQLQueryResultFormat given its name.
     6.8 +	 * Gets the TupleQueryResultFormat given its name. It may be an
     6.9 +	 * stSPARQLQueryResultFormat.
    6.10  	 * 
    6.11  	 * @param formatName
    6.12  	 * @return
    6.13  	 */
    6.14 -	public static stSPARQLQueryResultFormat valueOf(String formatName) {
    6.15 +	public static TupleQueryResultFormat valueOf(String formatName) {
    6.16  		for (TupleQueryResultFormat format : values()) {
    6.17 -			if (format instanceof stSPARQLQueryResultFormat && 
    6.18 -					format.getName().equalsIgnoreCase(formatName)) {
    6.19 -				return (stSPARQLQueryResultFormat) format;
    6.20 +			if (format.getName().equalsIgnoreCase(formatName)) {
    6.21 +				return format;
    6.22  			}
    6.23  		}
    6.24  		
     7.1 --- a/runtime/pom.xml	Sat Apr 06 18:05:36 2013 +0300
     7.2 +++ b/runtime/pom.xml	Mon Apr 08 15:41:13 2013 +0300
     7.3 @@ -44,6 +44,14 @@
     7.4  			<groupId>org.openrdf.sesame</groupId>
     7.5  			<artifactId>sesame-queryresultio-spatial-text</artifactId>
     7.6  		</dependency>
     7.7 +		<dependency>
     7.8 +			<groupId>org.openrdf.sesame</groupId>
     7.9 +			<artifactId>sesame-queryresultio-sparqljson</artifactId>
    7.10 +		</dependency>
    7.11 +		<dependency>
    7.12 +			<groupId>org.openrdf.sesame</groupId>
    7.13 +			<artifactId>sesame-queryresultio-binary</artifactId>
    7.14 +		</dependency>
    7.15  
    7.16  
    7.17  		<dependency>
     8.1 --- a/runtime/src/main/java/eu/earthobservatory/utils/Format.java	Sat Apr 06 18:05:36 2013 +0300
     8.2 +++ b/runtime/src/main/java/eu/earthobservatory/utils/Format.java	Mon Apr 08 15:41:13 2013 +0300
     8.3 @@ -62,6 +62,31 @@
     8.4  	TSV("TSV"),
     8.5  	
     8.6  	/**
     8.7 +	 * Sesame's JSON format 
     8.8 +	 */
     8.9 +	SESAME_JSON("SPARQL/JSON"), 
    8.10 +	
    8.11 +	/**
    8.12 +	 * Sesame's XML format
    8.13 +	 */
    8.14 +	SESAME_XML("SPARQL/XML"),
    8.15 +	
    8.16 +	/**
    8.17 +	 * Sesame's Binary format
    8.18 +	 */
    8.19 +	SESAME_BINARY("BINARY"),
    8.20 +	
    8.21 +	/**
    8.22 +	 * Sesame's CSV format
    8.23 +	 */
    8.24 +	SESAME_CSV("SPARQL/CSV"),
    8.25 +	
    8.26 +	/**
    8.27 +	 * Sesame's TSV format
    8.28 +	 */
    8.29 +	SESAME_TSV("SPARQL/TSV"),
    8.30 +	
    8.31 +	/**
    8.32  	 * Invalid format.
    8.33  	 */
    8.34  	INVALID("INVALID");
     9.1 --- a/runtime/src/main/java/eu/earthobservatory/utils/stSPARQLQueryResultToFormatAdapter.java	Sat Apr 06 18:05:36 2013 +0300
     9.2 +++ b/runtime/src/main/java/eu/earthobservatory/utils/stSPARQLQueryResultToFormatAdapter.java	Mon Apr 08 15:41:13 2013 +0300
     9.3 @@ -11,6 +11,8 @@
     9.4  
     9.5  import java.io.OutputStream;
     9.6  
     9.7 +import org.openrdf.query.resultio.QueryResultIO;
     9.8 +import org.openrdf.query.resultio.TupleQueryResultFormat;
     9.9  import org.openrdf.query.resultio.TupleQueryResultWriter;
    9.10  import org.openrdf.query.resultio.TupleQueryResultWriterFactory;
    9.11  import org.openrdf.query.resultio.sparqlgeojson.stSPARQLResultsGeoJSONWriterFactory;
    9.12 @@ -70,6 +72,30 @@
    9.13  			
    9.14  			case TSV:
    9.15  				writer = tsv.getWriter(out);
    9.16 +				break;
    9.17 +
    9.18 +			case SESAME_XML:
    9.19 +				writer = QueryResultIO.createWriter(TupleQueryResultFormat.SPARQL, out);
    9.20 +				break;
    9.21 +			
    9.22 +			case SESAME_BINARY:
    9.23 +				writer = QueryResultIO.createWriter(TupleQueryResultFormat.BINARY, out);
    9.24 +				break;
    9.25 +				
    9.26 +			case SESAME_JSON:
    9.27 +				writer = QueryResultIO.createWriter(TupleQueryResultFormat.JSON, out);
    9.28 +				break;
    9.29 +			
    9.30 +			case SESAME_CSV:
    9.31 +				writer = QueryResultIO.createWriter(TupleQueryResultFormat.CSV, out);
    9.32 +				break;
    9.33 +				
    9.34 +			case SESAME_TSV:
    9.35 +				writer = QueryResultIO.createWriter(TupleQueryResultFormat.TSV, out);
    9.36 +				break;
    9.37 +				
    9.38 +			default:
    9.39 +				// return NULL
    9.40  		}
    9.41  		
    9.42  		return writer;