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 lt...@apache.org on 2011/04/05 13:54:43 UTC
svn commit: r1088993 - in /maven/doxia/doxia/trunk/doxia-core/src:
main/java/org/apache/maven/doxia/sink/
main/java/org/apache/maven/doxia/sink/render/
main/java/org/apache/maven/doxia/util/ test/java/org/apache/maven/doxia/util/
Author: ltheussl
Date: Tue Apr 5 11:54:42 2011
New Revision: 1088993
URL: http://svn.apache.org/viewvc?rev=1088993&view=rev
Log:
javadocs and minor code cleaning
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/render/RenderingContext.java
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/DoxiaUtils.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/XmlValidator.java
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/util/HtmlToolsTest.java
Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java?rev=1088993&r1=1088992&r2=1088993&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/AbstractSink.java Tue Apr 5 11:54:42 2011
@@ -64,6 +64,8 @@ public abstract class AbstractSink
* make sure that text output is filtered through this method.
*
* @param text the text to scan.
+ * May be null in which case null is returned.
+ *
* @return a String that contains only System EOLs.
*/
protected static String unifyEOLs( String text )
Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/render/RenderingContext.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/render/RenderingContext.java?rev=1088993&r1=1088992&r2=1088993&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/render/RenderingContext.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/render/RenderingContext.java Tue Apr 5 11:54:42 2011
@@ -99,7 +99,7 @@ public class RenderingContext
}
else
{
- this.outputName = document.substring( 0, document.indexOf( "." ) ).replace( '\\', '/' ) + ".html";
+ this.outputName = document.substring( 0, document.indexOf( '.' ) ).replace( '\\', '/' ) + ".html";
}
this.relativePath = PathTool.getRelativePath( basedir.getPath(), new File( basedir, document ).getPath() );
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=1088993&r1=1088992&r2=1088993&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 Tue Apr 5 11:54:42 2011
@@ -50,20 +50,24 @@ import org.apache.maven.doxia.sink.SinkE
*/
public class DoxiaUtils
{
-
private static final int MINUS_ONE = 0xFF;
/**
* Checks if the given string corresponds to an internal link,
* ie it is a link to an anchor within the same document.
+ * If link is not null, then exactly one of the three methods
+ * {@link #isInternalLink(java.lang.String)}, {@link #isExternalLink(java.lang.String)} and
+ * {@link #isLocalLink(java.lang.String)} will return true.
*
- * @param link The link to check.
+ * @param link The link to check. Not null.
* @return True if the link starts with "#".
*
+ * @throws NullPointerException if link is null.
+ *
* @see #isExternalLink(String)
* @see #isLocalLink(String)
*/
- public static boolean isInternalLink( String link )
+ public static boolean isInternalLink( final String link )
{
return link.startsWith( "#" );
}
@@ -72,17 +76,23 @@ public class DoxiaUtils
* 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) of the same site.
+ * If link is not null, then exactly one of the three methods
+ * {@link #isInternalLink(java.lang.String)}, {@link #isExternalLink(java.lang.String)} and
+ * {@link #isLocalLink(java.lang.String)} will return true.
+ *
+ * @param link The link to check. Not null.
*
- * @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
* for URIs, see http://www.ietf.org/rfc/rfc2396.txt , section 2.4.3.
*
+ * @throws NullPointerException if link is null.
+ *
* @see #isInternalLink(String)
* @see #isLocalLink(String)
*/
- public static boolean isExternalLink( String link )
+ public static boolean isExternalLink( final String link )
{
String text = link.toLowerCase( Locale.ENGLISH );
@@ -95,14 +105,20 @@ public class DoxiaUtils
* 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.
+ * If link is not null, then exactly one of the three methods
+ * {@link #isInternalLink(java.lang.String)}, {@link #isExternalLink(java.lang.String)} and
+ * {@link #isLocalLink(java.lang.String)} will return true.
+ *
+ * @param link The link to check. Not null.
*
- * @param link The link to check.
* @return True if the link is neither an external nor an internal link.
*
+ * @throws NullPointerException if link is null.
+ *
* @see #isExternalLink(String)
* @see #isInternalLink(String)
*/
- public static boolean isLocalLink( String link )
+ public static boolean isLocalLink( final String link )
{
return ( !isExternalLink( link ) && !isInternalLink( link ) );
}
@@ -115,10 +131,13 @@ public class DoxiaUtils
* </p>
*
* @param id The id to be encoded.
+ * May be null in which case null is returned.
+ *
* @return The trimmed and encoded id, or null if id is null.
+ *
* @see #encodeId(java.lang.String, boolean)
*/
- public static String encodeId( String id )
+ public static String encodeId( final String id )
{
return encodeId( id, false );
}
@@ -179,22 +198,26 @@ public class DoxiaUtils
* </pre>
*
* @param id The id to be encoded.
+ * May be null in which case null is returned.
* @param chop true if non-ASCII characters should be ignored.
* If false, any non-ASCII characters will be replaced as specified above.
+ *
* @return The trimmed and encoded id, or null if id is null.
* If id is not null, the return value is guaranteed to be a valid Doxia id.
*
+ * @see #isValidId(java.lang.String)
+ *
* @since 1.1.1
*/
- public static String encodeId( String id, boolean chop )
+ public static String encodeId( final String id, final boolean chop )
{
if ( id == null )
{
return null;
}
- id = id.trim();
- int length = id.length();
+ final String idd = id.trim();
+ int length = idd.length();
if ( length == 0 )
{
@@ -205,7 +228,7 @@ public class DoxiaUtils
for ( int i = 0; i < length; ++i )
{
- char c = id.charAt( i );
+ char c = idd.charAt( i );
if ( ( i == 0 ) && ( !isAsciiLetter( c ) ) )
{
@@ -261,7 +284,7 @@ public class DoxiaUtils
*
* @since 1.1.1
*/
- public static String byteToHex( byte b )
+ public static String byteToHex( final byte b )
{
return Integer.toHexString( b & MINUS_ONE );
}
@@ -271,10 +294,13 @@ public class DoxiaUtils
* laid out in {@link #encodeId(String)}.
*
* @param text The text to be tested.
+ * May be null in which case false is returned.
+ *
* @return <code>true</code> if the text is a valid id, otherwise <code>false</code>.
+ *
* @see #encodeId(String)
*/
- public static boolean isValidId( String text )
+ public static boolean isValidId( final String text )
{
if ( text == null || text.length() == 0 )
{
@@ -324,13 +350,16 @@ public class DoxiaUtils
* (ignoring case) return the current date.</p>
*
* @param str the date to parse, not null.
+ *
* @return the parsed date, or the current date if the input String (ignoring case) was
* <code>"today"</code> or <code>"now"</code>.
+ *
* @throws ParseException if no pattern matches.
+ * @throws NullPointerException if str is null.
*
* @since 1.1.1.
*/
- public static Date parseDate( String str )
+ public static Date parseDate( final String str )
throws ParseException
{
if ( "today".equals( str.toLowerCase( Locale.ENGLISH ) )
@@ -358,12 +387,12 @@ public class DoxiaUtils
// private
//
- private static boolean isAsciiLetter( char c )
+ private static boolean isAsciiLetter( final char c )
{
return ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) );
}
- private static boolean isAsciiDigit( char c )
+ private static boolean isAsciiDigit( final char c )
{
return ( c >= '0' && c <= '9' );
}
@@ -372,12 +401,16 @@ public class DoxiaUtils
* Determine width and height of an image. If successful, the returned SinkEventAttributes
* contain width and height attribute keys whose values are the width and height of the image (as a String).
*
- * @param logo a String containing either a URL or a path to an image file.
+ * @param logo a String containing either a URL or a path to an image file. Not null.
+ *
* @return a set of SinkEventAttributes, or null if no ImageReader was found to read the image.
+ *
* @throws java.io.IOException if an error occurs during reading.
+ * @throws NullPointerException if logo is null.
+ *
* @since 1.1.1
*/
- public static MutableAttributeSet getImageAttributes( String logo )
+ public static MutableAttributeSet getImageAttributes( final String logo )
throws IOException
{
BufferedImage img = null;
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=1088993&r1=1088992&r2=1088993&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 Tue Apr 5 11:54:42 2011
@@ -21,7 +21,7 @@ package org.apache.maven.doxia.util;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
-import java.util.Hashtable;
+import java.util.HashMap;
import java.util.List;
import javax.swing.text.html.HTML.Tag;
@@ -61,7 +61,7 @@ public class HtmlTools
HtmlMarkup.TR, HtmlMarkup.TT, HtmlMarkup.U, HtmlMarkup.UL, HtmlMarkup.VAR
};
- private static final Hashtable TAG_HASHTABLE = new Hashtable( ALL_TAGS.length );
+ private static final HashMap TAG_MAP = new HashMap( ALL_TAGS.length );
private static final int ASCII = 0x7E;
@@ -69,7 +69,7 @@ public class HtmlTools
{
for ( int i = 0; i < ALL_TAGS.length; i++ )
{
- TAG_HASHTABLE.put( ALL_TAGS[i].toString(), ALL_TAGS[i] );
+ TAG_MAP.put( ALL_TAGS[i].toString(), ALL_TAGS[i] );
}
}
@@ -87,9 +87,9 @@ public class HtmlTools
*/
public static Tag getHtmlTag( String tagName )
{
- Object t = TAG_HASHTABLE.get( tagName );
+ Object t = TAG_MAP.get( tagName );
- return ( t == null ? null : (Tag) t );
+ return (Tag) t;
}
/**
@@ -134,7 +134,7 @@ public class HtmlTools
* @see <a href="http://www.w3.org/TR/2000/REC-xml-20001006#sec-predefined-ent">http://www.w3.org/TR/2000/REC-xml-20001006#sec-predefined-ent</a>
* @see <a href="http://www.w3.org/TR/html401/charset.html#h-5.3">http://www.w3.org/TR/html401/charset.html#h-5.3</a>
*/
- public static final String escapeHTML( String text, boolean xmlMode )
+ public static String escapeHTML( final String text, final boolean xmlMode )
{
if ( text == null )
{
Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/XmlValidator.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/XmlValidator.java?rev=1088993&r1=1088992&r2=1088993&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/XmlValidator.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/util/XmlValidator.java Tue Apr 5 11:54:42 2011
@@ -149,7 +149,7 @@ public class XmlValidator
/**
* Convenience class to beautify <code>SAXParseException</code> messages.
*/
- static class MessagesErrorHandler
+ private static class MessagesErrorHandler
extends DefaultHandler
{
private static final int TYPE_UNKNOWN = 0;
@@ -170,7 +170,7 @@ public class XmlValidator
private boolean hasDtdAndXsd;
- public MessagesErrorHandler( Log log )
+ private MessagesErrorHandler( Log log )
{
this.log = log;
}
@@ -243,11 +243,11 @@ public class XmlValidator
}
message.append( EOL );
- message.append( " Public ID: " + e.getPublicId() ).append( EOL );
- message.append( " System ID: " + e.getSystemId() ).append( EOL );
- message.append( " Line number: " + e.getLineNumber() ).append( EOL );
- message.append( " Column number: " + e.getColumnNumber() ).append( EOL );
- message.append( " Message: " + e.getMessage() ).append( EOL );
+ message.append( " Public ID: " ).append( e.getPublicId() ).append( EOL );
+ message.append( " System ID: " ).append( e.getSystemId() ).append( EOL );
+ message.append( " Line number: " ).append( e.getLineNumber() ).append( EOL );
+ message.append( " Column number: " ).append( e.getColumnNumber() ).append( EOL );
+ message.append( " Message: " ).append( e.getMessage() ).append( EOL );
final String logMessage = message.toString();
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=1088993&r1=1088992&r2=1088993&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 Tue Apr 5 11:54:42 2011
@@ -152,6 +152,7 @@ public class HtmlToolsTest
*/
public void testGetHtmlTag()
{
+ assertNull( HtmlTools.getHtmlTag( null ) );
assertNull( HtmlTools.getHtmlTag( "" ) );
assertNull( HtmlTools.getHtmlTag( "weirdHtmlTag" ) );
assertNotNull( HtmlTools.getHtmlTag( "strong" ) );