You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by vs...@apache.org on 2006/07/27 21:19:01 UTC

svn commit: r426203 - in /maven/doxia/trunk/doxia-sandbox/doxia-book: ./ src/main/java/org/apache/maven/doxia/book/services/indexer/ src/main/java/org/apache/maven/doxia/book/services/renderer/ src/main/java/org/apache/maven/doxia/book/services/rendere...

Author: vsiveton
Date: Thu Jul 27 12:19:00 2006
New Revision: 426203

URL: http://svn.apache.org/viewvc?rev=426203&view=rev
Log:
o Improved the XdocBookRenderer, more like latex2html layout
o Improved anchor links (see MSITE-168)
o Added i18n support
o Added javadoc, copyright stuff
o Moved BookIndexerTest.java from main to test
o Removed unused System.out.println()

Added:
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/AbstractXdocBookSink.java
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/ChapterXdocBookSink.java
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/IndexXdocBookSink.java
      - copied, changed from r425808, maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/XdocBookSink.java
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/SectionXdocBookSink.java
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/resources/book-renderer.properties
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/resources/book-renderer_fr.properties
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java
      - copied, changed from r425808, maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java
Removed:
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/XdocBookSink.java
Modified:
    maven/doxia/trunk/doxia-sandbox/doxia-book/pom.xml
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java
    maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java

Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/pom.xml
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/pom.xml?rev=426203&r1=426202&r2=426203&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-sandbox/doxia-book/pom.xml (original)
+++ maven/doxia/trunk/doxia-sandbox/doxia-book/pom.xml Thu Jul 27 12:19:00 2006
@@ -1,4 +1,26 @@
-<project>
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!--
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
     <groupId>org.apache.maven.doxia</groupId>
@@ -28,6 +50,11 @@
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-container-default</artifactId>
       <version>1.0-alpha-8</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-i18n</artifactId>
+      <version>1.0-beta-6</version>
     </dependency>
   </dependencies>
   <build>

Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java?rev=426203&r1=426202&r2=426203&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java (original)
+++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexingSink.java Thu Jul 27 12:19:00 2006
@@ -1,43 +1,74 @@
 package org.apache.maven.doxia.book.services.indexer;
 
-import org.apache.maven.doxia.sink.SinkAdapter;
-import org.apache.maven.doxia.book.context.IndexEntry;
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
-import java.util.List;
 import java.util.Stack;
 
+import org.apache.maven.doxia.book.context.IndexEntry;
+import org.apache.maven.doxia.module.HtmlTools;
+import org.apache.maven.doxia.sink.SinkAdapter;
+
 /**
+ * A simk implementation for book index
+ *
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
  * @version $Id$
  */
 public class BookIndexingSink
     extends SinkAdapter
 {
     private final static int TYPE_SECTION_1 = 1;
+
     private final static int TYPE_SECTION_2 = 2;
+
     private final static int TYPE_SECTION_3 = 3;
+
     private final static int TYPE_SECTION_4 = 4;
+
     private final static int TYPE_SECTION_5 = 5;
+
     private final static int TYPE_DEFINED_TERM = 6;
+
     private final static int TYPE_FIGURE = 7;
+
     private final static int TYPE_TABLE = 8;
+
     private final static int TITLE = 9;
 
     private int type;
 
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
-
     private String title;
 
     private Stack stack = new Stack();
 
+    /**
+     * Default constructor
+     *
+     * @param sectionEntry
+     */
     public BookIndexingSink( IndexEntry sectionEntry )
     {
         stack.push( sectionEntry );
     }
 
+    /**
+     * @return the title
+     */
     public String getTitle()
     {
         return title;
@@ -104,26 +135,26 @@
         pop();
     }
 
-//    public void definedTerm()
-//    {
-//        type = TYPE_DEFINED_TERM;
-//    }
-//
-//    public void figureCaption()
-//    {
-//        type = TYPE_FIGURE;
-//    }
-//
-//    public void tableCaption()
-//    {
-//        type = TYPE_TABLE;
-//    }
+    //    public void definedTerm()
+    //    {
+    //        type = TYPE_DEFINED_TERM;
+    //    }
+    //
+    //    public void figureCaption()
+    //    {
+    //        type = TYPE_FIGURE;
+    //    }
+    //
+    //    public void tableCaption()
+    //    {
+    //        type = TYPE_TABLE;
+    //    }
 
     public void text( String text )
     {
         IndexEntry entry;
 
-        switch( type )
+        switch ( type )
         {
             case TITLE:
                 this.title = text;
@@ -137,15 +168,7 @@
                 // Sanitize the id. The most important step is to remove any blanks
                 // -----------------------------------------------------------------------
 
-                String id = text;
-                id = id.toLowerCase();
-                id = id.replace( '\'', '_' );
-                id = id.replace( '\"', '_' );
-                id = id.replace( ' ', '_' );
-
-                // -----------------------------------------------------------------------
-                //
-                // -----------------------------------------------------------------------
+                String id = HtmlTools.encodeId( text );
 
                 entry = new IndexEntry( peek(), id );
 
@@ -162,18 +185,27 @@
         type = 0;
     }
 
+    /**
+     * Pushes an IndexEntry onto the top of this stack
+     *
+     * @param entry to put
+     */
     public void push( IndexEntry entry )
     {
-//        System.out.println(  "push: " + entry.getId() );
         stack.push( entry );
     }
 
+    /**
+     * Removes the IndexEntry at the top of this stack
+     */
     public void pop()
     {
-//        System.out.println(  "pop: " + peek().getId() );
         stack.pop();
     }
 
+    /**
+     * @return Looks at the IndexEntry at the top of this stack
+     */
     public IndexEntry peek()
     {
         return (IndexEntry) stack.peek();

Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java?rev=426203&r1=426202&r2=426203&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java (original)
+++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java Thu Jul 27 12:19:00 2006
@@ -1,31 +1,56 @@
 package org.apache.maven.doxia.book.services.renderer;
 
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+
 import org.apache.maven.doxia.Doxia;
-import org.apache.maven.doxia.module.xdoc.XdocSink;
 import org.apache.maven.doxia.book.BookDoxiaException;
 import org.apache.maven.doxia.book.context.BookContext;
 import org.apache.maven.doxia.book.context.IndexEntry;
 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.book.services.renderer.xdoc.XdocBookSink;
+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.editor.io.PipelineSink;
+import org.apache.maven.doxia.module.HtmlTools;
+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.codehaus.plexus.i18n.I18N;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
+ * An implementation of <code>BookRenderer</code> for Xdoc
+ *
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
  * @version $Id$
  * @plexus.component role-hint="xdoc"
  */
@@ -38,6 +63,11 @@
      */
     private Doxia doxia;
 
+    /**
+     * @plexus.requirement
+     */
+    private I18N i18n;
+
     // ----------------------------------------------------------------------
     // BookRenderer Implementation
     // ----------------------------------------------------------------------
@@ -51,29 +81,50 @@
         {
             if ( !context.getOutputDirectory().mkdirs() )
             {
-                throw new BookDoxiaException(
-                    "Could not make directory: " + context.getOutputDirectory().getAbsolutePath() + "." );
+                throw new BookDoxiaException( "Could not make directory: "
+                    + context.getOutputDirectory().getAbsolutePath() + "." );
             }
         }
 
-        // -----------------------------------------------------------------------
-        //
-        // -----------------------------------------------------------------------
-
         renderBook( book, context );
     }
 
     // -----------------------------------------------------------------------
+    // Protected
+    // -----------------------------------------------------------------------
+
+    /**
+     * Gets a trimmed String for the given key from the resource bundle defined by Plexus.
+     *
+     * @param key the key for the desired string
+     * @return the string for the given key
+     * @throws IllegalArgumentException if the parameter is empty.
+     */
+    protected String getString( String key )
+    {
+        if ( StringUtils.isEmpty( key ) )
+        {
+            throw new IllegalArgumentException( "The key cannot be empty" );
+        }
+
+        // TODO Handle locale
+        return i18n.getString( "book-renderer", Locale.getDefault(), key ).trim();
+    }
+
+    // -----------------------------------------------------------------------
     // Private
     // -----------------------------------------------------------------------
 
+    /**
+     * Render the book, ie the book index and all chapter index
+     *
+     * @param book
+     * @param context
+     * @throws BookDoxiaException if any
+     */
     private void renderBook( BookModel book, BookContext context )
         throws BookDoxiaException
     {
-        // -----------------------------------------------------------------------
-        // Render the book index.xml page
-        // -----------------------------------------------------------------------
-
         File index = new File( context.getOutputDirectory(), "index.xml" );
 
         try
@@ -86,12 +137,6 @@
         }
 
         // -----------------------------------------------------------------------
-        // Render the index.html files for each chapter
-        // -----------------------------------------------------------------------
-
-        // TODO: Implement
-
-        // -----------------------------------------------------------------------
         // Render all the chapters
         // -----------------------------------------------------------------------
 
@@ -105,14 +150,20 @@
         }
     }
 
