maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r810011 - in /maven/doxia: doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/ doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ doxia-sitetool...
Date Tue, 01 Sep 2009 12:59:49 GMT
Author: vsiveton
Date: Tue Sep  1 12:59:49 2009
New Revision: 810011

URL: http://svn.apache.org/viewvc?rev=810011&view=rev
Log:
DOXIASITETOOLS-33: Add an option to include or not the TOC

o using the context

Modified:
    maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/FoPdfRenderer.java
    maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ITextPdfRenderer.java
    maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/pdf/itext/TOC.xslt
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java

Modified: maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/FoPdfRenderer.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/FoPdfRenderer.java?rev=810011&r1=810010&r2=810011&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/FoPdfRenderer.java
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/fo/FoPdfRenderer.java
Tue Sep  1 12:59:49 2009
@@ -120,7 +120,11 @@
                 getLogger().debug( "Loaded pdf config file: " + fOConfigFile.getAbsolutePath()
);
             }
 
-            sink.setDocumentModel( documentModel  );
+            boolean addToc =
+                ( context != null && context.get( "includeTOC" ) != null ? ( (Boolean)
context.get( "includeTOC" ) )
+                                                                                        
                           .booleanValue()
+                                : true );
+            sink.setDocumentModel( documentModel, addToc );
 
             sink.beginDocument();
 

Modified: maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ITextPdfRenderer.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ITextPdfRenderer.java?rev=810011&r1=810010&r2=810011&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ITextPdfRenderer.java
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/java/org/apache/maven/doxia/docrenderer/pdf/itext/ITextPdfRenderer.java
Tue Sep  1 12:59:49 2009
@@ -180,10 +180,15 @@
             iTextFiles = parseTOCFiles( outputDirectory, documentModel, context );
         }
 
+        boolean addToc =
+            ( context != null && context.get( "includeTOC" ) != null ? ( (Boolean)
context.get( "includeTOC" ) )
+                                                                                        
                       .booleanValue()
+                            : true );
+
         File iTextFile = new File( outputDirectory, outputName + ".xml" );
         File iTextOutput = new File( outputDirectory, outputName + "." + getOutputExtension()
);
         Document document = generateDocument( iTextFiles );
-        transform( documentModel, document, iTextFile );
+        transform( documentModel, document, iTextFile, addToc );
         generatePdf( iTextFile, iTextOutput );
     }
 
@@ -369,14 +374,18 @@
      * @param transformer the Transformer to set the parameters.
      * @param documentModel the DocumentModel to take the parameters from, could be null.
      * @param iTextFile the iTextFile not null for the relative paths.
+     * @param addToc to include or not the TOC.
      */
