marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ans...@apache.org
Subject [4/4] git commit: MARMOTTA-325 : Autogenerate the list of available response types
Date Fri, 27 Sep 2013 03:04:33 GMT
MARMOTTA-325 : Autogenerate the list of available response types

Uses the registries to generate the list of response types, which
previously included application/rdf+xml for tuple and boolean results
and will not include them after this update.

Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/8b698154
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/8b698154
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/8b698154

Branch: refs/heads/develop
Commit: 8b69815459a3b7c4db067ba0fcd2929b47c22d2d
Parents: 7c956c9
Author: Peter Ansell <p_ansell@yahoo.com>
Authored: Fri Sep 27 12:59:40 2013 +1000
Committer: Peter Ansell <p_ansell@yahoo.com>
Committed: Fri Sep 27 12:59:40 2013 +1000

----------------------------------------------------------------------
 .../sparql/webservices/SparqlWebService.java    | 23 ++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/8b698154/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
index 887158d..570ba2a 100644
--- a/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
+++ b/platform/marmotta-sparql/src/main/java/org/apache/marmotta/platform/sparql/webservices/SparqlWebService.java
@@ -23,8 +23,10 @@ import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URLDecoder;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -65,10 +67,14 @@ import org.openrdf.query.QueryLanguage;
 import org.openrdf.query.UpdateExecutionException;
 import org.openrdf.query.resultio.BooleanQueryResultFormat;
 import org.openrdf.query.resultio.BooleanQueryResultWriter;
+import org.openrdf.query.resultio.BooleanQueryResultWriterRegistry;
+import org.openrdf.query.resultio.QueryResultFormat;
 import org.openrdf.query.resultio.QueryResultIO;
 import org.openrdf.query.resultio.QueryResultWriter;
 import org.openrdf.query.resultio.TupleQueryResultFormat;
 import org.openrdf.query.resultio.TupleQueryResultWriter;
+import org.openrdf.query.resultio.TupleQueryResultWriterRegistry;
+import org.openrdf.rio.RDFParserRegistry;
 import org.slf4j.Logger;
 
 import com.google.common.collect.Lists;
@@ -236,9 +242,9 @@ public class SparqlWebService {
 	        		acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(acceptHeader);
 	        	}
 	        	if (QueryType.TUPLE.equals(queryType)) {
-	        		offeredTypes  = MarmottaHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json",
"text/html", "application/rdf+xml", "text/csv"));
+	        		offeredTypes  = MarmottaHttpUtils.parseStringList(getTypes(TupleQueryResultWriterRegistry.getInstance().getKeys()));
 	        	} else if (QueryType.BOOL.equals(queryType)) {
-	        		offeredTypes  = MarmottaHttpUtils.parseStringList(Lists.newArrayList("application/sparql-results+xml","application/sparql-results+json",
"text/html", "application/rdf+xml", "text/csv"));
+	        		offeredTypes  = MarmottaHttpUtils.parseStringList(getTypes(BooleanQueryResultWriterRegistry.getInstance().getKeys()));
 	        	} else if (QueryType.GRAPH.equals(queryType)) {
 	        		Set<String> producedTypes = new HashSet<String>(exportService.getProducedTypes());
 	        		producedTypes.remove("application/xml");
@@ -523,6 +529,19 @@ public class SparqlWebService {
         return r;
     }
 
+    /**
+     * Build a set of mime types based on the given formats
+     * @param types
+     * @return
+     */
+    private Set<String> getTypes(Collection<? extends QueryResultFormat> types)
{
+        Set<String> results = new LinkedHashSet<String>();
+        for(QueryResultFormat type : types) {
+            results.addAll(type.getMIMETypes());
+        }
+        return results;
+    }
+    
     private static Pattern subTypePattern = Pattern.compile("[a-z]+/([a-z0-9-._]+\\+)?([a-z0-9-._]+)(;.*)?");
     private String parseSubType(String mimeType) {
         Matcher matcher = subTypePattern.matcher(mimeType);


Mime
View raw message