-    // -----------------------------------------------------------------------
-    // Index Rendering
-    // -----------------------------------------------------------------------
-
+    /**
+     * Write the book index, ie a TOC
+     *
+     * @param index
+     * @param book
+     * @param context
+     * @throws IOException if any
+     */
     private void writeBookIndex( File index, BookModel book, BookContext context )
         throws IOException
     {
-        XdocSink sink = new XdocSink( new FileWriter( index ) );
+        FileWriter writer = new FileWriter( index );
+
+        XdocSink sink = new IndexXdocBookSink( writer, context.getIndex().getFirstEntry(), i18n );
 
         // -----------------------------------------------------------------------
         // Head
@@ -121,7 +172,7 @@
         sink.head();
 
         sink.title();
-        sink.text( book.getTitle() + " - Index" );
+        sink.text( book.getTitle() + " - " + getString( "toc" ) );
         sink.title_();
 
         sink.head_();
@@ -134,7 +185,7 @@
 
         sink.section1();
         sink.sectionTitle1();
-        sink.text( book.getTitle() + " - Index" );
+        sink.text( book.getTitle() + " - " + getString( "toc" ) );
         sink.sectionTitle1_();
 
         sink.list();
@@ -149,6 +200,12 @@
         sink.body_();
     }
 
+    /**
+     * Write the chapter index for the book index
+     *
+     * @param sink
+     * @param chapterEntry
+     */
     private void writeChapterIndexForBookIndex( XdocSink sink, IndexEntry chapterEntry )
     {
         sink.listItem();
@@ -167,6 +224,12 @@
         sink.listItem_();
     }
 
+    /**
+     * Write the section index for the book index
+     *
+     * @param sink
+     * @param sectionIndex
+     */
     private void writeSectionIndexForBookIndex( XdocSink sink, IndexEntry sectionIndex )
     {
         sink.listItem();
@@ -185,10 +248,17 @@
         sink.listItem_();
     }
 
