Author: ltheussl
Date: Fri May 23 04:38:39 2008
New Revision: 659507
URL: http://svn.apache.org/viewvc?rev=659507&view=rev
Log:
Better definition of external/internal/local links and adaptation in the apt case.
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java
Modified: 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=659507&r1=659506&r2=659507&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.java
(original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.java
Fri May 23 04:38:39 2008
@@ -39,6 +39,9 @@
*
* @param link The link to check.
* @return True if the link starts with "#".
+ *
+ * @see #isExternalLink(String)
+ * @see #isLocalLink(String)
*/
public static boolean isInternalLink( String link )
{
@@ -48,13 +51,16 @@
/**
* 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).
+ * to another document (a local link) of the same site.
*
* @param link The link to check.
- * @return True if the link (ignoring case) starts with either of the
- * following: "http:/", "https:/", "ftp:/", "mailto:", "file:/".
+ * @return True if the link (ignoring case) starts with either "http:/",
+ * "https:/", "ftp:/", "mailto:", "file:/", or contains the string "://".
* Note that Windows style separators "\" are not allowed
* for URIs, see http://www.ietf.org/rfc/rfc2396.txt , section 2.4.3.
+ *
+ * @see #isInternalLink(String)
+ * @see #isLocalLink(String)
*/
public static boolean isExternalLink( String link )
{
@@ -62,14 +68,19 @@
return ( text.indexOf( "http:/" ) == 0 || text.indexOf( "https:/" ) == 0
|| text.indexOf( "ftp:/" ) == 0 || text.indexOf( "mailto:" ) == 0
- || text.indexOf( "file:/" ) == 0 );
+ || text.indexOf( "file:/" ) == 0 || text.indexOf( "://" ) != -1 );
}
/**
- * Checks if the given string corresponds to a relative link to another document.
+ * Checks if the given string corresponds to a relative link to another document
+ * within the same site, ie it is neither an {@link #isInternalLink(String) internal}
+ * nor an {@link #isExternalLink(String) external} link.
*
* @param link The link to check.
* @return True if the link is neither an external nor an internal link.
+ *
+ * @see #isExternalLink(String)
+ * @see #isInternalLink(String)
*/
public static boolean isLocalLink( String link )
{
Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.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/AptParser.java?rev=659507&r1=659506&r2=659507&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java
Fri May 23 04:38:39 2008
@@ -25,6 +25,7 @@
import org.apache.maven.doxia.parser.AbstractTextParser;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.sink.SinkAdapter;
+import org.apache.maven.doxia.sink.SinkEventAttributeSet;
import org.apache.maven.doxia.util.DoxiaUtils;
import org.codehaus.plexus.util.IOUtil;
@@ -433,7 +434,7 @@
linkAnchor = getTraversedLink( text, i + 1, end );
}
- if ( !AptUtils.isExternalLink( linkAnchor ) )
+ if ( AptUtils.isInternalLink( linkAnchor ) )
{
linkAnchor = "#" + linkAnchor;
}
@@ -2209,7 +2210,7 @@
public void traverse()
throws AptParseException
{
- AptParser.this.sink.verbatim( boxed );
+ AptParser.this.sink.verbatim( SinkEventAttributeSet.BOXED );
// TODO: filter out lineBreak
AptParser.this.sink.text( text );
AptParser.this.sink.verbatim_();
Modified: 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=659507&r1=659506&r2=659507&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java
Fri May 23 04:38:39 2008
@@ -54,13 +54,18 @@
/**
* Checks if the given string corresponds to an external URI,
- * ie is not a link within the same document.
+ * ie is not a link within the same document nor a link to another
+ * document on the same filesystem.
*
* @param link The link to check.
* @return True if the link (ignoring case) starts with either "http:/",
- * "https:/", "ftp:/", "mailto:", "file:/", "../", "./" or contains the
- * string "://". Note that Windows style separators "\" are not allowed
+ * "https:/", "ftp:/", "mailto:", "file:/", or contains the string "://".
+ * Note that Windows style separators "\" are not allowed
* for URIs, see http://www.ietf.org/rfc/rfc2396.txt , section 2.4.3.
+ *
+ * @see org.apache.maven.doxia.util.DoxiaUtils#isExternalLink(String)
+ * @see #isInternalLink(String)
+ * @see #isLocalLink(String)
*/
public static boolean isExternalLink( String link )
{
@@ -68,8 +73,40 @@
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 || text.indexOf( "://" ) != -1 );
+ || text.indexOf( "file:/" ) == 0 || text.indexOf( "://" ) != -1 );
+ }
+
+ /**
+ * 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 link is neither an {@link #isExternalLink(String) external}
+ * nor a {@link #isLocalLink(String) local} link.
+ *
+ * @see org.apache.maven.doxia.util.DoxiaUtils#isInternalLink(String)
+ * @see #isExternalLink(String)
+ * @see #isLocalLink(String)
+ */
+ public static boolean isInternalLink( String link )
+ {
+ return ( !isExternalLink( link ) && !isLocalLink( link ) );
+ }
+
+ /**
+ * Checks if the given string corresponds to a relative link to another document
+ * within the same site.
+ *
+ * @param link The link to check.
+ * @return True if the link starts with either "/", "./" or "../".
+ *
+ * @see org.apache.maven.doxia.util.DoxiaUtils#isLocalLink(String)
+ * @see #isExternalLink(String)
+ * @see #isInternalLink(String)
+ */
+ public static boolean isLocalLink( String link )
+ {
+ return ( link.startsWith( "/" ) || link.startsWith( "./" ) || link.startsWith( "../"
) );
}
/**
|