maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r576042 - in /maven/sandbox/trunk/doxia/doxia-module-fo/src/main: java/org/apache/maven/doxia/module/fo/FoAggregateSink.java java/org/apache/maven/doxia/module/fo/FoSink.java resources/fo-styles.xslt
Date Sun, 16 Sep 2007 06:21:06 GMT
Author: ltheussl
Date: Sat Sep 15 23:21:05 2007
New Revision: 576042

URL: http://svn.apache.org/viewvc?rev=576042&view=rev
Log:
Add TOC

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/resources/fo-styles.xslt

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=576042&r1=576041&r2=576042&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
Sat Sep 15 23:21:05 2007
@@ -21,7 +21,11 @@
 
 import java.io.Writer;
 
+import java.util.Iterator;
+
 import org.apache.maven.doxia.docrenderer.document.DocumentMeta;
+import org.apache.maven.doxia.docrenderer.document.DocumentTOC;
+import org.apache.maven.doxia.docrenderer.document.DocumentTOCItem;
 import org.apache.maven.doxia.util.HtmlTools;
 
 /**
@@ -33,9 +37,12 @@
     /** Counts the current chapter level. */
     private int chapter = 0;
 
-    /** A name for the current document. */
+    /** Name of the source file of the current document. */
     private String docName;
 
+    /** Title of the chapter. */
+    private String docTitle = "";
+
     /** In fragment mode, some text has to be ignored (title...). */
     private boolean ignoreText;
 
@@ -104,10 +111,12 @@
     /** {@inheritDoc} */
     public void body()
     {
-        startPageSequence();
-
         chapter++;
 
+        resetSectionCounter();
+
+        startPageSequence();
+
         if ( docName == null )
         {
             // TODO: log.warn( "No document root specified, local links might not be resolved
correctly!" )
@@ -131,24 +140,47 @@
     }
 
     /**
+     * Sets the title of the current document. This is used as a chapter title.
+     *
+     * @param name the title of the current document.
+     */
+    public void setDocumentTitle( String title )
+    {
+        this.docTitle = title;
+
+        if ( title == null )
+        {
+            this.docTitle = "";
+        }
+    }
+
+
+    /**
      * Sets the name for the current document. This should allow anchors to be resolved uniquely.
      *
      * @param name the name for the current document.
      */
     public void setDocumentName( String name )
     {
-        this.docName = name;
+        this.docName = getIdName( name );
+    }
+
+    private String getIdName( String name )
+    {
+        String idName = name;
 
         // prepend "./" and strip extension
-        if ( !docName.startsWith( "./" ) )
+        if ( !idName.startsWith( "./" ) )
         {
-            this.docName = "./" + docName;
+            idName = "./" + idName;
         }
 
-        if ( docName.indexOf( ".", 2 ) != -1)
+        if ( idName.indexOf( ".", 2 ) != -1)
         {
-            this.docName = docName.substring( 0, docName.indexOf( ".", 2 ) );
+            idName = idName.substring( 0, idName.indexOf( ".", 2 ) );
         }
+
+        return idName;
     }
 
     // -----------------------------------------------------------------------
@@ -343,7 +375,7 @@
     /** Starts a page sequence. */
     protected void startPageSequence()
     {
-        if ( chapter == 0 )
+        if ( chapter == 1 )
         {
             super.startPageSequence( "0" );
         }
@@ -353,7 +385,12 @@
         }
     }
 
-    protected void regionBefore()
+    protected String getChapterString()
+    {
+        return Integer.toString( chapter ) + ".";
+    }
+
+    protected void regionBefore( String headerText )
     {
         writeStartTag( "static-content", "flow-name", "xsl-region-before" );
         writeln( "<fo:table table-layout=\"fixed\" width=\"100%\" >" );
@@ -363,8 +400,7 @@
         writeStartTag( "table-row", null );
         writeStartTag( "table-cell", null );
         writeStartTag( "block", "header.style" );
-        // TODO
-        write( "Header text" );
+        write( headerText );
         writeEndTag( "block" );
         writeEndTag( "table-cell" );
         writeStartTag( "table-cell", null );
@@ -378,14 +414,103 @@
         writeEndTag( "static-content" );
     }
 
