Class HtmlTextUtils

java.lang.Object
com.nomagic.text.html.HtmlTextUtils

@OpenApiAll public class HtmlTextUtils extends Object
HTML text related utility methods.
  • Constructor Details

    • HtmlTextUtils

      public HtmlTextUtils()
  • Method Details

    • isHtml

      public static boolean isHtml(@CheckForNull String text)
      Checks if given string is html string - starts with <html> tag
      Parameters:
      text - text
    • isDocTypeHtml

      public static boolean isDocTypeHtml(String text)
    • removeHtmlBodyPTags

      public static String removeHtmlBodyPTags(String htmlText)
      Extracts body from the given html text. If body is wrapped with P tags, removes them as well.
      Parameters:
      htmlText - html text
      Returns:
      body text
    • removeHtmlBodyTags

      public static String removeHtmlBodyTags(String htmlText)
      Extracts body from the given html text
      Parameters:
      htmlText - html text
      Returns:
      body text
    • wrapInHtmlTag

      public static String wrapInHtmlTag(String text)
      Wrap given text with <html> tag
      Parameters:
      text - text
      Returns:
      wrapped text
    • wrapInHtmlTag

      public static StringBuilder wrapInHtmlTag(StringBuilder text)
      Wrap given text with <html> tag
      Parameters:
      text - text
      Returns:
      wrapped text
    • wrapInHtmlBodyPTags

      public static String wrapInHtmlBodyPTags(String text)
      Wrap given text in <html><body><p> tags
      Parameters:
      text - text
      Returns:
      wrapped text
    • wrapInHtmlBodyNewLineTags

      public static String wrapInHtmlBodyNewLineTags(String text)
      Wrap given text in <html><body>new_line tags
      Parameters:
      text - text
      Returns:
      wrapped text
    • wrapInHtmlBodyTags

      public static String wrapInHtmlBodyTags(String text)
      Wrap given text in <html><body> tags
      Parameters:
      text - text
      Returns:
      wrapped text
    • wrapInHtmlLightBodyTags

      public static String wrapInHtmlLightBodyTags(String text)
      Wrap given text in <html light="true"><body> tags
      Parameters:
      text - text
      Returns:
      wrapped text
    • wrapInHtmlLightBodyPTags

      public static String wrapInHtmlLightBodyPTags(String text)
      Wrap given text in <html light="true"><body><p> tags
      Parameters:
      text - text
      Returns:
      wrapped text
    • startTag

      public static String startTag(String tag)
      Create start tag for the given tag.
      Parameters:
      tag - The given tag.
      Returns:
      tag wrapped to <tag>
    • endTag

      public static String endTag(String tag)
      Create end tag for the given tag.
      Parameters:
      tag - The given tag.
      Returns:
      tag wrapped to </tag>
    • toHtmlText

      public static String toHtmlText(String text)
      Convert given text to html text. Characters are converter to html characters. Does nothing if text is html text already.
      Parameters:
      text - the given text
      Returns:
      the html text
    • encodeHtmlCharacters

      public static String encodeHtmlCharacters(String text)
      Encodes string characters to html characters. For example convert space to nbps;, < to &lt; and etc.
      Parameters:
      text - plain text
      Returns:
      string with encoded characters
    • toPlainText

      public static String toPlainText(String htmlText)
      Converts html text to plain text. Important - pass html text, not a plain text!
      Parameters:
      htmlText - html text
      Returns:
      plain text
    • toPlainText

      public static String toPlainText(Document doc)
      Converts document to plain text
      Returns:
      the plain text
    • escapeLongSpaces

      public static String escapeLongSpaces(String text)
      Replaces sequece of 2 or more spaces with same amount of not breaking spaces. Required for HTML text, which shrinks multiple spaces into single
    • replaceNBSP

      public static String replaceNBSP(String text)