maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r591687 [1/2] - in /maven/doxia/doxia/trunk/doxia-modules: doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/ doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/ doxia-module-xhtml/src/test/java/org/apache...
Date Sat, 03 Nov 2007 20:59:15 GMT
Author: ltheussl
Date: Sat Nov  3 13:59:15 2007
New Revision: 591687

URL: http://svn.apache.org/viewvc?rev=591687&view=rev
Log:
Extend new base classes

Modified:
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java?rev=591687&r1=591686&r2=591687&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java Sat Nov  3 13:59:15 2007
@@ -32,10 +32,9 @@
 import org.apache.maven.doxia.macro.MacroExecutionException;
 import org.apache.maven.doxia.macro.manager.MacroNotFoundException;
 import org.apache.maven.doxia.macro.MacroRequest;
-import org.apache.maven.doxia.parser.AbstractXmlParser;
 import org.apache.maven.doxia.parser.ParseException;
+import org.apache.maven.doxia.parser.XhtmlBaseParser;
 import org.apache.maven.doxia.sink.Sink;
-import org.apache.maven.doxia.util.HtmlTools;
 
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
@@ -51,38 +50,24 @@
  * @plexus.component role="org.apache.maven.doxia.parser.Parser" role-hint="xdoc"
  */
 public class XdocParser
-    extends AbstractXmlParser
+    extends XhtmlBaseParser
     implements XdocMarkup
 {
     /** The source content of the input reader. Used to pass into macros. */
     private String sourceContent;
 
-    /** Used to distinguish <a href=""> from <a name="">. */
-    private boolean isLink;
-
-    /** Used to distinguish <a href=""> from <a name="">. */
-    private boolean isAnchor;
-
-    /** True if a <script></script> block is read. CDATA sections within are handles as rawText. */
+    /** True if a <script></script> block is read. CDATA sections within are handled as rawText. */
     private boolean scriptBlock;
 
     /** Empty elements don't write a closing tag. */
     private boolean isEmptyElement;
 
-    /** Used for nested lists. */
-    private int orderedListDepth = 0;
-
     /** A macro name. */
     private String macroName;
 
     /** The macro parameters. */
     private Map macroParameters = new HashMap();
 
-    /** For tables. */
-    private boolean hasCaption;
-
-    /** Counts section level. */
-    private int sectionLevel;
 
     /** {@inheritDoc} */
     public void parse( Reader source, Sink sink )
@@ -119,6 +104,10 @@
             //Do nothing
             return;
         }
+        else if ( parser.getName().equals( Tag.HEAD.toString() ) )
+        {
+            sink.head();
+        }
         else if ( parser.getName().equals( Tag.TITLE.toString() ) )
         {
             sink.title();
@@ -159,171 +148,14 @@
 
             sink.sectionTitle2_();
         }
-        else if ( parser.getName().equals( Tag.H4.toString() ) )
-        {
-            closeOpenSections( Sink.SECTION_LEVEL_3, sink );
-
-            sink.section3();
-
-            sink.sectionTitle3();
-        }
-        else if ( parser.getName().equals( Tag.H5.toString() ) )
-        {
-            closeOpenSections( Sink.SECTION_LEVEL_4, sink );
-
-            sink.section4();
-
-            sink.sectionTitle4();
-        }
-        else if ( parser.getName().equals( Tag.H6.toString() ) )
-        {
-            closeOpenSections( Sink.SECTION_LEVEL_5, sink );
-
-            sink.section5();
-
-            sink.sectionTitle5();
-        }
-        else if ( parser.getName().equals( Tag.P.toString() ) )
-        {
-            sink.paragraph();
-        }
         else if ( parser.getName().equals( SOURCE_TAG.toString() ) )
         {
             sink.verbatim( true );
         }
-        /*
-         * The PRE element tells visual user agents that the enclosed text is
-         * "preformatted". When handling preformatted text, visual user agents:
-         * - May leave white space intact.
-         * - May render text with a fixed-pitch font.
-         * - May disable automatic word wrap.
-         * - Must not disable bidirectional processing.
-         * Non-visual user agents are not required to respect extra white space
-         * in the content of a PRE element.
-         */
-        else if ( parser.getName().equals( Tag.PRE.toString() ) )
-        {
-            sink.verbatim( false );
-        }
-        else if ( parser.getName().equals( Tag.UL.toString() ) )
-        {
-            sink.list();
-        }
-        else if ( parser.getName().equals( Tag.OL.toString() ) )
-        {
-            int numbering = Sink.NUMBERING_DECIMAL;
-
-            // this will have to be generalized if we handle styles
-            String style = parser.getAttributeValue( null, Attribute.STYLE.toString() );
-
-            if ( style != null )
-            {
-                if ( "list-style-type: upper-alpha".equals( style ) )
-                {
-                    numbering = Sink.NUMBERING_UPPER_ALPHA;
-                }
-                else if ( "list-style-type: lower-alpha".equals( style ) )
-                {
-                    numbering = Sink.NUMBERING_LOWER_ALPHA;
-                }
-                else if ( "list-style-type: upper-roman".equals( style ) )
-                {
-                    numbering = Sink.NUMBERING_UPPER_ROMAN;
-                }
-                else if ( "list-style-type: lower-roman".equals( style ) )
-                {
-                    numbering = Sink.NUMBERING_LOWER_ROMAN;
-                }
-                else if ( "list-style-type: decimal".equals( style ) )
-                {
-                    numbering = Sink.NUMBERING_DECIMAL;
-                }
-            }
-
-            sink.numberedList( numbering );
-            orderedListDepth++;
-        }
-        else if ( parser.getName().equals( Tag.LI.toString() ) )
-        {
-            if ( orderedListDepth == 0 )
-            {
-                sink.listItem();
-            }
-            else
-            {
-                sink.numberedListItem();
-            }
-        }
-        else if ( parser.getName().equals( Tag.DL.toString() ) )
-        {
-            sink.definitionList();
-        }
-        else if ( parser.getName().equals( Tag.DT.toString() ) )
-        {
-            sink.definitionListItem();
-            sink.definedTerm();
-        }
-        else if ( parser.getName().equals( Tag.DD.toString() ) )
-        {
-            sink.definition();
-        }
         else if ( parser.getName().equals( PROPERTIES_TAG.toString() ) )
         {
             sink.head();
         }
-        else if ( ( parser.getName().equals( Tag.B.toString() ) ) || ( parser.getName().equals( Tag.STRONG.toString() ) ) )
-        {
-            sink.bold();
-        }
-        else if ( ( parser.getName().equals( Tag.I.toString() ) ) || ( parser.getName().equals( Tag.EM.toString() ) ) )
-        {
-            sink.italic();
-        }
-        else if ( ( parser.getName().equals( Tag.CODE.toString() ) ) || ( parser.getName().equals( Tag.SAMP.toString() ) ) ||
-            ( parser.getName().equals( Tag.TT.toString() ) ) )
-        {
-            sink.monospaced();
-        }
-        else if ( parser.getName().equals( Tag.A.toString() ) )
-        {
-            String href = parser.getAttributeValue( null, Attribute.HREF.toString() );
-
-            if ( href != null )
-            {
-                String link = href;
-
-                if ( link.startsWith( "#" ) )
-                {
-                    link = link.substring( 1 );
-                }
-
-                sink.link( link );
-
-                isLink = true;
-            }
-            else
-            {
-                String name = parser.getAttributeValue( null, Attribute.NAME.toString() );
-
-                if ( name != null )
-                {
-                    sink.anchor( name );
-
-                    isAnchor = true;
-                }
-                else
-                {
-                    String id = parser.getAttributeValue( null, Attribute.ID.toString() );
-
-                    if ( id != null )
-                    {
-                        sink.anchor( id );
-
-                        isAnchor = true;
-                    }
-                }
-            }
-        }
 
         // ----------------------------------------------------------------------
         // Macro
