Class TextUtils


  • @OpenApiAll
    public class TextUtils
    extends java.lang.Object
    Utility class to check the text formats and convert text from one format to other.

    Several text formats are supported:
    • plain - text without any formatting
    • html (or full html) - html text
    • light html - restricted html flavor which supports only <a> tags and href with "mdel://" protocol
    • rich - an extended version of plain text which support colored fragments (<font color=#> tags) and fragments with references (<a> tags and href with "mdel://" protocol)
    • Constructor Summary

      Constructors 
      Constructor Description
      TextUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static com.nomagic.text.rich.parser.RichTextHtmlParser.HTMLParserOptions createHTMLParserOptions()  
      private static java.lang.String fullHtmlToLightHtml​(java.lang.String text)  
      static boolean isFullHtml​(java.lang.String text)
      Checks if given text is html text, but not a "light" one.
      static boolean isHtml​(java.lang.String text)
      Checks if given text is html text.
      static boolean isLightHtml​(java.lang.String text)
      Checks if given text is "light" html.
      static boolean isPlainText​(java.lang.String text)
      Checks if given text is rich text.
      static boolean isRichText​(java.lang.String text)
      Checks if given text is rich text.
      private static java.lang.String lightHtmlToRichText​(java.lang.String text)  
      static java.lang.String toFullHtml​(java.lang.String text)
      Converts given text to full html.
      static java.lang.String toLightHtml​(java.lang.String text)
      Converts given text to light html.
      static java.lang.String toLightHtmlIfFullHtml​(java.lang.String text)
      Converts given text to light html if text is full html, otherwise returns the same text.
      static java.lang.String toLightHtmlIfRichText​(java.lang.String text)
      Converts given rich text to light html, otherwise returns the same text.
      static java.lang.String toPlainText​(java.lang.String text)
      Converts given rich or html text to plain text.
      static java.lang.String toPlainTextIfFullHtml​(java.lang.String text)
      Converts given full html text to plain text, otherwise returns the same text
      static java.lang.String toPlainTextIfHtml​(java.lang.String text)
      Converts given html text to plain text, otherwise returns the same text
      static java.lang.String toPlainTextIfLightHtml​(java.lang.String text)
      Converts given light html text to plain text, otherwise returns the same text
      static java.lang.String toRichText​(java.lang.String text)
      Converts given html text to rich text, otherwise returns the same text.
      static java.lang.String toRichTextIfLightHtml​(java.lang.String text)
      Converts given light html to rich text, otherwise returns the same text.
      • Methods inherited from class java.lang.Object

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

      • ELEMENT_HYPERLINK_PROTOCOL

        private static final java.lang.String ELEMENT_HYPERLINK_PROTOCOL
        See Also:
        Constant Field Values
    • Constructor Detail

      • TextUtils

        public TextUtils()
    • Method Detail

      • isHtml

        public static boolean isHtml​(@CheckForNull
                                     java.lang.String text)
        Checks if given text is html text.
        Parameters:
        text - text
        Returns:
        true if text is html
      • isFullHtml

        public static boolean isFullHtml​(@CheckForNull
                                         java.lang.String text)
        Checks if given text is html text, but not a "light" one.
        Parameters:
        text - text
        Returns:
        true if text is full html
      • isLightHtml

        public static boolean isLightHtml​(@CheckForNull
                                          java.lang.String text)
        Checks if given text is "light" html.
        Parameters:
        text - text
        Returns:
        true if text is light html
      • isRichText

        public static boolean isRichText​(@CheckForNull
                                         java.lang.String text)
        Checks if given text is rich text.
        Parameters:
        text - text
        Returns:
        true if text is rich one
      • isPlainText

        public static boolean isPlainText​(@CheckForNull
                                          java.lang.String text)
        Checks if given text is rich text.
        Parameters:
        text - text
        Returns:
        true if text is plain one
      • toFullHtml

        public static java.lang.String toFullHtml​(java.lang.String text)
        Converts given text to full html.
        Parameters:
        text - text
        Returns:
        full html text
      • toLightHtmlIfFullHtml

        public static java.lang.String toLightHtmlIfFullHtml​(java.lang.String text)
        Converts given text to light html if text is full html, otherwise returns the same text.
        Parameters:
        text - text
        Returns:
        light html text or same text
      • fullHtmlToLightHtml

        private static java.lang.String fullHtmlToLightHtml​(java.lang.String text)
      • toLightHtml

        public static java.lang.String toLightHtml​(java.lang.String text)
        Converts given text to light html. If text is full html converts to light html. If text is plain text converts to light html.
        Parameters:
        text - text
        Returns:
        light html text
      • toRichText

        public static java.lang.String toRichText​(java.lang.String text)
        Converts given html text to rich text, otherwise returns the same text.
        Parameters:
        text - text
        Returns:
        rich text
      • lightHtmlToRichText

        private static java.lang.String lightHtmlToRichText​(java.lang.String text)
      • createHTMLParserOptions

        private static com.nomagic.text.rich.parser.RichTextHtmlParser.HTMLParserOptions createHTMLParserOptions()
      • toRichTextIfLightHtml

        public static java.lang.String toRichTextIfLightHtml​(java.lang.String text)
        Converts given light html to rich text, otherwise returns the same text.
        Parameters:
        text - text
        Returns:
        rich text
      • toLightHtmlIfRichText

        public static java.lang.String toLightHtmlIfRichText​(java.lang.String text)
        Converts given rich text to light html, otherwise returns the same text.
        Parameters:
        text - text
        Returns:
        light html or same text
      • toPlainText

        public static java.lang.String toPlainText​(java.lang.String text)
        Converts given rich or html text to plain text.
        Parameters:
        text - text
        Returns:
        plain text
      • toPlainTextIfLightHtml

        public static java.lang.String toPlainTextIfLightHtml​(java.lang.String text)
        Converts given light html text to plain text, otherwise returns the same text
        Parameters:
        text - text
        Returns:
        plain text or same text
      • toPlainTextIfHtml

        public static java.lang.String toPlainTextIfHtml​(java.lang.String text)
        Converts given html text to plain text, otherwise returns the same text
        Parameters:
        text - text
        Returns:
        plain text or same text
      • toPlainTextIfFullHtml

        public static java.lang.String toPlainTextIfFullHtml​(java.lang.String text)
        Converts given full html text to plain text, otherwise returns the same text
        Parameters:
        text - text
        Returns:
        plain text or same text