You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ca...@apache.org on 2011/10/21 14:42:00 UTC
svn commit: r1187316 - in
/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot:
SysRIOT.java out/RDFJSONWriter.java system/JenaWriterRdfJson.java
Author: castagna
Date: Fri Oct 21 12:42:00 2011
New Revision: 1187316
URL: http://svn.apache.org/viewvc?rev=1187316&view=rev
Log:
JENA-135
Added a JenaWriterRdfJson, it extends JenaWriterBase however RiotWriter.writeRDFJSON(...) method wants an OutputStream.
Searching what's the best way to go around this.
A Jena writer has methods to write on a Writer as well as an OutputStream. Writers are discouraged. Would a JenaWriterRdfJson which works with only OutputStream be acceptable?
Added:
incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterRdfJson.java (with props)
Modified:
incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/SysRIOT.java
incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/RDFJSONWriter.java
Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/SysRIOT.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/SysRIOT.java?rev=1187316&r1=1187315&r2=1187316&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/SysRIOT.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/SysRIOT.java Fri Oct 21 12:42:00 2011
@@ -18,14 +18,16 @@
package org.openjena.riot;
-import org.openjena.atlas.event.EventType ;
-import org.openjena.riot.system.JenaReaderNTriples2 ;
+import org.openjena.atlas.event.EventType ;
+import org.openjena.riot.out.RDFJSONWriter ;
+import org.openjena.riot.system.JenaReaderNTriples2 ;
import org.openjena.riot.system.JenaReaderRdfJson ;
-import org.openjena.riot.system.JenaReaderTurtle2 ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-import com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl ;
+import org.openjena.riot.system.JenaReaderTurtle2 ;
+import org.openjena.riot.system.JenaWriterRdfJson;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+import com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl ;
public class SysRIOT
{
@@ -73,10 +75,6 @@ public class SysRIOT
com.hp.hpl.jena.n3.turtle.TurtleReader
*/
- //Add in the RDF/JSON reader
- String readerRdfJson = JenaReaderRdfJson.class.getName();
- RDFReaderFImpl.setBaseReaderClassName("RDF/JSON", readerRdfJson) ;
-
// Override N-TRIPLES and Turtle with faster implementations.
String readerNT = JenaReaderNTriples2.class.getName() ;
RDFReaderFImpl.setBaseReaderClassName("N-TRIPLES", readerNT) ;
@@ -88,12 +86,16 @@ public class SysRIOT
RDFReaderFImpl.setBaseReaderClassName("Turtle", readerTTL) ;
RDFReaderFImpl.setBaseReaderClassName("TTL", readerTTL) ;
+ // Add in the RDF/JSON reader
+ String readerRdfJson = JenaReaderRdfJson.class.getName() ;
+ RDFReaderFImpl.setBaseReaderClassName("RDF/JSON", readerRdfJson) ;
+ String writerRdfJson = JenaWriterRdfJson.class.getName() ;
+ // TODO: JENA-131, the static method below is not yet available in a released version of Jena
+ // RDFWriterFImpl.setBaseWriterClassName("RDF/JSON", writerRdfJson) ;
}
public static void resetJenaReaders()
{
- //TODO: Should we unwire RDF/JSON reader here?
-
RDFReaderFImpl.setBaseReaderClassName("N-TRIPLES", jenaNTriplesReader) ;
RDFReaderFImpl.setBaseReaderClassName("N-TRIPLE", jenaNTriplesReader) ;
@@ -101,6 +103,10 @@ public class SysRIOT
RDFReaderFImpl.setBaseReaderClassName("TURTLE", jenaTurtleReader) ;
RDFReaderFImpl.setBaseReaderClassName("Turtle", jenaTurtleReader) ;
RDFReaderFImpl.setBaseReaderClassName("TTL", jenaTurtleReader) ;
+
+ RDFReaderFImpl.setBaseReaderClassName("RDF/JSON", null) ;
+ // TODO: JENA-131, the static method below is not yet available in a released version of Jena
+ // RDFWriterFImpl.setBaseWriterClassName("RDF/JSON", null) ;
}
}
Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/RDFJSONWriter.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/RDFJSONWriter.java?rev=1187316&r1=1187315&r2=1187316&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/RDFJSONWriter.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/out/RDFJSONWriter.java Fri Oct 21 12:42:00 2011
@@ -18,29 +18,32 @@
package org.openjena.riot.out;
-import java.io.OutputStream;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.openjena.atlas.lib.Pair;
-import org.openjena.atlas.lib.Sink;
-import org.openjena.riot.system.Prologue;
-import org.openjena.riot.system.SyntaxLabels;
-
-import com.hp.hpl.jena.graph.Graph;
-import com.hp.hpl.jena.graph.Node;
-import com.hp.hpl.jena.graph.Triple;
-import com.hp.hpl.jena.graph.query.QueryHandler;
-import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import java.io.OutputStream ;
+import java.util.HashMap ;
+import java.util.HashSet ;
+import java.util.Map ;
+import java.util.Set ;
+
+import org.openjena.atlas.lib.Pair ;
+import org.openjena.atlas.lib.Sink ;
+import org.openjena.riot.system.Prologue ;
+import org.openjena.riot.system.SyntaxLabels ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.graph.query.QueryHandler ;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
public class RDFJSONWriter {
public static void write (OutputStream out, Graph graph) {
Prologue prologue = Prologue.create(null, null) ; // (null, graph.getPrefixMapping()) ;
Sink<Pair<Node, Map<Node, Set<Node>>>> sink = new SinkEntityOutput(out, prologue, SyntaxLabels.createNodeToLabel()) ;
-
+ write ( sink, graph ) ;
+ }
+
+ private static void write (Sink<Pair<Node, Map<Node, Set<Node>>>> sink, Graph graph) {
QueryHandler queryHandler = graph.queryHandler() ;
ExtendedIterator<Node> subjects = queryHandler.subjectsFor(Node.ANY, Node.ANY) ;
try {
@@ -69,7 +72,7 @@ public class RDFJSONWriter {
} finally {
if ( subjects != null ) subjects.close() ;
sink.close() ;
- }
+ }
}
-
+
}
Added: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterRdfJson.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterRdfJson.java?rev=1187316&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterRdfJson.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterRdfJson.java Fri Oct 21 12:42:00 2011
@@ -0,0 +1,34 @@
+/**
+ * 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.openjena.riot.system;
+
+import java.io.Writer ;
+
+import com.hp.hpl.jena.graph.Graph ;
+
+public class JenaWriterRdfJson extends JenaWriterBase
+{
+
+ @Override
+ protected void write(Graph graph, Writer out, String base) {
+ // TODO: RiotWriter wants an OutputStream not a Writer...
+ // RiotWriter.writeRDFJSON(out, graph) ;
+ }
+
+}
Propchange: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/JenaWriterRdfJson.java
------------------------------------------------------------------------------
svn:mime-type = text/plain