You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2013/08/03 14:27:38 UTC
svn commit: r1509970 - in
/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence: ./
src/main/java/org/apache/maven/doxia/module/confluence/parser/table/
src/test/java/org/apache/maven/doxia/module/confluence/
Author: rfscholte
Date: Sat Aug 3 12:27:37 2013
New Revision: 1509970
URL: http://svn.apache.org/r1509970
Log:
[DOXIA-493] Images within table are not shown
Patch contributed by Mark Schenk, reviewed and adjusted by Robert Scholte
Modified:
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/pom.xml
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/table/TableBlockParser.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/pom.xml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/pom.xml?rev=1509970&r1=1509969&r2=1509970&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/pom.xml (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/pom.xml Sat Aug 3 12:27:37 2013
@@ -59,4 +59,10 @@ under the License.
<timezone>-5</timezone>
</developer>
</developers>
+
+ <contributors>
+ <contributor>
+ <name>Mark Schenk</name>
+ </contributor>
+ </contributors>
</project>
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/table/TableBlockParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/table/TableBlockParser.java?rev=1509970&r1=1509969&r2=1509970&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/table/TableBlockParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/main/java/org/apache/maven/doxia/module/confluence/parser/table/TableBlockParser.java Sat Aug 3 12:27:37 2013
@@ -24,21 +24,22 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
-import org.apache.maven.doxia.util.ByLineReaderSource;
import org.apache.maven.doxia.module.confluence.ConfluenceMarkup;
+import org.apache.maven.doxia.module.confluence.parser.Block;
+import org.apache.maven.doxia.module.confluence.parser.BlockParser;
+import org.apache.maven.doxia.module.confluence.parser.BoldBlock;
import org.apache.maven.doxia.module.confluence.parser.FigureBlockParser;
import org.apache.maven.doxia.module.confluence.parser.ParagraphBlockParser;
import org.apache.maven.doxia.module.confluence.parser.SectionBlockParser;
-import org.apache.maven.doxia.util.ByLineSource;
-import org.apache.maven.doxia.module.confluence.parser.BlockParser;
-import org.apache.maven.doxia.module.confluence.parser.Block;
-import org.apache.maven.doxia.module.confluence.parser.BoldBlock;
+import org.apache.maven.doxia.module.confluence.parser.list.ListBlockParser;
import org.apache.maven.doxia.parser.ParseException;
+import org.apache.maven.doxia.util.ByLineReaderSource;
+import org.apache.maven.doxia.util.ByLineSource;
import org.codehaus.plexus.util.StringUtils;
/**
* Parse tables
- *
+ *
* @author Juan F. Codagnone
* @version $Id$
*/
@@ -46,17 +47,37 @@ public class TableBlockParser
implements BlockParser
{
private static final String EMPTY_STRING = "";
+
private static final String ANY_CHARACTER = ".*";
+
private static final String ESCAPE_CHARACTER = "\\";
+ private BlockParser[] parsers;
+
+ /**
+ * Default constructor TableBlockParser.
+ */
+ public TableBlockParser()
+ {
+ BlockParser headingParser = new SectionBlockParser();
+ BlockParser figureParser = new FigureBlockParser();
+ BlockParser listParser = new ListBlockParser();
+
+ BlockParser[] subparsers = new BlockParser[] { headingParser, figureParser, listParser };
+ BlockParser paragraphParser = new ParagraphBlockParser( subparsers );
+
+ this.parsers = new BlockParser[] { headingParser, figureParser, listParser, paragraphParser };
+
+ }
+
/** {@inheritDoc} */
- public boolean accept( String line, ByLineSource source )
+ public boolean accept( String line, ByLineSource source )
{
return line.startsWith( "|" );
}
/** {@inheritDoc} */
- public Block visit( String line, ByLineSource source )
+ public Block visit( String line, ByLineSource source )
throws ParseException
{
if ( !accept( line, source ) )
@@ -74,22 +95,15 @@ public class TableBlockParser
List<Block> cells = new ArrayList<Block>();
- BlockParser headingParser = new SectionBlockParser();
- BlockParser figureParser = new FigureBlockParser();
- BlockParser[] subparsers = new BlockParser[] { headingParser, figureParser };
- BlockParser paragraphParser = new ParagraphBlockParser( subparsers );
-
if ( l.startsWith( "||" ) )
{
String[] text = StringUtils.split( l, "||" );
-
for ( int i = 0; i < text.length; i++ )
{
List<Block> textBlocks = new ArrayList<Block>();
- textBlocks.add( ( ( ParagraphBlockParser) paragraphParser )
- .visit( text[i], new ByLineReaderSource( new StringReader( EMPTY_STRING ) ), false ) );
+ textBlocks.add( parseLine( text[i], new ByLineReaderSource( new StringReader( EMPTY_STRING ) ) ) );
List<Block> blocks = new ArrayList<Block>();
@@ -104,29 +118,27 @@ public class TableBlockParser
String[] text = StringUtils.split( l, "|" );
List<String> texts = new LinkedList<String>();
-
while ( it < text.length )
{
- if ( text[it].matches( ANY_CHARACTER + ESCAPE_CHARACTER
- + ConfluenceMarkup.LINK_START_MARKUP + ANY_CHARACTER )
- && !text[it].matches( ANY_CHARACTER + ESCAPE_CHARACTER
- + ConfluenceMarkup.LINK_END_MARKUP + ANY_CHARACTER ) )
+ if ( text[it].matches( ANY_CHARACTER + ESCAPE_CHARACTER + ConfluenceMarkup.LINK_START_MARKUP
+ + ANY_CHARACTER )
+ && !text[it].matches( ANY_CHARACTER + ESCAPE_CHARACTER + ConfluenceMarkup.LINK_END_MARKUP
+ + ANY_CHARACTER ) )
{
texts.add( text[it] + ConfluenceMarkup.TABLE_CELL_MARKUP + text[it + 1] );
it += 2;
continue;
- }
+ }
texts.add( text[it] );
it++;
}
- Object[] pText = texts.toArray();
+ String[] pText = texts.toArray( new String[0] );
for ( int i = 0; i < pText.length; i++ )
{
List<Block> blocks = new ArrayList<Block>();
- blocks.add( ( (ParagraphBlockParser) paragraphParser ).visit( (String) pText[i],
- new ByLineReaderSource( new StringReader( EMPTY_STRING ) ), false ) );
+ blocks.add( parseLine( pText[i], new ByLineReaderSource( new StringReader( EMPTY_STRING ) ) ) );
cells.add( new TableCellBlock( blocks ) );
}
@@ -141,4 +153,27 @@ public class TableBlockParser
return new TableBlock( rows );
}
+
+ private Block parseLine( String text, ByLineSource source )
+ throws ParseException
+ {
+ if ( text.trim().length() > 0 )
+ {
+ for ( BlockParser parser : parsers )
+ {
+ if ( parser.accept( text, source ) )
+ {
+ if ( parser instanceof ParagraphBlockParser )
+ {
+ return ( (ParagraphBlockParser) parser ).visit( text, source, false );
+ }
+ else
+ {
+ return parser.visit( text, source );
+ }
+ }
+ }
+ }
+ return null;
+ }
}
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java?rev=1509970&r1=1509969&r2=1509970&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-confluence/src/test/java/org/apache/maven/doxia/module/confluence/ConfluenceParserTest.java Sat Aug 3 12:27:37 2013
@@ -315,6 +315,31 @@ public class ConfluenceParserTest
}
/** @throws Exception */
+ public void testTableWithImages()
+ throws Exception
+ {
+ // DOXIA-493
+ StringReader reader =
+ new StringReader( "Table containing image in cell:\n" + "\n" + "||Header 1||\n"
+ + "|!images/test/Image.png!|" );
+
+ SinkEventTestingSink sink = new SinkEventTestingSink();
+
+ parser.parse( reader, sink );
+
+ Iterator<SinkEventElement> it = sink.getEventList().iterator();
+
+ assertEquals( it, "head", "head_", "body", "paragraph" );
+ assertEquals( it.next(), "text", "Table containing image in cell:" );
+ assertEquals( it, "paragraph_", "table", "tableRows", "tableRow", "tableHeaderCell", "bold" );
+ assertEquals( it.next(), "text", "Header 1" );
+ assertEquals( it, "bold_", "tableHeaderCell_", "tableRow_", "tableRow", "tableCell", "figure" );
+ assertEquals( it.next(), "figureGraphics", "images/test/Image.png" );
+ assertEquals( it, "figure_", "tableCell_", "tableRow_", "tableRows_", "table_", "body_" );
+ assertFalse( it.hasNext() );
+ }
+
+ /** @throws Exception */
public void testParagraphWithList()
throws Exception
{