maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r652905 - in /maven/doxia/doxia/trunk: doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/ doxia-core/src/main/java/org/apache/maven/doxia/parser/ doxia-core/src/main/java/org/apache/maven/doxia/util/ doxia-core/...
Date Fri, 02 May 2008 20:56:52 GMT
Author: ltheussl
Date: Fri May  2 13:56:52 2008
New Revision: 652905

URL: http://svn.apache.org/viewvc?rev=652905&view=rev
Log:
[DOXIA-208] Start cleaning up link-anchor handling. Deprecate StructureSinkUtils. It is still
used in XhtmlBaseSink, this has to be fixed together with the behaviour of AptParser.

Added:
    maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.java
  (with props)
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/DoxiaUtilsTest.java
  (with props)
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java
  (with props)
Modified:
    maven/doxia/doxia/trunk/doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/DocBookBookSinkTest.java
    maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
    maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/HtmlTools.java
    maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/StructureSinkUtils.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-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocBookSink.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/test/java/org/apache/maven/doxia/module/docbook/DocBookSinkTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XmlWriterXdocSink.java

Modified: maven/doxia/doxia/trunk/doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/DocBookBookSinkTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/DocBookBookSinkTest.java?rev=652905&r1=652904&r2=652905&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/DocBookBookSinkTest.java
(original)
+++ maven/doxia/doxia/trunk/doxia-book/src/test/java/org/apache/maven/doxia/book/services/renderer/docbook/DocBookBookSinkTest.java
Fri May  2 13:56:52 2008
@@ -386,15 +386,13 @@
     /** {@inheritDoc} */
     protected String getAnchorBlock( String anchor )
     {
-        // TODO: fix id
-        return "<anchor id=\"a.anchor\" />" + anchor;
+        return "<anchor id=\"" + anchor + "\" />" + anchor;
     }
 
     /** {@inheritDoc} */
     protected String getLinkBlock( String link, String text )
     {
-        // TODO: fix link
-        return "<link linkend=\"a.link\">" + text + "</link>";
+        return "<link linkend=\"" + link + "\">" + text + "</link>";
     }
 
     /** {@inheritDoc} */

Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java?rev=652905&r1=652904&r2=652905&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
(original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
Fri May  2 13:56:52 2008
@@ -687,7 +687,7 @@
         char[] chars = parser.getTextCharacters( holder );
         String textChars = String.valueOf( chars, holder[0], holder[1] );
 
-        if ( "#160".equals( textChars ) )
+        if ( "#160".equals( textChars ) || "nbsp".equals( textChars ) )
         {
             sink.nonBreakingSpace();
         }

Added: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.java?rev=652905&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.java
(added)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.java
Fri May  2 13:56:52 2008
@@ -0,0 +1,79 @@
+package org.apache.maven.doxia.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * General Doxia utility methods. The methods in this class should not assume
+ * any specific Doxia module or document format.
+ *
+ * @author ltheussl
+ * @since 1.0-beta-1
+ * @version $Id$
+ */
+public class DoxiaUtils {
+
+    /**
+     * Checks if the given string corresponds to an internal link,
+     * ie it is a link to an anchor within the same document.
+     *
+     * @param link The link to check.
+     * @return True if the link starts with "#".
+     */
+    public static boolean isInternalLink( String link )
+    {
+        return link.startsWith( "#" );
+    }
+
+    /**
+     * Checks if the given string corresponds to an external URI,
+     * ie is not a link within the same document nor a relative link
+     * to another document (a local link).
+     *
+     * @param link The link to check.
+     * @return True if the link (ignoring case) starts with either of the
+     * following: "http:/", "https:/", "ftp:/", "mailto:", "file:/".
+     * Note that Windows style separators "\" are not allowed
+     * for URIs, see  http://www.ietf.org/rfc/rfc2396.txt , section 2.4.3.
+     */
+    public static boolean isExternalLink( String link )
+    {
+        String text = link.toLowerCase();
+
+        return ( text.indexOf( "http:/" ) == 0 || text.indexOf( "https:/" ) == 0
+            || text.indexOf( "ftp:/" ) == 0 || text.indexOf( "mailto:" ) == 0
+            || text.indexOf( "file:/" ) == 0 );
+    }
+
+    /**
+     * Checks if the given string corresponds to a relative link to another document.
+     *
+     * @param link The link to check.
+     * @return True if the link is neither an external nor an internal link.
+     */
+    public static boolean isLocalLink( String link )
+    {
+        return ( !isExternalLink( link ) && !isInternalLink( link ) );
+    }
+
+    private DoxiaUtils() {
+        // utility class
+    }
+
+}

Propchange: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

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?rev=652905&r1=652904&r2=652905&view=diff
==============================================================================
--- 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
Fri May  2 13:56:52 2008
@@ -198,27 +198,6 @@
     }
 
     /**
-     * Replace all characters in a text.
-     *
-     * <pre>
-     * HtmlTools.encodeFragment( null ) = null
-     * HtmlTools.encodeFragment( "" ) = ""
-     * HtmlTools.encodeFragment( "http://www.google.com" ) = "httpwwwgooglecom"
-     * </pre>
-     *
-     * @param text the String to check, may be null
-     * @return the text with only letter and digit, null if null String input
-     */
-    public static String encodeFragment( String text )
-    {
-        if ( text == null )
-        {
-            return null;
-        }
-        return encodeURL( StructureSinkUtils.linkToKey( text ) );
-    }
-
-    /**
      * Construct a valid id.
      * <p>
      * According to the <a href="http://www.w3.org/TR/html4/types.html#type-name">
@@ -269,8 +248,8 @@
      * HtmlTools.encodeId( "myAnchor" )  = "myAnchor"
      * </pre>
      *
-     * @param id The id to be encoded
-     * @return The id trimmed and encoded
+     * @param id The id to be encoded.
+     * @return The trimmed and encoded id, or null if id is null.
      */
     public static String encodeId( String id )
     {
@@ -286,10 +265,12 @@
         for ( int i = 0; i < length; ++i )
         {
             char c = id.charAt( i );
+
             if ( ( i == 0 ) && ( !Character.isLetter( c ) ) )
             {
                 buffer.append( "a" );
             }
+
             if ( c == ' ' )
             {
                 buffer.append( "_" );
@@ -305,11 +286,11 @@
 
     /**
      * Determines if the specified text is a valid id according to the rules
-     * laid out in encodeId(String).
+     * laid out in {@link #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>
+     * @param text The text to be tested.
+     * @return <code>true</code> if the text is a valid id, otherwise <code>false</code>.
+     * @see #encodeId(String).
      */
     public static boolean isId( String text )
     {
@@ -321,10 +302,12 @@
         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;
@@ -337,4 +320,8 @@
 
         return true;
     }
+
+    private HtmlTools() {
+        // utility class
+}
 }

Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/StructureSinkUtils.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/StructureSinkUtils.java?rev=652905&r1=652904&r2=652905&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/StructureSinkUtils.java
(original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/StructureSinkUtils.java
Fri May  2 13:56:52 2008
@@ -23,7 +23,7 @@
  * Utility methods for Sinks.
  *
  * @version $Id$
- * @since 1.0-beta-1
+ * @deprecated Use o.a.m.d.sink.SinkUtils for Sink Utility methods.
  */
 public class StructureSinkUtils
 {
@@ -36,6 +36,8 @@
      * following: "http:/", "https:/", "ftp:/", "mailto:", "file:/",
      * "../" or "./". Note that Windows style separators "\" are not allowed
      * for URIs, see  http://www.ietf.org/rfc/rfc2396.txt , section 2.4.3.
+     * @deprecated This method is apt specific, it should not be used by a general Sink.
+     * Use DoxiaUtils.isExternalLink() or SinkUtils.isExternalLink() instead.
      */
     public static boolean isExternalLink( String link )
     {
@@ -52,7 +54,8 @@
      *
      * @param text The text to transform.
      * @return A text with escaped special characters.
-     * @todo This is apt specific, need to clarify general use.
+     * @deprecated This method is apt specific, it should not be used by a general Sink.
+     * Use AptUtils.linkToKey() instead.
      */
     public static String linkToKey( String text )
     {

Added: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/DoxiaUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/DoxiaUtilsTest.java?rev=652905&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/DoxiaUtilsTest.java
(added)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/DoxiaUtilsTest.java
Fri May  2 13:56:52 2008
@@ -0,0 +1,134 @@
+package org.apache.maven.doxia.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.PlexusTestCase;
+
+/**
+ * Test case for <code>DoxiaUtils</code>.
+ *
+ * @author ltheussl
+ * @version $Id$
+ */
+public class DoxiaUtilsTest
+    extends PlexusTestCase
+{
+    /**
+     * Verify the expected results.
+     */
+    public void testIsInternalLink()
+    {
+        String link = "#anchor";
+        assertTrue( "Should be an internal link: " + link,
+            DoxiaUtils.isInternalLink( link ) );
+
+        link = "http://maven.apache.org/index.html#anchor";
+        assertFalse( "Should NOT be an internal link: " + link,
+            DoxiaUtils.isInternalLink( link ) );
+
+        link = "./index.html";
+        assertFalse( "Should NOT be an internal link: " + link,
+            DoxiaUtils.isInternalLink( link ) );
+    }
+
+    /**
+     * Verify the expected results.
+     */
+    public void testIsExternalLink()
+    {
+        String link = "http://maven.apache.org/";
+        assertTrue( "Should be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = "https://maven.apache.org/";
+        assertTrue( "Should be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = "HTTPS://MAVEN.APACHE.ORG/";
+        assertTrue( "Should be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = "ftp:/maven.apache.org/";
+        assertTrue( "Should be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = "mailto:maven@apache.org";
+        assertTrue( "Should be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = "file:/index.html";
+        assertTrue( "Should be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = "index.html";
+        assertFalse( "Should NOT be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = "example.pdf";
+        assertFalse( "Should NOT be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = "./index.html";
+        assertFalse( "Should NOT be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = "../index.html";
+        assertFalse( "Should NOT be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        // Windows style separators "\" are not allowed
+
+        link = "file:\\index.html";
+        assertFalse( "Should NOT be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = ".\\index.html";
+        assertFalse( "Should NOT be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+
+        link = "..\\index.html";
+        assertFalse( "Should NOT be an external link: " + link,
+            DoxiaUtils.isExternalLink( link ) );
+    }
+
+    /**
+     * Verify the expected results.
+     */
+    public void testIsLocalLink()
+    {
+        String link = "index.html";
+        assertTrue( "Should be a local link: " + link,
+            DoxiaUtils.isLocalLink( link ) );
+
+        link = "./index.html";
+        assertTrue( "Should be a local link: " + link,
+            DoxiaUtils.isLocalLink( link ) );
+
+        link = "../index.html";
+        assertTrue( "Should be a local link: " + link,
+            DoxiaUtils.isLocalLink( link ) );
+
+        link = "#anchor";
+        assertFalse( "Should NOT be a local link: " + link,
+            DoxiaUtils.isLocalLink( link ) );
+
+    }
+
+}

Propchange: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/DoxiaUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/DoxiaUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

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?rev=652905&r1=652904&r2=652905&view=diff
==============================================================================
--- 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
Fri May  2 13:56:52 2008
@@ -41,10 +41,14 @@
         assertEquals( HtmlTools.escapeHTML( "&" ), "&amp;" );
         assertEquals( HtmlTools.escapeHTML( "\"" ), "&quot;" );
         assertEquals( HtmlTools.escapeHTML( "&amp;" ), "&amp;amp;" );
+
+        // xml mode
+        assertEquals( HtmlTools.escapeHTML( "\u00e4", true ), "\u00e4" );
+        assertEquals( HtmlTools.escapeHTML( "\u00e4", false ), "&#228;" );
     }
 
     /**
-     * Verify the expected results
+     * Verify the expected results.
      */
     public void testEncodeId()
     {
@@ -61,7 +65,24 @@
     }
 
     /**
-     * Verify the expected results
+     * Verify the expected results.
+     */
+    public void testEncodeURL()
+    {
+        assertNull( HtmlTools.encodeURL( null ) );
+        assertEquals( HtmlTools.encodeURL( "" ), "" );
+        assertEquals( HtmlTools.encodeURL(
+            "http://www.example.com/?This is a simple test." ),
+            "http://www.example.com/?This%20is%20a%20simple%20test." );
+
+        // TODO: the & is not encoded?
+        //assertEquals( HtmlTools.encodeURL(
+        //    "http://www.example.com/?This is a simple & short test." ),
+        //    "http://www.example.com/?This%20is%20a%20simple%20%26%20short%20test." );
+    }
+
+    /**
+     * Verify the expected results.
      */
     public void testIsId()
     {

Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java?rev=652905&view=auto
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java
(added)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java
Fri May  2 13:56:52 2008
@@ -0,0 +1,101 @@
+package org.apache.maven.doxia.module.apt;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * A collection of utility methods for dealing with APT documents.
+ *
+ * @author ltheussl
+ * @since 1.0-beta-1
+ * @version $Id$
+ */
+public class AptUtils {
+
+    /**
+     * Replace all characters in a text.
+     *
+     * <pre>
+     * AptTools.encodeFragment( null ) = null
+     * AptTools.encodeFragment( "" ) = ""
+     * AptTools.encodeFragment( "http://www.google.com" ) = "httpwwwgooglecom"
+     * </pre>
+     *
+     * @param text the String to check, may be null.
+     * @return the text with only letter and digit, null if null String input.
+     */
+    public static String encodeFragment( String text )
+    {
+        if ( text == null )
+        {
+            return null;
+        }
+
+        return linkToKey( text );
+    }
+
+    /**
+     * Checks if the given string corresponds to an external URI,
+     * ie is not a link within the same document.
+     *
+     * @param link The link to check.
+     * @return True if the link (ignoring case) starts with either of the
+     * following: "http:/", "https:/", "ftp:/", "mailto:", "file:/",
+     * "../" or "./". Note that Windows style separators "\" are not allowed
+     * for URIs, see  http://www.ietf.org/rfc/rfc2396.txt , section 2.4.3.
+     */
+    public static boolean isExternalLink( String link )
+    {
+        String text = link.toLowerCase();
+
+        return ( text.indexOf( "http:/" ) == 0 || text.indexOf( "https:/" ) == 0
+            || text.indexOf( "ftp:/" ) == 0 || text.indexOf( "mailto:" ) == 0
+            || text.indexOf( "file:/" ) == 0 || text.indexOf( "../" ) == 0
+            || text.indexOf( "./" ) == 0 );
+    }
+
+    /**
+     * Transforms the given text such that it can be used as a link.
+     * All non-LetterOrDigit characters are removed and the remaining
+     * characters are transformed to lower-case.
+     *
+     * @param text The text to transform.
+     * @return The text with all non-LetterOrDigit characters removed.
+     */
+    public static String linkToKey( String text )
+    {
+        int length = text.length();
+        StringBuffer buffer = new StringBuffer( length );
+
+        for ( int i = 0; i < length; ++i )
+        {
+            char c = text.charAt( i );
+            if ( Character.isLetterOrDigit( c ) )
+            {
+                buffer.append( Character.toLowerCase( c ) );
+            }
+        }
+
+        return buffer.toString();
+    }
+
+    private AptUtils() {
+        // utility class
+    }
+}

Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocBookSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocBookSink.java?rev=652905&r1=652904&r2=652905&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocBookSink.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/main/java/org/apache/maven/doxia/module/docbook/DocBookSink.java
Fri May  2 13:56:52 2008
@@ -30,8 +30,10 @@
 
 import org.apache.maven.doxia.parser.Parser;
 import org.apache.maven.doxia.sink.AbstractXmlSink;
+import org.apache.maven.doxia.util.DoxiaUtils;
+import org.apache.maven.doxia.util.HtmlTools;
 import org.apache.maven.doxia.util.LineBreaker;
-import org.apache.maven.doxia.util.StructureSinkUtils;
+
 import org.codehaus.plexus.util.FileUtils;
 
 /**
@@ -1489,7 +1491,7 @@
         {
             // First char of ID cannot be a digit.
             MutableAttributeSet att = new SimpleAttributeSet();
-            att.addAttribute( Attribute.ID, "a." + StructureSinkUtils.linkToKey( name ) );
+            att.addAttribute( Attribute.ID, HtmlTools.encodeId( name ) );
 
             // TODO: why?
             if ( xmlMode )
@@ -1529,7 +1531,7 @@
      */
     public void link( String name )
     {
-        if ( StructureSinkUtils.isExternalLink( name ) )
+        if ( DoxiaUtils.isExternalLink( name ) )
         {
             externalLinkFlag = true;
             MutableAttributeSet att = new SimpleAttributeSet();
@@ -1541,7 +1543,7 @@
         {
             // First char of ID cannot be a digit.
             MutableAttributeSet att = new SimpleAttributeSet();
-            att.addAttribute( LINKEND_ATTRIBUTE, "a." + StructureSinkUtils.linkToKey( name
) );
+            att.addAttribute( LINKEND_ATTRIBUTE, HtmlTools.encodeId( name ) );
 
             writeStartTag( LINK_TAG, att );
         }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/test/java/org/apache/maven/doxia/module/docbook/DocBookSinkTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/test/java/org/apache/maven/doxia/module/docbook/DocBookSinkTest.java?rev=652905&r1=652904&r2=652905&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/test/java/org/apache/maven/doxia/module/docbook/DocBookSinkTest.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-docbook-simple/src/test/java/org/apache/maven/doxia/module/docbook/DocBookSinkTest.java
Fri May  2 13:56:52 2008
@@ -174,15 +174,13 @@
     /** {@inheritDoc} */
     protected String getAnchorBlock( String anchor )
     {
-        // TODO: fix id
-        return "<anchor id=\"a.anchor\">" + anchor + "</anchor>";
+        return "<anchor id=\"" + anchor + "\">" + anchor + "</anchor>";
     }
 
     /** {@inheritDoc} */
     protected String getLinkBlock( String link, String text )
     {
-        // TODO: fix link
-        return "<link linkend=\"a.link\">" + text + "</link>";
+        return "<link linkend=\"" + link + "\">" + text + "</link>";
     }
 
     /** {@inheritDoc} */

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java?rev=652905&r1=652904&r2=652905&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-latex/src/main/java/org/apache/maven/doxia/module/latex/LatexSink.java
Fri May  2 13:56:52 2008
@@ -21,8 +21,8 @@
 
 import org.apache.maven.doxia.parser.Parser;
 import org.apache.maven.doxia.sink.AbstractTextSink;
+import org.apache.maven.doxia.util.DoxiaUtils;
 import org.apache.maven.doxia.util.LineBreaker;
-import org.apache.maven.doxia.util.StructureSinkUtils;
 
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
@@ -899,7 +899,7 @@
     public void link( String name )
     {
         // TODO: use \\url for simple links
-        if ( StructureSinkUtils.isExternalLink( name ) )
+        if ( DoxiaUtils.isExternalLink( name ) )
         {
             markup( "\\href{" + name + "}{" );
         }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java?rev=652905&r1=652904&r2=652905&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
Fri May  2 13:56:52 2008
@@ -30,7 +30,6 @@
 import org.apache.maven.doxia.sink.SinkUtils;
 import org.apache.maven.doxia.sink.XhtmlBaseSink;
 import org.apache.maven.doxia.util.HtmlTools;
-import org.apache.maven.doxia.util.StructureSinkUtils;
 
 /**
  * A doxia Sink which produces an xdoc model.
@@ -406,14 +405,7 @@
             att.addAttribute( Attribute.TARGET, target );
         }
 
-        if ( StructureSinkUtils.isExternalLink( name ) || isExternalHtml( name ) )
-        {
             att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name ) );
-        }
-        else
-        {
-            att.addAttribute( Attribute.HREF, "#" + HtmlTools.escapeHTML( name ) );
-        }
 
         writeStartTag( Tag.A, att );
     }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XmlWriterXdocSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XmlWriterXdocSink.java?rev=652905&r1=652904&r2=652905&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XmlWriterXdocSink.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XmlWriterXdocSink.java
Fri May  2 13:56:52 2008
@@ -22,7 +22,6 @@
 import org.apache.maven.doxia.parser.Parser;
 import org.apache.maven.doxia.sink.SinkAdapter;
 import org.apache.maven.doxia.util.HtmlTools;
-import org.apache.maven.doxia.util.StructureSinkUtils;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.XMLWriter;
 
@@ -528,7 +527,7 @@
     {
         if ( !headFlag )
         {
-            String id = StructureSinkUtils.linkToKey( name );
+            String id = HtmlTools.encodeId( name );
             writer.startElement( "a" );
             writer.addAttribute( "id", id );
             writer.addAttribute( "name", id );



Mime
View raw message