maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r1003021 - in /maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer: AbstractITextBookRenderer.java DocbookBookRenderer.java LatexBookRenderer.java XdocBookRenderer.java
Date Thu, 30 Sep 2010 11:51:11 GMT
Author: ltheussl
Date: Thu Sep 30 11:51:11 2010
New Revision: 1003021

URL: http://svn.apache.org/viewvc?rev=1003021&view=rev
Log:
[DOXIA-413] properly close sinks

Modified:
    maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java
    maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/DocbookBookRenderer.java
    maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java
    maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java

Modified: maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java?rev=1003021&r1=1003020&r2=1003021&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java
(original)
+++ maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/AbstractITextBookRenderer.java
Thu Sep 30 11:51:11 2010
@@ -25,10 +25,8 @@ import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
 import java.text.DateFormat;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.Iterator;
-import java.util.List;
 
 import org.apache.maven.doxia.Doxia;
 import org.apache.maven.doxia.book.BookDoxiaException;
@@ -36,7 +34,6 @@ import org.apache.maven.doxia.book.conte
 import org.apache.maven.doxia.book.model.BookModel;
 import org.apache.maven.doxia.book.model.Chapter;
 import org.apache.maven.doxia.book.model.Section;
-import org.apache.maven.doxia.sink.PipelineSink;
 import org.apache.maven.doxia.module.itext.ITextSinkFactory;
 import org.apache.maven.doxia.parser.ParseException;
 import org.apache.maven.doxia.parser.manager.ParserNotFoundException;
@@ -138,6 +135,7 @@ public abstract class AbstractITextBookR
         // TODO: Write out TOC
 
         System.setProperty( "itext.basedir", bookFile.getParentFile().getAbsolutePath() );
+        Sink sink = new ITextSinkFactory().createSink( writer );
 
         try
         {
@@ -145,13 +143,16 @@ public abstract class AbstractITextBookR
             {
                 Chapter chapter = (Chapter) it.next();
 
-                renderChapter( writer, chapter, context );
+                renderChapter( sink, writer, chapter, context );
             }
 
             writer.endElement(); // itext
         }
         finally
         {
+            sink.flush();
+            sink.close();
+
             IOUtil.close( fileWriter );
             System.getProperties().remove( "itext.basedir" );
         }
@@ -199,7 +200,7 @@ public abstract class AbstractITextBookR
      * @param context the BookContext.
      * @throws BookDoxiaException if the chapter cannot be written.
      */
