[EMAIL PROTECTED] 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:[EMAIL PROTECTED]">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">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

Reply via email to