Hi Vincent,

[I'm back! :) ]

IIUC, according to the xdoc schema it is perfectly legal to specify a <title> in both <properties> and <head>, so throwing an Exception is not the right solution IMO. I would prefer one of the following two alternatives:

1) define and document which title gets used if both are specified and emit a warning that the other is ignored

2) if a second title is encountered, emit it as an (unkown) meta event


I think 1) is good enough since specifying two titles is not logical (even if legal) and should be fixed in the source document.

-Lukas


vsive...@apache.org wrote:
Author: vsiveton
Date: Tue Aug 18 21:04:23 2009
New Revision: 805576

URL: http://svn.apache.org/viewvc?rev=805576&view=rev
Log:
DOXIA-359: Xdoc parser doesnt make the difference for <title/>

o added an exception when 2 <title/> are defined in <properties/> and also in 
<head/>

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/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.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=805576&r1=805575&r2=805576&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
 Tue Aug 18 21:04:23 2009
@@ -69,6 +69,9 @@
     /** Indicates that we're inside &lt;properties&gt; or &lt;head&gt;.*/
     private boolean inHead;
+ /** Indicates that &lt;title&gt; was called from &lt;properties&gt; or &lt;head&gt;.*/
+    private boolean hasTitle;
+
     /** {...@inheritdoc} */
     public void parse( Reader source, Sink sink )
         throws ParseException
@@ -94,6 +97,8 @@
         //setIgnorableWhitespace( true );
super.parse( tmp, sink );
+
+        this.hasTitle = false;
     }
/** {...@inheritdoc} */
@@ -120,7 +125,13 @@
         }
         else if ( parser.getName().equals( TITLE.toString() ) )
         {
+            if ( hasTitle )
+            {
+                throw new XmlPullParserException( "<title/> should be defined in 
<properties/> or in <head/>, "
+                    + "not both." );
+            }
             sink.title( attribs );
+            this.hasTitle = true;
         }
         else if ( parser.getName().equals( AUTHOR_TAG.toString() ) )
         {

Modified: 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
URL: 
http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java?rev=805576&r1=805575&r2=805576&view=diff
==============================================================================
--- 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
 (original)
+++ 
maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java
 Tue Aug 18 21:04:23 2009
@@ -189,6 +189,20 @@
         assertEquals( "body", ( (SinkEventElement) it.next() ).getName() );
         assertEquals( "body_", ( (SinkEventElement) it.next() ).getName() );
         assertFalse( it.hasNext() );
+
+        text = "<document>"
+                + "<properties><title>title</title>"
+                + "<author email=\"a...@b.c\">John Doe</author></properties>"
+                + "<head><title>title</title></head><body></body></document>";
+        try
+        {
+            parser.parse( text, sink );
+            assertTrue( false );
+        }
+        catch ( ParseException e )
+        {
+            assertTrue( true );
+        }
     }
/** @throws Exception */



Reply via email to