maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r557051 - in /maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc: XdocParser.java XdocSink.java
Date Tue, 17 Jul 2007 20:45:48 GMT
Author: ltheussl
Date: Tue Jul 17 13:45:47 2007
New Revision: 557051

URL: http://svn.apache.org/viewvc?view=rev&rev=557051
Log:
Various fixes to Xdoc parser:
 - don't emit anchor for section titles (should be done by a sink if desired)
 - handle <h4>, <h5>, <h6> tags as section3, section4, section5
 - distinguish between un-ordered and ordered list items
 - only use the colspan attribute of table (header) cells if it is non-null
 - add lineBreak, horizontalRule, monospaced, definition list and img parsing
 - don't emit text events if text is just white space
 

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

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?view=diff&rev=557051&r1=557050&r2=557051
==============================================================================
--- 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
Tue Jul 17 13:45:47 2007
@@ -29,6 +29,7 @@
 import org.apache.maven.doxia.parser.AbstractParser;
 import org.apache.maven.doxia.parser.ParseException;
 import org.apache.maven.doxia.sink.Sink;
+
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.pull.MXParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
@@ -49,6 +50,8 @@
 
     private boolean isLink;
     private boolean isAnchor;
+    private boolean isEmptyElement;
+    private int orderedListDepth = 0;
 
     public void parse( Reader reader, Sink sink )
         throws ParseException
@@ -98,9 +101,6 @@
                 }
                 else if ( parser.getName().equals( "section" ) )
                 {
-                    sink.anchor( parser.getAttributeValue( null, "name" ) );
-                    sink.anchor_();
-
                     sink.section1();
 
                     sink.sectionTitle1();
@@ -111,9 +111,6 @@
                 }
                 else if ( parser.getName().equals( "subsection" ) )
                 {
-                    sink.anchor( parser.getAttributeValue( null, "name" ) );
-                    sink.anchor_();
-
                     sink.section2();
 
                     sink.sectionTitle2();
@@ -122,6 +119,19 @@
 
                     sink.sectionTitle2_();
                 }
