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 2013/02/08 19:40:55 UTC

svn commit: r1444182 - in /jena/Experimental/riot-output/src/main/java: dev/ riot/ riot/writer/

Author: andy
Date: Fri Feb  8 18:40:55 2013
New Revision: 1444182

URL: http://svn.apache.org/r1444182
Log:
Incorporate NT and NQ writers

Added:
    jena/Experimental/riot-output/src/main/java/riot/writer/NQuadsWriter.java
    jena/Experimental/riot-output/src/main/java/riot/writer/NTriplesWriter.java
    jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFTuples.java
Modified:
    jena/Experimental/riot-output/src/main/java/dev/PROJECT_RiotWriter.java
    jena/Experimental/riot-output/src/main/java/riot/RDFWriterRegistry.java
    jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLWriter.java
    jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java
    jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamBase.java

Modified: jena/Experimental/riot-output/src/main/java/dev/PROJECT_RiotWriter.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/dev/PROJECT_RiotWriter.java?rev=1444182&r1=1444181&r2=1444182&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/dev/PROJECT_RiotWriter.java (original)
+++ jena/Experimental/riot-output/src/main/java/dev/PROJECT_RiotWriter.java Fri Feb  8 18:40:55 2013
@@ -18,23 +18,13 @@
 
 package dev;
 
