jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [7/8] git commit: Cope with multiple nested start/finish calls.
Date Wed, 08 Oct 2014 17:43:57 GMT
Cope with multiple nested start/finish calls.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/0e6c4f56
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/0e6c4f56
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/0e6c4f56

Branch: refs/heads/master
Commit: 0e6c4f566f0862cfa069bb631aa17ffc731d2b35
Parents: a2d728c
Author: Andy Seaborne <andy@apache.org>
Authored: Mon Oct 6 22:30:05 2014 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Mon Oct 6 22:30:05 2014 +0100

----------------------------------------------------------------------
 .../jena/riot/writer/StreamWriterTriX.java      | 26 ++++++++++++--------
 1 file changed, 16 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/0e6c4f56/jena-arq/src/main/java/org/apache/jena/riot/writer/StreamWriterTriX.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/riot/writer/StreamWriterTriX.java b/jena-arq/src/main/java/org/apache/jena/riot/writer/StreamWriterTriX.java
index bd6f447..e39f9f9 100644
--- a/jena-arq/src/main/java/org/apache/jena/riot/writer/StreamWriterTriX.java
+++ b/jena-arq/src/main/java/org/apache/jena/riot/writer/StreamWriterTriX.java
@@ -54,24 +54,24 @@ public class StreamWriterTriX implements StreamRDF {
     private Node gn = null ;
     private boolean inGraph = false ; 
     private PrefixMap pmap = PrefixMapFactory.create() ;
+    private int depth = 0 ;     // Start/finish count 
 
     public StreamWriterTriX(OutputStream out)   { this.out = new IndentedWriter(out) ; }
     public StreamWriterTriX(IndentedWriter out) { this.out = out ; }
 
     @Override public void start() {
-        // Delay until NS known?
-        StreamWriterTriX.startXML(out) ;
-        StreamWriterTriX.startTag(out, TriX.tagTriX, "xmlns", TriX.NS) ;
-        out.println() ;
-    }
-    
-    @Override public void base(String base) {} // Ignore.
-    
-    @Override public void prefix(String prefix, String iri) {
-        pmap.add(prefix, iri) ;
+        if ( depth == 0 ) {
+            StreamWriterTriX.startXML(out) ;
+            StreamWriterTriX.startTag(out, TriX.tagTriX, "xmlns", TriX.NS) ;
+            out.println() ;
+        }
+        depth ++ ;
     }
     
     @Override public void finish() {
+        depth-- ;
+        if ( depth != 0 )
+            return ;
         if ( inGraph ) {
             StreamWriterTriX.endTag(out, TriX.tagGraph) ;
             out.println() ;
@@ -81,6 +81,12 @@ public class StreamWriterTriX implements StreamRDF {
         out.flush() ;
     }
     
+    @Override public void base(String base) {} // Ignore.
+    
+    @Override public void prefix(String prefix, String iri) {
+        pmap.add(prefix, iri) ;
+    }
+    
     @Override
     public void triple(Triple triple) {
         if ( inGraph && gn != null ) {


Mime
View raw message