Class TextUtils

java.lang.Object
com.nomagic.text.TextUtils

@OpenApiAll public class TextUtils extends 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 Details

    • TextUtils

      public TextUtils()
  • Method Details

    • isHtml

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

      public static boolean isFullHtml(@CheckForNull 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 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 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 String text)
      Checks if given text is rich text.
      Parameters:
      text - text
      Returns:
      true if text is plain one
    • toFullHtml

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

      public static String toLightHtmlIfFullHtml(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
    • toLightHtml

      public static String toLightHtml(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 String toRichText(String text)
      Converts given html text to rich text, otherwise returns the same text.
      Parameters:
      text - text
      Returns:
      rich text
    • toRichTextIfLightHtml

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

      public static String toLightHtmlIfRichText(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 String toPlainText(String text)
      Converts given rich or html text to plain text.
      Parameters:
      text - text
      Returns:
      plain text
    • toPlainTextIfLightHtml

      public static String toPlainTextIfLightHtml(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 String toPlainTextIfHtml(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 String toPlainTextIfFullHtml(String text)
      Converts given full html text to plain text, otherwise returns the same text
      Parameters:
      text - text
      Returns:
      plain text or same text