Index: src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java =================================================================== --- src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java (revision 754510) +++ src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java (working copy) @@ -37,421 +37,424 @@ /** * Test class for ConfluenceParser. */ -public class ConfluenceParserTest - extends AbstractParserTest -{ - private ConfluenceParser parser; +public class ConfluenceParserTest extends AbstractParserTest { + private ConfluenceParser parser; - private StringWriter output; + private StringWriter output; - private Reader reader; + private Reader reader; - private Writer writer; + private Writer writer; - /** {@inheritDoc} */ - protected void setUp() - throws Exception - { - super.setUp(); + /** {@inheritDoc} */ + protected void setUp() throws Exception { + super.setUp(); - parser = (ConfluenceParser) lookup( Parser.ROLE, "confluence" ); + parser = (ConfluenceParser) lookup(Parser.ROLE, "confluence"); - output = null; - reader = null; - writer = null; - } + output = null; + reader = null; + writer = null; + } - /** {@inheritDoc} */ - protected void tearDown() - throws Exception - { - IOUtil.close( output ); - IOUtil.close( reader ); - IOUtil.close( writer ); + /** {@inheritDoc} */ + protected void tearDown() throws Exception { + IOUtil.close(output); + IOUtil.close(reader); + IOUtil.close(writer); - super.tearDown(); - } + super.tearDown(); + } - /** {@inheritDoc} */ - protected Parser createParser() - { - return parser; - } + /** {@inheritDoc} */ + protected Parser createParser() { + return parser; + } - /** {@inheritDoc} */ - protected String outputExtension() - { - return "confluence"; - } + /** {@inheritDoc} */ + protected String outputExtension() { + return "confluence"; + } - /** @throws Exception */ - public void testParagraphWithSimpleFormatting() - throws Exception - { - String result = locateAndParseTestSourceFile( "simple-paragraph" ); + /** @throws Exception */ + public void testParagraphWithSimpleFormatting() throws Exception { + String result = locateAndParseTestSourceFile("simple-paragraph"); - assertContainsLines( result, "begin:bold\ntext: bold\n" ); - assertContainsLines( result, "begin:italic\ntext: italic\n" ); - assertContainsLines( result, "begin:monospaced\ntext: monospaced\n" ); - assertContainsLines( result, "begin:link, name: http://jira.codehaus.org\ntext: http://jira.codehaus.org" ); - assertContainsLines( result, "begin:link, name: http://jira.codehaus.org\ntext: JIRA\n" ); - // four paragraphs in the input... - assertEquals( 5, result.split( "end:paragraph" ).length ); - } + assertContainsLines(result, "begin:bold\ntext: bold\n"); + assertContainsLines(result, "begin:italic\ntext: italic\n"); + assertContainsLines(result, "begin:monospaced\ntext: monospaced\n"); + assertContainsLines(result, + "begin:link, name: http://jira.codehaus.org\ntext: http://jira.codehaus.org"); + assertContainsLines(result, + "begin:link, name: http://jira.codehaus.org\ntext: JIRA\n"); + // four paragraphs in the input... + assertEquals(5, result.split("end:paragraph").length); + } - /** @throws Exception */ - public void testLineBreak() - throws Exception - { - String lineBreak = getLineBreakString(); + /** @throws Exception */ + public void testLineBreak() throws Exception { + String lineBreak = getLineBreakString(); - String result = locateAndParseTestSourceFile( "linebreak" ); + String result = locateAndParseTestSourceFile("linebreak"); - assertContainsLines( result, "Line\n" + lineBreak ); - assertContainsLines( result, "with 2\n" + lineBreak ); - assertContainsLines( result, "inline\n" + lineBreak ); - } + assertContainsLines(result, "Line\n" + lineBreak); + assertContainsLines(result, "with 2\n" + lineBreak); + assertContainsLines(result, "inline\n" + lineBreak); + } - /** @throws Exception */ - public void testEscapes() - throws Exception - { - String result = locateAndParseTestSourceFile( "escapes" ); + /** @throws Exception */ + public void testEscapes() throws Exception { + String result = locateAndParseTestSourceFile("escapes"); - assertContainsLines( result, "asterisk *" ); - assertContainsLines( result, "underline _" ); - assertContainsLines( result, "asterisk *not bold*" ); - assertContainsLines( result, "underline _not italic_" ); - assertContainsLines( result, "normal character" ); - } + assertContainsLines(result, "asterisk *"); + assertContainsLines(result, "underline _"); + assertContainsLines(result, "asterisk *not bold*"); + assertContainsLines(result, "underline _not italic_"); + assertContainsLines(result, "normal character"); + } - /** @throws Exception */ - public void testSectionTitles() - throws Exception - { - String result = locateAndParseTestSourceFile( "section" ); + /** @throws Exception */ + public void testSectionTitles() throws Exception { + String result = locateAndParseTestSourceFile("section"); - for ( int i = 1; i <= 5; i++ ) - { - assertContainsLines( "Could not locate section " + i + " title", result, "sectionTitle" + i + - "\ntext: Section" + i ); - } + for (int i = 1; i <= 5; i++) { + assertContainsLines("Could not locate section " + i + " title", + result, "sectionTitle" + i + "\ntext: Section" + i); + } - assertContainsLines( "Section title has leading space", result, "sectionTitle1\ntext: TitleWithLeadingSpace" ); - } + assertContainsLines("Section title has leading space", result, + "sectionTitle1\ntext: TitleWithLeadingSpace"); + } - /** @throws Exception */ - public void testNestedBulletList() - throws Exception - { - String result = locateAndParseTestSourceFile( "nested-list" ); + /** @throws Exception */ + public void testNestedBulletList() throws Exception { + String result = locateAndParseTestSourceFile("nested-list"); - assertContainsLines( "Nested list not found", result, "begin:listItem\ntext: A top level list item\nbegin:list" ); - // two lists in the input... - assertEquals( 3, result.split( "end:list\n" ).length ); - // ...and 4 list items - assertEquals( 5, result.split( "end:listItem\n" ).length ); - } + assertContainsLines("Nested list not found", result, + "begin:listItem\ntext: A top level list item\nbegin:list"); + // two lists in the input... + assertEquals(3, result.split("end:list\n").length); + // ...and 4 list items + assertEquals(5, result.split("end:listItem\n").length); + } - /** @throws Exception */ - public void testListWithSimpleFormatting() - throws Exception - { - String result = locateAndParseTestSourceFile( "simple-list" ); + /** @throws Exception */ + public void testListWithSimpleFormatting() throws Exception { + String result = locateAndParseTestSourceFile("simple-list"); - assertContainsLines( result, "begin:bold\ntext: bold\n" ); - assertContainsLines( result, "begin:italic\ntext: italic\n" ); - assertContainsLines( result, "begin:monospaced\ntext: monospaced\n" ); - assertContainsLines( result, "begin:link, name: http://jira.codehaus.org\ntext: http://jira.codehaus.org\n" ); - assertContainsLines( result, "begin:link, name: http://jira.codehaus.org\ntext: JIRA\n" ); - assertContainsLines( result, "begin:listItem\ntext: Item with no formatting\nend:listItem\n" ); - assertContainsLines( result, "begin:listItem\ntext: One bullet\nend:listItem\n" ); - assertContainsLines( result, "begin:listItem\ntext: A list item with more than one line\nend:listItem\n" ); - // 3 lists in the input... - assertEquals( 4, result.split( "end:list\n" ).length ); - // ...and 7 list items - assertEquals( 8, result.split( "end:listItem\n" ).length ); - } + assertContainsLines(result, "begin:bold\ntext: bold\n"); + assertContainsLines(result, "begin:italic\ntext: italic\n"); + assertContainsLines(result, "begin:monospaced\ntext: monospaced\n"); + assertContainsLines(result, + "begin:link, name: http://jira.codehaus.org\ntext: http://jira.codehaus.org\n"); + assertContainsLines(result, + "begin:link, name: http://jira.codehaus.org\ntext: JIRA\n"); + assertContainsLines(result, + "begin:listItem\ntext: Item with no formatting\nend:listItem\n"); + assertContainsLines(result, + "begin:listItem\ntext: One bullet\nend:listItem\n"); + assertContainsLines(result, + "begin:listItem\ntext: A list item with more than one line\nend:listItem\n"); + // 3 lists in the input... + assertEquals(4, result.split("end:list\n").length); + // ...and 7 list items + assertEquals(8, result.split("end:listItem\n").length); + } - /** @throws Exception */ - public void testAnchor() - throws Exception - { - String result = locateAndParseTestSourceFile( "anchor" ); + /** @throws Exception */ + public void testNestedHeterogenousList() throws Exception { + String result = locateAndParseTestSourceFile("nested-list-heterogenous"); - assertContainsLines( result, "begin:paragraph\nbegin:anchor, name: start\nend:anchor" ); - assertContainsLines( result, "begin:anchor, name: middle\nend:anchor" ); - assertContainsLines( result, "begin:paragraph\ntext: Simple paragraph\nbegin:anchor, name: end\nend:anchor" ); - // 3 anchors in the input... - assertEquals( 4, result.split( "end:anchor\n" ).length ); - } + assertContainsLines("Nested list not found", result, + "begin:listItem\ntext: A top level list item\nbegin:numberedList"); - /** @throws Exception */ - public void testUnknownMacro() - throws Exception - { - String result = locateAndParseTestSourceFile( "unknown-macro" ); + // exactly one list and one numberedList + assertEquals(2, result.split("begin:list\n").length); + assertEquals(2, result.split("begin:numberedList").length); - assertContainsLines( result, "begin:paragraph\ntext: {unknown:start}" ); - } + // ...and 4 list items + assertEquals(5, result.split("end:listItem\n").length); + } - /** @throws Exception */ - public void testCodeMacro() - throws Exception - { - String result = locateAndParseTestSourceFile( "code" ); + /** @throws Exception */ + public void testAnchor() throws Exception { + String result = locateAndParseTestSourceFile("anchor"); - assertContainsLines( result, "begin:verbatim, boxed: true\ntext: public class Cat {" ); - // 3 paragraphs in the input... - assertEquals( 4, result.split( "end:paragraph\n" ).length ); - // 1 verbatim in the input... - assertEquals( 2, result.split( "end:verbatim\n" ).length ); - } + assertContainsLines(result, + "begin:paragraph\nbegin:anchor, name: start\nend:anchor"); + assertContainsLines(result, "begin:anchor, name: middle\nend:anchor"); + assertContainsLines(result, + "begin:paragraph\ntext: Simple paragraph\nbegin:anchor, name: end\nend:anchor"); + // 3 anchors in the input... + assertEquals(4, result.split("end:anchor\n").length); + } - /** @throws Exception */ - public void testFigure() - throws Exception - { - String result = locateAndParseTestSourceFile( "figure" ); + /** @throws Exception */ + public void testUnknownMacro() throws Exception { + String result = locateAndParseTestSourceFile("unknown-macro"); - assertContainsLines( result, "begin:figure\nfigureGraphics, name: images/photo.jpg\nend:figure\n" ); - assertContainsLines( result, "attempted inline !image.jpg! (should fail)" ); - // this isn't ideal... Doxia captions are not the same as what people would use to add text to a confluence - assertContainsLines( result, "figureGraphics, name: images/photo.jpg\n" - + "begin:figureCaption\ntext: With caption on same line\n" + "end:figureCaption" ); - assertContainsLines( result, "figureGraphics, name: images/nolinebreak.jpg\n" - + "begin:figureCaption\ntext: With caption underneath and no linebreak\nend:figureCaption" ); - // ignore linebreak after figure insert... - assertContainsLines( result, "figureGraphics, name: images/linebreak.jpg\n" - + "begin:figureCaption\ntext: With caption underneath and linebreak\nend:figureCaption" ); - // ignore formtting in caption... - assertContainsLines( result, "figureGraphics, name: images/bold.jpg\n" - + "begin:figureCaption\ntext: With *bold* caption underneath\nend:figureCaption" ); - // 2 paragraphs in the input... (the figures do not go in a paragraph by analogy with AptParser) - assertEquals( 3, result.split( "end:paragraph\n" ).length ); - } + assertContainsLines(result, "begin:paragraph\ntext: {unknown:start}"); + } - /** @throws Exception */ - public void testLink() - throws Exception - { - String result = locateAndParseTestSourceFile( "link" ); + /** @throws Exception */ + public void testCodeMacro() throws Exception { + String result = locateAndParseTestSourceFile("code"); - assertContainsLines( result, "begin:link, name: middle\ntext: middle\nend:link" ); - assertContainsLines( result, "begin:link, name: end\ntext: end\nend:link" ); - assertContainsLines( result, "begin:link, name: link\ntext: alias\nend:link" ); - assertContainsLines( result, "begin:link, name: link#anchor\ntext: link#anchor\nend:link" ); - assertContainsLines( result, "begin:link, name: #simple\ntext: simple\nend:link" ); - // 3 paragraphs in the input... - assertEquals( 4, result.split( "end:paragraph\n" ).length ); - // 5 links in the input... - assertEquals( 6, result.split( "end:link\n" ).length ); - } + assertContainsLines(result, + "begin:verbatim, boxed: true\ntext: public class Cat {"); + // 3 paragraphs in the input... + assertEquals(4, result.split("end:paragraph\n").length); + // 1 verbatim in the input... + assertEquals(2, result.split("end:verbatim\n").length); + } - /** @throws Exception */ - public void testParagraphWithList() - throws Exception - { - String result = locateAndParseTestSourceFile( "paragraph-list" ); + /** @throws Exception */ + public void testFigure() throws Exception { + String result = locateAndParseTestSourceFile("figure"); - assertContainsLines( result, "begin:paragraph\ntext: A paragraph\nend:paragraph\n" ); - assertContainsLines( result, "begin:listItem\ntext: A nested list item\nend:listItem\n" ); - assertContainsLines( result, "begin:listItem\ntext: Another nested list item with two lines\nend:listItem\n" ); - // 2 paragraphs in the input... - assertEquals( 3, result.split( "end:paragraph\n" ).length ); - // 1 list in the input... - assertEquals( 2, result.split( "end:list\n" ).length ); - } + assertContainsLines(result, + "begin:figure\nfigureGraphics, name: images/photo.jpg\nend:figure\n"); + assertContainsLines(result, + "attempted inline !image.jpg! (should fail)"); + // this isn't ideal... Doxia captions are not the same as what people + // would use to add text to a confluence + assertContainsLines(result, "figureGraphics, name: images/photo.jpg\n" + + "begin:figureCaption\ntext: With caption on same line\n" + + "end:figureCaption"); + assertContainsLines( + result, + "figureGraphics, name: images/nolinebreak.jpg\n" + + "begin:figureCaption\ntext: With caption underneath and no linebreak\nend:figureCaption"); + // ignore linebreak after figure insert... + assertContainsLines( + result, + "figureGraphics, name: images/linebreak.jpg\n" + + "begin:figureCaption\ntext: With caption underneath and linebreak\nend:figureCaption"); + // ignore formtting in caption... + assertContainsLines( + result, + "figureGraphics, name: images/bold.jpg\n" + + "begin:figureCaption\ntext: With *bold* caption underneath\nend:figureCaption"); + // 2 paragraphs in the input... (the figures do not go in a paragraph by + // analogy with AptParser) + assertEquals(3, result.split("end:paragraph\n").length); + } - /** @throws Exception */ - public void testParagraphWithFigure() - throws Exception - { - String result = locateAndParseTestSourceFile( "paragraph-figure" ); + /** @throws Exception */ + public void testLink() throws Exception { + String result = locateAndParseTestSourceFile("link"); - assertContainsLines( result, "begin:paragraph\ntext: A paragraph\nend:paragraph\n" ); - assertContainsLines( result, "begin:figure\nfigureGraphics, name: images/logo.png\nbegin:figureCaption\ntext: with a figure\nend:figureCaption" ); - // 2 paragraphs in the input... - assertEquals( 3, result.split( "end:paragraph\n" ).length ); - // 1 figure in the input... - assertEquals( 2, result.split( "end:figure\n" ).length ); - } + assertContainsLines(result, + "begin:link, name: middle\ntext: middle\nend:link"); + assertContainsLines(result, + "begin:link, name: end\ntext: end\nend:link"); + assertContainsLines(result, + "begin:link, name: link\ntext: alias\nend:link"); + assertContainsLines(result, + "begin:link, name: link#anchor\ntext: link#anchor\nend:link"); + assertContainsLines(result, + "begin:link, name: #simple\ntext: simple\nend:link"); + // 3 paragraphs in the input... + assertEquals(4, result.split("end:paragraph\n").length); + // 5 links in the input... + assertEquals(6, result.split("end:link\n").length); + } - /** @throws Exception */ - public void testParagraphWithHeader() - throws Exception - { - String result = locateAndParseTestSourceFile( "paragraph-header" ); + /** @throws Exception */ + public void testParagraphWithList() throws Exception { + String result = locateAndParseTestSourceFile("paragraph-list"); - assertContainsLines( result, "begin:paragraph\ntext: A paragraph\nend:paragraph\n" ); - assertContainsLines( result, "begin:section2\nbegin:sectionTitle2\ntext: A header\nend:sectionTitle2" ); - // 3 paragraphs in the input... - assertEquals( 4, result.split( "end:paragraph\n" ).length ); - // 1 header in the input... - assertEquals( 2, result.split( "end:sectionTitle2\n" ).length ); - } + assertContainsLines(result, + "begin:paragraph\ntext: A paragraph\nend:paragraph\n"); + assertContainsLines(result, + "begin:listItem\ntext: A nested list item\nend:listItem\n"); + assertContainsLines(result, + "begin:listItem\ntext: Another nested list item with two lines\nend:listItem\n"); + // 2 paragraphs in the input... + assertEquals(3, result.split("end:paragraph\n").length); + // 1 list in the input... + assertEquals(2, result.split("end:list\n").length); + } - /** @throws Exception */ - public void testNestedFormats() - throws Exception - { - String result = locateAndParseTestSourceFile( "nested-format" ); + /** @throws Exception */ + public void testParagraphWithFigure() throws Exception { + String result = locateAndParseTestSourceFile("paragraph-figure"); - assertContainsLines( result, "begin:bold\nbegin:italic\ntext: bold italic\nend:italic" ); - assertContainsLines( result, "begin:italic\nbegin:bold\ntext: italic bold\nend:bold" ); - assertContainsLines( result, "begin:bold\nbegin:monospaced\ntext: bold monospaced\nend:monospaced" ); - assertContainsLines( result, "text: A paragraph with \nbegin:bold\ntext: bold \nbegin:italic\ntext: italic\nend:italic" ); - assertContainsLines( result, "begin:italic\ntext: italic \nbegin:bold\ntext: bold\nend:bold" ); - assertContainsLines( result, "begin:bold\ntext: bold \nbegin:monospaced\ntext: monospaced\nend:monospaced" ); - // 2 paragraphs in the input... - assertEquals( 3, result.split( "end:paragraph\n" ).length ); - // 6 bolds in the input... - assertEquals( 7, result.split( "end:bold\n" ).length ); - // 4 italics in the input... - assertEquals( 5, result.split( "end:italic\n" ).length ); - // 2 monospaced in the input... - assertEquals( 3, result.split( "end:monospaced\n" ).length ); - } + assertContainsLines(result, + "begin:paragraph\ntext: A paragraph\nend:paragraph\n"); + assertContainsLines( + result, + "begin:figure\nfigureGraphics, name: images/logo.png\nbegin:figureCaption\ntext: with a figure\nend:figureCaption"); + // 2 paragraphs in the input... + assertEquals(3, result.split("end:paragraph\n").length); + // 1 figure in the input... + assertEquals(2, result.split("end:figure\n").length); + } - /** @throws Exception */ - public void testNoteInfoTipQuote() - throws Exception - { - String result = locateAndParseTestSourceFile( "note-tip-info" ); + /** @throws Exception */ + public void testParagraphWithHeader() throws Exception { + String result = locateAndParseTestSourceFile("paragraph-header"); - assertContainsLines( result, "begin:definedTerm\ntext: Be Careful\nend:definedTerm\n" ); - assertContainsLines( result, "begin:definition\ntext: The body of the note here..\nend:definition" ); - assertContainsLines( result, "begin:definedTerm\ntext: Guess What?\nend:definedTerm\n" ); - assertContainsLines( result, "begin:definition\ntext: The body of the tip here..\nend:definition" ); - assertContainsLines( result, "begin:definedTerm\ntext: Some Info\nend:definedTerm\n" ); - assertContainsLines( result, "begin:definition\ntext: The body of the info here..\nend:definition" ); - assertContainsLines( result, "begin:definedTerm\ntext: Simon Says\nend:definedTerm\n" ); - assertContainsLines( result, "begin:definition\ntext: The body of the \nbegin:bold\ntext: quote\nend:bold" ); + assertContainsLines(result, + "begin:paragraph\ntext: A paragraph\nend:paragraph\n"); + assertContainsLines(result, + "begin:section2\nbegin:sectionTitle2\ntext: A header\nend:sectionTitle2"); + // 3 paragraphs in the input... + assertEquals(4, result.split("end:paragraph\n").length); + // 1 header in the input... + assertEquals(2, result.split("end:sectionTitle2\n").length); + } - // 5 paragraphs in the input... - assertEquals( 6, result.split( "end:paragraph\n" ).length ); - // 4 dinitionList in the input... - assertEquals( 5, result.split( "end:definitionList\n" ).length ); - } + /** @throws Exception */ + public void testNestedFormats() throws Exception { + String result = locateAndParseTestSourceFile("nested-format"); - /** - * DOXIA-247 - * - * @throws ParseException - */ - public void testEndBracket() - throws ParseException - { - String document = "Test" - + "\n\n* list1" - + "\n\n* list2" - + "\n\n* list2" - + "\n{pre}123{/pre}"; + assertContainsLines(result, + "begin:bold\nbegin:italic\ntext: bold italic\nend:italic"); + assertContainsLines(result, + "begin:italic\nbegin:bold\ntext: italic bold\nend:bold"); + assertContainsLines(result, + "begin:bold\nbegin:monospaced\ntext: bold monospaced\nend:monospaced"); + assertContainsLines( + result, + "text: A paragraph with \nbegin:bold\ntext: bold \nbegin:italic\ntext: italic\nend:italic"); + assertContainsLines(result, + "begin:italic\ntext: italic \nbegin:bold\ntext: bold\nend:bold"); + assertContainsLines(result, + "begin:bold\ntext: bold \nbegin:monospaced\ntext: monospaced\nend:monospaced"); + // 2 paragraphs in the input... + assertEquals(3, result.split("end:paragraph\n").length); + // 6 bolds in the input... + assertEquals(7, result.split("end:bold\n").length); + // 4 italics in the input... + assertEquals(5, result.split("end:italic\n").length); + // 2 monospaced in the input... + assertEquals(3, result.split("end:monospaced\n").length); + } - output = new StringWriter(); - Sink sink = new TextSink( output ); + /** @throws Exception */ + public void testNoteInfoTipQuote() throws Exception { + String result = locateAndParseTestSourceFile("note-tip-info"); - /* parsing with additional space at end works */ - createParser().parse( new StringReader( document + " " ), sink ); - assertTrue( "generated document should have a size > 0", output.toString().length() > 0 ); + assertContainsLines(result, + "begin:definedTerm\ntext: Be Careful\nend:definedTerm\n"); + assertContainsLines(result, + "begin:definition\ntext: The body of the note here..\nend:definition"); + assertContainsLines(result, + "begin:definedTerm\ntext: Guess What?\nend:definedTerm\n"); + assertContainsLines(result, + "begin:definition\ntext: The body of the tip here..\nend:definition"); + assertContainsLines(result, + "begin:definedTerm\ntext: Some Info\nend:definedTerm\n"); + assertContainsLines(result, + "begin:definition\ntext: The body of the info here..\nend:definition"); + assertContainsLines(result, + "begin:definedTerm\ntext: Simon Says\nend:definedTerm\n"); + assertContainsLines(result, + "begin:definition\ntext: The body of the \nbegin:bold\ntext: quote\nend:bold"); - /* parsing with document ending in } should not fail */ - try - { - createParser().parse( new StringReader( document ), sink ); - } - catch ( Exception e ) - { - e.printStackTrace(); - fail( "parsing with document ending in } should not fail" ); - } + // 5 paragraphs in the input... + assertEquals(6, result.split("end:paragraph\n").length); + // 4 dinitionList in the input... + assertEquals(5, result.split("end:definitionList\n").length); + } - assertTrue( "generated document should have a size > 0", output.toString().length() > 0 ); - } + /** + * DOXIA-247 + * + * @throws ParseException + */ + public void testEndBracket() throws ParseException { + String document = "Test" + "\n\n* list1" + "\n\n* list2" + + "\n\n* list2" + "\n{pre}123{/pre}"; - /** - * DOXIA-247 - * - * @throws ParseException - */ - public void testEndBracketInList() - throws ParseException - { - String document1 = "Test" - + "\n\n* list1" - + "\n\n* list2" - + "\n\n* list2{pre}123{/pre} " - + "\n123"; + output = new StringWriter(); + Sink sink = new TextSink(output); - String document2 = "Test" - + "\n\n* list1" - + "\n\n* list2" - + "\n\n* list2{pre}123{/pre}" - + "\n123"; + /* parsing with additional space at end works */ + createParser().parse(new StringReader(document + " "), sink); + assertTrue("generated document should have a size > 0", output + .toString().length() > 0); - output = new StringWriter(); - Sink sink = new TextSink( output ); + /* parsing with document ending in } should not fail */ + try { + createParser().parse(new StringReader(document), sink); + } catch (Exception e) { + e.printStackTrace(); + fail("parsing with document ending in } should not fail"); + } - /* parsing with additional space at end of list item works */ - createParser().parse( new StringReader( document1 ), sink ); - assertTrue( "generated document should have a size > 0", output.toString().length() > 0 ); + assertTrue("generated document should have a size > 0", output + .toString().length() > 0); + } - /* parsing with end of list item ending in } should not fail */ - try - { - createParser().parse( new StringReader( document2 ), sink ); - } - catch ( Exception e ) - { - e.printStackTrace(); - fail( "parsing with end of list item ending in } should not fail" ); - } + /** + * DOXIA-247 + * + * @throws ParseException + */ + public void testEndBracketInList() throws ParseException { + String document1 = "Test" + "\n\n* list1" + "\n\n* list2" + + "\n\n* list2{pre}123{/pre} " + "\n123"; - assertTrue( "generated document should have a size > 0", output.toString().length() > 0 ); - } + String document2 = "Test" + "\n\n* list1" + "\n\n* list2" + + "\n\n* list2{pre}123{/pre}" + "\n123"; - private void assertContainsLines( String message, String result, String lines ) - { - lines = StringUtils.replace( lines, "\n", EOL ); - if ( message != null ) - { - assertTrue( message, result.indexOf( lines ) != -1 ); - } - else - { - assertTrue( result.indexOf( lines ) != -1 ); - } - } + output = new StringWriter(); + Sink sink = new TextSink(output); - private void assertContainsLines( String result, String lines ) - { - this.assertContainsLines( null, result, lines ); - } + /* parsing with additional space at end of list item works */ + createParser().parse(new StringReader(document1), sink); + assertTrue("generated document should have a size > 0", output + .toString().length() > 0); - private String getLineBreakString() - { - StringWriter sw = new StringWriter(); - Sink sink = new TextSink( sw ); - sink.lineBreak(); + /* parsing with end of list item ending in } should not fail */ + try { + createParser().parse(new StringReader(document2), sink); + } catch (Exception e) { + e.printStackTrace(); + fail("parsing with end of list item ending in } should not fail"); + } - return sw.toString(); - } + assertTrue("generated document should have a size > 0", output + .toString().length() > 0); + } - private String locateAndParseTestSourceFile( String stem ) - throws IOException, ParseException - { - output = new StringWriter(); - reader = getTestReader( stem, outputExtension() ); - writer = getTestWriter( stem, "txt" ); + private void assertContainsLines(String message, String result, String lines) { + lines = StringUtils.replace(lines, "\n", EOL); + if (message != null) { + assertTrue(message, result.indexOf(lines) != -1); + } else { + assertTrue(result.indexOf(lines) != -1); + } + } - Sink sink = new TextSink( output ); - createParser().parse( reader, sink ); + private void assertContainsLines(String result, String lines) { + this.assertContainsLines(null, result, lines); + } - // write to file - String expected = output.toString(); - writer.write( expected ); - writer.flush(); - return expected; - } + private String getLineBreakString() { + StringWriter sw = new StringWriter(); + Sink sink = new TextSink(sw); + sink.lineBreak(); + return sw.toString(); + } + + private String locateAndParseTestSourceFile(String stem) + throws IOException, ParseException { + output = new StringWriter(); + reader = getTestReader(stem, outputExtension()); + writer = getTestWriter(stem, "txt"); + + Sink sink = new TextSink(output); + createParser().parse(reader, sink); + + // write to file + String expected = output.toString(); + writer.write(expected); + writer.flush(); + return expected; + } + } Index: src/test/resources/nested-list-heterogenous.confluence =================================================================== --- src/test/resources/nested-list-heterogenous.confluence (revision 0) +++ src/test/resources/nested-list-heterogenous.confluence (revision 0) @@ -0,0 +1,8 @@ + +A paragraph + +* A top level list item +*# A nested list item +*# Another nested list item +* Back at the top level + Index: src/main/java/org/apache/maven/doxia/module/confluence/parser/list/TreeComponent.java =================================================================== --- src/main/java/org/apache/maven/doxia/module/confluence/parser/list/TreeComponent.java (revision 754510) +++ src/main/java/org/apache/maven/doxia/module/confluence/parser/list/TreeComponent.java (working copy) @@ -27,98 +27,84 @@ * @author Jason van Zyl * @version $Id$ */ -class TreeComponent -{ - private static final String EOL = System.getProperty( "line.separator" ); +class TreeComponent { + private static final String EOL = System.getProperty("line.separator"); - private List children = new ArrayList(); + private List children = new ArrayList(); - private String text; + private String text; - private TreeComponent father; + private TreeComponent father; - private int type; + private String type; - TreeComponent( TreeComponent father, String text, int type ) - { - this.text = text; - this.father = father; - this.type = type; - } + TreeComponent(TreeComponent father, String text, String type) { + this.text = text; + this.father = father; + this.type = type; + } - List getChildren() - { - return children; - } + List getChildren() { + return children; + } - TreeComponent addChildren( String t, int ttype ) - { - if ( t == null ) - { - throw new IllegalArgumentException( "argument is null" ); - } + TreeComponent addChildren(String t, String ttype) { + if (t == null) { + throw new IllegalArgumentException("argument is null"); + } - TreeComponent ret = new TreeComponent( this, t, ttype ); + TreeComponent ret = new TreeComponent(this, t, ttype); - children.add( ret ); + children.add(ret); - return ret; - } + return ret; + } - TreeComponent getFather() - { - return father; - } + public TreeComponent getFather() { + return father; + } - int getDepth() - { - int ret = 0; + int getDepth() { + int ret = 0; - TreeComponent c = this; + TreeComponent c = this; - while ( ( c = c.getFather() ) != null ) - { - ret++; - } + while ((c = c.getFather()) != null) { + ret++; + } - return ret; - } + return ret; + } - /** {@inheritDoc} */ - public String toString() - { - return toString( "" ); - } + /** {@inheritDoc} */ + public String toString() { + return toString(""); + } - String toString( String indent ) - { - StringBuffer sb = new StringBuffer(); + String toString(String indent) { + StringBuffer sb = new StringBuffer(); - if ( father != null ) - { - sb.append( indent ); - sb.append( "- " ); - sb.append( text ); - sb.append( EOL ); - } + if (father != null) { + sb.append(indent); + sb.append("- "); + sb.append(text); + sb.append(EOL); + } - for ( Iterator i = children.iterator(); i.hasNext(); ) - { - TreeComponent lc = (TreeComponent) i.next(); + for (Iterator i = children.iterator(); i.hasNext();) { + TreeComponent lc = (TreeComponent) i.next(); - sb.append( lc.toString( indent + " " ) ); - } + sb.append(lc.toString(indent + " ")); + } - return sb.toString(); - } + return sb.toString(); + } - String getText() - { - return text; - } + String getText() { + return text; + } - int getType() - { - return type; - } + String getType() { + return type; + } } Index: src/main/java/org/apache/maven/doxia/module/confluence/parser/list/TreeListBuilder.java =================================================================== --- src/main/java/org/apache/maven/doxia/module/confluence/parser/list/TreeListBuilder.java (revision 754510) +++ src/main/java/org/apache/maven/doxia/module/confluence/parser/list/TreeListBuilder.java (working copy) @@ -24,116 +24,98 @@ import java.util.List; import org.apache.maven.doxia.module.confluence.parser.ChildBlocksBuilder; +import org.apache.maven.doxia.parser.ParseException; /** - *
TreeListBuilder class.
- * + *+ * TreeListBuilder class. + *
+ * * @version $Id$ */ -public class TreeListBuilder -{ - private TreeComponent root; +public class TreeListBuilder { + private TreeComponent root; - private TreeComponent current; + private TreeComponent current; - TreeListBuilder() - throws IllegalArgumentException - { - root = new TreeComponent( null, "root", 0 ); + TreeListBuilder() throws IllegalArgumentException { + root = new TreeComponent(null, "root", ""); - current = root; - } + current = root; + } - void feedEntry( int type, int level, String text ) - { - int currentDepth = current.getDepth(); + void feedEntry(String type, String text) { + String currentType = current.getType(); + if (type.length() == currentType.length() + 1) { + // nothing to move + } else if (type.length() > currentType.length() + 1) { + if (currentType.compareTo(type.substring(0, currentType.length())) != 0) + throw new IllegalStateException(); + List components = current.getChildren(); - int incomingLevel = level - 1; + if (components.size() > 0) { + // if we have children we must go down the tree + current = (TreeComponent) components.get(components.size() - 1); + } - if ( incomingLevel == currentDepth ) - { - // nothing to move - } - else if ( incomingLevel > currentDepth ) - { - // el actual ahora es el �ltimo que insert� - List components = current.getChildren(); + // we must create as much fake lists (empty items) as much is + // difference between + // last item lenght and the current one. + for (int i = currentType.length() + 1; i < type.length() - 1; i++) { + current = current.addChildren("", type.substring(0, i + 1)); + } + } else { + // we must to get back up the tree + for (int i = currentType.length(); i >= type.length(); i--) { + current = current.getFather(); + if (current == null) { + throw new IllegalStateException(); + } + } + } + // finally we are adding the item + current.addChildren(text, type); + } - if ( components.size() == 0 ) - { - /* for example: - * * item1 - * * item2 - */ - for ( int i = 0, n = incomingLevel - currentDepth; i < n; i++ ) - { - current = current.addChildren( "", type ); - } - } - else - { - current = (TreeComponent) components.get( components.size() - 1 ); - } - } - else - { - for ( int i = 0, n = currentDepth - incomingLevel; i < n; i++ ) - { - current = current.getFather(); + public ListBlock getBlock() throws ParseException { + return getList(root); + } - if ( current == null ) - { - throw new IllegalStateException(); - } - } - } - current.addChildren( text.trim(), type ); - } + private ListBlock getList(TreeComponent treeComponent) + throws ParseException { + List list = getListItems(treeComponent); + String type = ((TreeComponent) treeComponent.getChildren().get(0)) + .getType(); - ListBlock getBlock() - { - return getList( root ); - } + if (type.charAt(type.length() - 1) == '*' + || type.charAt(type.length() - 1) == '-') { + return new BulletedListBlock(list); + } else { + return new NumberedListBlock(list); + } + } - private ListBlock getList( TreeComponent treeComponent ) - { - List list = getListItems( treeComponent ); + private List getListItems(TreeComponent tc) throws ParseException { + List blocks = new ArrayList(); - int type = ( (TreeComponent) treeComponent.getChildren().get( 0 ) ).getType(); + for (Iterator i = tc.getChildren().iterator(); i.hasNext();) { + TreeComponent child = (TreeComponent) i.next(); + List childBlocks = new ArrayList(); + if (child.getFather() != null) { + childBlocks.addAll(new ChildBlocksBuilder(child.getText()) + .getBlocks()); + } + if (child.getChildren().size() != 0) { + blocks.add(new ListItemBlock(childBlocks, getList(child))); + } else { + blocks.add(new ListItemBlock(childBlocks)); + } + } - if ( type == ListBlockParser.BULLETED_LIST ) - { - return new BulletedListBlock( list ); - } + return blocks; + } - return new NumberedListBlock( list ); - } - - private List getListItems( TreeComponent tc ) - { - List blocks = new ArrayList(); - - for ( Iterator i = tc.getChildren().iterator(); i.hasNext(); ) - { - TreeComponent child = (TreeComponent) i.next(); - - List childBlocks = new ArrayList(); - - if ( child.getFather() != null ) - { - childBlocks.addAll( new ChildBlocksBuilder( child.getText() ).getBlocks() ); - } - - if ( child.getChildren().size() != 0 ) - { - blocks.add( new ListItemBlock( childBlocks, getList( child ) ) ); - } - else - { - blocks.add( new ListItemBlock( childBlocks ) ); - } - } - - return blocks; - } + public String toString() { + return root.toString(); + } } Index: src/main/java/org/apache/maven/doxia/module/confluence/parser/list/ListBlockParser.java =================================================================== --- src/main/java/org/apache/maven/doxia/module/confluence/parser/list/ListBlockParser.java (revision 754510) +++ src/main/java/org/apache/maven/doxia/module/confluence/parser/list/ListBlockParser.java (working copy) @@ -25,111 +25,76 @@ import org.apache.maven.doxia.parser.ParseException; /** - *ListBlockParser class.
- * + *+ * ListBlockParser class. + *
+ * * @author Jason van Zyl * @version $Id$ */ -public class ListBlockParser - implements BlockParser -{ - /** ConstantBULLETED_LIST=0 */
- public static final int BULLETED_LIST = 0;
+public class ListBlockParser implements BlockParser {
+ /** Constant BULLETED_LIST=0 */
+ public static final int BULLETED_LIST = 0;
- /** Constant NUMBERED_LIST=1 */
- public static final int NUMBERED_LIST = 1;
+ /** Constant NUMBERED_LIST=1 */
+ public static final int NUMBERED_LIST = 1;
- /** {@inheritDoc} */
- public boolean accept( String line, ByLineSource source )
- {
- if ( isList( line ) )
- {
- return true;
- }
+ /** {@inheritDoc} */
+ public boolean accept(String line, ByLineSource source) {
+ if (isList(line)) {
+ return true;
+ }
- return false;
- }
+ return false;
+ }
- /** {@inheritDoc} */
- public Block visit( String line, ByLineSource source )
- throws ParseException
- {
- TreeListBuilder treeListBuilder = new TreeListBuilder();
+ /** {@inheritDoc} */
+ public Block visit(String line, ByLineSource source) throws ParseException {
+ TreeListBuilder treeListBuilder = new TreeListBuilder();
- StringBuffer text = new StringBuffer();
+ StringBuffer text = new StringBuffer();
- do
- {
- if ( line.trim().length() == 0 )
- {
- break;
- }
+ do {
+ if (line.trim().length() == 0) {
+ break;
+ }
- if ( text.length() > 0 && isList( line ) )
- {
- // We reached a new line with list prefix
- addItem( treeListBuilder, text );
- }
+ if (text.length() > 0 && isList(line)) {
+ String item = text.toString();
+ treeListBuilder.feedEntry(getPrefix(item), item.substring(
+ getPrefix(item).length()).trim());
+ text.setLength(0);
+ }
- if ( text.length() == 0 )
- {
- text.append( line.trim() );
- }
- else
- {
- text.append( " " + line.trim() );
- }
+ if (text.length() == 0) {
+ text.append(line.trim());
+ } else {
+ text.append(" " + line.trim());
+ }
- }
- while ( ( line = source.getNextLine() ) != null );
+ } while ((line = source.getNextLine()) != null);
- if ( text.length() > 0 )
- {
- addItem( treeListBuilder, text );
- }
+ if (text.length() > 0) {
+ String item = text.toString();
+ treeListBuilder.feedEntry(getPrefix(item), item.substring(
+ getPrefix(item).length()).trim());
+ }
+ return treeListBuilder.getBlock();
+ }
- return treeListBuilder.getBlock();
- }
+ private String getPrefix(String line) {
+ int i = 0;
+ while (i < line.length()
+ && (line.charAt(i) == '-' || line.charAt(i) == '*' || line
+ .charAt(i) == '#'))
+ i++;
+ return line.substring(0, i);
+ }
- private void addItem( TreeListBuilder treeListBuilder, StringBuffer text )
- {
- String item = text.toString();
- if ( isBulletedList( item ) )
- {
- int level = getLevel( item, '*' );
+ private boolean isList(String line) {
+ line = line.trim();
- treeListBuilder.feedEntry( BULLETED_LIST, level, item.substring( level ) );
- }
- else
- {
- int level = getLevel( item, '#' );
-
- treeListBuilder.feedEntry( NUMBERED_LIST, level, item.substring( level ) );
- }
- text.setLength( 0 );
- }
-
- private int getLevel( String line, char c )
- {
- int level = 0;
-
- while ( line.charAt( level ) == c )
- {
- level++;
- }
-
- return level;
- }
-
- private boolean isBulletedList( String line )
- {
- return ( line.startsWith( "*" ) || line.startsWith( "-" ) );
- }
-
- private boolean isList( String line )
- {
- line = line.trim();
-
- return ( line.startsWith( "*" ) || line.startsWith( "-" ) || line.startsWith( "#" ) );
- }
+ return (line.startsWith("*") || line.startsWith("-") || line
+ .startsWith("#"));
+ }
}