git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@418567 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2006-07-02 10:31:34 +00:00
parent b014341965
commit 5c20e64552
1 changed files with 22 additions and 24 deletions

View File

@ -438,12 +438,11 @@ public static void unescapeJavaScript(Writer out, String str) throws IOException
* @see <a href="http://www.w3.org/TR/REC-html40/sgml/entities.html">HTML 4.0 Character entity references</a>
* @see <a href="http://www.w3.org/TR/html401/charset.html#h-5.3">HTML 4.01 Character References</a>
* @see <a href="http://www.w3.org/TR/html401/charset.html#code-position">HTML 4.01 Code positions</a>
**/
*/
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;
}
}
/**
* <p>Escapes the characters in a <code>String</code> using HTML entities and writes
* them to a <code>Writer</code>.</p>
@ -471,9 +470,9 @@ public static String escapeHtml(String str) {
* Note that the commonly used apostrophe escape character (&amp;apos;)
* is not a legal entity and so is not supported). </p>
*
* @param writer The <code>Writer</code> to write the result to. This must not be <code>null</code>.
* @param string The <code>String</code> to escape. This may be <code>null</code>.
*
* @param writer the writer receiving the escaped string, not null
* @param string the <code>String</code> to escape, may be null
* @throws IllegalArgumentException if the writer is null
* @throws IOException when <code>Writer</code> 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);
}
//-----------------------------------------------------------------------
/**
* <p>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 <code>String</code> to unescape, may be null
* @return a new unescaped <code>String</code>, <code>null</code> 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;
}
}
/**
* <p>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. "&amp;gt;&amp;zzzz;x" will
* become "&gt;&amp;zzzz;x".</p>
*
* @param writer writer receiving the unescaped string
* @param writer the writer receiving the unescaped string, not null
* @param string the <code>String</code> 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);
}
//-----------------------------------------------------------------------
/**
* <p>Escapes the characters in a <code>String</code> using XML entities.</p>
*
@ -569,16 +566,16 @@ public static void unescapeHtml(Writer writer, String string) throws IOException
* <p>Supports only the five basic XML entities (gt, lt, quot, amp, apos).
* Does not support DTDs or external entities.</p>
*
* @param writer writer receiving the unescaped string
* @param writer the writer receiving the unescaped string, not null
* @param str the <code>String</code> to escape, may be null
* @return a new escaped <code>String</code>, <code>null</code> 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 <code>String</code> to escape, may be null
* @return a new escaped <code>String</code>, <code>null</code> 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);
}
//-----------------------------------------------------------------------
/**
* <p>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) {
* <p>Supports only the five basic XML entities (gt, lt, quot, amp, apos).
* Does not support DTDs or external entities.</p>
*
* @param writer writer receiving the unescaped string
* @param writer the writer receiving the unescaped string, not null
* @param str the <code>String</code> to unescape, may be null
* @return a new unescaped <code>String</code>, <code>null</code> 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 <code>String</code> to unescape, may be null
* @return a new unescaped <code>String</code>, <code>null</code> 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);
}
//-----------------------------------------------------------------------
/**
* <p>Escapes the characters in a <code>String</code> to be suitable to pass to
* an SQL query.</p>
@ -675,4 +674,3 @@ public static String escapeSql(String str) {
}
}