-    private void renderChapter( PrettyPrintXMLWriter writer, Chapter chapter, BookContext
context )
+    private void renderChapter( Sink sink, PrettyPrintXMLWriter writer, Chapter chapter,
BookContext context )
         throws BookDoxiaException
     {
         writer.startElement( "chapter" );
@@ -216,7 +217,7 @@ public abstract class AbstractITextBookR
         {
             Section section = (Section) it.next();
 
-            renderSection( writer, section, context );
+            renderSection( sink, writer, section, context );
         }
         //        writer.endElement(); // sectioncontent
 
@@ -231,7 +232,7 @@ public abstract class AbstractITextBookR
      * @param context the BookContext.
      * @throws BookDoxiaException if the section cannot be written.
      */
-    private void renderSection( PrettyPrintXMLWriter writer, Section section, BookContext
context )
+    private void renderSection( Sink sink, PrettyPrintXMLWriter writer, Section section,
BookContext context )
         throws BookDoxiaException
     {
         //        writer.startElement( "section" );
@@ -251,12 +252,6 @@ public abstract class AbstractITextBookR
         //
         // ----------------------------------------------------------------------
 
-        Sink itextSink = new ITextSinkFactory().createSink( writer );
-
-        List pipeline = new ArrayList();
-        pipeline.add( itextSink );
-        Sink sink = PipelineSink.newInstance( pipeline );
-
         Reader reader = null;
         try
         {
@@ -282,6 +277,10 @@ public abstract class AbstractITextBookR
             throw new BookDoxiaException( "Error while rendering book: "
                       + bookFile.getFile().getAbsolutePath() + ".", e );
         }
+        finally
+        {
+            IOUtil.close( reader );
+        }
     }
 
     /**

Modified: maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/DocbookBookRenderer.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/DocbookBookRenderer.java?rev=1003021&r1=1003020&r2=1003021&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/DocbookBookRenderer.java
(original)
+++ maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/DocbookBookRenderer.java
Thu Sep 30 11:51:11 2010
@@ -139,7 +139,7 @@ public class DocbookBookRenderer
                     sink.chapterTitle_();
                 }
 
-                renderChapter( fileWriter, chapter, context, sink );
+                renderChapter( chapter, context, sink );
 
                 sink.chapter_();
             }
@@ -165,14 +165,14 @@ public class DocbookBookRenderer
      * @param sink a Sink.
      * @throws BookDoxiaException if the chapter cannot be written.
      */
-    private void renderChapter( Writer writer, Chapter chapter, BookContext context, Sink
sink )
+    private void renderChapter( Chapter chapter, BookContext context, Sink sink )
         throws BookDoxiaException
     {
         for ( Iterator it = chapter.getSections().iterator(); it.hasNext(); )
         {
             Section section = (Section) it.next();
 
-            renderSection( writer, section, context, sink );
+            renderSection( section, context, sink );
         }
     }
 
@@ -185,7 +185,7 @@ public class DocbookBookRenderer
      * @param sink a Sink.
      * @throws BookDoxiaException if the section cannot be written.
      */
-    private void renderSection( Writer writer, Section section, BookContext context, Sink
sink )
+    private void renderSection( Section section, BookContext context, Sink sink )
         throws BookDoxiaException
     {
         BookContext.BookFile bookFile = (BookContext.BookFile) context.getFiles().get( section.getId()
);

Modified: maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java?rev=1003021&r1=1003020&r2=1003021&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java
(original)
+++ maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/LatexBookRenderer.java
Thu Sep 30 11:51:11 2010
@@ -239,6 +239,9 @@ public class LatexBookRenderer
         }
         finally
         {
+            sink.flush();
+            sink.close();
+
             IOUtil.close( reader );
             IOUtil.close( writer );
         }

Modified: maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java?rev=1003021&r1=1003020&r2=1003021&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java
(original)
+++ maven/doxia/doxia/trunk/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java
Thu Sep 30 11:51:11 2010
@@ -24,9 +24,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Locale;
 
 import org.apache.maven.doxia.Doxia;
@@ -38,12 +36,10 @@ import org.apache.maven.doxia.book.model
 import org.apache.maven.doxia.book.services.renderer.xdoc.ChapterXdocBookSink;
 import org.apache.maven.doxia.book.services.renderer.xdoc.IndexXdocBookSink;
 import org.apache.maven.doxia.book.services.renderer.xdoc.SectionXdocBookSink;
-import org.apache.maven.doxia.sink.PipelineSink;
 import org.apache.maven.doxia.index.IndexEntry;
 import org.apache.maven.doxia.module.xdoc.XdocSink;
 import org.apache.maven.doxia.parser.ParseException;
 import org.apache.maven.doxia.parser.manager.ParserNotFoundException;
-import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.doxia.util.HtmlTools;
 import org.codehaus.plexus.i18n.I18N;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
@@ -419,16 +415,11 @@ public class XdocBookRenderer
                 throw new BookDoxiaException( "No document that matches section with id="
+ section.getId() + "." );
             }
 
-            List pipeline = new ArrayList();
-            //            pipeline.add( DebugSink.newInstance() );
-            pipeline.add( sink );
-            Sink pipelineSink = PipelineSink.newInstance( pipeline );
-
             Reader reader = null;
             try
             {
                 reader = ReaderFactory.newReader( bookFile.getFile(), context.getInputEncoding()
);
-                doxia.parse( reader, bookFile.getParserId(), pipelineSink );
+                doxia.parse( reader, bookFile.getParserId(), sink );
             }
             catch ( ParserNotFoundException e )
             {
@@ -446,6 +437,9 @@ public class XdocBookRenderer
             }
             finally
             {
+                sink.flush();
+                sink.close();
+
                 IOUtil.close( reader );
                 IOUtil.close( writer );
             }



Mime
View raw message