Strabon

changeset 1540:5d214ccaeb64

Added support for JSON, GeoJSON and KML when we using http requests.
author George Stamoulis <gstam@di.uoa.gr>
date Wed Oct 11 14:13:13 2017 +0300 (2017-10-11)
parents c18b84e14117
children f9ad4e3a214a
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Tue Sep 22 20:56:35 2015 +0300
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/QueryBean.java	Wed Oct 11 14:13:13 2017 +0300
     1.3 @@ -168,9 +168,9 @@
     1.4       */
     1.5  	private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
     1.6  		ServletOutputStream out = response.getOutputStream();
     1.7 -		
     1.8 +				
     1.9  		// get desired formats (we check only the Accept header)
    1.10 -		List<stSPARQLQueryResultFormat> formats = parseMultiValuedAcceptHeader(request.getHeader("accept"));
    1.11 +		List<TupleQueryResultFormat> formats = parseMultiValuedAcceptHeader(request.getHeader("accept"));
    1.12  		
    1.13  		// get the query and the limit
    1.14  		String query = request.getParameter("query");
    1.15 @@ -186,8 +186,8 @@
    1.16  			
    1.17  		} else {
    1.18  			// just use the first specified format
    1.19 -			stSPARQLQueryResultFormat format = formats.get(0);
    1.20 -		
    1.21 +			TupleQueryResultFormat format = formats.get(0);
    1.22 +					
    1.23  			// do not decode the SPARQL query (see bugs #65 and #49)
    1.24  			//query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    1.25  			query = request.getParameter("query");
    1.26 @@ -196,6 +196,7 @@
    1.27  	    	
    1.28  	    	try {
    1.29  				query = strabonWrapper.addLimit(query, maxLimit);
    1.30 +				System.out.println(format.getName());
    1.31  				strabonWrapper.query(query, format.getName(), out);
    1.32  				response.setStatus(HttpServletResponse.SC_OK);
    1.33  				
    1.34 @@ -236,6 +237,7 @@
    1.35  			
    1.36  			String query = request.getParameter("query");
    1.37  			String format = request.getParameter("format");
    1.38 +			System.out.println(format);
    1.39  			String handle = request.getParameter("handle");
    1.40  			String maxLimit = request.getParameter("maxLimit");
    1.41  			
    1.42 @@ -401,8 +403,8 @@
    1.43  	 * @param header
    1.44  	 * @return
    1.45  	 */
    1.46 -	private List<stSPARQLQueryResultFormat> parseMultiValuedAcceptHeader(String header) {
    1.47 -		List<stSPARQLQueryResultFormat> formats = new ArrayList<stSPARQLQueryResultFormat>();
    1.48 +	private List<TupleQueryResultFormat> parseMultiValuedAcceptHeader(String header) {
    1.49 +		List<TupleQueryResultFormat> formats = new ArrayList<TupleQueryResultFormat>();
    1.50  		
    1.51  		StringTokenizer token = new StringTokenizer(header, ", ");
    1.52  		
    1.53 @@ -417,8 +419,9 @@
    1.54  			}
    1.55  			
    1.56  			// get the stSPARQL Query Result format 
    1.57 -	        stSPARQLQueryResultFormat format = stSPARQLQueryResultFormat.forMIMEType(value);
    1.58 -	        
    1.59 +			String valueFromMime = getValueFromMime(value); 
    1.60 +			TupleQueryResultFormat format = stSPARQLQueryResultFormat.valueOf(valueFromMime);		
    1.61 +				        
    1.62  	        // keep only the valid formats (non-null)
    1.63  	        if (format != null) {
    1.64  	        	formats.add(format);
    1.65 @@ -427,5 +430,27 @@
    1.66  
    1.67          return formats;
    1.68  	}
    1.69 +	
    1.70 +	private String getValueFromMime(String value) {
    1.71 +		if (value.equalsIgnoreCase("application/sparql-results+json")) {
    1.72 +			return "SPARQL/JSON";
    1.73 +		}
    1.74 +		else if (value.equalsIgnoreCase("application/json") || value.equalsIgnoreCase("application/geojson")) {
    1.75 +			return "GeoJSON";
    1.76 +		}
    1.77 +		else if (value.equalsIgnoreCase("application/vnd.google-earth.kml+xml") || value.equalsIgnoreCase("application/kml")) {
    1.78 +			return "KML";
    1.79 +		}
    1.80 +		else if (value.equalsIgnoreCase("text/tab-separated-values")) {
    1.81 +			return "TSV";
    1.82 +		}
    1.83 +		else if (value.equalsIgnoreCase("text/html")) {
    1.84 +			return "HTML";
    1.85 +		}
    1.86 +		else {
    1.87 +			return "XML";
    1.88 +		}
    1.89 +		
    1.90 +	}
    1.91  
    1.92  }
     2.1 --- a/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java	Tue Sep 22 20:56:35 2015 +0300
     2.2 +++ b/resultio-spatial/api/src/main/java/org/openrdf/query/resultio/stSPARQLQueryResultFormat.java	Wed Oct 11 14:13:13 2017 +0300
     2.3 @@ -72,7 +72,6 @@
     2.4  	public static final stSPARQLQueryResultFormat HTML = new stSPARQLQueryResultFormat("HTML", 
     2.5  			Arrays.asList("text/html"), Charset.forName("UTF-8"), Arrays.asList("html", "htm"));
     2.6  	
     2.7 -
     2.8  	/**
     2.9  	 * CHART format (so that results can be displayed using google charts)  
    2.10  	 */