Class 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 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HTMLUtilities

        public HTMLUtilities()
    • Method Detail

      • escapeString

        public static java.lang.String escapeString​(java.lang.String string,
                                                    boolean doLineBreaks)
        Escapes a 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>'.
        • White space characters (Tab, VT, FF) are left as is.
        • '&' is replaced by '&amp;'
        • '<' and '>' are replaced with '&lt;' and '&gt;'
        • " is replaced by &quot;
        • All control characters (below space/0x20/32) are replaced by &#nnn;, & to &amp;, double-quote to &quot;, < to &lt; and > to &gt;.
        Parameters:
        string - The input string.
        doLineBreaks - Flag to replace CR/LF combinations with '<br>' when true, false not to replace and leave as is.
        Returns:
        The escaped string, to surround with double-quotes when passed as a HTML value parameter in a tag.
      • 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, CR, LF, VT, FF) are left as is.
        • '&' is replaced by '&amp;'
        • '<' and '>' are replaced with '&lt;' and '&gt;'
        • " is replaced by &quot;
        • All control characters (below space/0x20/32) are replaced by &#nnn;, & to &amp;, double-quote to &quot;, < to &lt; and > to &gt;.
        Parameters:
        string - The input string.
        Returns:
        The escaped string, to surround with double-quotes when passed as a HTML value parameter in a tag.
      • 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 &copy; &#00; &x0000; to character values.
        Parameters:
        string - Input string.
        Returns:
        The "decoded" string (kind of inverted encode function).