+    /**
+     * Write subsection index for the book index
+     *
+     * @param sink
+     * @param sectionIndex
+     * @param subsectionIndex
+     */
     private void writeSubsectionIndexForBookIndex( XdocSink sink, IndexEntry sectionIndex, IndexEntry subsectionIndex )
     {
         sink.listItem();
-        sink.link( sectionIndex.getId() + ".html#" + subsectionIndex.getId() );
+        sink.link( sectionIndex.getId() + ".html#" + HtmlTools.encodeId( subsectionIndex.getId() ) );
         sink.text( subsectionIndex.getTitle() );
         sink.link_();
         sink.listItem_();
@@ -198,9 +268,28 @@
     // Rendering
     // -----------------------------------------------------------------------
 
+    /**
+     * Render all chapter index
+     *
+     * @param chapter
+     * @param context
+     * @param chapterIndex
+     * @throws BookDoxiaException if any
+     */
     private void renderChapter( Chapter chapter, BookContext context, IndexEntry chapterIndex )
         throws BookDoxiaException
     {
+        File index = new File( context.getOutputDirectory(), chapter.getId() + ".xml" );
+
+        try
+        {
+            writeChapterIndex( index, chapter, chapterIndex );
+        }
+        catch ( IOException e )
+        {
+            throw new BookDoxiaException( "Error while rendering index page to: '" + index.getAbsolutePath() + "'.", e );
+        }
+
         Iterator ii = chapterIndex.getChildEntries().iterator();
 
         for ( Iterator it = chapter.getSections().iterator(); it.hasNext(); )
@@ -211,6 +300,65 @@
         }
     }
 
