Author: ltheussl Date: Thu May 28 09:39:34 2009 New Revision: 779509 URL: http://svn.apache.org/viewvc?rev=779509&view=rev Log: Move parsing of script tags into XhtmlBaseParser, it can be re-used.
Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocParser.java Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java?rev=779509&r1=779508&r2=779509&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java Thu May 28 09:39:34 2009 @@ -28,6 +28,7 @@ import javax.swing.text.html.HTML.Tag; import org.apache.maven.doxia.macro.MacroExecutionException; +import org.apache.maven.doxia.markup.HtmlMarkup; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.SinkEventAttributeSet; import org.apache.maven.doxia.sink.SinkEventAttributes; @@ -47,7 +48,11 @@ */ public class XhtmlBaseParser extends AbstractXmlParser + implements HtmlMarkup { + /** True if a <script></script> block is read. CDATA sections within are handled as rawText. */ + private boolean scriptBlock; + /** Used to distinguish <a href=""> from <a name="">. */ private boolean isLink; @@ -245,6 +250,11 @@ { handleImgStart( parser, sink, attribs ); } + else if ( parser.getName().equals( Tag.SCRIPT.toString() ) ) + { + handleUnknown( parser, sink, TAG_TYPE_START ); + scriptBlock = true; + } else { visited = false; @@ -399,6 +409,12 @@ { sink.sectionTitle5_(); } + else if ( parser.getName().equals( Tag.SCRIPT.toString() ) ) + { + handleUnknown( parser, sink, TAG_TYPE_END ); + + scriptBlock = false; + } else { visited = false; @@ -476,6 +492,22 @@ } } + /** {...@inheritdoc} */ + protected void handleCdsect( XmlPullParser parser, Sink sink ) + throws XmlPullParserException + { + String text = getText( parser ); + + if ( isScriptBlock() ) + { + sink.rawText( text ); + } + else + { + sink.text( text ); + } + } + /** * Make sure sections are nested consecutively. * @@ -629,6 +661,18 @@ } /** + * Checks if we are currently inside a <script> tag. + * + * @return true if we are currently inside <code><script></code> tags. + * + * @since 1.1.1. + */ + protected boolean isScriptBlock() + { + return this.scriptBlock; + } + + /** * Checks if the given id is a valid Doxia id and if not, returns a transformed one. * * @param id The id to validate. 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=779509&r1=779508&r2=779509&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 Thu May 28 09:39:34 2009 @@ -58,9 +58,6 @@ /** The source content of the input reader. Used to pass into macros. */ private String sourceContent; - /** 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; @@ -273,11 +270,6 @@ } } } - else if ( parser.getName().equals( Tag.SCRIPT.toString() ) ) - { - handleUnknown( parser, sink, TAG_TYPE_START ); - scriptBlock = true; - } else if ( !baseStartTag( parser, sink ) ) { if ( isEmptyElement ) @@ -393,12 +385,6 @@ { consecutiveSections( Sink.SECTION_LEVEL_1, sink ); } - else if ( parser.getName().equals( Tag.SCRIPT.toString() ) ) - { - handleUnknown( parser, sink, TAG_TYPE_END ); - - scriptBlock = false; - } else if ( !baseEndTag( parser, sink ) ) { if ( !isEmptyElement ) @@ -411,22 +397,6 @@ } /** {...@inheritdoc} */ - protected void handleCdsect( XmlPullParser parser, Sink sink ) - throws XmlPullParserException - { - String text = getText( parser ); - - if ( scriptBlock ) - { - sink.rawText( text ); - } - else - { - sink.text( text ); - } - } - - /** {...@inheritdoc} */ protected void consecutiveSections( int newLevel, Sink sink ) { closeOpenSections( newLevel, sink );