-    private void addTransformerParameters( Transformer transformer, DocumentModel documentModel,
File iTextFile )
+    private void addTransformerParameters( Transformer transformer, DocumentModel documentModel,
File iTextFile, boolean addToc )
     {
         if ( documentModel == null )
         {
             return;
         }
 
+        // TOC
+        addTransformerParameter( transformer, "toc.add", Boolean.toString( addToc ) );
+
         // Meta parameters
         boolean hasNullMeta = false;
         if ( documentModel.getMeta() == null )
@@ -482,14 +491,15 @@
      * @param documentModel the DocumentModel to take the parameters from, could be null.
      * @param document the Document to transform.
      * @param iTextFile the resulting iText xml file.
+     * @param addToc to include or not the TOC.
      * @throws DocumentRendererException in case of a transformation error.
      */
-    private void transform( DocumentModel documentModel, Document document, File iTextFile
)
+    private void transform( DocumentModel documentModel, Document document, File iTextFile,
boolean addToc )
         throws DocumentRendererException
     {
         Transformer transformer = initTransformer();
 
-        addTransformerParameters( transformer, documentModel, iTextFile );
+        addTransformerParameters( transformer, documentModel, iTextFile, addToc );
 
         // need a writer for StreamResult to prevent FileNotFoundException when iTextFile
contains spaces
         Writer writer = null;

Modified: maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/pdf/itext/TOC.xslt
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/pdf/itext/TOC.xslt?rev=810011&r1=810010&r2=810011&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/pdf/itext/TOC.xslt
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-doc-renderer/src/main/resources/org/apache/maven/doxia/docrenderer/pdf/itext/TOC.xslt
Tue Sep  1 12:59:49 2009
@@ -21,6 +21,9 @@
 <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
+    <!-- TOC Parameters -->
+    <xsl:param name="toc.add" />
+
     <!-- MetaData Parameters -->
     <xsl:param name="meta.author" />
     <xsl:param name="meta.creator" />
@@ -109,16 +112,23 @@
         <!-- End Front page -->
 
         <!-- Start TOC -->
-        <newpage />
-        <paragraph align="Center">
-          <!-- TODO i18N -->
-            <chunk font="Helvetica" size="24" fontstyle="bold" blue="0"
-                green="0" red="0">Table Of Contents</chunk>
-        </paragraph>
-        <paragraph align="Left" leading="24.0">
-            <newline />
-            <xsl:apply-templates select="*" mode="toc" />
-        </paragraph>
+        <xsl:choose>
+          <xsl:when test="$toc.add = 'true'">
+            <newpage />
+            <paragraph align="Center">
+              <!-- TODO i18N -->
+                <chunk font="Helvetica" size="24" fontstyle="bold" blue="0"
+                    green="0" red="0">Table Of Contents</chunk>
+            </paragraph>
+            <paragraph align="Left" leading="24.0">
+                <newline />
+                <xsl:apply-templates select="*" mode="toc" />
+            </paragraph>
+          </xsl:when>
+          <xsl:otherwise>
+            <newpage />
+          </xsl:otherwise>
+        </xsl:choose>
         <!-- End TOC -->
 
         <xsl:apply-templates select="*" mode="body" />

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java?rev=810011&r1=810010&r2=810011&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
Tue Sep  1 12:59:49 2009
@@ -84,6 +84,9 @@
     /** Content in head is ignored in aggregated documents. */
     private boolean ignoreText;
 
+    /** Flag to include of not the toc */
+    private boolean addToc;
+
     /** Used to get the current position in the TOC. */
     private final Stack tocStack = new Stack();
 
@@ -245,19 +248,37 @@
      * required to render a document, eg settings for the cover page, table of contents,
etc.
      *
      * @param model the DocumentModel.
+     * @see #setDocumentModel(DocumentModel, boolean)
      */
     public void setDocumentModel( DocumentModel model )
     {
+        setDocumentModel( model, true );
+    }
+
+    /**
+     * Sets the DocumentModel to be used by this sink. The DocumentModel provides all the
meta-information
+     * required to render a document, eg settings for the cover page, table of contents,
etc.
+     *
+     * @param model the DocumentModel.
+     * @param addToc true to include the TOC in the sink.
+     * @since 1.1.2
+     */
+    public void setDocumentModel( DocumentModel model, boolean addToc )
+    {
         this.docModel = model;
+        this.addToc = addToc;
 
-        DocumentTOCItem tocItem = new DocumentTOCItem();
-        tocItem.setName( this.docModel.getToc().getName() );
-        tocItem.setRef( "./toc" );
-        List items = new LinkedList();
-        items.add( tocItem );
-        items.addAll( this.docModel.getToc().getItems() );
+        if ( this.addToc )
+        {
+            DocumentTOCItem tocItem = new DocumentTOCItem();
+            tocItem.setName( this.docModel.getToc().getName() );
+            tocItem.setRef( "./toc" );
+            List items = new LinkedList();
+            items.add( tocItem );
+            items.addAll( this.docModel.getToc().getItems() );
 
-        this.docModel.getToc().setItems( items );
+            this.docModel.getToc().setItems( items );
+        }
     }
 
     /**
@@ -782,6 +803,11 @@
      */
     public void toc()
     {
+        if ( !this.addToc )
+        {
+            return;
+        }
+
         if ( docModel == null || docModel.getToc() == null || docModel.getToc().getItems()
== null )
         {
             return;



Mime
View raw message