+    /**
+     * Write a chapter index
+     *
+     * @param index
+     * @param chapter
+     * @param chapterIndex
+     * @throws IOException
+     */
+    private void writeChapterIndex( File index, Chapter chapter, IndexEntry chapterIndex )
+        throws IOException
+    {
+        FileWriter writer = new FileWriter( index );
+
+        ChapterXdocBookSink sink = new ChapterXdocBookSink( writer, chapterIndex, i18n );
+
+        // -----------------------------------------------------------------------
+        // Head
+        // -----------------------------------------------------------------------
+
+        sink.head();
+
+        sink.title();
+        sink.text( chapter.getTitle() );
+        sink.title_();
+
+        sink.head_();
+
+        // -----------------------------------------------------------------------
+        // Body
+        // -----------------------------------------------------------------------
+
+        sink.body();
+
+        sink.section1();
+        sink.sectionTitle1();
+        sink.text( chapter.getTitle() );
+        sink.sectionTitle1_();
+
+        sink.list();
+        for ( Iterator it = chapterIndex.getChildEntries().iterator(); it.hasNext(); )
+        {
+            IndexEntry sectionIndex = (IndexEntry) it.next();
+            writeSectionIndexForBookIndex( sink, sectionIndex );
+        }
+        sink.list_();
+
+        sink.section1_();
+
+        sink.body_();
+    }
+
+    /**
+     * Render all section pages
+     *
+     * @param context
+     * @param section
+     * @param sectionIndex
+     * @throws BookDoxiaException if any
+     */
     private void renderSection( BookContext context, Section section, IndexEntry sectionIndex )
         throws BookDoxiaException
     {
@@ -218,18 +366,17 @@
         {
             FileWriter writer = new FileWriter( context.getOutputDirectory() + "/" + section.getId() + ".xml" );
 
-            XdocBookSink sink = new XdocBookSink( writer, sectionIndex );
+            SectionXdocBookSink sink = new SectionXdocBookSink( writer, sectionIndex, i18n );
 
             BookContext.BookFile bookFile = (BookContext.BookFile) context.getFiles().get( section.getId() );
 
             if ( bookFile == null )
             {
-                throw new BookDoxiaException(
-                    "No document that matches section with id=" + section.getId() + "." );
+                throw new BookDoxiaException( "No document that matches section with id=" + section.getId() + "." );
             }
 
             List pipeline = new ArrayList();
-//            pipeline.add( DebugSink.newInstance() );
+            //            pipeline.add( DebugSink.newInstance() );
             pipeline.add( sink );
             Sink pipelineSink = PipelineSink.newInstance( pipeline );
 
@@ -243,13 +390,13 @@
             }
             catch ( ParseException e )
             {
-                throw new BookDoxiaException(
-                    "Error while parsing document: " + bookFile.getFile().getAbsolutePath() + ".", e );
+                throw new BookDoxiaException( "Error while parsing document: " + bookFile.getFile().getAbsolutePath()
+                    + ".", e );
             }
             catch ( FileNotFoundException e )
             {
-                throw new BookDoxiaException(
-                    "Could not find document: " + bookFile.getFile().getAbsolutePath() + ".", e );
+                throw new BookDoxiaException( "Could not find document: " + bookFile.getFile().getAbsolutePath() + ".",
+                                              e );
             }
         }
         catch ( IOException e )

Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/AbstractXdocBookSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/AbstractXdocBookSink.java?rev=426203&view=auto
==============================================================================
--- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/AbstractXdocBookSink.java (added)
+++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/AbstractXdocBookSink.java Thu Jul 27 12:19:00 2006
@@ -0,0 +1,169 @@
+package org.apache.maven.doxia.book.services.renderer.xdoc;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.Writer;
+import java.util.Locale;
+
+import org.apache.maven.doxia.module.xdoc.XdocSink;
+import org.codehaus.plexus.i18n.I18N;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Abstract <code>XdocSink</code> implementation for book.
+ *
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public abstract class AbstractXdocBookSink
+    extends XdocSink
+{
+    private I18N i18n;
+
+    /**
+     * Default constructor
+     *
+     * @param out
+     * @param i18n
+     */
+    public AbstractXdocBookSink( Writer out, I18N i18n )
+    {
+        super( out );
+
+        this.i18n = i18n;
+    }
+
+    /**
+     * @see org.apache.maven.doxia.module.xdoc.XdocSink#head()
+     */
+    public void head()
+    {
+        resetState();
+
+        headFlag = true;
+
+        markup( "<?xml version=\"1.0\" ?>" + EOL );
+
+        markup( "<document>" + EOL );
+
+        markup( "<properties>" + EOL );
+
+    }
+
+    /**
+     * @see org.apache.maven.doxia.module.xdoc.XdocSink#head_()
+     */
+    public void head_()
+    {
+        headFlag = false;
+
+        markup( "</properties>" + EOL );
+    }
+
+    /**
+     * @see org.apache.maven.doxia.module.xdoc.XdocSink#author_()
+     */
+    public void author_()
+    {
+        if ( buffer.length() > 0 )
+        {
+            markup( "<author>" );
+            content( buffer.toString() );
+            markup( "</author>" + EOL );
+            buffer = new StringBuffer();
+        }
+    }
+
+    /**
+     * @see org.apache.maven.doxia.module.xdoc.XdocSink#date_()
+     */
+    public void date_()
+    {
+        // nop
+    }
+
+    /**
+     * @see org.apache.maven.doxia.module.xdoc.XdocSink#body()
+     */
+    public void body()
+    {
+        markup( "<body>" + EOL );
+
+        navigationPanel();
+
+        horizontalRule();
+    }
+
+    /**
+     * @see org.apache.maven.doxia.module.xdoc.XdocSink#body_()
+     */
+    public void body_()
+    {
+        horizontalRule();
+
+        navigationPanel();
+
+        markup( "</body>" + EOL );
+
+        markup( "</document>" + EOL );
+
+        out.flush();
+
+        resetState();
+    }
+
+    /**
+     * @see org.apache.maven.doxia.module.xdoc.XdocSink#title_()
+     */
+    public void title_()
+    {
+        if ( buffer.length() > 0 )
+        {
+            markup( "<title>" );
+            content( buffer.toString() );
+            markup( "</title>" + EOL );
+            buffer = new StringBuffer();
+        }
+    }
+
+    // -----------------------------------------------------------------------
+    // Protected
+    // -----------------------------------------------------------------------
+
+    /**
+     * Gets a trimmed String for the given key from the resource bundle defined by Plexus.
+     *
+     * @param key the key for the desired string
+     * @return the string for the given key
+     * @throws IllegalArgumentException if the parameter is empty.
+     */
+    protected String getString( String key )
+    {
+        if ( StringUtils.isEmpty( key ) )
+        {
+            throw new IllegalArgumentException( "The key cannot be empty" );
+        }
+
+        return i18n.getString( "book-renderer", Locale.getDefault(), key ).trim();
+    }
+
+    /**
+     * Add a navigation panel.
+     */
+    protected abstract void navigationPanel();
+}

Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/ChapterXdocBookSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/ChapterXdocBookSink.java?rev=426203&view=auto
==============================================================================
--- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/ChapterXdocBookSink.java (added)
+++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/ChapterXdocBookSink.java Thu Jul 27 12:19:00 2006
@@ -0,0 +1,151 @@
+package org.apache.maven.doxia.book.services.renderer.xdoc;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.doxia.book.context.IndexEntry;
+import org.codehaus.plexus.i18n.I18N;
+
+import java.io.Writer;
+
+/**
+ * A <code>XdocSink</code> implementation for chapter in a book
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class ChapterXdocBookSink
+    extends AbstractXdocBookSink
+{
+    private IndexEntry chapterIndex;
+
+    /**
+     * Default constructor
+     *
+     * @param out
+     * @param chapterIndex
+     * @param i18n
+     */
+    public ChapterXdocBookSink( Writer out, IndexEntry chapterIndex, I18N i18n )
+    {
+        super( out, i18n );
+
+        this.chapterIndex = chapterIndex;
+    }
+
+    /**
+     * @see org.apache.maven.doxia.book.services.renderer.xdoc.AbstractXdocBookSink#navigationPanel()
+     */
+    protected void navigationPanel()
+    {
+        markup( "<!--Navigation Panel-->" + EOL );
+
+        markup( "<table width=\"100%\" align=\"center\">" + EOL );
+        markup( "<tr>" + EOL );
+
+        // -----------------------------------------------------------------------
+        // Prev
+        // -----------------------------------------------------------------------
+
+        IndexEntry prevChapter = chapterIndex.getPrevEntry();
+
+        markup( "<td><div align='left'>" );
+
+        previous( prevChapter );
+
+        markup( "</div></td>" + EOL );
+
+        // -----------------------------------------------------------------------
+        // Parent
+        // -----------------------------------------------------------------------
+
+        markup( "<td><div align='center'>" );
+        up();
+        markup( "</div></td>" + EOL );
+
+        // -----------------------------------------------------------------------
+        // Next
+        // -----------------------------------------------------------------------
+
+        markup( "<td><div align='right'>" );
+
+        next();
+
+        markup( "</div></td>" + EOL );
+
+        markup( "</tr>" + EOL );
+        markup( "</table>" + EOL );
+
+        markup( "<!--End of Navigation Panel-->" + EOL );
+    }
+
+    /**
+     * Add previous link
+     *
+     * @param prevChapter
+     */
+    protected void previous( IndexEntry prevChapter )
+    {
+        if ( prevChapter != null )
+        {
+            IndexEntry lastEntry = prevChapter.getLastEntry();
+            if ( lastEntry == null )
+            {
+                markup( "<i>Start of book</i>" );
+            }
+            else
+            {
+                markup( getString( "previous" ) + ": <a href='" + lastEntry.getId() + ".html'>" );
+                content( lastEntry.getTitle() );
+                markup( "</a>" );
+            }
+        }
+        else
+        {
+            markup( getString( "previous" ) + ":<a href='index.html'>" + getString( "toc" ) + "</a>" );
+        }
+    }
+
+    /**
+     * Add parent/up link
+     *
+     * @param parent
+     */
+    protected void up()
+    {
+        markup( getString( "up" ) + ": <a href='index.html'>" + getString( "toc" ) + "</a>" );
+    }
+
+    /**
+     * Add next link
+     *
+     * @param nextChapter
+     */
+    protected void next()
+    {
+        IndexEntry firstEntry = chapterIndex.getFirstEntry();
+        if ( firstEntry == null )
+        {
+            markup( "<i>End of book</i>" );
+        }
+        else
+        {
+            markup( getString( "next" ) + ": <a href='" + firstEntry.getId() + ".html'>" );
+            content( firstEntry.getTitle() );
+            markup( "</a>" );
+        }
+    }
+}