@@ -368,124 +200,16 @@
                 }
             }
         }
-
-        // ----------------------------------------------------------------------
-        // Tables
-        // ----------------------------------------------------------------------
-
-        else if ( parser.getName().equals( Tag.TABLE.toString() ) )
-        {
-            sink.table();
-
-            String border = parser.getAttributeValue( null, Attribute.BORDER.toString() );
-
-            boolean grid = true;
-
-            if ( "0".equals( border ) )
-            {
-                grid = false;
-            }
-
-            String align = parser.getAttributeValue( null, Attribute.ALIGN.toString() );
-
-            int[] justif = { JUSTIFY_CENTER };
-
-            if ( "left".equals( align ) )
-            {
-                justif[0] = JUSTIFY_LEFT;
-            }
-            else if ( "right".equals( align ) )
-            {
-                justif[0] = JUSTIFY_RIGHT;
-            }
-
-            sink.tableRows( justif, grid );
-        }
-        else if ( parser.getName().equals( Tag.TR.toString() ) )
-        {
-            sink.tableRow();
-        }
-        else if ( parser.getName().equals( Tag.TH.toString() ) )
-        {
-            String width = parser.getAttributeValue( null, Attribute.WIDTH.toString() );
-
-            if ( width ==  null )
-            {
-                sink.tableHeaderCell();
-            }
-            else
-            {
-                sink.tableHeaderCell( width );
-            }
-        }
-        else if ( parser.getName().equals( Tag.TD.toString() ) )
-        {
-            String width = parser.getAttributeValue( null, Attribute.WIDTH.toString() );
-
-            if ( width ==  null )
-            {
-                sink.tableCell();
-            }
-            else
-            {
-                sink.tableCell( width );
-            }
-        }
-        else if ( parser.getName().equals( Tag.CAPTION.toString() ) )
-        {
-            sink.tableRows_();
-            this.hasCaption = true;
-            sink.tableCaption();
-        }
-
-        // ----------------------------------------------------------------------
-        // Empty elements: <br/>, <hr/> and <img />
-        // ----------------------------------------------------------------------
-
-        else if ( parser.getName().equals( Tag.BR.toString() ) )
-        {
-            sink.lineBreak();
-        }
-        else if ( parser.getName().equals( Tag.HR.toString() ) )
-        {
-            sink.horizontalRule();
-        }
-        else if ( parser.getName().equals( Tag.IMG.toString() ) )
-        {
-            String src = parser.getAttributeValue( null, Attribute.SRC.toString() );
-            String title = parser.getAttributeValue( null, Attribute.TITLE.toString() );
-            String alt = parser.getAttributeValue( null, Attribute.ALT.toString() );
-
-            sink.figure();
-
-            if ( src != null )
-            {
-                sink.figureGraphics( src );
-            }
-
-            if ( title != null )
-            {
-                sink.figureCaption();
-                sink.text( title );
-                sink.figureCaption_();
-            }
-            else if ( alt != null )
-            {
-                sink.figureCaption();
-                sink.text( alt );
-                sink.figureCaption_();
-            }
-
-            sink.figure_();
-        }
         else if ( parser.getName().equals( Tag.SCRIPT.toString() ) )
         {
             handleRawText( sink, parser );
             scriptBlock = true;
         }
-        else
+        else if ( !baseStartTag( parser, sink ) )
         {
+            // TODO: remove
             handleRawText( sink, parser );
+            // TODO: log( "Unrecognized tag!" );
         }
     }
 
@@ -498,17 +222,9 @@
             //Do nothing
             return;
         }
-        else if ( parser.getName().equals( Tag.TITLE.toString() ) )
-        {
-            sink.title_();
-        }
-        else if ( parser.getName().equals( AUTHOR_TAG.toString() ) )
+        else if ( parser.getName().equals( Tag.HEAD.toString() ) )
         {
-            sink.author_();
-        }
-        else if ( parser.getName().equals( DATE_TAG.toString() ) )
-        {
-            sink.date_();
+            sink.head_();
         }
         else if ( parser.getName().equals( Tag.BODY.toString() ) )
         {
@@ -516,83 +232,26 @@
 
             sink.body_();
         }
-        else if ( parser.getName().equals( Tag.P.toString() ) )
-        {
-            sink.paragraph_();
-        }
-        else if ( parser.getName().equals( SOURCE_TAG.toString() ) )
-        {
-            sink.verbatim_();
-        }
-        else if ( parser.getName().equals( Tag.PRE.toString() ) )
-        {
-            sink.verbatim_();
-        }
-        else if ( parser.getName().equals( Tag.UL.toString() ) )
-        {
-            sink.list_();
-        }
-        else if ( parser.getName().equals( Tag.OL.toString() ) )
-        {
-            sink.numberedList_();
-            orderedListDepth--;
-        }
-        else if ( parser.getName().equals( Tag.LI.toString() ) )
+        else if ( parser.getName().equals( Tag.TITLE.toString() ) )
         {
-            if ( orderedListDepth == 0 )
-            {
-                sink.listItem_();
-            }
-            else
-            {
-                sink.numberedListItem_();
-            }
+            sink.title_();
         }
-        else if ( parser.getName().equals( Tag.DL.toString() ) )
+        else if ( parser.getName().equals( AUTHOR_TAG.toString() ) )
         {
-            sink.definitionList_();
+            sink.author_();
         }
-        else if ( parser.getName().equals( Tag.DT.toString() ) )
+        else if ( parser.getName().equals( DATE_TAG.toString() ) )
         {
-            sink.definedTerm_();
+            sink.date_();
         }
-        else if ( parser.getName().equals( Tag.DD.toString() ) )
+        else if ( parser.getName().equals( SOURCE_TAG.toString() ) )
         {
-            sink.definition_();
-            sink.definitionListItem_();
+            sink.verbatim_();
         }
         else if ( parser.getName().equals( PROPERTIES_TAG.toString() ) )
         {
             sink.head_();
         }
-        else if ( ( parser.getName().equals( Tag.B.toString() ) ) || ( parser.getName().equals( Tag.STRONG.toString() ) ) )
-        {
-            sink.bold_();
-        }
-        else if ( ( parser.getName().equals( Tag.I.toString() ) ) || ( parser.getName().equals( Tag.EM.toString() ) ) )
-        {
-            sink.italic_();
-        }
-        else if ( ( parser.getName().equals( Tag.CODE.toString() ) ) || ( parser.getName().equals( Tag.SAMP.toString() ) ) ||
-            ( parser.getName().equals( Tag.TT.toString() ) ) )
-        {
-            sink.monospaced_();
-        }
-        else if ( parser.getName().equals( Tag.A.toString() ) )
-        {
-            if ( isLink )
-            {
-                sink.link_();
-
-                isLink = false;
-            }
-            else if ( isAnchor )
-            {
-                sink.anchor_();
-
-                isAnchor = false;
-            }
-        }
 
         // ----------------------------------------------------------------------
         // Macro
@@ -632,38 +291,6 @@
         {
             // do nothing
         }