+                // TODO section3 section4 section5
+                else if ( parser.getName().equals( "h4" ) )
+                {
+                    sink.sectionTitle3();
+                }
+                else if ( parser.getName().equals( "h5" ) )
+                {
+                    sink.sectionTitle4();
+                }
+                else if ( parser.getName().equals( "h6" ) )
+                {
+                    sink.sectionTitle5();
+                }
                 else if ( parser.getName().equals( "p" ) )
                 {
                     sink.paragraph();
@@ -137,10 +147,31 @@
                 else if ( parser.getName().equals( "ol" ) )
                 {
                     sink.numberedList( Sink.NUMBERING_DECIMAL );
+                    orderedListDepth++;
                 }
                 else if ( parser.getName().equals( "li" ) )
                 {
-                    sink.listItem();
+                    if ( orderedListDepth == 0 )
+                    {
+                        sink.listItem();
+                    }
+                    else
+                    {
+                        sink.numberedListItem();
+                    }
+                }
+                else if ( parser.getName().equals( "dl" ) )
+                {
+                    sink.definitionList();
+                }
+                else if ( parser.getName().equals( "dt" ) )
+                {
+                    sink.definitionListItem();
+                    sink.definedTerm();
+                }
+                else if ( parser.getName().equals( "dd" ) )
+                {
+                    sink.definition();
                 }
                 else if ( parser.getName().equals( "properties" ) )
                 {
@@ -154,6 +185,10 @@
                 {
                     sink.italic();
                 }
+                else if ( parser.getName().equals( "tt" ) )
+                {
+                    sink.monospaced();
+                }
                 else if ( parser.getName().equals( "a" ) )
                 {
                     String href = parser.getAttributeValue( null, "href" );
@@ -217,16 +252,65 @@
                 }
                 else if ( parser.getName().equals( "th" ) )
                 {
-                    sink.tableHeaderCell(parser.getAttributeValue( null, "colspan" ));
+                    String colspan = parser.getAttributeValue( null, "colspan" );
+                    if ( colspan ==  null)
+                    {
+                        sink.tableHeaderCell();
+                    }
+                    else
+                    {
+                        sink.tableHeaderCell( colspan );
+                    }
                 }
                 else if ( parser.getName().equals( "td" ) )
                 {
-                    sink.tableCell(parser.getAttributeValue( null, "colspan" ));
+                    String colspan = parser.getAttributeValue( null, "colspan" );
+                    if ( colspan ==  null)
+                    {
+                        sink.tableCell();
+                    }
+                    else
+                    {
+                        sink.tableCell( colspan );
+                    }
+                }
+
+                // ----------------------------------------------------------------------
+                // Empty elements: <br/>, <hr/> and <img />
+                // ----------------------------------------------------------------------
+
+                else if ( parser.getName().equals( "br" ) )
+                {
+                    sink.lineBreak();
+                }
+                else if ( parser.getName().equals( "hr" ) )
+                {
+                    sink.horizontalRule();
+                }
+                else if ( parser.getName().equals( "img" ) )
+                {
+                    String src = parser.getAttributeValue( null, "src" );
+                    String alt = parser.getAttributeValue( null, "alt" );
+
+                    sink.figure();
+                    sink.figureGraphics( src );
+
+                    if ( alt != null )
+                    {
+                        sink.figureCaption();
+                        sink.text( alt );
+                        sink.figureCaption_();
+                    }
+
+                    sink.figure_();
                 }
                 else
                 {
                     handleRawText( sink, parser );
                 }
+
+                isEmptyElement = parser.isEmptyElementTag();
+
             }
             else if ( eventType == XmlPullParser.END_TAG )
             {
@@ -261,10 +345,31 @@
                 else if ( parser.getName().equals( "ol" ) )
                 {
                     sink.numberedList_();
+                    orderedListDepth--;
                 }
                 else if ( parser.getName().equals( "li" ) )
                 {
-                    sink.listItem_();
+                    if ( orderedListDepth == 0 )
+                    {
+                        sink.listItem_();
+                    }
+                    else
+                    {
+                        sink.numberedListItem_();
+                    }
+                }
+                else if ( parser.getName().equals( "dl" ) )
+                {
+                    sink.definitionList_();
+                }
+                else if ( parser.getName().equals( "dt" ) )
+                {
+                    sink.definedTerm_();
+                }
+                else if ( parser.getName().equals( "dd" ) )
+                {
+                    sink.definition_();
+                    sink.definitionListItem_();
                 }
                 else if ( parser.getName().equals( "properties" ) )
                 {
@@ -278,6 +383,10 @@
                 {
                     sink.italic_();
                 }
+                else if ( parser.getName().equals( "tt" ) )
+                {
+                    sink.monospaced_();
+                }
                 else if ( parser.getName().equals( "a" ) )
                 {
                     if ( isLink )
@@ -329,7 +438,19 @@
                 {
                     sink.section2_();
                 }
-                else
+                else if ( parser.getName().equals( "h4" ) )
+                {
+                    sink.sectionTitle3_();
+                }
+                else if ( parser.getName().equals( "h5" ) )
+                {
+                    sink.sectionTitle4_();
+                }
+                else if ( parser.getName().equals( "h6" ) )
+                {
+                    sink.sectionTitle5_();
+                }
+                else if ( !isEmptyElement )
                 {
                     sink.rawText( "</" );
 
@@ -337,14 +458,19 @@
 
                     sink.rawText( ">" );
                 }
+                else
+                {
+                    isEmptyElement = false;
+                }
 
-                // ----------------------------------------------------------------------
-                // Sections
-                // ----------------------------------------------------------------------
             }
             else if ( eventType == XmlPullParser.TEXT )
             {
-                sink.text( parser.getText() );
+                String text = parser.getText();
+                if ( !"".equals( text.trim() ) )
+                {
+                    sink.text( text );
+                }
             }
 
             eventType = parser.next();

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?view=diff&rev=557051&r1=557050&r2=557051
==============================================================================
--- 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
Tue Jul 17 13:45:47 2007
@@ -257,7 +257,7 @@
         {
             markup( "<section name=\"" );
         }
-        else
+        else if ( depth == 2 )
         {
             markup( "<subsection name=\"" );
         }
@@ -265,12 +265,40 @@
 
     private void onSectionTitle( int depth )
     {
+        if ( depth == 3 )
+        {
+            markup( "<h4>" );
+        }
+        else if ( depth == 4 )
+        {
+            markup( "<h5>" );
+        }
+        else if ( depth == 5 )
+        {
+            markup( "<h6>" );
+        }
+
         titleFlag = true;
     }
 
     private void onSectionTitle_( int depth )
     {
-        markup( "\">" );
+        if ( depth == 1 || depth == 2 )
+        {
+            markup( "\">" );
+        }
+        else if ( depth == 3 )
+        {
+            markup( "</h4>" );
+        }
+        else if ( depth == 4 )
+        {
+            markup( "</h5>" );
+        }
+        else if ( depth == 5 )
+        {
+            markup( "</h6>" );
+        }
 
         titleFlag = false;
     }
@@ -281,7 +309,7 @@
         {
             markup( "</section>" );
         }
-        else
+        else if ( depth == 2 )
         {
             markup( "</subsection>" );
         }
@@ -358,7 +386,7 @@
 
     public void definitionList()
     {
-        markup( "<dl compact=\"compact\">" + EOL );
+        markup( "<dl>" + EOL );
     }
 
     public void definitionList_()
@@ -369,12 +397,12 @@
 
     public void definedTerm()
     {
-        markup( "<dt><b>" );
+        markup( "<dt>" );
     }
 
     public void definedTerm_()
     {
-        markup( "</b></dt>" + EOL );
+        markup( "</dt>" + EOL );
     }
 
     public void definition()



Mime
View raw message