Copied: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/IndexXdocBookSink.java (from r425808, maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/XdocBookSink.java)
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/IndexXdocBookSink.java?p2=maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/IndexXdocBookSink.java&p1=maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/XdocBookSink.java&r1=425808&r2=426203&rev=426203&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/XdocBookSink.java (original)
+++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/IndexXdocBookSink.java Thu Jul 27 12:19:00 2006
@@ -1,179 +1,80 @@
 package org.apache.maven.doxia.book.services.renderer.xdoc;
 
-import org.apache.maven.doxia.module.xdoc.XdocSink;
-import org.apache.maven.doxia.book.context.IndexEntry;
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 import java.io.Writer;
 
+import org.apache.maven.doxia.book.context.IndexEntry;
+import org.codehaus.plexus.i18n.I18N;
+
 /**
+ * A <code>XdocSink</code> implementation for index book.
+ *
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
  * @version $Id$
  */
-public class XdocBookSink
-    extends XdocSink
+public class IndexXdocBookSink
+    extends AbstractXdocBookSink
 {
-    private IndexEntry indexEntry;
-
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
-
-    public XdocBookSink( Writer out, IndexEntry indexEntry )
-    {
-        super( out );
-
-        this.indexEntry = indexEntry;
-    }
-
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
+    private IndexEntry firstEntry;
 
-    public void head()
+    /**
+     * Default constructor
+     *
+     * @param out
+     * @param firstEntry
+     * @param i18n
+     */
+    public IndexXdocBookSink( Writer out, IndexEntry firstEntry, I18N i18n )
     {
-        resetState();
-
-        headFlag = true;
-
-        markup( "<?xml version=\"1.0\" ?>" + EOL );
-
-        markup( "<document>" + EOL );
-
-        markup( "<properties>" + EOL );
+        super( out, i18n );
 
+        this.firstEntry = firstEntry;
     }
 
-    public void head_()
+    /**
+     * @see org.apache.maven.doxia.book.services.renderer.xdoc.AbstractXdocBookSink#navigationPanel()
+     */
+    protected void navigationPanel()
     {
-        headFlag = false;
-
-        markup( "</properties>" + EOL );
-    }
-
-    public void author_()
-    {
-        if ( buffer.length() > 0 )
-        {
-            markup( "<author>" );
-            content( buffer.toString() );
-            markup( "</author>" + EOL );
-            buffer = new StringBuffer();
-        }
-    }
-
-    public void date_()
-    {
-    }
-
-    public void body()
-    {
-        markup( "<body>" + EOL );
+        markup( "<!--Navigation Panel-->" + EOL );
 
         markup( "<table width=\"100%\" align=\"center\">" + EOL );
         markup( "<tr>" + EOL );
 
-        IndexEntry parent = indexEntry.getParent();
-
         // -----------------------------------------------------------------------
-        // Prev
+        // Next
         // -----------------------------------------------------------------------
 
-        IndexEntry prevEntry = indexEntry.getPrevEntry();
-
-        markup( "<td><div align='left'>" );
-
-        if ( prevEntry != null )
+        if ( firstEntry != null )
         {
-            markup( "Previous: <a href='" + prevEntry.getId() + ".html'>" );
-            content( prevEntry.getTitle() );
-            markup( "</a>" );
-        }
-        else
-        {
-            IndexEntry prevChapter = parent.getPrevEntry();
-
-            if ( prevChapter == null )
-            {
-                markup( "<i>Start of book</i>" );
-            }
-            else
-            {
-                IndexEntry lastEntry = prevChapter.getLastEntry();
-
-                markup( "Previous: <a href='" + lastEntry.getId() + ".html'>" );
-                content( lastEntry.getTitle() );
-                markup( "</a>" );
-            }
-        }
-
-        markup( "</div></td>" + EOL );
-
-        // -----------------------------------------------------------------------
-        // Parent
-        // -----------------------------------------------------------------------
-
-        markup( "<td><div align='center'><b><i>NOT IMPLEMENTED</i></b> Up: <a href='" + parent.getId() + ".html'>" + parent.getTitle() + "</a></div></td>" + EOL );
+            markup( "<td><div align='right'>" );
 
-        // -----------------------------------------------------------------------
-        //
-        // -----------------------------------------------------------------------
-
-        IndexEntry nextEntry = indexEntry.getNextEntry();
-
-        markup( "<td><div align='right'>" );
-
-        if ( nextEntry != null )
-        {
-            markup( "Next: <a href='" + nextEntry.getId() + ".html'>" );
-            content( nextEntry.getTitle() );
+            markup( getString( "next" ) + ": <a href='" + firstEntry.getId() + ".html'>" );
+            content( firstEntry.getTitle() );
             markup( "</a>" );
-        }
-        else
-        {
-            IndexEntry nextChapter = parent.getNextEntry();
 
-            if ( nextChapter == null )
-            {
-                markup( "<i>End of book</i>" );
-            }
-            else
-            {
-                IndexEntry firstEntry = nextChapter.getFirstEntry();
-                markup( "Next: <a href='" + firstEntry.getId() + ".html'>" );
-                content( firstEntry.getTitle() );
-                markup( "</a>" );
-            }
+            markup( "</div></td>" + EOL );
         }
 
-        markup( "</div></td>" + EOL );
-
-        // -----------------------------------------------------------------------
-        //
-        // -----------------------------------------------------------------------
-
         markup( "</tr>" + EOL );
         markup( "</table>" + EOL );
-    }
-
-    public void body_()
-    {
-        markup( "</body>" + EOL );
 
-        markup( "</document>" + EOL );
-
-        out.flush();
-
-        resetState();
-    }
-
-    public void title_()
-    {
-        if ( buffer.length() > 0 )
-        {
-            markup( "<title>" );
-            content( "Book " + buffer.toString() );
-            markup( "</title>" + EOL );
-            buffer = new StringBuffer();
-        }
+        markup( "<!--End of Navigation Panel-->" + EOL );
     }
 }

Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/SectionXdocBookSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/SectionXdocBookSink.java?rev=426203&view=auto
==============================================================================
--- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/SectionXdocBookSink.java (added)
+++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/xdoc/SectionXdocBookSink.java Thu Jul 27 12:19:00 2006
@@ -0,0 +1,159 @@
+package org.apache.maven.doxia.book.services.renderer.xdoc;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.doxia.book.context.IndexEntry;
+import org.codehaus.plexus.i18n.I18N;
+
+import java.io.Writer;
+
+/**
+ * A <code>XdocSink</code> implementation for section in a book
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class SectionXdocBookSink
+    extends AbstractXdocBookSink
+{
+    private IndexEntry indexEntry;
+
+    /**
+     * Default constructor
+     *
+     * @param out
+     * @param indexEntry
+     * @param i18n
+     */
+    public SectionXdocBookSink( Writer out, IndexEntry indexEntry, I18N i18n )
+    {
+        super( out, i18n );
+
+        this.indexEntry = indexEntry;
+    }
+
+    /**
+     * @see org.apache.maven.doxia.book.services.renderer.xdoc.AbstractXdocBookSink#navigationPanel()
+     */
+    protected void navigationPanel()
+    {
+        markup( "<!--Navigation Panel-->" + EOL );
+
+        markup( "<table width=\"100%\" align=\"center\">" + EOL );
+        markup( "<tr>" + EOL );
+
+        IndexEntry parent = indexEntry.getParent();
+
+        // -----------------------------------------------------------------------
+        // Prev
+        // -----------------------------------------------------------------------
+
+        IndexEntry prevEntry = indexEntry.getPrevEntry();
+
+        markup( "<td><div align='left'>" );
+
+        previous( parent, prevEntry );
+
+        markup( "</div></td>" + EOL );
+
+        // -----------------------------------------------------------------------
+        // Parent
+        // -----------------------------------------------------------------------
+
+        markup( "<td><div align='center'>" );
+        up( parent );
+        markup( "</div></td>" + EOL );
+
+        // -----------------------------------------------------------------------
+        // Next
+        // -----------------------------------------------------------------------
+
+        IndexEntry nextEntry = indexEntry.getNextEntry();
+
+        markup( "<td><div align='right'>" );
+
+        next( parent, nextEntry );
+
+        markup( "</div></td>" + EOL );
+
+        markup( "</tr>" + EOL );
+        markup( "</table>" + EOL );
+
+        markup( "<!--End of Navigation Panel-->" + EOL );
+    }
+
+    /**
+     * Add previous link
+     *
+     * @param parent
+     * @param prevEntry
+     */
+    protected void previous( IndexEntry parent, IndexEntry prevEntry )
+    {
+        if ( prevEntry != null )
+        {
+            markup( getString( "previous" ) + ": <a href='" + prevEntry.getId() + ".html'>" );
+            content( prevEntry.getTitle() );
+            markup( "</a>" );
+        }
+        else
+        {
+            markup( getString( "previous" ) + ": <a href='" + parent.getId() + ".html'>" );
+            content( parent.getTitle() );
+            markup( "</a>" );
+        }
+    }
+
+    /**
+     * @see org.apache.maven.doxia.book.services.renderer.xdoc.ChapterXdocBookSink#up(org.apache.maven.doxia.book.context.IndexEntry)
+     */
+    protected void up( IndexEntry parent )
+    {
+        markup( getString( "up" ) + ": <a href='" + parent.getId() + ".html'>" + parent.getTitle() + "</a>" );
+    }
+
+    /**
+     * Add next link
+     *
+     * @param parent
+     * @param nextEntry
+     */
+    protected void next( IndexEntry parent, IndexEntry nextEntry )
+    {
+        if ( nextEntry != null )
+        {
+            markup( getString( "next" ) + ": <a href='" + nextEntry.getId() + ".html'>" );
+            content( nextEntry.getTitle() );
+            markup( "</a>" );
+        }
+        else
+        {
+            IndexEntry nextChapter = parent.getNextEntry();
+
+            if ( nextChapter == null )
+            {
+                markup( "<i>End of book</i>" );
+            }
+            else
+            {
+                markup( getString( "next" ) + ": <a href='" + nextChapter.getId() + ".html'>" );
+                content( nextChapter.getTitle() );
+                markup( "</a>" );
+            }
+        }
+    }
+}

Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/resources/book-renderer.properties
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/resources/book-renderer.properties?rev=426203&view=auto
==============================================================================
--- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/resources/book-renderer.properties (added)
+++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/resources/book-renderer.properties Thu Jul 27 12:19:00 2006
@@ -0,0 +1,20 @@
+# -------------------------------------------------------------------
+# Copyright 2006 The Apache Software Foundation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -------------------------------------------------------------------
+
+toc=Table Of Content
+previous=Previous
+up=Up
+next=Next

