------------------------------------------------------------------------ r17 | christian | 2007-11-07 16:56:44 -0300 (Wed, 07 Nov 2007) | 2 lines Links like [[http://twiki.com]] were transformed to wikiwords links. Bug fixed ------------------------------------------------------------------------ Index: doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java =================================================================== --- doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java (revision 16) +++ doxia-modules/doxia-module-twiki/src/test/java/org/apache/maven/doxia/module/twiki/parser/WordsTest.java (revision 17) @@ -198,6 +198,14 @@ }; blocks = (Block[]) textParser.parse( "foo[[wiki syntax]]bar" ).toArray( TOARRAY ); assertTrue( Arrays.equals( expected, blocks ) ); + + expected = new Block[]{ + new TextBlock( "foo" ), + new LinkBlock( "http://twiki.com", "http://twiki.com" ), + new TextBlock( "bar" ), + }; + blocks = (Block[]) textParser.parse( "foo[[http://twiki.com]]bar" ).toArray( TOARRAY ); + assertTrue( Arrays.equals( expected, blocks ) ); } /** Index: doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java =================================================================== --- doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java (revision 16) +++ doxia-modules/doxia-module-twiki/src/main/java/org/apache/maven/doxia/module/twiki/parser/TextParser.java (revision 17) @@ -182,24 +182,44 @@ } else { - final StringTokenizer tokenizer = - new StringTokenizer( showText ); - final StringBuffer sb = new StringBuffer(); + ret.addAll( parse( line.substring( 0, + forcedLinkMatcher.start() ) ) ); + ret.add( createLink( showText, showText ) ); + ret.addAll( parse( line.substring( forcedLinkMatcher.end(), + line.length() ) ) ); + } + } + } - while ( tokenizer.hasMoreElements() ) - { - final String s = tokenizer.nextToken(); - sb.append( s.substring( 0, 1 ).toUpperCase() ); - sb.append( s.substring( 1 ) ); - } + /** + * Decides between a WikiWordBlock or a a LinkBlock + * @param link the link text + * @param showText the show text. + * @return either a WikiWordBlock or a LinkBlock + */ + private Block createLink( final String link, final String showText ) + { + if ( URL_PATTERN.matcher( showText ).matches() ) + { + return new LinkBlock( showText, showText ); + } + else + { + final StringTokenizer tokenizer = + new StringTokenizer( showText ); + final StringBuffer sb = new StringBuffer(); - ret.addAll( parse( line.substring( 0, forcedLinkMatcher.start() ) ) ); - ret.add( new WikiWordBlock( sb.toString(), showText ) ); - ret.addAll( parse( line.substring( forcedLinkMatcher.end(), line.length() ) ) ); + while ( tokenizer.hasMoreElements() ) + { + final String s = tokenizer.nextToken(); + sb.append( s.substring( 0, 1 ).toUpperCase() ); + sb.append( s.substring( 1 ) ); } + return new WikiWordBlock( sb.toString(), showText ); } } + /** * Parses a wiki word * @param line the line to parse