Package com.iizix.text
Class HTMLUtilities
- java.lang.Object
- com.iizix.text.HTMLUtilities
public class HTMLUtilities extends java.lang.Object
Utility routines for HTML text.- Author:
- Christopher Mindus
Constructor Summary
Constructors Constructor Description HTMLUtilities()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
escapeCharsCodes(java.lang.String string)
Escapes all characters in the string that are below 32 (space) or above or equal to 127 to a "&#nnn;".static java.lang.String
escapeString(java.lang.String string, boolean doLineBreaks)
Escapes a HTML format string as the rules for quoted value for HTML.static java.lang.String
escapeTagValueString(java.lang.String string)
Escapes a string as the rules for quoted value in HTML tag specifies.static java.lang.String
replaceCharacterEntities(java.lang.String string)
Replaces all strings such as © � &x0000; to character values.
Method Detail
escapeString
public static java.lang.String escapeString(java.lang.String string, boolean doLineBreaks)
Escapes a HTML format string as the rules for quoted value for HTML.The following rules apply:
- Single CR, Single LF, CR/LF or LF/CR is replaced with '<br>' depending on the
doLineBreaks = true
. - White space characters (Tab, VT, FF) are left as is.
- '&' is replaced by '&'
- '<' is replaced with '<'
- '>' is replaced with '>'
- " is replaced by "
- All control characters (below space/0x20/32) are replaced by &#nnn;
- Parameters:
string
- The input string.doLineBreaks
- Flag indicating line breaks should be replaced with '<br>' (valid for CR+LF, a single LF or a single CR).- Returns:
- The escaped string, to surround with double-quotes when passed as a HTML value parameter in a tag.
- Single CR, Single LF, CR/LF or LF/CR is replaced with '<br>' depending on the
escapeTagValueString
public static java.lang.String escapeTagValueString(java.lang.String string)
Escapes a string as the rules for quoted value in HTML tag specifies.- White space characters (Tab, VT, FF, etc., see
Character.isWhitespace(char)
) are left as is. - '&' is replaced by '&'
- '<' and '>' are replaced with '<' and '>'
- " is replaced by "
- All control characters (below space/0x20/32) are replaced by &#nnn;, & to &, double-quote to ", < to < and > to >.
- Parameters:
string
- The input string.- Returns:
- The escaped string, to surround with double-quotes when passed as a HTML value parameter in a tag.
- White space characters (Tab, VT, FF, etc., see
escapeCharsCodes
public static java.lang.String escapeCharsCodes(java.lang.String string)
Escapes all characters in the string that are below 32 (space) or above or equal to 127 to a "&#nnn;".- Parameters:
string
- The input string.- Returns:
- The escaped string.
replaceCharacterEntities
public static java.lang.String replaceCharacterEntities(java.lang.String string)
Replaces all strings such as © � &x0000; to character values.- Parameters:
string
- Input string.- Returns:
- The "encoded" string (kind of inverted encode function).