-import org.apache.jena.riot.system.Prologue ;
 
 public class PROJECT_RiotWriter
 {
-    
-    Prologue p ;
     // Prologue
     // JSON-LD
-    // check prefixes from model.
     // Remove prefixes options on statics
     
-    // TurtleWriter - use WriterContext
-    
-    // Base class for WriterContext and then Trutle, trig 
-    // write prefixes, write graph 
-    // TurtleWriter
-    
     // RDF/XML adapter. [done]
     // baseURI.
     

Modified: jena/Experimental/riot-output/src/main/java/riot/RDFWriterRegistry.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/RDFWriterRegistry.java?rev=1444182&r1=1444181&r2=1444182&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/RDFWriterRegistry.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/RDFWriterRegistry.java Fri Feb  8 18:40:55 2013
@@ -19,6 +19,8 @@
 package riot;
 
 import static org.apache.jena.riot.RDFLanguages.* ;
+import static org.apache.jena.riot.RDFLanguages.TRIG ;
+import static org.apache.jena.riot.RDFLanguages.TURTLE ;
 
 import java.io.OutputStream ;
 import java.util.HashMap ;
@@ -28,10 +30,7 @@ import org.apache.jena.atlas.lib.Lib ;
 import org.apache.jena.riot.Lang ;
 import org.apache.jena.riot.RDFLanguages ;
 import org.apache.jena.riot.RiotException ;
-import riot.writer.TurtleWriter ;
-import riot.writer.TurtleWriterBlocks ;
-import riot.writer.TriGWriter ; 
-import riot.writer.TriGWriterBlocks ;
+import riot.writer.* ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
@@ -87,16 +86,16 @@ public class RDFWriterRegistry
             if ( Lib.equal(RDFJSON, serialization) )
                 return createRDFJSON(out, graph) ;
             if ( Lib.equal(RDFXMLPretty, serialization) )
-                return createRDFXML(out, graph) ;
+                return createRDFXMLAbbrev(out, graph) ;
             if ( Lib.equal(RDFXMLPlain, serialization) )
-                return null ;
+                return createRDFXMLPlain(out, graph) ;
             // graphs in quad format.
             if ( Lib.equal(TrigPretty, serialization) )
                 return createTrig(out, graph) ;
             if ( Lib.equal(TrigBlocks, serialization) )
                 return createTrigStreaming(out, graph) ;
             if ( Lib.equal(TrigFlat, serialization) )
-                return null ;
+                return createTrigFlat(out,graph) ;
             if ( Lib.equal(NQuads, serialization) )
                 return createNQuads(out, graph) ;
             return null ;
@@ -167,38 +166,41 @@ public class RDFWriterRegistry
     // builtins.
     
     private static RiotSerializer createTurtle(final OutputStream out, final Graph graph)
-    {
-        // TODO Temporary
-        return new RiotSerializer() {
-            @Override public void write() { TurtleWriter.write(out, graph) ; }
-            @Override public Lang getLang() { return TURTLE ; }
-        } ;
-    }
+    { return new RiotSerializer() {
+        @Override public void write() { TurtleWriter.write(out, graph) ; }
+        @Override public Lang getLang() { return TURTLE ; }
+    } ; }
 
     private static RiotSerializer createTurtleStreaming(final OutputStream out, final Graph graph)
-    {
-        // TODO Temporary
-        return new RiotSerializer() {
-            @Override public void write() { TurtleWriterBlocks.write(out, graph) ; }
-            @Override public Lang getLang() { return TURTLE ; }
-        } ;
-    }
+    { return new RiotSerializer() {
+        @Override public void write() { TurtleWriterBlocks.write(out, graph) ; }
+        @Override public Lang getLang() { return TURTLE ; }
+    } ; }
 
-    private static RiotSerializer createNTriples(OutputStream out, Graph graph)
-    { return null ; }
+    private static RiotSerializer createNTriples(final OutputStream out, final Graph graph)
+    { return new RiotSerializer() {
+        @Override public void write() { NTriplesWriter.write(out, graph) ; }
+        @Override public Lang getLang() { return NTRIPLES ; }
+    } ; }
+
+    private static RiotSerializer createRDFXMLAbbrev(final OutputStream out, final Graph graph)
+    { return new RiotSerializer() {
+        @Override public void write() { RDFXMLWriter.writeAbbrev(out, graph) ; }
+        @Override public Lang getLang() { return Lang.RDFXML ; }
+    } ; }
+
+    private static RiotSerializer createRDFXMLPlain(final OutputStream out, final Graph graph)
+    { return new RiotSerializer() {
+        @Override public void write() { RDFXMLWriter.writePlain(out, graph) ; }
+        @Override public Lang getLang() { return Lang.RDFXML ; }
+    } ; }
 
-    private static RiotSerializer createRDFXML(OutputStream out, Graph graph)
-    {
-        return null ;
-    }
 
     private static RiotSerializer createRDFJSON(OutputStream out, Graph graph)
     { return null ; }
 
     private static RiotSerializer createN3(OutputStream out, Graph graph)
-    {
-        return createTurtle(out, graph) ;
-    }
+    { return createTurtle(out, graph) ; }
 
     private static RiotSerializer createTrig(final OutputStream out, final Graph graph)
     { return new RiotSerializer() {
@@ -224,8 +226,29 @@ public class RDFWriterRegistry
         @Override public Lang getLang() { return TRIG ; }
     } ; }
 
-    private static RiotSerializer createNQuads(OutputStream out, Graph graph)
-    { return null ; }
+    private static RiotSerializer createTrigFlat(final OutputStream out, final DatasetGraph dsg)
+    { return new RiotSerializer() {
+        @Override public void write() { TriGWriterFlat.write(out, dsg) ; }
+        @Override public Lang getLang() { return TRIG ; }
+    } ; }
 
+    private static RiotSerializer createTrigFlat(final OutputStream out, final Graph graph)
+    { return new RiotSerializer() {
+        @Override public void write() { TriGWriterFlat.write(out, graph) ; }
+        @Override public Lang getLang() { return TRIG ; }
+    } ; }
+
+
+    private static RiotSerializer createNQuads(final OutputStream out, final Graph graph)
+    { return new RiotSerializer() {
+        @Override public void write() { NTriplesWriter.write(out, graph) ; }
+        @Override public Lang getLang() { return NQUADS ; }
+    } ; }
+
+    private static RiotSerializer createNQuads(final OutputStream out, final DatasetGraph dsg)
+    { return new RiotSerializer() {
+        @Override public void write() { NQuadsWriter.write(out, dsg) ; }
+        @Override public Lang getLang() { return NQUADS ; }
+    } ; }
 }
 

