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 lt...@apache.org on 2009/06/03 13:25:29 UTC

svn commit: r781342 - in /maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src: main/java/org/apache/maven/doxia/module/fml/ test/java/org/apache/maven/doxia/module/fml/

Author: ltheussl
Date: Wed Jun  3 11:25:29 2009
New Revision: 781342

URL: http://svn.apache.org/viewvc?rev=781342&view=rev
Log:
[DOXIA-328] correctly parse part <title>

Modified:
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlContentParser.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlParser.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlContentParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlContentParser.java?rev=781342&r1=781341&r2=781342&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlContentParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlContentParser.java Wed Jun  3 11:25:29 2009
@@ -48,6 +48,7 @@
         isEmptyElement = parser.isEmptyElementTag();
 
         if ( parser.getName().equals( QUESTION_TAG.toString() )
+                || parser.getName().equals( TITLE.toString() )
             || parser.getName().equals( ANSWER_TAG.toString() ) )
         {
             // ignore
@@ -86,6 +87,7 @@
         throws XmlPullParserException, MacroExecutionException
     {
         if ( parser.getName().equals( QUESTION_TAG.toString() )
+                || parser.getName().equals( TITLE.toString() )
             || parser.getName().equals( ANSWER_TAG.toString() ) )
         {
             // ignore

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlParser.java?rev=781342&r1=781341&r2=781342&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/main/java/org/apache/maven/doxia/module/fml/FmlParser.java Wed Jun  3 11:25:29 2009
@@ -19,8 +19,8 @@
  * under the License.
  */
 
-import java.io.IOException;
 import java.io.Reader;
+
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -82,24 +82,7 @@
 
         writeFaqs( sink );
 
-        if ( getLog().isWarnEnabled() && this.warnMessages != null && !isSecondParsing() )
-        {
-            for ( Iterator it = this.warnMessages.entrySet().iterator(); it.hasNext(); )
-            {
-                Map.Entry entry = (Map.Entry) it.next();
-
-                Set set = (Set) entry.getValue();
-
-                for ( Iterator it2 = set.iterator(); it2.hasNext(); )
-                {
-                    String msg = (String) it2.next();
-
-                    getLog().warn( msg );
-                }
-            }
-
-            this.warnMessages = null;
-        }
+        logWarnings();
     }
 
     /** {@inheritDoc} */
@@ -152,20 +135,10 @@
         }
         else if ( parser.getName().equals( TITLE.toString() ) )
         {
-            if ( currentPart == null )
-            {
-                throw new XmlPullParserException( "Missing <part> at: ("
-                    + parser.getLineNumber() + ":" + parser.getColumnNumber() + ")" );
-            }
+            buffer = new StringBuffer();
 
-            try
-            {
-                currentPart.setTitle( parser.nextText().trim() );
-            }
-            catch ( IOException e )
-            {
-                throw new XmlPullParserException( "Error reading title: " + e.getMessage(), parser, e );
-            }
+            buffer.append( String.valueOf( LESS_THAN ) ).append( parser.getName() )
+                .append( String.valueOf( GREATER_THAN ) );
         }
         else if ( parser.getName().equals( FAQ_TAG.toString() ) )
         {
@@ -188,7 +161,7 @@
                 currentFaq.setId( linkAnchor );
             }
         }
-        if ( parser.getName().equals( QUESTION_TAG.toString() ) )
+        else if ( parser.getName().equals( QUESTION_TAG.toString() ) )
         {
             buffer = new StringBuffer();
 
@@ -282,9 +255,24 @@
 
             buffer = null;
         }
+        else if ( parser.getName().equals( TITLE.toString() ) )
+        {
+            if ( currentPart == null )
+            {
+                throw new XmlPullParserException( "Missing <part> at: ("
+                    + parser.getLineNumber() + ":" + parser.getColumnNumber() + ")" );
+            }
+
+            buffer.append( String.valueOf( LESS_THAN ) ).append( String.valueOf( SLASH ) )
+                .append( parser.getName() ).append( String.valueOf( GREATER_THAN ) );
+
+            currentPart.setTitle( buffer.toString() );
+
+            buffer = null;
+        }
         else if ( buffer != null )
         {
-            if ( buffer.charAt( buffer.length() - 1 ) == SPACE )
+            if ( buffer.length() > 0 && buffer.charAt( buffer.length() - 1 ) == SPACE )
             {
                 buffer.deleteCharAt( buffer.length() - 1 );
             }
@@ -302,8 +290,7 @@
         {
             buffer.append( parser.getText() );
         }
-        // only text contents in fml files are within <question> or <answer>,
-        // except <title> which is registered via nextText().
+        // only significant text content in fml files is in <question>, <answer> or <title>
     }
 
     /** {@inheritDoc} */
@@ -406,7 +393,7 @@
             {
                 sink.paragraph();
                 sink.bold();
-                sink.text( part.getTitle() );
+                xdocParser.parse( part.getTitle(), sink );
                 sink.bold_();
                 sink.paragraph_();
             }
@@ -450,7 +437,7 @@
                 sink.section1();
 
                 sink.sectionTitle1();
-                sink.text( part.getTitle() );
+                xdocParser.parse( part.getTitle(), sink );
                 sink.sectionTitle1_();
             }
 
@@ -557,4 +544,22 @@
         set.add( msg );
         warnMessages.put( key, set );
     }
+
+    private void logWarnings()
+    {
+        if ( getLog().isWarnEnabled() && this.warnMessages != null && !isSecondParsing() )
+        {
+            for ( Iterator it = this.warnMessages.entrySet().iterator(); it.hasNext(); )
+            {
+                Map.Entry entry = (Map.Entry) it.next();
+                Set set = (Set) entry.getValue();
+                for ( Iterator it2 = set.iterator(); it2.hasNext(); )
+                {
+                    String msg = (String) it2.next();
+                    getLog().warn( msg );
+                }
+            }
+            this.warnMessages = null;
+        }
+    }
 }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java?rev=781342&r1=781341&r2=781342&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fml/src/test/java/org/apache/maven/doxia/module/fml/FmlParserTest.java Wed Jun  3 11:25:29 2009
@@ -161,8 +161,9 @@
         assertEquals( "paragraph", ( (SinkEventElement) it.next() ).getName() );
         assertEquals( "bold", ( (SinkEventElement) it.next() ).getName() );
 
-        // part title in TOC TODO: should be two events
-        assertTextEvent( (SinkEventElement) it.next(), "<&#913;" );
+        // part title in TOC
+        assertTextEvent( (SinkEventElement) it.next(), "<" );
+        assertTextEvent( (SinkEventElement) it.next(), "\u0391" );
 
         assertEquals( "bold_", ( (SinkEventElement) it.next() ).getName() );
         assertEquals( "paragraph_", ( (SinkEventElement) it.next() ).getName() );
@@ -181,8 +182,9 @@
         assertEquals( "section1", ( (SinkEventElement) it.next() ).getName() );
         assertEquals( "sectionTitle1", ( (SinkEventElement) it.next() ).getName() );
 
-        // part title TODO: should be two events
-        assertTextEvent( (SinkEventElement) it.next(), "<&#913;" );
+        // part title
+        assertTextEvent( (SinkEventElement) it.next(), "<" );
+        assertTextEvent( (SinkEventElement) it.next(), "\u0391" );
 
         assertEquals( "sectionTitle1_", ( (SinkEventElement) it.next() ).getName() );
         assertEquals( "definitionList", ( (SinkEventElement) it.next() ).getName() );