-
-        // ----------------------------------------------------------------------
-        // Tables
-        // ----------------------------------------------------------------------
-
-        else if ( parser.getName().equals( Tag.TABLE.toString() ) )
-        {
-            if ( !hasCaption )
-            {
-                sink.tableRows_();
-            }
-
-            this.hasCaption = false;
-
-            sink.table_();
-        }
-        else if ( parser.getName().equals( Tag.TR.toString() ) )
-        {
-            sink.tableRow_();
-        }
-        else if ( parser.getName().equals( Tag.TH.toString() ) )
-        {
-            sink.tableHeaderCell_();
-        }
-        else if ( parser.getName().equals( Tag.TD.toString() ) )
-        {
-            sink.tableCell_();
-        }
-        else if ( parser.getName().equals( Tag.CAPTION.toString() ) )
-        {
-            sink.tableCaption_();
-        }
         else if ( parser.getName().equals( SECTION_TAG.toString() ) )
         {
             closeOpenSections( 0, sink );
@@ -676,18 +303,6 @@
 
             sink.section2_();
         }
-        else if ( parser.getName().equals( Tag.H4.toString() ) )
-        {
-            sink.sectionTitle3_();
-        }
-        else if ( parser.getName().equals( Tag.H5.toString() ) )
-        {
-            sink.sectionTitle4_();
-        }
-        else if ( parser.getName().equals( Tag.H6.toString() ) )
-        {
-            sink.sectionTitle5_();
-        }
         else if ( parser.getName().equals( Tag.SCRIPT.toString() ) )
         {
             // TODO: this is HTML specific, factor out into a specialized parser
@@ -700,36 +315,21 @@
 
             scriptBlock = false;
         }
-        else if ( !isEmptyElement )
-        {
-            // TODO: this is HTML specific, factor out into a specialized parser
-
-            sink.rawText( String.valueOf( LESS_THAN ) + String.valueOf( SLASH ) );
-
-            sink.rawText( parser.getName() );
-
-            sink.rawText( String.valueOf( GREATER_THAN ) );
-        }
-        else
+        else if ( !baseEndTag( parser, sink ) )
         {
-            isEmptyElement = false;
-        }
-    }
+            if ( !isEmptyElement )
+            {
+                // TODO: this is HTML specific, factor out into a specialized parser
 
-    /** {@inheritDoc} */
-    protected void handleText( XmlPullParser parser, Sink sink )
-        throws XmlPullParserException
-    {
-        String text = parser.getText();
+                sink.rawText( String.valueOf( LESS_THAN ) + String.valueOf( SLASH ) );
 
-        if ( StringUtils.isNotEmpty( text.trim() ) )
-        {
-            // emit separate text events for different lines
-            String[] lines = StringUtils.split( text, EOL );
+                sink.rawText( parser.getName() );
 
-            for ( int i = 0; i < lines.length; i++ )
+                sink.rawText( String.valueOf( GREATER_THAN ) );
+            }
+            else
             {
-                sink.text( lines[i] );
+                isEmptyElement = false;
             }
         }
     }
@@ -750,40 +350,33 @@
         }
     }
 
-    /** {@inheritDoc} */
-    protected void handleComment( XmlPullParser parser, Sink sink )
-        throws XmlPullParserException
+    /**
+     * Close open h4, h5, h6 sections. The current level is set to newLevel afterwards.
+     *
+     * @param newLevel the new section level, all upper levels have to be closed.
+     * @param sink the sink to receive the events.
+     */
+    protected void closeOpenSections( int newLevel, Sink sink )
     {
-        String text = parser.getText();
-
-        if ( "PB".equals( text.trim() ) )
-        {
-            sink.pageBreak();
-        }
-        else
+        while ( getSectionLevel() >= newLevel )
         {
-            sink.comment( text.trim() );
-        }
-    }
-
-    /** {@inheritDoc} */
-    protected void handleEntity( XmlPullParser parser, Sink sink )
-        throws XmlPullParserException
-    {
-        String text = parser.getText();
-
-        int[] holder = new int[] {0, 0};
-        char[] chars = parser.getTextCharacters( holder );
-        String textChars = String.valueOf( chars, holder[0], holder[1] );
+            if ( getSectionLevel() == Sink.SECTION_LEVEL_5)
+            {
+                sink.section5_();
+            }
+            else if ( getSectionLevel() == Sink.SECTION_LEVEL_4)
+            {
+                sink.section4_();
+            }
+            else if ( getSectionLevel() == Sink.SECTION_LEVEL_3)
+            {
+                sink.section3_();
+            }
 
-        if ( "#160".equals( textChars ) )
-        {
-            sink.nonBreakingSpace();
-        }
-        else
-        {
-            sink.text( text );
+            setSectionLevel( getSectionLevel() - 1 );
         }
+
+        setSectionLevel( newLevel );
     }
 
     // ----------------------------------------------------------------------
@@ -821,35 +414,6 @@
         }
 
         sink.rawText( String.valueOf( GREATER_THAN ) );
-    }
-
-    /**
-     * Close open h4, h5, h6 sections. The current level is set to newLevel afterwards.
-     *
-     * @param newLevel the new section level, all upper levels have to be closed.
-     * @param sink the sink to receive the events.
-     */
-    private void closeOpenSections( int newLevel, Sink sink )
-    {
-        while ( this.sectionLevel >= newLevel )
-        {
-            if ( sectionLevel == Sink.SECTION_LEVEL_5)
-            {
-                sink.section5_();
-            }
-            else if ( sectionLevel == Sink.SECTION_LEVEL_4)
-            {
-                sink.section4_();
-            }
-            else if ( sectionLevel == Sink.SECTION_LEVEL_3)
-            {
-                sink.section3_();
-            }
-
-            this.sectionLevel--;
-        }
-
-        this.sectionLevel = newLevel;
     }
 
 }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java?rev=591687&r1=591686&r2=591687&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java Sat Nov  3 13:59:15 2007
@@ -19,7 +19,6 @@
  * under the License.
  */
 
-import java.io.PrintWriter;
 import java.io.Writer;
 
 import javax.swing.text.MutableAttributeSet;
@@ -27,9 +26,8 @@
 import javax.swing.text.html.HTML.Attribute;
 import javax.swing.text.html.HTML.Tag;
 
-import org.apache.maven.doxia.parser.Parser;
-import org.apache.maven.doxia.sink.AbstractXmlSink;
 import org.apache.maven.doxia.sink.StructureSink;
+import org.apache.maven.doxia.sink.XhtmlBaseSink;
 import org.apache.maven.doxia.util.HtmlTools;
 
 /**
@@ -41,46 +39,28 @@
  * @plexus.component role="org.apache.maven.doxia.sink.Sink" role-hint="xdoc"
  */
 public class XdocSink
