Author: vsiveton Date: Mon Aug 24 11:59:25 2009 New Revision: 807164 URL: http://svn.apache.org/viewvc?rev=807164&view=rev Log: DOXIA-364: Guarantee the state of sinks and parsers impl
o add init() method in AbstractSink/AbstractParser and implement it Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/WellformednessCheckingSink.java Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java?rev=807164&r1=807163&r2=807164&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java Mon Aug 24 11:59:25 2009 @@ -68,7 +68,7 @@ private String title; /** The stack. */ - private Stack stack = new Stack(); + private final Stack stack; /** * Default constructor. @@ -77,7 +77,10 @@ */ public IndexingSink( IndexEntry sectionEntry ) { + stack = new Stack(); stack.push( sectionEntry ); + + init(); } /** @@ -242,4 +245,19 @@ { return (IndexEntry) stack.peek(); } + + /** {...@inheritdoc} */ + public void close() + { + super.close(); + + init(); + } + + /** {...@inheritdoc} */ + protected void init() + { + this.type = 0; + this.title = null; + } } Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java?rev=807164&r1=807163&r2=807164&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractParser.java Mon Aug 24 11:59:25 2009 @@ -166,4 +166,16 @@ { return macroManager; } + + /** + * Initialize the parser. This is called first by + * {...@link #parse(java.io.Reader, org.apache.maven.doxia.sink.Sink)} and can be used + * to set the parser into a clear state so it can be re-used. + * + * @since 1.1.2 + */ + protected void init() + { + // nop + } } Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java?rev=807164&r1=807163&r2=807164&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/AbstractXmlParser.java Mon Aug 24 11:59:25 2009 @@ -164,6 +164,9 @@ { throw new ParseException( "Macro execution failed: " + ex.getMessage(), ex ); } + + setSecondParsing( false ); + init(); } /** @@ -210,18 +213,6 @@ } /** - * Initialize the parser. This is called first by - * {...@link #parse(java.io.Reader, org.apache.maven.doxia.sink.Sink)} and can be used - * to set the parser into a clear state so it can be re-used. - * - * @since 1.1.1 - */ - protected void init() - { - // default: empty - } - - /** * Parse the model from the XmlPullParser into the given sink. * * @param parser A parser, not null. 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=807164&r1=807163&r2=807164&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 Mon Aug 24 11:59:25 2009 @@ -83,6 +83,8 @@ public void parse( Reader source, Sink sink ) throws ParseException { + init(); + try { super.parse( source, sink ); @@ -90,6 +92,9 @@ finally { logWarnings(); + + setSecondParsing( false ); + init(); } } @@ -693,6 +698,25 @@ return id; } + /** {...@inheritdoc} */ + protected void init() + { + super.init(); + + this.scriptBlock = false; + this.isLink = false; + this.isAnchor = false; + this.orderedListDepth = 0; + this.sectionLevel = 0; + this.inVerbatim = false; + this.inFigure = false; + while( this.decoration.getAttributeNames().hasMoreElements() ) + { + this.decoration.removeAttribute( this.decoration.getAttributeNames().nextElement() ); + } + this.warnMessages = null; + } + private void handleAEnd( Sink sink ) { if ( isLink ) Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java?rev=807164&r1=807163&r2=807164&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java Mon Aug 24 11:59:25 2009 @@ -100,4 +100,15 @@ return buffer.toString(); } + + /** + * This is called in {...@link #head()} or in {...@link #close()}, and can be used + * to set the sink into a clear state so it can be re-used. + * + * @since 1.1.2 + */ + protected void init() + { + // nop + } } Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java?rev=807164&r1=807163&r2=807164&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java Mon Aug 24 11:59:25 2009 @@ -59,7 +59,7 @@ // ---------------------------------------------------------------------- /** The PrintWriter to write the result. */ - private PrintWriter writer; + private final PrintWriter writer; /** Used to collect text events mainly for the head events. */ private StringBuffer textBuffer = new StringBuffer(); @@ -149,6 +149,8 @@ this.tableCaptionWriterStack = new LinkedList(); this.tableCaptionXMLWriterStack = new LinkedList(); this.tableCaptionStack = new LinkedList(); + + init(); } // ---------------------------------------------------------------------- @@ -248,9 +250,19 @@ /** * Reset all variables. + * + * @deprecated since 1.1.2, use {...@link #init()} instead of. */ protected void resetState() { + init(); + } + + /** {...@inheritdoc} */ + protected void init() + { + super.init(); + resetTextBuffer(); this.headFlag = false; @@ -263,6 +275,18 @@ this.tableCaptionWriterStack.clear(); this.tableCaptionXMLWriterStack.clear(); this.tableCaptionStack.clear(); + + this.headFlag = false; + this.figureCaptionFlag = false; + this.paragraphFlag = false; + this.verbatimFlag = false; + this.evenTableRow = true; + this.tableAttributes = null; + this.legacyFigure = false; + this.legacyFigureCaption = false; + this.inFigure = false; + this.tableRows = false; + this.warnMessages = null; } /** @@ -1937,7 +1961,7 @@ this.warnMessages = null; } - resetState(); + init(); } // ---------------------------------------------------------------------- Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/WellformednessCheckingSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/WellformednessCheckingSink.java?rev=807164&r1=807163&r2=807164&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/WellformednessCheckingSink.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/sink/WellformednessCheckingSink.java Mon Aug 24 11:59:25 2009 @@ -34,449 +34,549 @@ public class WellformednessCheckingSink extends AbstractSink { - private Stack elements = new Stack(); + private final Stack elements = new Stack(); - private List errors = new LinkedList(); + private final List errors = new LinkedList(); + /** {...@inheritdoc} */ public void head() { startElement( "head" ); } + /** {...@inheritdoc} */ public void head_() { checkWellformedness( "head" ); } + /** {...@inheritdoc} */ public void body() { startElement( "body" ); } + /** {...@inheritdoc} */ public void body_() { checkWellformedness( "body" ); } + /** {...@inheritdoc} */ public void section1() { startElement( "section1" ); } + /** {...@inheritdoc} */ public void section1_() { checkWellformedness( "section1" ); } + /** {...@inheritdoc} */ public void section2() { startElement( "section2" ); } + /** {...@inheritdoc} */ public void section2_() { checkWellformedness( "section2" ); } + /** {...@inheritdoc} */ public void section3() { startElement( "section3" ); } + /** {...@inheritdoc} */ public void section3_() { checkWellformedness( "section3" ); } + /** {...@inheritdoc} */ public void section4() { startElement( "section4" ); } + /** {...@inheritdoc} */ public void section4_() { checkWellformedness( "section4" ); } + /** {...@inheritdoc} */ public void section5() { startElement( "section5" ); } + /** {...@inheritdoc} */ public void section5_() { checkWellformedness( "section5" ); } + /** {...@inheritdoc} */ public void list() { startElement( "list" ); } + /** {...@inheritdoc} */ public void list_() { checkWellformedness( "list" ); } + /** {...@inheritdoc} */ public void listItem() { startElement( "listItem" ); } + /** {...@inheritdoc} */ public void listItem_() { checkWellformedness( "listItem" ); } + /** {...@inheritdoc} */ public void numberedList( int numbering ) { startElement( "numberedList" ); } + /** {...@inheritdoc} */ public void numberedList_() { checkWellformedness( "numberedList" ); } + /** {...@inheritdoc} */ public void numberedListItem() { startElement( "numberedListItem" ); } + /** {...@inheritdoc} */ public void numberedListItem_() { checkWellformedness( "numberedListItem" ); } + /** {...@inheritdoc} */ public void definitionList() { startElement( "definitionList" ); } + /** {...@inheritdoc} */ public void definitionList_() { checkWellformedness( "definitionList" ); } + /** {...@inheritdoc} */ public void definitionListItem() { startElement( "definitionListItem" ); } + /** {...@inheritdoc} */ public void definitionListItem_() { checkWellformedness( "definitionListItem" ); } + /** {...@inheritdoc} */ public void definition() { startElement( "definition" ); } + /** {...@inheritdoc} */ public void definition_() { checkWellformedness( "definition" ); } + /** {...@inheritdoc} */ public void figure() { startElement( "figure" ); } + /** {...@inheritdoc} */ public void figure_() { checkWellformedness( "figure" ); } + /** {...@inheritdoc} */ public void table() { startElement( "table" ); } + /** {...@inheritdoc} */ public void table_() { checkWellformedness( "table" ); } + /** {...@inheritdoc} */ public void tableRows( int[] justification, boolean grid ) { startElement( "tableRows" ); } + /** {...@inheritdoc} */ public void tableRows_() { checkWellformedness( "tableRows" ); } + /** {...@inheritdoc} */ public void tableRow() { startElement( "tableRow" ); } + /** {...@inheritdoc} */ public void tableRow_() { checkWellformedness( "tableRow" ); } + /** {...@inheritdoc} */ public void title() { startElement( "title" ); } + /** {...@inheritdoc} */ public void title_() { checkWellformedness( "title" ); } + /** {...@inheritdoc} */ public void author() { startElement( "author" ); } + /** {...@inheritdoc} */ public void author_() { checkWellformedness( "author" ); } + /** {...@inheritdoc} */ public void date() { startElement( "date" ); } + /** {...@inheritdoc} */ public void date_() { checkWellformedness( "date" ); } + /** {...@inheritdoc} */ public void sectionTitle() { startElement( "sectionTitle" ); } + /** {...@inheritdoc} */ public void sectionTitle_() { checkWellformedness( "sectionTitle" ); } + /** {...@inheritdoc} */ public void sectionTitle1() { startElement( "sectionTitle1" ); } + /** {...@inheritdoc} */ public void sectionTitle1_() { checkWellformedness( "sectionTitle1" ); } + /** {...@inheritdoc} */ public void sectionTitle2() { startElement( "sectionTitle2" ); } + /** {...@inheritdoc} */ public void sectionTitle2_() { checkWellformedness( "sectionTitle2" ); } + /** {...@inheritdoc} */ public void sectionTitle3() { startElement( "sectionTitle3" ); } + /** {...@inheritdoc} */ public void sectionTitle3_() { checkWellformedness( "sectionTitle3" ); } + /** {...@inheritdoc} */ public void sectionTitle4() { startElement( "sectionTitle4" ); } + /** {...@inheritdoc} */ public void sectionTitle4_() { checkWellformedness( "sectionTitle4" ); } + /** {...@inheritdoc} */ public void sectionTitle5() { startElement( "sectionTitle5" ); } + /** {...@inheritdoc} */ public void sectionTitle5_() { checkWellformedness( "sectionTitle5" ); } + /** {...@inheritdoc} */ public void paragraph() { startElement( "paragraph" ); } + /** {...@inheritdoc} */ public void paragraph_() { checkWellformedness( "paragraph" ); } + /** {...@inheritdoc} */ public void verbatim( boolean boxed ) { startElement( "verbatim" ); } + /** {...@inheritdoc} */ public void verbatim_() { checkWellformedness( "verbatim" ); } + /** {...@inheritdoc} */ public void definedTerm() { startElement( "definedTerm" ); } + /** {...@inheritdoc} */ public void definedTerm_() { checkWellformedness( "definedTerm" ); } + /** {...@inheritdoc} */ public void figureCaption() { startElement( "figureCaption" ); } + /** {...@inheritdoc} */ public void figureCaption_() { checkWellformedness( "figureCaption" ); } + /** {...@inheritdoc} */ public void tableCell() { startElement( "tableCell" ); } + /** {...@inheritdoc} */ public void tableCell( String width ) { startElement( "tableCell" ); } + /** {...@inheritdoc} */ public void tableCell_() { checkWellformedness( "tableCell" ); } + /** {...@inheritdoc} */ public void tableHeaderCell() { startElement( "tableHeaderCell" ); } + /** {...@inheritdoc} */ public void tableHeaderCell( String width ) { startElement( "tableHeaderCell" ); } + /** {...@inheritdoc} */ public void tableHeaderCell_() { checkWellformedness( "tableHeaderCell" ); } + /** {...@inheritdoc} */ public void tableCaption() { startElement( "tableCaption" ); } + /** {...@inheritdoc} */ public void tableCaption_() { checkWellformedness( "tableCaption" ); } + /** {...@inheritdoc} */ public void figureGraphics( String name ) { + // nop } + /** {...@inheritdoc} */ public void horizontalRule() { + // nop } + /** {...@inheritdoc} */ public void pageBreak() { + // nop } + /** {...@inheritdoc} */ public void anchor( String name ) { startElement( "anchor" ); } + /** {...@inheritdoc} */ public void anchor_() { checkWellformedness( "anchor" ); } + /** {...@inheritdoc} */ public void link( String name ) { startElement( "link" ); } + /** {...@inheritdoc} */ public void link_() { checkWellformedness( "link" ); } + /** {...@inheritdoc} */ public void italic() { startElement( "italic" ); } + /** {...@inheritdoc} */ public void italic_() { checkWellformedness( "italic" ); } + /** {...@inheritdoc} */ public void bold() { startElement( "bold" ); } + /** {...@inheritdoc} */ public void bold_() { checkWellformedness( "bold" ); } + /** {...@inheritdoc} */ public void monospaced() { startElement( "monospaced" ); } + /** {...@inheritdoc} */ public void monospaced_() { checkWellformedness( "monospaced" ); } + /** {...@inheritdoc} */ public void lineBreak() { + // nop } + /** {...@inheritdoc} */ public void nonBreakingSpace() { + // nop } + /** {...@inheritdoc} */ public void text( String text ) { + // nop } + /** {...@inheritdoc} */ public void rawText( String text ) { + // nop } /** {...@inheritdoc} */ public void comment( String comment ) { + // nop } + /** {...@inheritdoc} */ public void flush() { + // nop } + /** {...@inheritdoc} */ public void close() { + this.elements.clear(); + this.errors.clear(); } /**