Author: ltheussl
Date: Wed Sep 19 08:03:15 2007
New Revision: 577325

URL: http://svn.apache.org/viewvc?rev=577325&view=rev
Log:
Write page header and footer text. Clean up some code.

Modified:
    
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
    
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
    
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoUtils.java
    
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/NumberedListItem.java

Modified: 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java?rev=577325&r1=577324&r2=577325&view=diff
==============================================================================
--- 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
 (original)
+++ 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoAggregateSink.java
 Wed Sep 19 08:03:15 2007
@@ -112,13 +112,14 @@
 
         resetSectionCounter();
 
-        startPageSequence();
+        startPageSequence( getHeaderText(), getFooterText() );
 
         if ( docName == null )
         {
             // TODO: log.warn( "No document root specified, local links will 
not be resolved correctly!" )
         }
-        else {
+        else
+        {
             writeStartTag( "block", "id", docName );
         }
 
@@ -139,7 +140,7 @@
     /**
      * Sets the title of the current document. This is used as a chapter title 
in the page header.
      *
-     * @param name the title of the current document.
+     * @param title the title of the current document.
      */
     public void setDocumentTitle( String title )
     {
@@ -162,6 +163,7 @@
     {
         this.docName = getIdName( name );
     }
+
     /**
      * Translates the given name to a usable id.
      * Prepends "./" and strips any extension.
@@ -179,7 +181,7 @@
             idName = "./" + idName;
         }
 
-        if ( idName.indexOf( ".", 2 ) != -1)
+        if ( idName.indexOf( ".", 2 ) != -1 )
         {
             idName = idName.substring( 0, idName.indexOf( ".", 2 ) );
         }
@@ -235,7 +237,7 @@
 
             int dot = anchor.indexOf( ".", 2 );
 
-            if ( dot != -1)
+            if ( dot != -1 )
             {
                 int hash = anchor.indexOf( "#", dot );
 
@@ -243,7 +245,7 @@
                 {
                     int dot2 = anchor.indexOf( ".", hash );
 
-                    if ( dot2 != -1)
+                    if ( dot2 != -1 )
                     {
                         anchor = anchor.substring( 0, dot ) + "#"
                             + HtmlTools.encodeId( anchor.substring( hash + 1, 
dot2 ) );
@@ -425,24 +427,60 @@
         }
     }
 
-    /** Starts a page sequence. */
-    protected void startPageSequence()
+    /**
+     * Starts a page sequence, depending on the current chapter.
+     *
+     * @param headerText The text to write in the header, if null, nothing is 
written.
+     * @param footerText The text to write in the footer, if null, nothing is 
written.
+     */
+    protected void startPageSequence( String headerText, String footerText )
     {
         if ( chapter == 1 )
         {
-            super.startPageSequence( "0" );
+            startPageSequence( "0", headerText, footerText );
         }
         else
         {
-            super.startPageSequence( "auto" );
+            startPageSequence( "auto", headerText, footerText );
         }
     }
 
+    /**
+     * Returns the text to write in the header of each page.
+     *
+     * @return String
+     */
+    protected String getHeaderText()
+    {
+        return Integer.toString( chapter ) + "   " + docTitle;
+    }
+
+    /**
+     * Returns the text to write in the footer of each page.
+     *
+     * @return String
+     */
+    protected String getFooterText()
+    {
+        // TODO: year and company have to come from DocumentMeta
+        return "©2007 The Apache Software Foundation • ALL RIGHTS 
RESERVED";
+    }
+
+    /**
+     * Returns the current chapter number as a string.
+     *
+     * @return String
+     */
     protected String getChapterString()
     {
         return Integer.toString( chapter ) + ".";
     }
 
+    /**
+     * Writes a 'xsl-region-before' block.
+     *
+     * @param headerText The text to write in the header, if null, nothing is 
written.
+     */
     protected void regionBefore( String headerText )
     {
         writeStartTag( "static-content", "flow-name", "xsl-region-before" );
@@ -453,7 +491,12 @@
         writeStartTag( "table-row", null );
         writeStartTag( "table-cell", null );
         writeStartTag( "block", "header.style" );
-        write( headerText );
+
+        if ( headerText != null )
+        {
+            write( headerText );
+        }
+
         writeEndTag( "block" );
         writeEndTag( "table-cell" );
         writeStartTag( "table-cell", null );
@@ -467,15 +510,31 @@
         writeEndTag( "static-content" );
     }
 
+    /**
+     * Writes a 'xsl-region-after' block.
+     *
+     * @param footerText The text to write in the footer, if null, nothing is 
written.
+     */
     protected void regionAfter( String footerText )
     {
         writeStartTag( "static-content", "flow-name", "xsl-region-after" );
         writeStartTag( "block", "footer.style" );
-        write( footerText );
+
+        if ( footerText != null )
+        {
+            write( footerText );
+        }
+
         writeEndTag( "block" );
         writeEndTag( "static-content" );
     }
 
+    /**
+     * Writes a chapter heading.
+     *
+     * @param headerText The text to write in the header, if null, the current 
document title is written.
+     * @param chapterNumber True if the chapter number should be written in 
front of the text.
+     */
     protected void chapterHeading( String headerText, boolean chapterNumber )
     {
         writeStartTag( "block", null );
@@ -513,12 +572,16 @@
         writeEndTag( "block" );
     }
 
+    /**
+     * Writes a table of contents.
+     *
+     * @param toc The DocumentTOC object that contains all information for the 
table of contents.
+     */
     public void toc( DocumentTOC toc )
     {
         writeln( "<fo:page-sequence master-reference=\"toc\" 
initial-page-number=\"1\" format=\"i\">" );
         regionBefore( toc.getName() );
-        // TODO
-        regionAfter( "FooterText" );
+        regionAfter( getFooterText() );
         writeStartTag( "flow", "flow-name", "xsl-region-body" );
         chapterHeading( toc.getName(), false );
         writeln( "<fo:table table-layout=\"fixed\" width=\"100%\" >" );
@@ -566,7 +629,11 @@
 
     }
 
-
+    /**
+     * Writes a cover page.
+     *
+     * @param meta The DocumentMeta object that contains all information for 
the cover page.
+     */
     public void coverPage( DocumentMeta meta )
     {
         String title = meta.getTitle();

Modified: 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java?rev=577325&r1=577324&r2=577325&view=diff
==============================================================================
--- 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
 (original)
+++ 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
 Wed Sep 19 08:03:15 2007
@@ -93,7 +93,7 @@
     public void head()
     {
         beginDocument();
-        startPageSequence( "0" );
+        startPageSequence( "0", null, null );
     }
 
     /** [EMAIL PROTECTED] */
@@ -356,11 +356,21 @@
         writeEndTag( "block" );
     }
 
+    /**
+     * Resets the section counter to 0.
+     * Only useful for overriding classes, like AggregateSink, the FoSink puts 
everything into one chapter.
+     */
     protected void resetSectionCounter()
     {
         this.section = 0;
     }
 
+    /**
+     * Returns the current chapter number as a string.
+     * By default does nothing, gets overridden by AggregateSink.
+     *
+     * @return an empty String.
+     */
     protected String getChapterString()
     {
         return "";
@@ -1106,27 +1116,48 @@
         return buffer.toString();
     }
 
-    /** Starts a page sequence. */
-    protected void startPageSequence( String initPageNumber )
+    /**
+     * Starts a page sequence.
+     *
+     * @param initPageNumber The initial page number. Should be either "0" 
(for the first page) or "auto".
+     * @param headerText The text to write in the header, if null, nothing is 
written.
+     * @param footerText The text to write in the footer, if null, nothing is 
written.
+     */
+    protected void startPageSequence( String initPageNumber, String 
headerText, String footerText )
     {
         writeln( "<fo:page-sequence initial-page-number=\"" + initPageNumber + 
"\" master-reference=\"body\">" );
-        // TODO
-        regionBefore( "Header text" );
-        regionAfter( "Footer text" );
+        regionBefore( headerText );
+        regionAfter( footerText );
         writeln( "<fo:flow flow-name=\"xsl-region-body\">" );
         chapterHeading( null, true );
     }
 
+    /**
+     * Writes a 'xsl-region-before' block.
+     *
+     * @param headerText The text to write in the header, if null, nothing is 
written.
+     */
     protected void regionBefore( String headerText )
     {
         // do nothing, overridden by AggregateSink
     }
 
+    /**
+     * Writes a 'xsl-region-after' block. By default does nothing, gets 
overridden by AggregateSink.
+     *
+     * @param footerText The text to write in the footer, if null, nothing is 
written.
+     */
     protected void regionAfter( String footerText )
     {
         // do nothing, overridden by AggregateSink
     }
 
+    /**
+     * Writes a chapter heading. By default does nothing, gets overridden by 
AggregateSink.
+     *
+     * @param headerText The text to write in the header, if null, the current 
document title is written.
+     * @param chapterNumber True if the chapter number should be written in 
front of the text.
+     */
     protected void chapterHeading( String headerText, boolean chapterNumber )
     {
         // do nothing, overridden by AggregateSink

Modified: 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoUtils.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoUtils.java?rev=577325&r1=577324&r2=577325&view=diff
==============================================================================
--- 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoUtils.java
 (original)
+++ 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoUtils.java
 Wed Sep 19 08:03:15 2007
@@ -25,9 +25,6 @@
 import java.io.IOException;
 import java.io.OutputStream;
 
-import java.util.Iterator;
-import java.util.List;
-
 import javax.xml.transform.Result;
 import javax.xml.transform.Source;
 import javax.xml.transform.Transformer;
@@ -51,6 +48,7 @@
 
     /**
      * Converts an FO file to a PDF file using FOP.
+     *
      * @param fo the FO file.
      * @param pdf the target PDF file.
      * @param resourceDir The base directory for relative path resolution.
@@ -117,6 +115,13 @@
         }
     }
 
+    /**
+     * Returns a base URL to be used by the FOUserAgent.
+     *
+     * @param fo the FO file.
+     * @param resourceDir the resource directory.
+     * @return String.
+     */
     private static String getBaseURL( File fo, String resourceDir )
     {
         String url = null;

Modified: 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/NumberedListItem.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/NumberedListItem.java?rev=577325&r1=577324&r2=577325&view=diff
==============================================================================
--- 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/NumberedListItem.java
 (original)
+++ 
maven/sandbox/trunk/doxia/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/NumberedListItem.java
 Wed Sep 19 08:03:15 2007
@@ -159,6 +159,7 @@
      * Determines if the given format is one of the formats defined in
      * [EMAIL PROTECTED] org.apache.maven.doxia.sink.Sink}.
      *
+     * @param itemFormat the format to check.
      * @return True if the format is a valid item format according to the Sink 
API.
      */
     private boolean isValidItemFormat( int itemFormat )


Reply via email to