Class HTMLUtilities

java.lang.Object
com.iizix.text.HTMLUtilities

public class HTMLUtilities extends Object
Utility routines for HTML text.
Author:
Christopher Mindus
  • Constructor Details

    • HTMLUtilities

      public HTMLUtilities()
  • Method Details

    • escapeString

      public static String escapeString(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 '&amp;'
      • '<' is replaced with '&lt;'
      • '>' is replaced with '&gt;'
      • " is replaced by &quot;
      • 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.
    • escapeTagValueString

      public static String escapeTagValueString(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 '&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 String escapeCharsCodes(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 String replaceCharacterEntities(String string)
      Replaces all strings such as &copy; &#00; &x0000; to character values.
      Parameters:
      string - Input string.
      Returns:
      The "encoded" string (kind of inverted encode function).