-    protected void regionAfter()
+    protected void regionAfter( String footerText )
     {
         writeStartTag( "static-content", "flow-name", "xsl-region-after" );
         writeStartTag( "block", "footer.style" );
-        // TODO
-        write( "Footer text" );
+        write( footerText );
         writeEndTag( "block" );
         writeEndTag( "static-content" );
+    }
+
+    protected void chapterHeading( String headerText, boolean chapterNumber )
+    {
+        writeStartTag( "block", null );
+        writeStartTag( "list-block", null );
+        writeStartTag( "list-item", null );
+        writeln( "<fo:list-item-label end-indent=\"6.375in\" start-indent=\"-1in\">"
);
+        writeStartTag( "block", "outdented.number.style" );
+
+        if ( chapterNumber )
+        {
+            write( Integer.toString( chapter ) );
+        }
+
+        writeEndTag( "block" );
+        writeEndTag( "list-item-label" );
+        writeln( "<fo:list-item-body end-indent=\"1in\" start-indent=\"0in\">" );
+        writeStartTag( "block", "chapter.title" );
+
+        if ( headerText == null )
+        {
+            write( docTitle );
+        }
+        else
+        {
+            write( headerText );
+        }
+
+        writeEndTag( "block" );
+        writeEndTag( "list-item-body" );
+        writeEndTag( "list-item" );
+        writeEndTag( "list-block" );
+        writeEndTag( "block" );
+        writeStartTag( "block", "space-after.optimum", "0em" );
+        writeEmptyTag( "leader", "chapter.rule" );
+        writeEndTag( "block" );
+    }
+
+    public void toc( DocumentTOC toc )
+    {
+        writeln( "<fo:page-sequence master-reference=\"toc\" initial-page-number=\"1\"
format=\"i\">" );
+        regionBefore( toc.getName() );
+        // TODO
+        regionAfter( "FooterText" );
+        writeStartTag( "flow", "flow-name", "xsl-region-body" );
+        chapterHeading( "Table of Contents", false );
+        writeln( "<fo:table table-layout=\"fixed\" width=\"100%\" >" );
+        writeEmptyTag( "table-column", "column-width", "0.45in" );
+        writeEmptyTag( "table-column", "column-width", "0.4in" );
+        writeEmptyTag( "table-column", "column-width", "0.4in" );
+        writeEmptyTag( "table-column", "column-width", "5in" ); // TODO
+        writeStartTag( "table-body", null );
+
+        int count = 0;
+
+        for ( Iterator k = toc.getItems().iterator(); k.hasNext(); )
+        {
+            DocumentTOCItem tocItem = (DocumentTOCItem) k.next();
+            count++;
+
+            String ref = getIdName( tocItem.getRef() );
+
+            writeStartTag( "table-row", "keep-with-next", "always" );
+            writeStartTag( "table-cell", "toc.cell" );
+            writeStartTag( "block", "toc.number.style" );
+            write( Integer.toString( count ) );
+            writeEndTag( "block" );
+            writeEndTag( "table-cell" );
+            writeStartTag( "table-cell", "number-columns-spanned", "3", "toc.cell" );
+            // TODO: writeStartTag( "block", "text-align-last", "justify", "toc.h1.style"
);
+            writeStartTag( "block", "toc.h1.style" );
+            writeStartTag( "basic-link", "internal-destination", ref );
+            write( tocItem.getName() );
+            writeEndTag( "basic-link" );
+            writeEmptyTag( "leader", "toc.leader.style" );
+            writeStartTag( "inline", "page.number" );
+            writeEmptyTag( "page-number-citation", "ref-id", ref );
+            writeEndTag( "inline" );
+            writeEndTag( "block" );
+            writeEndTag( "table-cell" );
+            writeEndTag( "table-row" );
+        }
+
+        writeEndTag( "table-body" );
+        writeEndTag( "table" );
+        writeEndTag( "flow" );
+        writeEndTag( "page-sequence" );
+
+
     }
 
 

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=576042&r1=576041&r2=576042&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
Sat Sep 15 23:21:05 2007
@@ -312,6 +312,8 @@
     {
         StringBuffer title = new StringBuffer( 16 );
 
+        title.append( getChapterString() );
+
         newline();
         if ( depth == Sink.SECTION_LEVEL_1 )
         {
@@ -355,6 +357,16 @@
         writeEndTag( "block" );
     }
 
+    protected void resetSectionCounter()
+    {
+        this.section = 0;
+    }
+
+    protected String getChapterString()
+    {
+        return "";
+    }
+
     // -----------------------------------------------------------------------
     //
     // -----------------------------------------------------------------------
@@ -936,6 +948,7 @@
      */
     protected void writeStartTag( String tag, String id, String name, String attributeId
)
     {
+        // TODO: check if id is already in attributeId, if yes, override
         String attribs = config.getAttributeSet( attributeId );
         newline();
         write( "<fo:" + tag + " " + id + "=\"" + name + "\"" + attribs + ">" );
@@ -1080,17 +1093,24 @@
     protected void startPageSequence( String initPageNumber )
     {
         writeln( "<fo:page-sequence initial-page-number=\"" + initPageNumber + "\" master-reference=\"body\">"
);
-        regionBefore();
-        regionAfter();
+        // TODO
+        regionBefore( "Header text" );
+        regionAfter( "Footer text" );
         writeln( "<fo:flow flow-name=\"xsl-region-body\">" );
+        chapterHeading( null, true );
+    }
+
+    protected void regionBefore( String headerText )
+    {
+        // do nothing, overridden by AggregateSink
     }
 
-    protected void regionBefore()
+    protected void regionAfter( String footerText )
     {
         // do nothing, overridden by AggregateSink
     }
 
-    protected void regionAfter()
+    protected void chapterHeading( String headerText, boolean chapterNumber )
     {
         // do nothing, overridden by AggregateSink
     }

Modified: maven/sandbox/trunk/doxia/doxia-module-fo/src/main/resources/fo-styles.xslt
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/doxia/doxia-module-fo/src/main/resources/fo-styles.xslt?rev=576042&r1=576041&r2=576042&view=diff
==============================================================================
--- maven/sandbox/trunk/doxia/doxia-module-fo/src/main/resources/fo-styles.xslt (original)
+++ maven/sandbox/trunk/doxia/doxia-module-fo/src/main/resources/fo-styles.xslt Sat Sep 15
23:21:05 2007
@@ -169,7 +169,7 @@
     </xsl:attribute-set>
 
     <!-- Chapter heading styles -->
-    <xsl:attribute-set name="chapter.title" use-attribute-sets="base.heading.style body.title">
+    <xsl:attribute-set name="chapter.title" use-attribute-sets="body.title">
         <xsl:attribute name="line-height">10pt</xsl:attribute>
         <xsl:attribute name="space-after">6pt</xsl:attribute>
     </xsl:attribute-set>
@@ -183,7 +183,7 @@
     <!-- Outdented numbers -->
     <xsl:attribute-set name="outdented.number.style" use-attribute-sets="base.heading.style">
         <xsl:attribute name="font-size">9.5pt</xsl:attribute>
-        <xsl:attribute name="color">#454545</xsl:attribute>
+        <!--<xsl:attribute name="color">#454545</xsl:attribute>-->
         <xsl:attribute name="line-height">10pt</xsl:attribute>
         <xsl:attribute name="text-align">right</xsl:attribute>
     </xsl:attribute-set>
@@ -460,7 +460,8 @@
     <xsl:attribute-set name="toc.base.style">
         <xsl:attribute name="font-family">Helvetica,sans-serif</xsl:attribute>
         <xsl:attribute name="line-height">16pt</xsl:attribute>
-        <xsl:attribute name="text-align-last">start</xsl:attribute>
+        <!-- <xsl:attribute name="text-align-last">start</xsl:attribute>-->
+        <xsl:attribute name="text-align-last">justify</xsl:attribute>
         <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
     </xsl:attribute-set>
     <xsl:attribute-set name="toc.leader.style">



Mime
View raw message