Author: ltheussl
Date: Mon Sep 24 07:09:57 2007
New Revision: 578816

URL: http://svn.apache.org/viewvc?rev=578816&view=rev
Log:
Add pdf bookmarks

Modified:
    
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
    
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoMarkup.java
    
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
    
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java

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=578816&r1=578815&r2=578816&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
 Mon Sep 24 07:09:57 2007
@@ -26,6 +26,7 @@
 import javax.swing.text.html.HTML.Tag;
 
 import org.apache.maven.doxia.docrenderer.document.DocumentMeta;
+import org.apache.maven.doxia.docrenderer.document.DocumentModel;
 import org.apache.maven.doxia.docrenderer.document.DocumentTOC;
 import org.apache.maven.doxia.docrenderer.document.DocumentTOCItem;
 import org.apache.maven.doxia.util.HtmlTools;
@@ -39,6 +40,8 @@
  */
 public class FoAggregateSink extends FoSink
 {
+    /** The document model to be used by this sink. */
+    private DocumentModel docModel;
 
     /** Counts the current chapter level. */
     private int chapter = 0;
@@ -171,6 +174,17 @@
     }
 
     /**
+     * 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.
+     */
+    public void setDocumentModel( DocumentModel model )
+    {
+        this.docModel = model;
+    }
+
+    /**
      * Translates the given name to a usable id.
      * Prepends "./" and strips any extension.
      *
@@ -579,12 +593,22 @@
     }
 
     /**
-     * Writes a table of contents.
-     *
-     * @param toc The DocumentTOC object that contains all information for the 
table of contents.
+     * Writes a table of contents. The DocumentModel has to contain a 
DocumentTOC for this to work.
      */
-    public void toc( DocumentTOC toc )
+    public void toc()
     {
+        if ( this.docModel == null )
+        {
+            return;
+        }
+
+        DocumentTOC toc = docModel.getToc();
+
+        if ( toc == null )
+        {
+            return;
+        }
+
         writeln( "<fo:page-sequence master-reference=\"toc\" 
initial-page-number=\"1\" format=\"i\">" );
         regionBefore( toc.getName() );
         regionAfter( getFooterText() );
@@ -636,12 +660,61 @@
     }
 
     /**
-     * Writes a cover page.
-     *
-     * @param meta The DocumentMeta object that contains all information for 
the cover page.
+     * Writes a fo:bookmark-tree. The DocumentModel has to contain a 
DocumentTOC for this to work.
+     */
+    protected void pdfBookmarks()
+    {
+        if ( this.docModel == null )
+        {
+            return;
+        }
+
+        DocumentTOC toc = docModel.getToc();
+
+        if ( toc == null )
+        {
+            return;
+        }
+
+        writeStartTag( BOOKMARK_TREE_TAG, "" );
+
+        for ( Iterator k = toc.getItems().iterator(); k.hasNext(); )
+        {
+            DocumentTOCItem tocItem = (DocumentTOCItem) k.next();
+
+            String ref = getIdName( tocItem.getRef() );
+
+            writeStartTag( BOOKMARK_TAG, "internal-destination", ref );
+
+            writeStartTag( BOOKMARK_TITLE_TAG, "" );
+
+            write( tocItem.getName() );
+
+            writeEndTag( BOOKMARK_TITLE_TAG );
+
+            writeEndTag( BOOKMARK_TAG );
+        }
+
+        writeEndTag( BOOKMARK_TREE_TAG );
+    }
+
+    /**
+     * Writes a cover page. The DocumentModel has to contain a DocumentMeta 
for this to work.
      */
-    public void coverPage( DocumentMeta meta )
+    public void coverPage()
     {
+        if ( this.docModel == null )
+        {
+            return;
+        }
+
+        DocumentMeta meta = docModel.getMeta();
+
+        if ( meta == null )
+        {
+            return;
+        }
+
         String title = meta.getTitle();
         String author = meta.getAuthor();
 

Modified: 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoMarkup.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/FoMarkup.java?rev=578816&r1=578815&r2=578816&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoMarkup.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoMarkup.java
 Mon Sep 24 07:09:57 2007
@@ -298,4 +298,33 @@
         }
     };
 
+    /** FO tag for <code>bookmark-tree</code>. */
+    Tag BOOKMARK_TREE_TAG = new Tag()
+    {
+        /** [EMAIL PROTECTED] */
+        public String toString()
+        {
+            return "bookmark-tree";
+        }
+    };
+
+    /** FO tag for <code>bookmark</code>. */
+    Tag BOOKMARK_TAG = new Tag()
+    {
+        /** [EMAIL PROTECTED] */
+        public String toString()
+        {
+            return "bookmark";
+        }
+    };
+
+    /** FO tag for <code>bookmark-title</code>. */
+    Tag BOOKMARK_TITLE_TAG = new Tag()
+    {
+        /** [EMAIL PROTECTED] */
+        public String toString()
+        {
+            return "bookmark-title";
+        }
+    };
 }

Modified: 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.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/FoSink.java?rev=578816&r1=578815&r2=578816&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
 Mon Sep 24 07:09:57 2007
@@ -934,6 +934,8 @@
         writeEndTag( SIMPLE_PAGE_MASTER_TAG );
 
         writeEndTag( LAYOUT_MASTER_SET_TAG );
+
+        pdfBookmarks();
     }
 
     /**
@@ -1175,4 +1177,11 @@
         // do nothing, overridden by AggregateSink
     }
 
+    /**
+     * Writes a fo:bookmark-tree. By default does nothing, gets overridden by 
AggregateSink.
+     */
+    protected void pdfBookmarks()
+    {
+        // do nothing, overridden by AggregateSink
+    }
 }

Modified: 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java?rev=578816&r1=578815&r2=578816&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
 Mon Sep 24 07:09:57 2007
@@ -23,6 +23,7 @@
 import java.io.Writer;
 
 import org.apache.maven.doxia.docrenderer.document.DocumentMeta;
+import org.apache.maven.doxia.docrenderer.document.DocumentModel;
 import org.apache.maven.doxia.docrenderer.document.DocumentTOC;
 import org.apache.maven.doxia.docrenderer.document.DocumentTOCItem;
 
@@ -65,11 +66,13 @@
     {
         FoAggregateSink fosink = new FoAggregateSink( getTestWriter( 
"aggregate" ) );
 
+        fosink.setDocumentModel( getModel() );
+
         fosink.beginDocument();
 
-        fosink.coverPage( getMeta() );
+        fosink.coverPage();
 
-        fosink.toc( getToc() );
+        fosink.toc();
 
         fosink.setDocumentName( "doc1" );
         fosink.setDocumentTitle( "Document 1" );
@@ -84,6 +87,14 @@
 
         // then generate PDF
         fo2pdf( "aggregate" );
+    }
+
+    private DocumentModel getModel()
+    {
+        DocumentModel model = new DocumentModel();
+        model.setToc( getToc() );
+        model.setMeta( getMeta() );
+        return model ;
     }
 
     private DocumentMeta getMeta()


Reply via email to