Added: jena/Experimental/riot-output/src/main/java/riot/writer/NQuadsWriter.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/NQuadsWriter.java?rev=1444182&view=auto
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/NQuadsWriter.java (added)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/NQuadsWriter.java Fri Feb  8 18:40:55 2013
@@ -0,0 +1,49 @@
+/*
+ * 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 riot.writer;
+
+import java.io.OutputStream ;
+import java.util.Iterator ;
+
+import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.riot.system.StreamRDFLib ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.query.Dataset ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+
+public class NQuadsWriter
+{
+    public static void write(OutputStream out, DatasetGraph dsg)
+    {
+        write(out, dsg.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY)) ;
+    }
+    
+    public static void write(OutputStream out, Dataset dsg)
+    {
+        write(out, dsg.asDatasetGraph()) ;
+    }
+    
+    public static void write(OutputStream out, Iterator<Quad> iter)
+    {
+        StreamRDF s = new WriterStreamRDFTuples(out) ;
+        StreamRDFLib.quadsToStream(s, iter) ;
+    }
+}

Added: jena/Experimental/riot-output/src/main/java/riot/writer/NTriplesWriter.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/NTriplesWriter.java?rev=1444182&view=auto
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/NTriplesWriter.java (added)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/NTriplesWriter.java Fri Feb  8 18:40:55 2013
@@ -0,0 +1,49 @@
+/*
+ * 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 riot.writer;
+
+import java.io.OutputStream ;
+import java.util.Iterator ;
+
+import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.riot.system.StreamRDFLib ;
+
+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.rdf.model.Model ;
+
+public class NTriplesWriter
+{
+    public static void write(OutputStream out, Model model)
+    {
+        write(out, model.getGraph()) ;
+    }
+
+    public static void write(OutputStream out, Graph graph)
+    {
+        write(out, graph.find(Node.ANY, Node.ANY, Node.ANY)) ;
+    }
+    
+    public static void write(OutputStream out, Iterator<Triple> iter)
+    {
+        StreamRDF s = new WriterStreamRDFTuples(out) ;
+        StreamRDFLib.triplesToStream(s, iter) ;
+    }
+}

Modified: jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLWriter.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLWriter.java?rev=1444182&r1=1444181&r2=1444182&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLWriter.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/RDFXMLWriter.java Fri Feb  8 18:40:55 2013
@@ -43,6 +43,16 @@ public class RDFXMLWriter
         RDFWriter w = new Abbreviated() ;
         w.write(model, out, null) ;
     }
+
+    public static void writePlain(OutputStream out, Graph graph)
+    {
+        writePlain(out, ModelFactory.createModelForGraph(graph)) ;
+    }
+    
+    public static void writeAbbrev(OutputStream out,  Graph graph)
+    {
+        writeAbbrev(out, ModelFactory.createModelForGraph(graph)) ;
+    }
     
     // RiotWriter
     public static void write(OutputStream out, RDFWriter writer, Graph graph)

Modified: jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java?rev=1444182&r1=1444181&r2=1444182&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/TriGWriterFlat.java Fri Feb  8 18:40:55 2013
@@ -25,8 +25,10 @@ import org.apache.jena.riot.system.Prefi
 import org.apache.jena.riot.system.PrefixMapFactory ;
 import org.apache.jena.riot.system.StreamRDF ;
 
+import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.query.Dataset ;
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.sparql.core.DatasetGraphFactory ;
 
 /** TriG writer that writes quads one per line
  *  in TriG form with prefixes and short form literals (e.g. integers) 
@@ -51,6 +53,12 @@ public class TriGWriterFlat
         write(out, datasetGraph, pmap, null) ;
     }
     
+    public static void write(OutputStream out, Graph graph)
+    {
+        DatasetGraph dsg = DatasetGraphFactory.createOneGraph(graph) ;
+        write(out, dsg) ;
+    }
+    
     public static void write(IndentedWriter out, DatasetGraph datasetGraph, PrefixMap prefixes, String baseURI) 
     {
         StreamRDF dest = new WriterStreamRDFFlat(out) ;

Modified: jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamBase.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamBase.java?rev=1444182&r1=1444181&r2=1444182&view=diff
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamBase.java (original)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamBase.java Fri Feb  8 18:40:55 2013
@@ -23,6 +23,7 @@ import java.util.Map.Entry ;
 
 import org.apache.jena.riot.system.PrefixMap ;
 import org.apache.jena.riot.system.StreamRDF ;
+import org.apache.jena.riot.system.StreamRDFLib ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Triple ;
@@ -43,31 +44,13 @@ public abstract class WriterStreamBase
             dest.prefix(e.getKey(), e.getValue()) ;
     }
 
-    protected static void writeTriples(StreamRDF dest, Iterator<Triple> iter)
-    {
-        for ( ; iter.hasNext() ; )
-        {
-            Triple t = iter.next() ;
-            dest.triple(t) ;
-        }
-    }
-
-    protected static void writeQuads(StreamRDF dest, Iterator<Quad> iter)
-    {
-        for ( ; iter.hasNext() ; )
-        {
-            Quad q = iter.next() ;
-            dest.quad(q) ;
-        }
-    }
-
     protected static void write(StreamRDF dest, DatasetGraph datasetGraph, PrefixMap prefixes, String baseURI) 
     {
         start(dest) ;
         dest.base(baseURI) ;
         writePrefixes(dest, prefixes) ;
         Iterator<Quad> iter = datasetGraph.find(null, null, null, null) ;
-        writeQuads(dest, iter) ;
+        StreamRDFLib.quadsToStream(dest, iter) ;
         finish(dest) ;
     }
 
@@ -77,7 +60,7 @@ public abstract class WriterStreamBase
         dest.base(baseURI) ;
         writePrefixes(dest, prefixes) ;
         Iterator<Triple> iter = graph.find(null, null, null) ;
-        writeTriples(dest, iter) ;
+        StreamRDFLib.triplesToStream(dest, iter) ;
         finish(dest) ;
     }
     

Added: jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFTuples.java
URL: http://svn.apache.org/viewvc/jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFTuples.java?rev=1444182&view=auto
==============================================================================
--- jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFTuples.java (added)
+++ jena/Experimental/riot-output/src/main/java/riot/writer/WriterStreamRDFTuples.java Fri Feb  8 18:40:55 2013
@@ -0,0 +1,208 @@
+/**
+ * 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 riot.writer;
+
+import java.io.* ;
+
+import org.apache.jena.atlas.io.IO ;
+import org.apache.jena.atlas.lib.Tuple ;
+import org.apache.jena.riot.RiotException ;
+import org.apache.jena.riot.out.EscapeStr ;
+import org.apache.jena.riot.out.NodeFmtLib ;
+import org.apache.jena.riot.system.StreamRDF ;
+
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.sparql.ARQInternalErrorException ;
+import com.hp.hpl.jena.sparql.core.Quad ;
+
+/** An output of triples / quads that is streaming.
+ *  It writes N-triples/N-quads.
+ */
+
+public class WriterStreamRDFTuples implements StreamRDF
+{
+    private final Writer out ;
+    public WriterStreamRDFTuples(OutputStream outs)
+    { 
+        try
+        {
+            Writer w = new OutputStreamWriter(outs, "ASCII") ;
+            out = new BufferedWriter(w, 32*1024) ;
+        } catch (UnsupportedEncodingException e)    // ASCII is required
+        { throw new RiotException(e) ; }
+    }
+
+    @Override
+    public void start()
+    {}
+
+    @Override
+    public void finish()
+    { IO.flush(out) ; }
+
+    @Override
+    public void triple(Triple triple)
+    {
+        try {
+            Node s = triple.getSubject() ;
+            Node p = triple.getPredicate() ;
+            Node o = triple.getObject() ;
+    
+            format(out, s) ;
+            out.write(" ") ;
+            format(out, p) ;
+            out.write(" ") ;
+            format(out, o) ;
+            out.write(" .\n") ;
+        } catch (IOException ex) { IO.exception(ex) ; }
+    }
+
+    @Override
+    public void quad(Quad quad)
+    {
+        try {
+            Node s = quad.getSubject() ;
+            Node p = quad.getPredicate() ;
+            Node o = quad.getObject() ;
+            Node g = quad.getGraph() ;
+
+            format(out, s) ;
+            out.write(" ") ;
+            format(out, p) ;
+            out.write(" ") ;
+            format(out, o) ;
+
+            if ( outputGraphSlot(g) ) 
+            {
+                out.write(" ") ;
+                format(out, g) ;
+            }
+            out.write(" .\n") ;
+        } catch (IOException ex) { IO.exception(ex) ; }
+    }
+
+    @Override
+    public void tuple(Tuple<Node> tuple)
+    {}
+
+    @Override
+    public void base(String base)
+    {}
+
+    @Override
+    public void prefix(String prefix, String iri)
+    {}
+
+    private static boolean outputGraphSlot(Node g)
+    {
+        return ( g != null && g != Quad.tripleInQuad && ! Quad.isDefaultGraph(g) ) ;
+    }
+
+    private static final boolean asciiOnly = true ;
+    private static final EscapeStr escapeProc = new EscapeStr(asciiOnly) ; 
+
+    static void format(Writer w, Node n) throws IOException
+    {
+        if ( n.isBlank() )
+            formatBNode(w, n) ;
+        else if ( n.isURI() )
+            formatURI(w, n) ;
+        else if ( n.isLiteral() )
+            formatLiteral(w, n) ;
+        else if ( n.isVariable() )
+            formatVar(w, n) ;
+        else if ( Node.ANY.equals(n) )
+            try { w.write("ANY") ; } catch (IOException ex) { IO.exception(ex) ; }
+        else
+            throw new ARQInternalErrorException("Unknown node type: "+n) ;
+    }
+
+    static void formatURI(Writer w, Node n) throws IOException
+    { formatURI(w, n.getURI()) ; }
+
+    static void formatBNode(Writer w, Node n) throws IOException
+    { formatBNode(w, n.getBlankNodeLabel()) ; }
+
+    static void formatLiteral(Writer w, Node n) throws IOException
+    {
+        String dt = n.getLiteralDatatypeURI() ;
+        String lang = n.getLiteralLanguage() ;
+        String lex = n.getLiteralLexicalForm() ;
+
+        if ( dt == null )
+        {
+            if ( lang == null || lang.equals("") )
+                formatLitString(w, lex) ;
+            else
+                formatLitLang(w, lex,lang) ;
+        }
+        else
+            formatLitDT(w, lex, dt) ;
+    }
+
+    static void formatVar(Writer w, Node n) throws IOException         { formatVar(w, n.getName()) ; }
+
+
+    static void formatURI(Writer w, String uriStr) throws IOException
+    {
+        w.write('<') ;
+        w.write(uriStr) ;
+        w.write('>') ;
+    }
+
+    static void formatVar(Writer w, String name) throws IOException
+    {
+        w.write('?') ;
+        w.write(name) ;
+    }
+
+    static void formatBNode(Writer w, String label) throws IOException
+    {
+        w.write("_:") ;
+        String lab = NodeFmtLib.encodeBNodeLabel(label) ;
+        w.write(lab) ;
+    }
+
+    static void formatLitString(Writer w, String lex) throws IOException
+    {
+        writeEscaped(w, lex) ;
+    }
+
+    static void writeEscaped(Writer w, String lex) throws IOException
+    {
+        w.write('"') ;
+        escapeProc.writeStr(w, lex) ;
+        w.write('"') ;
+    }
+
+    static void formatLitLang(Writer w, String lex, String langTag) throws IOException
+    {
+        writeEscaped(w, lex) ;
+        w.write('@') ;
+        w.write(langTag) ;
+    }
+
+    static void formatLitDT(Writer w, String lex, String datatypeURI) throws IOException
+    {
+        writeEscaped(w, lex) ;
+        w.write("^^") ;
+        formatURI(w, datatypeURI) ;
+    }
+}