Author: vsiveton Date: Wed Aug 26 22:04:08 2009 New Revision: 808200 URL: http://svn.apache.org/viewvc?rev=808200&view=rev Log: DOXIA-366: Wrong TOC when styles
o add test case o take care of title event Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/index/IndexingSink.java maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/toc/TocMacroTest.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=808200&r1=808199&r2=808200&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 Wed Aug 26 22:04:08 2009 @@ -103,21 +103,25 @@ /** {...@inheritdoc} */ public void title() { - super.title(); - - type = TITLE; + this.type = TITLE; } /** {...@inheritdoc} */ public void sectionTitle1() { this.currentEntry = null; - type = TYPE_SECTION_1; + this.type = TYPE_SECTION_1; + } + + /** {...@inheritdoc} */ + public void title_() + { + this.type = 0; } public void sectionTitle1_() { - type = 0; + this.type = 0; } /** {...@inheritdoc} */ @@ -130,12 +134,12 @@ public void sectionTitle2() { this.currentEntry = null; - type = TYPE_SECTION_2; + this.type = TYPE_SECTION_2; } public void sectionTitle2_() { - type = 0; + this.type = 0; } /** {...@inheritdoc} */ @@ -148,12 +152,12 @@ public void sectionTitle3() { this.currentEntry = null; - type = TYPE_SECTION_3; + this.type = TYPE_SECTION_3; } public void sectionTitle3_() { - type = 0; + this.type = 0; } /** {...@inheritdoc} */ @@ -166,12 +170,12 @@ public void sectionTitle4() { this.currentEntry = null; - type = TYPE_SECTION_4; + this.type = TYPE_SECTION_4; } public void sectionTitle4_() { - type = 0; + this.type = 0; } /** {...@inheritdoc} */ @@ -184,12 +188,12 @@ public void sectionTitle5() { this.currentEntry = null; - type = TYPE_SECTION_5; + this.type = TYPE_SECTION_5; } public void sectionTitle5_() { - type = 0; + this.type = 0; } /** {...@inheritdoc} */ @@ -216,7 +220,7 @@ /** {...@inheritdoc} */ public void text( String text ) { - switch ( type ) + switch ( this.type ) { case TITLE: this.title = text; @@ -230,11 +234,11 @@ // Sanitize the id. The most important step is to remove any blanks // ----------------------------------------------------------------------- - if ( currentEntry == null ) + if ( this.currentEntry == null ) { - currentEntry = new IndexEntry( peek(), HtmlTools.encodeId( text ) ); + this.currentEntry = new IndexEntry( peek(), HtmlTools.encodeId( text ) ); - currentEntry.setTitle( text ); + this.currentEntry.setTitle( text ); push( currentEntry ); } Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/toc/TocMacroTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/toc/TocMacroTest.java?rev=808200&r1=808199&r2=808200&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/toc/TocMacroTest.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/toc/TocMacroTest.java Wed Aug 26 22:04:08 2009 @@ -20,6 +20,7 @@ */ import java.io.File; +import java.io.StringWriter; import java.util.HashMap; import java.util.Iterator; @@ -33,23 +34,24 @@ import org.apache.maven.doxia.sink.SinkEventAttributeSet; import org.apache.maven.doxia.sink.SinkEventElement; import org.apache.maven.doxia.sink.SinkEventTestingSink; +import org.apache.maven.doxia.sink.XhtmlBaseSink; /** * Test toc macro. * * @author ltheussl + * @version $Id$ */ public class TocMacroTest - extends TestCase + extends TestCase { - /** * Test of execute method, of class TocMacro. * * @throws MacroExecutionException if a macro fails during testing. */ public void testExecute() - throws MacroExecutionException + throws MacroExecutionException { String sourceContent = "<div><h2>h21</h2><h2>h22</h2><h3>h3</h3><h4>h4</h4><h2>h23</h2></div>"; @@ -127,14 +129,14 @@ assertEquals( "link", ( (SinkEventElement) it.next() ).getName() ); event = (SinkEventElement) it.next(); assertEquals( "text", event.getName() ); - assertEquals( "h22", (String) event.getArgs()[0] ); + assertEquals( "h22", (String) event.getArgs()[0] ); assertEquals( "link_", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "list", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "listItem", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "link", ( (SinkEventElement) it.next() ).getName() ); event = (SinkEventElement) it.next(); assertEquals( "text", event.getName() ); - assertEquals( "h3", (String) event.getArgs()[0] ); + assertEquals( "h3", (String) event.getArgs()[0] ); assertEquals( "link_", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "listItem_", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "list_", ( (SinkEventElement) it.next() ).getName() ); @@ -142,4 +144,36 @@ assertEquals( "list_", ( (SinkEventElement) it.next() ).getName() ); assertFalse( it.hasNext() ); } + + /** + * Test DOXIA-366. + * + * @throws MacroExecutionException if a macro fails during testing. + */ + public void testTocStyle() + throws MacroExecutionException + { + String sourceContent = + "<div><h2>h<b>21</b></h2><h2>h<i>22</i></h2><h3>h<tt>3</tt></h3><h4>h4</h4><h2>h23</h2></div>"; + + XhtmlBaseParser parser = new XhtmlBaseParser(); + parser.setSecondParsing( true ); + + Map macroParameters = new HashMap(); + macroParameters.put( "parser", parser ); + macroParameters.put( "sourceContent", sourceContent ); + macroParameters.put( "section", "sec1" ); + + File basedir = new File( "" ); + + StringWriter out = new StringWriter(); + XhtmlBaseSink sink = new XhtmlBaseSink( out ); + MacroRequest request = new MacroRequest( macroParameters, basedir ); + TocMacro macro = new TocMacro(); + macro.execute( sink, request ); + + assertTrue( out.toString().indexOf( "<a href=\"#h21\">h21</a>" ) != -1 ); + assertTrue( out.toString().indexOf( "<a href=\"#h22\">h22</a>" ) != -1 ); + assertTrue( out.toString().indexOf( "<a href=\"#h3\">h3</a>" ) != -1 ); + } }