-    extends AbstractXmlSink
+    extends XhtmlBaseSink
     implements XdocMarkup
 {
     // ----------------------------------------------------------------------
     // Instance fields
     // ----------------------------------------------------------------------
 
-    /** The PrintWriter to write the result. */
-    private PrintWriter writer;
-
-    /** Used to collect text events. */
-    private StringBuffer buffer = new StringBuffer();
-
-    /** An indication on if we're inside a head. */
-    private boolean headFlag;
-
     /** An indication on if we're inside a box (verbatim). */
     private boolean boxedFlag;
 
-    /** An indication on if we're in verbatim mode. */
-    private boolean verbatimFlag;
-
-    /** Justification of table cells. */
-    private int[] cellJustif;
-
-    /** Number of cells in a table row. */
-    private int cellCount;
-
     // ----------------------------------------------------------------------
-    //
+    // Constructors
     // ----------------------------------------------------------------------
 
     /**
-     * Constructor, initialize the PrintWriter.
+     * Constructor, initialize the Writer.
      *
      * @param writer The writer to write the result.
      */
     public XdocSink( Writer writer )
     {
-        this.writer = new PrintWriter( writer );
+        super( writer );
     }
 
     // ----------------------------------------------------------------------
@@ -88,40 +68,12 @@
     // ----------------------------------------------------------------------
 
     /**
-     * @return the current buffer
-     */
-    protected StringBuffer getBuffer()
-    {
-        return buffer;
-    }
-
-    /**
-     * @param headFlag an header flag
-     */
-    protected void setHeadFlag( boolean headFlag )
-    {
-        this.headFlag = headFlag;
-    }
-
-    /**
      * Reset all variables.
      */
     protected void resetState()
     {
-        headFlag = false;
-        resetBuffer();
+        super.resetState();
         boxedFlag = false;
-        verbatimFlag = false;
-        cellJustif = null;
-        cellCount = 0;
-    }
-
-    /**
-     * Reset the buffer.
-     */
-    protected void resetBuffer()
-    {
-        buffer = new StringBuffer();
     }
 
     /**
@@ -133,7 +85,7 @@
     {
         resetState();
 
-        headFlag = true;
+        setHeadFlag( true );
 
         write( "<?xml version=\"1.0\" ?>" + EOL );
 
@@ -149,7 +101,7 @@
      */
     public void head_()
     {
-        headFlag = false;
+        setHeadFlag( false );
 
         writeEndTag( PROPERTIES_TAG );
     }
@@ -169,7 +121,7 @@
      */
     public void title_()
     {
-        content( buffer.toString() );
+        content( getBuffer().toString() );
 
         writeEndTag( Tag.TITLE );
 
@@ -182,10 +134,10 @@
      */
     public void author_()
     {
-        if ( buffer.length() > 0 )
+        if ( getBuffer().length() > 0 )
         {
             writeStartTag( AUTHOR_TAG );
-            content( buffer.toString() );
+            content( getBuffer().toString() );
             writeEndTag( AUTHOR_TAG );
             resetBuffer();
         }
@@ -197,10 +149,10 @@
      */
     public void date_()
     {
-        if ( buffer.length() > 0 )
+        if ( getBuffer().length() > 0 )
         {
             writeStartTag( DATE_TAG );
-            content( buffer.toString() );
+            content( getBuffer().toString() );
             writeEndTag( DATE_TAG );
             resetBuffer();
         }
@@ -235,126 +187,6 @@
     // Sections
     // ----------------------------------------------------------------------
 
-    /** {@inheritDoc} */
-    public void section1()
-    {
-        onSection( SECTION_LEVEL_1 );
-    }
-
-    /** {@inheritDoc} */
-    public void sectionTitle1()
-    {
-        onSectionTitle( SECTION_LEVEL_1 );
-    }
-
-    /** {@inheritDoc} */
-    public void sectionTitle1_()
-    {
-        onSectionTitle_( SECTION_LEVEL_1 );
-    }
-
-    /** {@inheritDoc} */
-    public void section1_()
-    {
-        onSection_( SECTION_LEVEL_1 );
-    }
-
-    /** {@inheritDoc} */
-    public void section2()
-    {
-        onSection( SECTION_LEVEL_2 );
-    }
-
-    /** {@inheritDoc} */
-    public void sectionTitle2()
-    {
-        onSectionTitle( SECTION_LEVEL_2 );
-    }
-
-    /** {@inheritDoc} */
-    public void sectionTitle2_()
-    {
-        onSectionTitle_( SECTION_LEVEL_2 );
-    }
-
-    /** {@inheritDoc} */
-    public void section2_()
-    {
-        onSection_( SECTION_LEVEL_2 );
-    }
-
-    /** {@inheritDoc} */
-    public void section3()
-    {
-        onSection( SECTION_LEVEL_3 );
-    }
-
-    /** {@inheritDoc} */
-    public void sectionTitle3()
-    {
-        onSectionTitle( SECTION_LEVEL_3 );
-    }
-
-    /** {@inheritDoc} */
-    public void sectionTitle3_()
-    {
-        onSectionTitle_( SECTION_LEVEL_3 );
-    }
-
-    /** {@inheritDoc} */
-    public void section3_()
-    {
-        onSection_( SECTION_LEVEL_3 );
-    }
-
-    /** {@inheritDoc} */
-    public void section4()
-    {
-        onSection( SECTION_LEVEL_4 );
-    }
-
-    /** {@inheritDoc} */
-    public void sectionTitle4()
-    {
-        onSectionTitle( SECTION_LEVEL_4 );
-    }
-
-    /** {@inheritDoc} */
-    public void sectionTitle4_()
-    {
-        onSectionTitle_( SECTION_LEVEL_4 );
-    }
-
-    /** {@inheritDoc} */
-    public void section4_()
-    {
-        onSection_( SECTION_LEVEL_4 );
-    }
-
-    /** {@inheritDoc} */
-    public void section5()
-    {
-        onSection( SECTION_LEVEL_5 );
-    }
-
-    /** {@inheritDoc} */
-    public void sectionTitle5()
-    {
-        onSectionTitle( SECTION_LEVEL_5 );
-    }
-
-    /** {@inheritDoc} */
-    public void sectionTitle5_()
-    {
-        onSectionTitle_( SECTION_LEVEL_5 );
-    }
-
-    /** {@inheritDoc} */
-    public void section5_()
-    {
-        onSection_( SECTION_LEVEL_5 );
-    }
-
     /**
      * Starts a section.
      *
@@ -362,7 +194,7 @@
      * @see XdocMarkup#SECTION_TAG
      * @see XdocMarkup#SUBSECTION_TAG
      */
-    private void onSection( int depth )
+    protected void onSection( int depth )
     {
         if ( depth == SECTION_LEVEL_1 )
         {
@@ -383,7 +215,7 @@
      * @see XdocMarkup#SECTION_TAG
      * @see XdocMarkup#SUBSECTION_TAG
      */
-    private void onSection_( int depth )
+    protected void onSection_( int depth )
     {
         if ( depth == SECTION_LEVEL_1 )
         {
@@ -403,7 +235,7 @@
      * @see javax.swing.text.html.HTML.Tag#H5
      * @see javax.swing.text.html.HTML.Tag#H6
      */
-    private void onSectionTitle( int depth )
+    protected void onSectionTitle( int depth )
     {
         if ( depth == SECTION_LEVEL_3 )
         {
@@ -427,7 +259,7 @@
      * @see javax.swing.text.html.HTML.Tag#H5
      * @see javax.swing.text.html.HTML.Tag#H6
      */
-    private void onSectionTitle_( int depth )
+    protected void onSectionTitle_( int depth )
     {
         if ( depth == SECTION_LEVEL_1 || depth == SECTION_LEVEL_2 )
         {
@@ -453,215 +285,12 @@
 
     /**
      * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#UL
-     */
-    public void list()
-    {
-        writeStartTag( Tag.UL );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#UL
-     */
-    public void list_()
-    {
-        writeEndTag( Tag.UL );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#LI
-     */
-    public void listItem()
-    {
-        writeStartTag( Tag.LI );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#LI
-     */
-    public void listItem_()
-    {
-        writeEndTag( Tag.LI );
-    }
-
-    /**
-     * The default list style depends on the numbering.
-     *
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#OL
-     */
-    public void numberedList( int numbering )
-    {
-        String style;
-        switch ( numbering )
-        {
-            case NUMBERING_UPPER_ALPHA:
-                style = "upper-alpha";
-                break;
-            case NUMBERING_LOWER_ALPHA:
-                style = "lower-alpha";
-                break;
-            case NUMBERING_UPPER_ROMAN:
-                style = "upper-roman";
-                break;
-            case NUMBERING_LOWER_ROMAN:
-                style = "lower-roman";
-                break;
-            case NUMBERING_DECIMAL:
-            default:
-                style = "decimal";
-        }
-
-        MutableAttributeSet att = new SimpleAttributeSet();
-        att.addAttribute( Attribute.STYLE, "list-style-type: " + style );
-
-        writeStartTag( Tag.OL, att );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#OL
-     */
-    public void numberedList_()
-    {
-        writeEndTag( Tag.OL );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#LI
-     */
-    public void numberedListItem()
-    {
-        writeStartTag( Tag.LI );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#LI
-     */
-    public void numberedListItem_()
-    {
-        writeEndTag( Tag.LI );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#DL
-     */
-    public void definitionList()
-    {
-        writeStartTag( Tag.DL );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#DL
-     */
-    public void definitionList_()
-    {
-        writeEndTag( Tag.DL );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#DT
-     */
-    public void definedTerm()
-    {
-        writeStartTag( Tag.DT );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#DT
-     */
-    public void definedTerm_()
-    {
-        writeEndTag( Tag.DT );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#DD
-     */
-    public void definition()
-    {
-        writeStartTag( Tag.DD );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#DD
-     */
-    public void definition_()
-    {
-        writeEndTag( Tag.DD );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#IMG
-     */
-    public void figure()
-    {
-        write( String.valueOf( LESS_THAN ) + Tag.IMG );
-    }
-
-    /** {@inheritDoc} */
-    public void figure_()
-    {
-        write( String.valueOf( SPACE ) + String.valueOf( SLASH ) + String.valueOf( GREATER_THAN ) );
-    }
-
-    /** {@inheritDoc} */
-    public void figureGraphics( String name )
-    {
-        write( String.valueOf( SPACE ) + Attribute.SRC + String.valueOf( EQUAL ) + String.valueOf( QUOTE ) + name
-            + String.valueOf( QUOTE ) );
-    }
-
-    /** {@inheritDoc} */
-    public void figureCaption()
-    {
-        write( String.valueOf( SPACE ) + Attribute.ALT + String.valueOf( EQUAL ) + String.valueOf( QUOTE ) );
-    }
-
-    /** {@inheritDoc} */
-    public void figureCaption_()
-    {
-        write( String.valueOf( QUOTE ) );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#P
-     */
-    public void paragraph()
-    {
-        writeStartTag( Tag.P );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#P
-     */
-    public void paragraph_()
-    {
-        writeEndTag( Tag.P );
-    }
-
-    /**
-     * {@inheritDoc}
      * @see XdocMarkup#SOURCE_TAG
      * @see javax.swing.text.html.HTML.Tag#PRE
      */
     public void verbatim( boolean boxed )
     {
-        verbatimFlag = true;
+        setVerbatimFlag( true );
 
         boxedFlag = boxed;
 
@@ -691,41 +320,12 @@
             writeEndTag( Tag.PRE );
         }
 
-        verbatimFlag = false;
+        setVerbatimFlag( false );
 
         boxedFlag = false;
     }
 
     /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#HR
-     */
-    public void horizontalRule()
-    {
-        writeSimpleTag( Tag.HR );
-    }
-
-    /**
-     * The default align is <code>center</code>.
-     *
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#TABLE
-     */
-    public void table()
-    {
-        // start table with tableRows
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#TABLE
-     */
-    public void table_()
-    {
-        writeEndTag( Tag.TABLE );
-    }
-
-    /**
      * The default align is <code>center</code>.
      *
      * {@inheritDoc}
@@ -733,7 +333,7 @@
      */
     public void tableRows( int[] justification, boolean grid )
     {
-        this.cellJustif = justification;
+        setCellJustif( justification );
 
         MutableAttributeSet att = new SimpleAttributeSet();
         att.addAttribute( Attribute.ALIGN, "center" );
@@ -743,15 +343,6 @@
     }
 
     /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#TABLE
-     */
-    public void tableRows_()
-    {
-        // nop
-    }
-
-    /**
      * The default valign is <code>top</code>.
      *
      * {@inheritDoc}
@@ -763,194 +354,30 @@
         att.addAttribute( Attribute.VALIGN, "top" );
 
         writeStartTag( Tag.TR, att );
-        cellCount = 0;
-    }
 
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#TR
-     */
-    public void tableRow_()
-    {
-        writeEndTag( Tag.TR );
-
-        cellCount = 0;
-    }
-
-    /** {@inheritDoc} */
-    public void tableCell()
-    {
-        tableCell( false );
-    }
-
-    /** {@inheritDoc} */
-    public void tableHeaderCell()
-    {
-        tableCell( true );
+        setCellCount( 0 );
     }
 
     /**
-     * Starts a table cell.
+     * Adds a link with an optional target.
      *
-     * @param headerRow true if it is an header row
-     * @see javax.swing.text.html.HTML.Tag#TH
-     * @see javax.swing.text.html.HTML.Tag#TD
+     * @param name the link name.
+     * @param target the link target, may be null.
      */
-    public void tableCell( boolean headerRow )
-    {
-        tableCell( headerRow, null );
-    }
-
-    /** {@inheritDoc} */
-    public void tableCell( String width )
+    public void link( String name, String target )
     {
-        tableCell( false, width );
-    }
-
-    /** {@inheritDoc} */
-    public void tableHeaderCell( String width )
-    {
-        tableCell( true, width );
-    }
-
-    /**
-     * @param headerRow true if it is an header row
-     * @param width the cell size
-     * @see javax.swing.text.html.HTML.Tag#TH
-     * @see javax.swing.text.html.HTML.Tag#TD
-     */
-    public void tableCell( boolean headerRow, String width )
-    {
-        String justif = null;
-
-        if ( cellJustif != null )
-        {
-            switch ( cellJustif[cellCount] )
-            {
-                case Parser.JUSTIFY_LEFT:
-                    justif = "left";
-                    break;
-                case Parser.JUSTIFY_RIGHT:
-                    justif = "right";
-                    break;
-                case Parser.JUSTIFY_CENTER:
-                default:
-                    justif = "center";
-                    break;
-            }
-        }
-
-
-        Tag t = ( headerRow ? Tag.TH : Tag.TD );
-
-        MutableAttributeSet att = new SimpleAttributeSet();
-
-        if ( width != null )
-        {
-            att.addAttribute( Attribute.WIDTH, width );
-        }
-
-        if ( justif != null )
+        if ( isHeadFlag() )
         {
-            att.addAttribute( Attribute.ALIGN, justif );
-        }
-
-        writeStartTag( t, att );
-    }
-
-    /** {@inheritDoc} */
-    public void tableCell_()
-    {
-        tableCell_( false );
-    }
-
-    /** {@inheritDoc} */
-    public void tableHeaderCell_()
-    {
-        tableCell_( true );
-    }
-
-    /**
-     * Ends a table cell.
-     *
-     * @param headerRow true if it is an header row
-     * @see javax.swing.text.html.HTML.Tag#TH
-     * @see javax.swing.text.html.HTML.Tag#TD
-     */
-    public void tableCell_( boolean headerRow )
-    {
-        Tag t = ( headerRow ? Tag.TH : Tag.TD );
-
-        writeEndTag( t );
-
-        ++cellCount;
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#CAPTION
-     */
-    public void tableCaption()
-    {
-        // TODO: tableCaption should be written before tableRows
-        writeStartTag( Tag.CAPTION );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#CAPTION
-     */
-    public void tableCaption_()
-    {
-        writeEndTag( Tag.CAPTION );
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#A
-     */
-    public void anchor( String name )
-    {
-        if ( !headFlag )
-        {
-            String id = HtmlTools.encodeId( name );
-
-            MutableAttributeSet att = new SimpleAttributeSet();
-
-            if ( id != null )
-            {
-                att.addAttribute( Attribute.NAME, id );
-            }
-
-            writeStartTag( Tag.A, att );
+            return;
         }
-    }
 
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#A
-     */
-    public void anchor_()
-    {
-        if ( !headFlag )
-        {
-            writeEndTag( Tag.A );
-        }
-    }
+        MutableAttributeSet att = new SimpleAttributeSet();
 
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#A
-     */
-    public void link( String name )
-    {
-        if ( headFlag )
+        if ( target != null )
         {
-            return;
+            att.addAttribute( Attribute.TARGET, target );
         }
 
-        MutableAttributeSet att = new SimpleAttributeSet();
-
         if ( StructureSink.isExternalLink( name ) || isExternalHtml( name ) )
         {
             att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name ) );
@@ -976,174 +403,6 @@
             || !HtmlTools.isId( text ) );
     }
 
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#A
-     */
-    public void link_()
-    {
-        if ( !headFlag )
-        {
-            writeEndTag( Tag.A );
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#I
-     */
-    public void italic()
-    {
-        if ( !headFlag )
-        {
-            writeStartTag( Tag.I );
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#I
-     */
-    public void italic_()
-    {
-        if ( !headFlag )
-        {
-            writeEndTag( Tag.I );
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#B
-     */
-    public void bold()
-    {
-        if ( !headFlag )
-        {
-            writeStartTag( Tag.B );
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#B
-     */
-    public void bold_()
-    {
-        if ( !headFlag )
-        {
-            writeEndTag( Tag.B );
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#TT
-     */
-    public void monospaced()
-    {
-        if ( !headFlag )
-        {
-            writeStartTag( Tag.TT );
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#TT
-     */
-    public void monospaced_()
-    {
-        if ( !headFlag )
-        {
-            writeEndTag( Tag.TT );
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     * @see javax.swing.text.html.HTML.Tag#BR
-     */
-    public void lineBreak()
-    {
-        if ( headFlag )
-        {
-            buffer.append( EOL );
-        }
-        else
-        {
-            writeSimpleTag( Tag.BR );
-        }
-    }
-
-    /** {@inheritDoc} */
-    public void pageBreak()
-    {
-        comment( "PB" );
-    }
-
-    /** {@inheritDoc} */
-    public void nonBreakingSpace()
-    {
-        if ( headFlag )
-        {
-            buffer.append( ' ' );
-        }
-        else
-        {
-            write( "&#160;" );
-        }
-    }
-
-    /** {@inheritDoc} */
-    public void text( String text )
-    {
-        if ( headFlag )
-        {
-            buffer.append( text );
-        }
-        else if ( verbatimFlag )
-        {
-            verbatimContent( text );
-        }
-        else
-        {
-            content( text );
-        }
-    }
-
-    /** {@inheritDoc} */
-    public void rawText( String text )
-    {
-        write( text );
-    }
-
-    /** {@inheritDoc} */
-    public void comment( String comment )
-    {
-        StringBuffer buffer = new StringBuffer( comment.length() + 9 );
-
-        buffer.append( LESS_THAN ).append( BANG ).append( MINUS ).append( MINUS ).append( SPACE );
-
-        buffer.append( comment );
-
-        buffer.append( SPACE ).append( MINUS ).append( MINUS ).append( GREATER_THAN );
-
-        rawText( buffer.toString() );
-    }
-
-    /** {@inheritDoc} */
-    public void flush()
-    {
-        writer.flush();
-    }
-
-    /** {@inheritDoc} */
-    public void close()
-    {
-        writer.close();
-    }
-
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
@@ -1157,55 +416,5 @@
     protected void markup( String text )
     {
         write( text );
-    }
-
-    /**
-     * Write HTML escaped text to output.
-     *
-     * @param text The text to write.
-     */
-    protected void content( String text )
-    {
-        write( escapeHTML( text ) );
-    }
-
-    /**
-     * Write HTML escaped text to output.
-     *
-     * @param text The text to write.
-     */
-    protected void verbatimContent( String text )
-    {
-        write( escapeHTML( text ) );
-    }
-
-    /**
-     * Forward to HtmlTools.escapeHTML( text ).
-     *
-     * @param text the String to escape, may be null
-     * @return the text escaped, "" if null String input
-     * @see org.apache.maven.doxia.util.HtmlTools#escapeHTML(String)
-     */
-    public static String escapeHTML( String text )
-    {
-        return HtmlTools.escapeHTML( text );
-    }
-
-    /**
-     * Forward to HtmlTools.encodeURL( text ).
-     *
-     * @param text the String to encode, may be null.
-     * @return the text encoded, null if null String input.
-     * @see org.apache.maven.doxia.util.HtmlTools#encodeURL(String)
-     */
-    public static String encodeURL( String text )
-    {
-        return HtmlTools.encodeURL( text );
-    }
-
-    /** {@inheritDoc} */
-    protected void write( String text )
-    {
-        writer.write( text );
     }
 }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java?rev=591687&r1=591686&r2=591687&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java Sat Nov  3 13:59:15 2007
@@ -23,14 +23,14 @@
 import javax.swing.text.html.HTML.Tag;
 
 import org.apache.maven.doxia.macro.MacroExecutionException;
-import org.apache.maven.doxia.parser.AbstractXmlParser;
+import org.apache.maven.doxia.parser.XhtmlBaseParser;
 import org.apache.maven.doxia.sink.Sink;
-import org.codehaus.plexus.util.StringUtils;
+
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 /**
- * Parse an xhtml model and emit events into the specified doxia Sink.
+ * Parse an xhtml model and emit events into a Doxia Sink.
  *
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
  * @version $Id$
@@ -38,24 +38,9 @@
  * @plexus.component role="org.apache.maven.doxia.parser.Parser" role-hint="xhtml"
  */
 public class XhtmlParser
-    extends AbstractXmlParser
+    extends XhtmlBaseParser
     implements XhtmlMarkup
 {
-    /** Used to distinguish <a href=""> from <a name="">. */
-    private boolean isLink;
-
-    /** Used to distinguish <a href=""> from <a name="">. */
-    private boolean isAnchor;
-
-    /** Used for nested lists. */
-    private int orderedListDepth = 0;
-
-    /** For tables. */
-    private boolean hasCaption;
-
-    /** Counts section level. */
-    private int sectionLevel;
-
     /** For boxed verbatim. */
     private boolean boxed;
 
@@ -68,6 +53,10 @@
             //Do nothing
             return;
         }
+        else if ( parser.getName().equals( Tag.HEAD.toString() ) )
+        {
+            sink.head();
+        }
         else if ( parser.getName().equals( Tag.TITLE.toString() ) )
         {
             sink.title();
@@ -108,50 +97,6 @@
         {
             sink.body();
         }
-        else if ( parser.getName().equals( Tag.H2.toString() ) )
-        {
-            closeOpenSections( Sink.SECTION_LEVEL_1, sink );
-
-            sink.section1();
-
-            sink.sectionTitle1();
-        }
-        else if ( parser.getName().equals( Tag.H3.toString() ) )
-        {
-            closeOpenSections( Sink.SECTION_LEVEL_2, sink );
-
-            sink.section2();
-
-            sink.sectionTitle2();
-        }
-        else if ( parser.getName().equals( Tag.H4.toString() ) )
-        {
-            closeOpenSections( Sink.SECTION_LEVEL_3, sink );
-
-            sink.section3();
-
-            sink.sectionTitle3();
-        }
-        else if ( parser.getName().equals( Tag.H5.toString() ) )
-        {
-            closeOpenSections( Sink.SECTION_LEVEL_4, sink );
-
-            sink.section4();
-
-            sink.sectionTitle4();
-        }
-        else if ( parser.getName().equals( Tag.H6.toString() ) )
-        {
-            closeOpenSections( Sink.SECTION_LEVEL_5, sink );
-
-            sink.section5();
-
-            sink.sectionTitle5();
-        }
-        else if ( parser.getName().equals( Tag.P.toString() ) )
-        {
-            sink.paragraph();
-        }
         else if ( parser.getName().equals( Tag.DIV.toString() ) )
         {
             String divclass = parser.getAttributeValue( null, Attribute.CLASS.toString() );
@@ -182,234 +127,9 @@
                 sink.verbatim( false );
             }
         }
-        else if ( parser.getName().equals( Tag.UL.toString() ) )
+        else if ( !baseStartTag( parser, sink ) )
         {
-            sink.list();
-        }
-        else if ( parser.getName().equals( Tag.OL.toString() ) )
-        {
-            int numbering = Sink.NUMBERING_DECIMAL;
-
-            // this will have to be generalized if we handle styles
-            String style = parser.getAttributeValue( null, Attribute.STYLE.toString() );
-
-            if ( style != null )
-            {
-                if ( "list-style-type: upper-alpha".equals( style ) )
-                {
-                    numbering = Sink.NUMBERING_UPPER_ALPHA;
-                }
-                else if ( "list-style-type: lower-alpha".equals( style ) )
-                {
-                    numbering = Sink.NUMBERING_LOWER_ALPHA;
-                }
-                else if ( "list-style-type: upper-roman".equals( style ) )
-                {
-                    numbering = Sink.NUMBERING_UPPER_ROMAN;
-                }
-                else if ( "list-style-type: lower-roman".equals( style ) )
-                {
-                    numbering = Sink.NUMBERING_LOWER_ROMAN;
-                }
-                else if ( "list-style-type: decimal".equals( style ) )
-                {
-                    numbering = Sink.NUMBERING_DECIMAL;
-                }
-            }
-
-            sink.numberedList( numbering );
-            orderedListDepth++;
-        }
-        else if ( parser.getName().equals( Tag.LI.toString() ) )
-        {
-            if ( orderedListDepth == 0 )
-            {
-                sink.listItem();
-            }
-            else
-            {
-                sink.numberedListItem();
-            }
-        }
-        else if ( parser.getName().equals( Tag.DL.toString() ) )
-        {
-            sink.definitionList();
-        }
-        else if ( parser.getName().equals( Tag.DT.toString() ) )
-        {
-            sink.definitionListItem();
-            sink.definedTerm();
-        }
-        else if ( parser.getName().equals( Tag.DD.toString() ) )
-        {
-            sink.definition();
-        }
-        else if ( parser.getName().equals( Tag.HEAD.toString() ) )
-        {
-            sink.head();
-        }
-        else if ( ( parser.getName().equals( Tag.B.toString() ) ) || ( parser.getName().equals( Tag.STRONG.toString() ) ) )
-        {
-            sink.bold();
-        }
-        else if ( ( parser.getName().equals( Tag.I.toString() ) ) || ( parser.getName().equals( Tag.EM.toString() ) ) )
-        {
-            sink.italic();
-        }
-        else if ( ( parser.getName().equals( Tag.CODE.toString() ) ) || ( parser.getName().equals( Tag.SAMP.toString() ) ) ||
-            ( parser.getName().equals( Tag.TT.toString() ) ) )
-        {
-            sink.monospaced();
-        }
-        else if ( parser.getName().equals( Tag.A.toString() ) )
-        {
-            String href = parser.getAttributeValue( null, Attribute.HREF.toString() );
-
-            if ( href != null )
-            {
-                String link = href;
-
-                if ( link.startsWith( "#" ) )
-                {
-                    link = link.substring( 1 );
-                }
-
-                sink.link( link );
-
-                isLink = true;
-            }
-            else
-            {
-                String name = parser.getAttributeValue( null, Attribute.NAME.toString() );
-
-                if ( name != null )
-                {
-                    sink.anchor( name );
-
-                    isAnchor = true;
-                }
-                else
-                {
-                    String id = parser.getAttributeValue( null, Attribute.ID.toString() );
-
-                    if ( id != null )
-                    {
-                        sink.anchor( id );
-
-                        isAnchor = true;
-                    }
-                }
-            }
-        }
-
-        // ----------------------------------------------------------------------
-        // Tables
-        // ----------------------------------------------------------------------
-
-        else if ( parser.getName().equals( Tag.TABLE.toString() ) )
-        {
-            sink.table();
-
-            String border = parser.getAttributeValue( null, Attribute.BORDER.toString() );
-
-            boolean grid = true;
-
-            if ( "0".equals( border ) )
-            {
-                grid = false;
-            }
-
-            String align = parser.getAttributeValue( null, Attribute.ALIGN.toString() );
-
-            int[] justif = { JUSTIFY_CENTER };
-
-            if ( "left".equals( align ) )
-            {
-                justif[0] = JUSTIFY_LEFT;
-            }
-            else if ( "right".equals( align ) )
-            {
-                justif[0] = JUSTIFY_RIGHT;
-            }
-
-            sink.tableRows( justif, grid );
-        }
-        else if ( parser.getName().equals( Tag.TR.toString() ) )
-        {
-            sink.tableRow();
-        }
-        else if ( parser.getName().equals( Tag.TH.toString() ) )
-        {
-            String width = parser.getAttributeValue( null, Attribute.WIDTH.toString() );
-
-            if ( width ==  null )
-            {
-                sink.tableHeaderCell();
-            }
-            else
-            {
-                sink.tableHeaderCell( width );
-            }
-        }
-        else if ( parser.getName().equals( Tag.TD.toString() ) )
-        {
-            String width = parser.getAttributeValue( null, Attribute.WIDTH.toString() );
-
-            if ( width ==  null )
-            {
-                sink.tableCell();
-            }
-            else
-            {
-                sink.tableCell( width );
-            }
-        }
-        else if ( parser.getName().equals( Tag.CAPTION.toString() ) )
-        {
-            sink.tableRows_();
-            this.hasCaption = true;
-            sink.tableCaption();
-        }
-
-        // ----------------------------------------------------------------------
-        // Empty elements: <br/>, <hr/> and <img />
-        // ----------------------------------------------------------------------
-
-        else if ( parser.getName().equals( Tag.BR.toString() ) )
-        {
-            sink.lineBreak();
-        }
-        else if ( parser.getName().equals( Tag.HR.toString() ) )
-        {
-            sink.horizontalRule();
-        }
-        else if ( parser.getName().equals( Tag.IMG.toString() ) )
-        {
-            String src = parser.getAttributeValue( null, Attribute.SRC.toString() );
-            String title = parser.getAttributeValue( null, Attribute.TITLE.toString() );
-            String alt = parser.getAttributeValue( null, Attribute.ALT.toString() );
-
-            sink.figure();
-
-            if ( src != null )
-            {
-                sink.figureGraphics( src );
-            }
-
-            if ( title != null )
-            {
-                sink.figureCaption();
-                sink.text( title );
-                sink.figureCaption_();
-            }
-            else if ( alt != null )
-            {
-                sink.figureCaption();
-                sink.text( alt );
-                sink.figureCaption_();
-            }
-
-            sink.figure_();
+            // TODO: log( "Unrecognized start tag!" );
         }
     }
 
@@ -422,13 +142,13 @@
             //Do nothing
             return;
         }
-        else if ( parser.getName().equals( Tag.TITLE.toString() ) )
+        else if ( parser.getName().equals( Tag.HEAD.toString() ) )
         {
-            sink.title_();
+            sink.head_();
         }
-        else if ( parser.getName().equals( Tag.ADDRESS.toString() ) )
+        else if ( parser.getName().equals( Tag.TITLE.toString() ) )
         {
-            sink.author_();
+            sink.title_();
         }
         else if ( parser.getName().equals( Tag.BODY.toString() ) )
         {
@@ -436,238 +156,19 @@
 
             sink.body_();
         }
-        else if ( parser.getName().equals( Tag.P.toString() ) )
+        else if ( parser.getName().equals( Tag.ADDRESS.toString() ) )
         {
-            sink.paragraph_();
+            sink.author_();
         }
         else if ( parser.getName().equals( Tag.DIV.toString() ) )
         {
             this.boxed = false;
         }
-        else if ( parser.getName().equals( Tag.PRE.toString() ) )
-        {
-            sink.verbatim_();
-        }
-        else if ( parser.getName().equals( Tag.UL.toString() ) )
-        {
-            sink.list_();
-        }
-        else if ( parser.getName().equals( Tag.OL.toString() ) )
-        {
-            sink.numberedList_();
-            orderedListDepth--;
-        }
-        else if ( parser.getName().equals( Tag.LI.toString() ) )
-        {
-            if ( orderedListDepth == 0 )
-            {
-                sink.listItem_();
-            }
-            else
-            {
-                sink.numberedListItem_();
-            }
-        }
-        else if ( parser.getName().equals( Tag.DL.toString() ) )
-        {
-            sink.definitionList_();
-        }
-        else if ( parser.getName().equals( Tag.DT.toString() ) )
-        {
-            sink.definedTerm_();
-        }
-        else if ( parser.getName().equals( Tag.DD.toString() ) )
-        {
-            sink.definition_();
-            sink.definitionListItem_();
-        }
-        else if ( parser.getName().equals( Tag.HEAD.toString() ) )
-        {
-            sink.head_();
-        }
-        else if ( ( parser.getName().equals( Tag.B.toString() ) ) || ( parser.getName().equals( Tag.STRONG.toString() ) ) )
-        {
-            sink.bold_();
-        }
-        else if ( ( parser.getName().equals( Tag.I.toString() ) ) || ( parser.getName().equals( Tag.EM.toString() ) ) )
-        {
-            sink.italic_();
-        }
-        else if ( ( parser.getName().equals( Tag.CODE.toString() ) ) || ( parser.getName().equals( Tag.SAMP.toString() ) ) ||
-            ( parser.getName().equals( Tag.TT.toString() ) ) )
-        {
-            sink.monospaced_();
-        }
-        else if ( parser.getName().equals( Tag.A.toString() ) )
-        {
-            if ( isLink )
-            {
-                sink.link_();
-
-                isLink = false;
-            }
-            else if ( isAnchor )
-            {
-                sink.anchor_();
-
-                isAnchor = false;
-            }
-        }
-        // ----------------------------------------------------------------------
-        // Tables
-        // ----------------------------------------------------------------------
-
-        else if ( parser.getName().equals( Tag.TABLE.toString() ) )
-        {
-            if ( !hasCaption )
-            {
-                sink.tableRows_();
-            }
-
-            this.hasCaption = false;
-
-            sink.table_();
-        }
-        else if ( parser.getName().equals( Tag.TR.toString() ) )
-        {
-            sink.tableRow_();
-        }
-        else if ( parser.getName().equals( Tag.TH.toString() ) )
-        {
-            sink.tableHeaderCell_();
-        }
-        else if ( parser.getName().equals( Tag.TD.toString() ) )
+        else if ( !baseEndTag( parser, sink ) )
         {
-            sink.tableCell_();
-        }
-        else if ( parser.getName().equals( Tag.CAPTION.toString() ) )
-        {
-            sink.tableCaption_();
-        }
-        else if ( parser.getName().equals( Tag.H2.toString() ) )
-        {
-            sink.sectionTitle1_();
-        }
-        else if ( parser.getName().equals( Tag.H3.toString() ) )
-        {
-            sink.sectionTitle2_();
-        }
-        else if ( parser.getName().equals( Tag.H4.toString() ) )
-        {
-            sink.sectionTitle3_();
-        }
-        else if ( parser.getName().equals( Tag.H5.toString() ) )
-        {
-            sink.sectionTitle4_();
-        }
-        else if ( parser.getName().equals( Tag.H6.toString() ) )
-        {
-            sink.sectionTitle5_();
-        }
-    }
-
-    /** {@inheritDoc} */
-    protected void handleText( XmlPullParser parser, Sink sink )
-        throws XmlPullParserException
-    {
-        String text = parser.getText();
-
-        if ( StringUtils.isNotEmpty( text.trim() ) )
-        {
-            // emit separate text events for different lines
-            String[] lines = StringUtils.split( text, EOL );
-
-            for ( int i = 0; i < lines.length; i++ )
-            {
-                sink.text( lines[i] );
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    protected void handleCdsect( XmlPullParser parser, Sink sink )
-        throws XmlPullParserException
-    {
-        String text = parser.getText();
-
-        sink.rawText( text );
-    }
-
-    /** {@inheritDoc} */
-    protected void handleComment( XmlPullParser parser, Sink sink )
-        throws XmlPullParserException
-    {
-        String text = parser.getText();
-
-        if ( "PB".equals( text.trim() ) )
-        {
-            sink.pageBreak();
-        }
-        else
-        {
-            sink.comment( text.trim() );
-        }
-    }
-
-    /** {@inheritDoc} */
-    protected void handleEntity( XmlPullParser parser, Sink sink )
-        throws XmlPullParserException
-    {
-        String text = parser.getText();
-
-        int[] holder = new int[] {0, 0};
-        char[] chars = parser.getTextCharacters( holder );
-        String textChars = String.valueOf( chars, holder[0], holder[1] );
-
-        if ( "#160".equals( textChars ) )
-        {
-            sink.nonBreakingSpace();
-        }
-        else
-        {
-            sink.text( text );
+            // TODO: log( "Unrecognized end tag!" );
         }
     }
 
-    // ----------------------------------------------------------------------
-    // Private methods
-    // ----------------------------------------------------------------------
-
-    /**
-     * Close open sections. The current level is set to newLevel afterwards.
-     *
-     * @param newLevel the new section level, all upper levels have to be closed.
-     * @param sink the sink to receive the events.
-     */
-    private void closeOpenSections( int newLevel, Sink sink )
-    {
-        while ( this.sectionLevel >= newLevel )
-        {
-            if ( sectionLevel == Sink.SECTION_LEVEL_5)
-            {
-                sink.section5_();
-            }
-            else if ( sectionLevel == Sink.SECTION_LEVEL_4)
-            {
-                sink.section4_();
-            }
-            else if ( sectionLevel == Sink.SECTION_LEVEL_3)
-            {
-                sink.section3_();
-            }
-            else if ( sectionLevel == Sink.SECTION_LEVEL_2)
-            {
-                sink.section2_();
-            }
-            else if ( sectionLevel == Sink.SECTION_LEVEL_1)
-            {
-                sink.section1_();
-            }
-
-            this.sectionLevel--;
-        }
-
-        this.sectionLevel = newLevel;
-    }
 
 }



Mime
View raw message