Re: svn commit: r805576 - in /maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src: main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r805576 - in /maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src: main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java

Lukas Theussl-4

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


[hidden email] 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=\"[hidden email]\">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 | Threaded
Open this post in threaded view
|

Re: svn commit: r805576 - in /maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src: main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java

Vincent Siveton
Hi Lukas,

2009/8/19 Lukas Theussl <[hidden email]>:
> 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:

Yes both are legal, but the doc doesn't specify which one is the
"official" title of a xdoc.

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

I was thinking about this idea but due to the parser impl, it will be
always head/title which emits a warn due to the exception actually.

IMHO head/title should be the right title, properties/title is more
for backward compatibility reasons. WDYT?

Cheers,

Vincent
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r805576 - in /maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src: main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java

Lukas Theussl-4


Vincent Siveton wrote:
> Hi Lukas,
>
> 2009/8/19 Lukas Theussl <[hidden email]>:
>> 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:
>
> Yes both are legal, but the doc doesn't specify which one is the
> "official" title of a xdoc.

properties/title is required by the xsd and should have priority, head/title is
only there for compatibility with xhtml, but it is optional.

>
>> 1) define and document which title gets used if both are specified and emit
>> a warning that the other is ignored
>
> I was thinking about this idea but due to the parser impl, it will be
> always head/title which emits a warn due to the exception actually.
>
> IMHO head/title should be the right title, properties/title is more
> for backward compatibility reasons. WDYT?

The other way round IMO. The properties/title is a required element, while
head/title is optional, and properties comes before head, so simply emit a warning
when a second title is encountered.

-Lukas

>
> Cheers,
>
> Vincent
>