Added: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/resources/book-renderer_fr.properties
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/resources/book-renderer_fr.properties?rev=426203&view=auto
==============================================================================
--- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/resources/book-renderer_fr.properties (added)
+++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/resources/book-renderer_fr.properties Thu Jul 27 12:19:00 2006
@@ -0,0 +1,20 @@
+# -------------------------------------------------------------------
+# Copyright 2006 The Apache Software Foundation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -------------------------------------------------------------------
+
+toc=Table des matières
+previous=Précédent
+up=Haut
+next=Suivant

Copied: maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java (from r425808, maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java)
URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java?p2=maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java&p1=maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java&r1=425808&r2=426203&rev=426203&view=diff
==============================================================================
--- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java (original)
+++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/test/java/org/apache/maven/doxia/book/services/indexer/BookIndexerTest.java Thu Jul 27 12:19:00 2006
@@ -1,11 +1,28 @@
 package org.apache.maven.doxia.book.services.indexer;
 
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.FileUtils;
 import org.apache.maven.doxia.book.services.io.BookIo;
 import org.apache.maven.doxia.book.model.BookModel;
 import org.apache.maven.doxia.book.context.BookContext;
 import org.apache.maven.doxia.book.context.IndexEntry;
+import org.apache.maven.doxia.module.HtmlTools;
 
 /**
  * @author <a href="mailto:trygve.laugstol@objectware.no">Trygve Laugst&oslash;l</a>
@@ -89,7 +106,7 @@
 
         assertEquals( title, indexEntry.getTitle() );
 
-        assertEquals( id, indexEntry.getId() );
+        assertEquals( HtmlTools.encodeId( id ), indexEntry.getId() );
 
         assertEquals( childCount, indexEntry.getChildEntries().size() );
 



Re: svn commit: r426203 - in /maven/doxia/trunk/doxia-sandbox/doxia-book: ./ src/main/java/org/apache/maven/doxia/book/services/indexer/ src/main/java/org/apache/maven/doxia/book/services/renderer/ src/main/java/org/apache/maven/doxia/book/services/rendere...

Posted by Trygve Laugstøl <tr...@apache.org>.
vsiveton@apache.org wrote:
> Author: vsiveton
> Date: Thu Jul 27 12:19:00 2006
> New Revision: 426203
> 
> URL: http://svn.apache.org/viewvc?rev=426203&view=rev
> Log:
> o Improved the XdocBookRenderer, more like latex2html layout
> o Improved anchor links (see MSITE-168)
> o Added i18n support
> o Added javadoc, copyright stuff
> o Moved BookIndexerTest.java from main to test
> o Removed unused System.out.println()
> 

[snip]

>  public class BookIndexingSink
>      extends SinkAdapter
>  {
>      private final static int TYPE_SECTION_1 = 1;
> +
>      private final static int TYPE_SECTION_2 = 2;
> +
>      private final static int TYPE_SECTION_3 = 3;
> +
>      private final static int TYPE_SECTION_4 = 4;
> +
>      private final static int TYPE_SECTION_5 = 5;
> +
>      private final static int TYPE_DEFINED_TERM = 6;
> +
>      private final static int TYPE_FIGURE = 7;
> +
>      private final static int TYPE_TABLE = 8;
> +
>      private final static int TITLE = 9;
>  
>      private int type;
>  
> -    // ----------------------------------------------------------------------
> -    //
> -    // ----------------------------------------------------------------------
> -
>      private String title;
>  
>      private Stack stack = new Stack();
>  
> +    /**
> +     * Default constructor
> +     *
> +     * @param sectionEntry
> +     */
 >      public BookIndexingSink( IndexEntry sectionEntry )
 >      {
 >          stack.push( sectionEntry );
 >      }

