diff --git a/src/java/org/apache/commons/lang/StringEscapeUtils.java b/src/java/org/apache/commons/lang/StringEscapeUtils.java index abcc6aa9b..08248e43a 100644 --- a/src/java/org/apache/commons/lang/StringEscapeUtils.java +++ b/src/java/org/apache/commons/lang/StringEscapeUtils.java @@ -438,12 +438,11 @@ public static void unescapeJavaScript(Writer out, String str) throws IOException * @see HTML 4.0 Character entity references * @see HTML 4.01 Character References * @see HTML 4.01 Code positions - **/ + */ public static String escapeHtml(String str) { if (str == null) { return null; } - try { StringWriter writer = new StringWriter ((int)(str.length() * 1.5)); escapeHtml(writer, str); @@ -455,7 +454,7 @@ public static String escapeHtml(String str) { return null; } } - + /** *

Escapes the characters in a String using HTML entities and writes * them to a Writer.

@@ -471,9 +470,9 @@ public static String escapeHtml(String str) { * Note that the commonly used apostrophe escape character (') * is not a legal entity and so is not supported).

* - * @param writer The Writer to write the result to. This must not be null. - * @param string The String to escape. This may be null. - * + * @param writer the writer receiving the escaped string, not null + * @param string the String to escape, may be null + * @throws IllegalArgumentException if the writer is null * @throws IOException when Writer passed throws the exception from * calls to the {@link Writer#write(int)} methods. * @@ -489,14 +488,13 @@ public static void escapeHtml(Writer writer, String string) throws IOException { if (writer == null ) { throw new IllegalArgumentException ("The Writer must not be null."); } - if (string == null) { return; } - Entities.HTML40.escape(writer, string); } + //----------------------------------------------------------------------- /** *

Unescapes a string containing entity escapes to a string * containing the actual Unicode characters corresponding to the @@ -512,12 +510,11 @@ public static void escapeHtml(Writer writer, String string) throws IOException { * @param str the String to unescape, may be null * @return a new unescaped String, null if null string input * @see #escapeHtml(Writer, String) - **/ + */ public static String unescapeHtml(String str) { if (str == null) { return null; } - try { StringWriter writer = new StringWriter ((int)(str.length() * 1.5)); unescapeHtml(writer, str); @@ -529,7 +526,7 @@ public static String unescapeHtml(String str) { return null; } } - + /** *

Unescapes a string containing entity escapes to a string * containing the actual Unicode characters corresponding to the @@ -542,23 +539,23 @@ public static String unescapeHtml(String str) { * verbatim into the result string. e.g. ">&zzzz;x" will * become ">&zzzz;x".

* - * @param writer writer receiving the unescaped string + * @param writer the writer receiving the unescaped string, not null * @param string the String to unescape, may be null + * @throws IllegalArgumentException if the writer is null * @throws IOException if an IOException occurs * @see #escapeHtml(String) - **/ + */ public static void unescapeHtml(Writer writer, String string) throws IOException { if (writer == null ) { throw new IllegalArgumentException ("The Writer must not be null."); } - if (string == null) { return; } - Entities.HTML40.unescape(writer, string); } + //----------------------------------------------------------------------- /** *

Escapes the characters in a String using XML entities.

* @@ -569,16 +566,16 @@ public static void unescapeHtml(Writer writer, String string) throws IOException *

Supports only the five basic XML entities (gt, lt, quot, amp, apos). * Does not support DTDs or external entities.

* - * @param writer writer receiving the unescaped string + * @param writer the writer receiving the unescaped string, not null * @param str the String to escape, may be null * @return a new escaped String, null if null string input + * @throws IllegalArgumentException if the writer is null * @see #unescapeXml(java.lang.String) - **/ + */ public static void escapeXml(Writer writer, String str) throws IOException { if (writer == null ) { throw new IllegalArgumentException ("The Writer must not be null."); } - if (str == null) { return; } @@ -598,7 +595,7 @@ public static void escapeXml(Writer writer, String str) throws IOException { * @param str the String to escape, may be null * @return a new escaped String, null if null string input * @see #unescapeXml(java.lang.String) - **/ + */ public static String escapeXml(String str) { if (str == null) { return null; @@ -606,6 +603,7 @@ public static String escapeXml(String str) { return Entities.XML.escape(str); } + //----------------------------------------------------------------------- /** *

Unescapes a string containing XML entity escapes to a string * containing the actual Unicode characters corresponding to the @@ -614,16 +612,16 @@ public static String escapeXml(String str) { *

Supports only the five basic XML entities (gt, lt, quot, amp, apos). * Does not support DTDs or external entities.

* - * @param writer writer receiving the unescaped string + * @param writer the writer receiving the unescaped string, not null * @param str the String to unescape, may be null * @return a new unescaped String, null if null string input + * @throws IllegalArgumentException if the writer is null * @see #escapeXml(String) - **/ + */ public static void unescapeXml(Writer writer, String str) throws IOException { if (writer == null ) { throw new IllegalArgumentException ("The Writer must not be null."); } - if (str == null) { return; } @@ -641,7 +639,7 @@ public static void unescapeXml(Writer writer, String str) throws IOException { * @param str the String to unescape, may be null * @return a new unescaped String, null if null string input * @see #escapeXml(String) - **/ + */ public static String unescapeXml(String str) { if (str == null) { return null; @@ -649,6 +647,7 @@ public static String unescapeXml(String str) { return Entities.XML.unescape(str); } + //----------------------------------------------------------------------- /** *

Escapes the characters in a String to be suitable to pass to * an SQL query.

@@ -675,4 +674,3 @@ public static String escapeSql(String str) { } } -