Class HtmlTextUtils


  • @OpenApiAll
    public class HtmlTextUtils
    extends java.lang.Object
    HTML text related utility methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      HtmlTextUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String encodeHtmlCharacters​(java.lang.String text)
      Encodes string characters to html characters.
      static java.lang.String endTag​(java.lang.String tag)
      Create end tag for the given tag.
      static java.lang.String escapeLongSpaces​(java.lang.String text)
      Replaces sequece of 2 or more spaces with same amount of not breaking spaces.
      static boolean isDocTypeHtml​(java.lang.String text)  
      static boolean isHtml​(java.lang.String text)
      Checks if given string is html string - starts with <html> tag
      static java.lang.String removeHtmlBodyPTags​(java.lang.String htmlText)
      Extracts body from the given html text.
      static java.lang.String removeHtmlBodyTags​(java.lang.String htmlText)
      Extracts body from the given html text
      static java.lang.String replaceNBSP​(java.lang.String text)  
      static java.lang.String startTag​(java.lang.String tag)
      Create start tag for the given tag.
      static java.lang.String toHtmlText​(java.lang.String text)
      Convert given text to html text.
      static java.lang.String toPlainText​(java.lang.String htmlText)
      Converts html text to plain text.
      static java.lang.String toPlainText​(javax.swing.text.Document doc)
      Converts document to plain text
      static java.lang.String wrapInHtmlBodyNewLineTags​(java.lang.String text)
      Wrap given text in <html><body>new_line tags
      static java.lang.String wrapInHtmlBodyPTags​(java.lang.String text)
      Wrap given text in <html><body><p> tags
      static java.lang.String wrapInHtmlBodyTags​(java.lang.String text)
      Wrap given text in <html><body> tags
      static java.lang.String wrapInHtmlLightBodyPTags​(java.lang.String text)
      Wrap given text in <html light="true"><body><p> tags
      static java.lang.String wrapInHtmlLightBodyTags​(java.lang.String text)
      Wrap given text in <html light="true"><body> tags
      static java.lang.String wrapInHtmlTag​(java.lang.String text)
      Wrap given text with <html> tag
      static java.lang.StringBuilder wrapInHtmlTag​(java.lang.StringBuilder text)
      Wrap given text with <html> tag
      • Methods inherited from class java.lang.Object

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

      • HtmlTextUtils

        public HtmlTextUtils()
    • Method Detail

      • isHtml

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

        public static boolean isDocTypeHtml​(java.lang.String text)
      • removeHtmlBodyPTags

        public static java.lang.String removeHtmlBodyPTags​(java.lang.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 java.lang.String removeHtmlBodyTags​(java.lang.String htmlText)
        Extracts body from the given html text
        Parameters:
        htmlText - html text
        Returns:
        body text
      • wrapInHtmlTag

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

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

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

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

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

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

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

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

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

        public static java.lang.String toHtmlText​(java.lang.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 java.lang.String encodeHtmlCharacters​(java.lang.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 java.lang.String toPlainText​(java.lang.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 java.lang.String toPlainText​(javax.swing.text.Document doc)
        Converts document to plain text
        Returns:
        the plain text
      • escapeLongSpaces

        public static java.lang.String escapeLongSpaces​(java.lang.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 java.lang.String replaceNBSP​(java.lang.String text)