You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2012/02/15 20:18:23 UTC
svn commit: r1244657 -
/incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java
Author: andy
Date: Wed Feb 15 19:18:22 2012
New Revision: 1244657
URL: http://svn.apache.org/viewvc?rev=1244657&view=rev
Log:
Outline of a quads-dump servlet. Work-in-progress.
Added:
incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java
Added: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java?rev=1244657&view=auto
==============================================================================
--- incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java (added)
+++ incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads.java Wed Feb 15 19:18:22 2012
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.fuseki.servlets;
+
+import static java.lang.String.format ;
+
+import java.io.IOException ;
+
+import javax.servlet.ServletOutputStream ;
+
+import org.apache.jena.fuseki.FusekiLib ;
+import org.apache.jena.fuseki.HttpNames ;
+import org.openjena.atlas.web.MediaType ;
+import org.openjena.atlas.web.TypedOutputStream ;
+import org.openjena.riot.Lang ;
+import org.openjena.riot.RiotWriter ;
+
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+
+/**
+ * Servlet that serves up quads for a dataset.
+ * Combine with something for RDF GET on graphs?
+ */
+
+public class REST_Quads extends SPARQL_REST
+{
+ // This is nearly SPARQL_REST_R
+
+ @Override
+ protected void doGet(HttpActionREST action)
+ {
+ if ( action.hasTarget() )
+ errorBadRequest("Attempt to use GET for quads and name a graph") ;
+
+ MediaType mediaType = contentNegotationQuads(action) ;
+ ServletOutputStream output ;
+ try { output = action.response.getOutputStream() ; }
+ catch (IOException ex) { errorOccurred(ex) ; output = null ; }
+
+ TypedOutputStream out = new TypedOutputStream(output, mediaType) ;
+ Lang lang = FusekiLib.langFromContentType(mediaType.getContentType()) ;
+
+
+ if ( action.verbose )
+ log.info(format("[%d] Get: Content-Type=%s, Charset=%s => %s",
+ action.id, mediaType.getContentType(), mediaType.getCharset(), lang.getName())) ;
+ if ( ! lang.isQuads() )
+ errorBadRequest("Not a quads format: "+mediaType) ;
+
+ action.beginRead() ;
+ try {
+ DatasetGraph dsg = action.getActiveDSG() ;
+
+ if ( lang == Lang.NQUADS )
+ RiotWriter.writeNQuads(out, dsg) ;
+ else if ( lang == Lang.TRIG )
+ errorBadRequest("TriG - Not implemented (yet) : "+mediaType) ;
+ else
+ errorBadRequest("No handled: "+mediaType) ;
+ success(action) ;
+ } finally { action.endRead() ; }
+ }
+
+ @Override
+ protected void doOptions(HttpActionREST action)
+ {
+ action.response.setHeader(HttpNames.hAllow, "GET, HEAD, OPTIONS") ;
+ action.response.setHeader(HttpNames.hContentLengh, "0") ;
+ success(action) ;
+ }
+
+ @Override
+ protected void doHead(HttpActionREST action)
+ {
+ if ( action.hasTarget() )
+ errorBadRequest("Attempt to use GET for quads and name a graph") ;
+
+ action.beginRead() ;
+ try {
+ MediaType mediaType = contentNegotationQuads(action) ;
+ success(action) ;
+ } finally { action.endRead() ; }
+ }
+
+ @Override
+ protected void doPost(HttpActionREST action)
+ { errorMethodNotAllowed("POST") ; }
+
+ @Override
+ protected void doDelete(HttpActionREST action)
+ { errorMethodNotAllowed("DELETE") ; }
+
+ @Override
+ protected void doPut(HttpActionREST action)
+ { errorMethodNotAllowed("PUT") ; }
+
+ @Override
+ protected void doPatch(HttpActionREST action)
+ { errorMethodNotAllowed("PATCH") ; }
+}
+