These comments are pretty useless, I'd rather not sprinkle the code with 
obvious comments.

[snip]

> -//    public void definedTerm()
> -//    {
> -//        type = TYPE_DEFINED_TERM;
> -//    }
> -//
> -//    public void figureCaption()
> -//    {
> -//        type = TYPE_FIGURE;
> -//    }
> -//
> -//    public void tableCaption()
> -//    {
> -//        type = TYPE_TABLE;
> -//    }
> +    //    public void definedTerm()
> +    //    {
> +    //        type = TYPE_DEFINED_TERM;
> +    //    }
> +    //
> +    //    public void figureCaption()
> +    //    {
> +    //        type = TYPE_FIGURE;
> +    //    }
> +    //
> +    //    public void tableCaption()
> +    //    {
> +    //        type = TYPE_TABLE;
> +    //    }

Any special reason for this other than you identing it by accident?

>  
>      public void text( String text )
>      {
>          IndexEntry entry;
>  
> -        switch( type )
> +        switch ( type )
>          {
>              case TITLE:
>                  this.title = text;
> @@ -137,15 +168,7 @@
>                  // Sanitize the id. The most important step is to remove any blanks
>                  // -----------------------------------------------------------------------
>  
> -                String id = text;
> -                id = id.toLowerCase();
> -                id = id.replace( '\'', '_' );
> -                id = id.replace( '\"', '_' );
> -                id = id.replace( ' ', '_' );
> -
> -                // -----------------------------------------------------------------------
> -                //
> -                // -----------------------------------------------------------------------
> +                String id = HtmlTools.encodeId( text );

Ah, I knew it was somewhere.

>                  entry = new IndexEntry( peek(), id );
>  
> @@ -162,18 +185,27 @@
>          type = 0;
>      }
>  
> +    /**
> +     * Pushes an IndexEntry onto the top of this stack
> +     *
> +     * @param entry to put
> +     */
>      public void push( IndexEntry entry )
>      {
> -//        System.out.println(  "push: " + entry.getId() );
>          stack.push( entry );
>      }
>  
> +    /**
> +     * Removes the IndexEntry at the top of this stack
> +     */
>      public void pop()
>      {
> -//        System.out.println(  "pop: " + peek().getId() );
>          stack.pop();
>      }
>  
> +    /**
> +     * @return Looks at the IndexEntry at the top of this stack
> +     */
>      public IndexEntry peek()
>      {
>          return (IndexEntry) stack.peek();
> 
> Modified: maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java
> URL: http://svn.apache.org/viewvc/maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java?rev=426203&r1=426202&r2=426203&view=diff
> ==============================================================================
> --- maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java (original)
> +++ maven/doxia/trunk/doxia-sandbox/doxia-book/src/main/java/org/apache/maven/doxia/book/services/renderer/XdocBookRenderer.java Thu Jul 27 12:19:00 2006
> @@ -1,31 +1,56 @@
>  package org.apache.maven.doxia.book.services.renderer;
>  
> +/*
> + * Copyright 2006 The Apache Software Foundation.
> + *
> + * Licensed under the Apache License, Version 2.0 (the "License");
> + * you may not use this file except in compliance with the License.
> + * You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +
> +import java.io.File;
> +import java.io.FileNotFoundException;
> +import java.io.FileReader;
> +import java.io.FileWriter;
> +import java.io.IOException;
> +import java.util.ArrayList;
> +import java.util.Iterator;
> +import java.util.List;
> +import java.util.Locale;
> +
>  import org.apache.maven.doxia.Doxia;
> -import org.apache.maven.doxia.module.xdoc.XdocSink;
>  import org.apache.maven.doxia.book.BookDoxiaException;
>  import org.apache.maven.doxia.book.context.BookContext;
>  import org.apache.maven.doxia.book.context.IndexEntry;
>  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.book.services.renderer.xdoc.XdocBookSink;
> +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.editor.io.PipelineSink;
> +import org.apache.maven.doxia.module.HtmlTools;
> +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.codehaus.plexus.i18n.I18N;
>  import org.codehaus.plexus.logging.AbstractLogEnabled;
> -
> -import java.io.FileNotFoundException;
> -import java.io.FileReader;
> -import java.io.FileWriter;
> -import java.io.IOException;
> -import java.io.File;
> -import java.util.ArrayList;
> -import java.util.Iterator;
> -import java.util.List;
> +import org.codehaus.plexus.util.StringUtils;
>  
>  /**
> + * An implementation of <code>BookRenderer</code> for Xdoc
> + *
>   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
> + * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
>   * @version $Id$
>   * @plexus.component role-hint="xdoc"
>   */
> @@ -38,6 +63,11 @@
>       */
>      private Doxia doxia;
>  
> +    /**
> +     * @plexus.requirement
> +     */
> +    private I18N i18n;
> +
>      // ----------------------------------------------------------------------
>      // BookRenderer Implementation
>      // ----------------------------------------------------------------------
> @@ -51,29 +81,50 @@
>          {
>              if ( !context.getOutputDirectory().mkdirs() )
>              {
> -                throw new BookDoxiaException(
> -                    "Could not make directory: " + context.getOutputDirectory().getAbsolutePath() + "." );
> +                throw new BookDoxiaException( "Could not make directory: "
> +                    + context.getOutputDirectory().getAbsolutePath() + "." );
>              }
>          }
>  
> -        // -----------------------------------------------------------------------
> -        //
> -        // -----------------------------------------------------------------------
> -

I like these, they are separators between logical parts of the method.

>          renderBook( book, context );
>      }
>  
>      // -----------------------------------------------------------------------
> +    // Protected
> +    // -----------------------------------------------------------------------
> +
> +    /**
> +     * Gets a trimmed String for the given key from the resource bundle defined by Plexus.
> +     *
> +     * @param key the key for the desired string
> +     * @return the string for the given key
> +     * @throws IllegalArgumentException if the parameter is empty.
> +     */
> +    protected String getString( String key )
> +    {
> +        if ( StringUtils.isEmpty( key ) )
> +        {
> +            throw new IllegalArgumentException( "The key cannot be empty" );
> +        }
> +
> +        // TODO Handle locale
> +        return i18n.getString( "book-renderer", Locale.getDefault(), key ).trim();
> +    }
> +
> +    // -----------------------------------------------------------------------
>      // Private
>      // -----------------------------------------------------------------------
>  
> +    /**
> +     * Render the book, ie the book index and all chapter index
> +     *
> +     * @param book
> +     * @param context
> +     * @throws BookDoxiaException if any
> +     */
>      private void renderBook( BookModel book, BookContext context )
>          throws BookDoxiaException
>      {
> -        // -----------------------------------------------------------------------
> -        // Render the book index.xml page
> -        // -----------------------------------------------------------------------
> -
>          File index = new File( context.getOutputDirectory(), "index.xml" );
>  
>          try
> @@ -86,12 +137,6 @@
>          }
>  
>          // -----------------------------------------------------------------------
> -        // Render the index.html files for each chapter
> -        // -----------------------------------------------------------------------
> -
> -        // TODO: Implement
> -
> -        // -----------------------------------------------------------------------
>          // Render all the chapters
>          // -----------------------------------------------------------------------

Ditto here about the commends. They explain the flow in the code.

> @@ -105,14 +150,20 @@
>          }
>      }
>  
> -    // -----------------------------------------------------------------------
> -    // Index Rendering
> -    // -----------------------------------------------------------------------
> -

I

> +    /**
> +     * Write the book index, ie a TOC
> +     *
> +     * @param index
> +     * @param book
> +     * @param context
> +     * @throws IOException if any
> +     */
>      private void writeBookIndex( File index, BookModel book, BookContext context )
>          throws IOException
>      {

[snip]

> +
> +    /**
> +     * Gets a trimmed String for the given key from the resource bundle defined by Plexus.
> +     *
> +     * @param key the key for the desired string
> +     * @return the string for the given key
> +     * @throws IllegalArgumentException if the parameter is empty.
> +     */
> +    protected String getString( String key )
> +    {
> +        if ( StringUtils.isEmpty( key ) )
> +        {
> +            throw new IllegalArgumentException( "The key cannot be empty" );
> +        }
> +
> +        return i18n.getString( "book-renderer", Locale.getDefault(), key ).trim();
> +    }

This should probably be moved to the i18n component or at least to a 
I18nUtil.

[snip]

--
Trygve