You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by de...@apache.org on 2007/08/02 17:46:38 UTC
svn commit: r562147 - in /maven/doxia/doxia/trunk:
doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java
doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java
pom.xml
Author: dennisl
Date: Thu Aug 2 08:46:37 2007
New Revision: 562147
URL: http://svn.apache.org/viewvc?view=rev&rev=562147
Log:
[DOXIA-131] HtmlTools.encodeId makes id lower case
o Add JavaDoc.
o Add test case that checks that we preserve character case.
o Bump to junit 3.8.2, to get better error messages.
o Use assertEquals() instead of assertTrue(), to get better error messages.
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/pom.xml
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=562147&r1=562146&r2=562147
==============================================================================
--- 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 Thu Aug 2 08:46:37 2007
@@ -187,23 +187,55 @@
}
/**
- * According to the <a href="http://www.w3.org/TR/html4/types.html#type-name">W3C recommendation</a>:
- * <p><i>
- * ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number
- * of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").</i>
+ * According to the <a href="http://www.w3.org/TR/html4/types.html#type-name">
+ * HTML 4.01 specification section 6.2 SGML basic types</a>:
* <p>
+ * <i>ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
+ * followed by any number of letters, digits ([0-9]), hyphens ("-"),
+ * underscores ("_"), colons (":"), and periods (".").</i>
+ * </p>
*
+ * <p>
+ * According to <a href="http://www.w3.org/TR/xhtml1/#C_8">XHTML 1.0
+ * section C.8. Fragment Identifiers</a>:
+ * </p>
+ * <p>
+ * <i>When defining fragment identifiers to be backward-compatible, only
+ * strings matching the pattern [A-Za-z][A-Za-z0-9:_.-]* should be used.</i>
+ * </p>
+ *
+ * <p>
+ * To achieve this we need to convert the <i>id</i> String. Two conversions
+ * are necessary and one is done to get prettier ids:
+ * </p>
+ * <ol>
+ * <li>If the first character is not a letter, prepend the id with the
+ * letter 'a'</li>
+ * <li>A space is replaced with an underscore '_'</li>
+ * <li>Remove whitespace at the start and end before starting to process</li>
+ * </ol>
+ *
+ * <p>
+ * For letters, the case is preserved in the conversion.
+ * </p>
+ *
+ * <p>
+ * Here are some examples:
+ * </p>
* <pre>
- * HtmlTools.encodeId( null ) = null
- * HtmlTools.encodeId( "" ) = ""
- * HtmlTools.encodeId( "1anchor" ) = "a1anchor"
- * HtmlTools.encodeId( "_anchor" ) = "a_anchor"
+ * HtmlTools.encodeId( null ) = null
+ * HtmlTools.encodeId( "" ) = ""
+ * HtmlTools.encodeId( " _ " ) = "a_"
+ * HtmlTools.encodeId( "1" ) = "a1"
+ * HtmlTools.encodeId( "1anchor" ) = "a1anchor"
+ * HtmlTools.encodeId( "_anchor" ) = "a_anchor"
* HtmlTools.encodeId( "a b-c123 " ) = "a_b-c123"
* HtmlTools.encodeId( " anchor" ) = "anchor"
+ * HtmlTools.encodeId( "myAnchor" ) = "myAnchor"
* </pre>
*
- * @param id an id to be format
- * @return the id trimmed and well formated
+ * @param id The id to be encoded
+ * @return The id trimmed and encoded
*/
public static String encodeId( String id )
{
@@ -223,16 +255,13 @@
{
buffer.append( "a" );
}
-
- if ( ( Character.isLetterOrDigit( c ) ) || ( c == '-' ) || ( c == '_' ) || ( c == ':' ) || ( c == '.' ) )
- {
- // TODO: why? see DOXIA-131
- buffer.append( Character.toLowerCase( c ) );
- }
- // Not part of W3C recommendation, just to produce much nicer id
if ( c == ' ' )
{
buffer.append( "_" );
+ }
+ else if ( ( Character.isLetterOrDigit( c ) ) || ( c == '-' ) || ( c == '_' ) || ( c == ':' ) || ( c == '.' ) )
+ {
+ buffer.append( c );
}
}
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=562147&r1=562146&r2=562147
==============================================================================
--- 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 Thu Aug 2 08:46:37 2007
@@ -20,10 +20,9 @@
*/
import org.codehaus.plexus.PlexusTestCase;
-import org.apache.maven.doxia.util.HtmlTools;
/**
- * Test case for <code>HtmlTools</code>
+ * Test case for <code>HtmlTools</code>.
*
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
* @version $Id$
@@ -45,15 +44,19 @@
}
/**
- * Verify the awaited results
+ * Verify the expected results
*/
public void testEncodeId()
{
- assertTrue( HtmlTools.encodeId( null ) == null );
- assertTrue( HtmlTools.encodeId( "" ).equals( "" ) );
- assertTrue( HtmlTools.encodeId( "1anchor" ).equals( "a1anchor" ) );
- assertTrue( HtmlTools.encodeId( "_anchor" ).equals( "a_anchor" ) );
- assertTrue( HtmlTools.encodeId( "a b-c123 " ).equals( "a_b-c123" ) );
- assertTrue( HtmlTools.encodeId( " anchor" ).equals( "anchor" ) );
+ assertEquals( HtmlTools.encodeId( null ), null );
+ assertEquals( HtmlTools.encodeId( "" ), "" );
+ assertEquals( HtmlTools.encodeId( " " ), "" );
+ assertEquals( HtmlTools.encodeId( " _ " ), "a_" );
+ assertEquals( HtmlTools.encodeId( "1" ), "a1" );
+ assertEquals( HtmlTools.encodeId( "1anchor" ), "a1anchor" );
+ assertEquals( HtmlTools.encodeId( "_anchor" ), "a_anchor" );
+ assertEquals( HtmlTools.encodeId( "a b-c123 " ), "a_b-c123" );
+ assertEquals( HtmlTools.encodeId( " anchor" ), "anchor" );
+ assertEquals( HtmlTools.encodeId( "myAnchor" ), "myAnchor" );
}
}
Modified: maven/doxia/doxia/trunk/pom.xml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/pom.xml?view=diff&rev=562147&r1=562146&r2=562147
==============================================================================
--- maven/doxia/doxia/trunk/pom.xml (original)
+++ maven/doxia/doxia/trunk/pom.xml Thu Aug 2 08:46:37 2007
@@ -168,7 +168,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.1</version>
+ <version>3.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>