Author: vsiveton Date: Mon Aug 24 12:02:43 2009 New Revision: 807166 URL: http://svn.apache.org/viewvc?rev=807166&view=rev Log: DOXIA-364: Guarantee the state of sinks and parsers impl
o impl init() method from r807164 o add logWarnings() method in AptParser Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java?rev=807166&r1=807165&r2=807166&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java Mon Aug 24 12:02:43 2009 @@ -187,19 +187,21 @@ public void parse( Reader source, Sink sink ) throws ParseException { + init(); + try { - try - { - StringWriter contentWriter = new StringWriter(); - IOUtil.copy( source, contentWriter ); - sourceContent = contentWriter.toString(); - } - catch ( IOException e ) - { - throw new AptParseException( "IOException: " + e.getMessage(), e ); - } + StringWriter contentWriter = new StringWriter(); + IOUtil.copy( source, contentWriter ); + sourceContent = contentWriter.toString(); + } + catch ( IOException e ) + { + throw new AptParseException( "IOException: " + e.getMessage(), e ); + } + try + { this.source = new AptReaderSource( new StringReader( sourceContent ) ); this.sink = sink; @@ -218,34 +220,18 @@ traverseHead(); traverseBody(); - - this.source = null; - - this.sink = null; } catch ( AptParseException ape ) { // TODO handle column number throw new AptParseException( ape.getMessage(), ape, getSourceName(), getSourceLineNumber(), -1 ); } - - if ( getLog().isWarnEnabled() && this.warnMessages != null && !isSecondParsing() ) + finally { - 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 ); - } - } + logWarnings(); - this.warnMessages = null; + setSecondParsing( false ); + init(); } } @@ -707,6 +693,21 @@ return replaced.toString(); } + /** {...@inheritdoc} */ + protected void init() + { + super.init(); + + this.sourceContent = null; + this.sink = null; + this.source = null; + this.block = null; + this.blockFileName = null; + this.blockLineNumber = 0; + this.line = null; + this.warnMessages = null; + } + // ---------------------------------------------------------------------- // Private methods // ---------------------------------------------------------------------- @@ -1612,6 +1613,31 @@ warnMessages.put( key, set ); } + /** + * @since 1.1.2 + */ + 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; + } + } + // ----------------------------------------------------------------------- /** A block of an apt source document. */ Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java?rev=807166&r1=807165&r2=807166&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java Mon Aug 24 12:02:43 2009 @@ -85,7 +85,7 @@ private int cellCount; /** The writer to use. */ - private PrintWriter writer; + private final PrintWriter writer; /** justification of table cells. */ private int cellJustif[]; @@ -97,7 +97,7 @@ private String listNestingIndent; /** listStyles. */ - private Stack listStyles; + private final Stack listStyles; // ---------------------------------------------------------------------- // Public protected methods @@ -111,11 +111,10 @@ */ protected AptSink( Writer writer ) { - this.buffer = new StringBuffer(); - this.tableCaptionBuffer = new StringBuffer(); this.writer = new PrintWriter( writer ); - this.listNestingIndent = ""; this.listStyles = new Stack(); + + init(); } /** @@ -140,14 +139,38 @@ /** * Reset all variables. + * + * @deprecated since 1.1.2, use {...@link #init()} instead of. */ protected void resetState() { - headerFlag = false; + init(); + } + + /** {...@inheritdoc} */ + protected void init() + { + super.init(); + resetBuffer(); - itemFlag = false; - verbatimFlag = false; - cellCount = 0; + + this.tableCaptionBuffer = new StringBuffer(); + this.listNestingIndent = ""; + + this.author = null; + this.title = null; + this.date = null; + this.tableCaptionFlag = false; + this.headerFlag = false; + this.bufferFlag = false; + this.itemFlag = false; + this.verbatimFlag = false; + this.isBoxed = false; + this.gridFlag = false; + this.cellCount = 0; + this.cellJustif = null; + this.rowLine = null; + this.listStyles.clear(); } /** @@ -169,7 +192,8 @@ /** {...@inheritdoc} */ public void head() { - resetState(); + init(); + headerFlag = true; } @@ -926,6 +950,8 @@ public void close() { writer.close(); + + init(); } // ----------------------------------------------------------------------