Author: dennisl Date: Sat Aug 11 15:00:50 2007 New Revision: 564980 URL: http://svn.apache.org/viewvc?view=rev&rev=564980 Log: o Try to fix the problems with links that are created as "#link" when they should be created as "link". This problem first arised with the fix for DOXIA-47 in r555417 and r559749.
Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java?view=diff&rev=564980&r1=564979&r2=564980 ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java Sat Aug 11 15:00:50 2007 @@ -267,4 +267,39 @@ return buffer.toString(); } + + /** + * Determines if the specified text is a valid id according to the rules + * laid out in encodeId(String). + * + * @see #encodeId(String) + * @param text The text to be tested + * @return <code>true</code> if the text is a valid id, otherwise <code>false</code> + */ + public static boolean isId( String text ) + { + if ( text == null || text.length() == 0 ) + { + return false; + } + + for ( int i = 0; i < text.length(); ++i ) + { + char c = text.charAt( i ); + if ( i == 0 && !Character.isLetter( c ) ) + { + return false; + } + if ( c == ' ' ) + { + return false; + } + else if ( !Character.isLetterOrDigit( c ) && c != '-' && c != '_' && c != ':' && c != '.' ) + { + return false; + } + } + + return true; + } } Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java?view=diff&rev=564980&r1=564979&r2=564980 ============================================================================== --- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java (original) +++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java Sat Aug 11 15:00:50 2007 @@ -59,4 +59,25 @@ assertEquals( HtmlTools.encodeId( " anchor" ), "anchor" ); assertEquals( HtmlTools.encodeId( "myAnchor" ), "myAnchor" ); } + + /** + * Verify the expected results + */ + public void testIsId() + { + assertFalse( HtmlTools.isId( null )); + assertFalse( HtmlTools.isId( "" ) ); + assertFalse( HtmlTools.isId( " " ) ); + assertFalse( HtmlTools.isId( " _ " ) ); + assertFalse( HtmlTools.isId( "1" ) ); + assertFalse( HtmlTools.isId( "1anchor" ) ); + assertFalse( HtmlTools.isId( "_anchor" ) ); + assertFalse( HtmlTools.isId( "a b-c123 " ) ); + assertFalse( HtmlTools.isId( " anchor" ) ); + assertTrue( HtmlTools.isId( "myAnchor" ) ); + assertTrue( HtmlTools.isId( "a_" ) ); + assertTrue( HtmlTools.isId( "a-" ) ); + assertTrue( HtmlTools.isId( "a:" ) ); + assertTrue( HtmlTools.isId( "a." ) ); + } } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java?view=diff&rev=564980&r1=564979&r2=564980 ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java Sat Aug 11 15:00:50 2007 @@ -1031,8 +1031,8 @@ { String text = href.toLowerCase(); return ( text.indexOf( ".html#" ) != -1 || text.indexOf( ".htm#" ) != -1 - || text.endsWith( ".htm" ) || text.endsWith( ".html" ) ); - + || text.endsWith( ".htm" ) || text.endsWith( ".html" ) + || !HtmlTools.isId( text ) ); } /**