Class HTMLFormatter


  • public class HTMLFormatter
    extends java.lang.Object
    Utility class which is used to substitute text containing various links (http://, mailto:, ftp: and so on) with actual HTML link and line feeds with <br/> tag.

    Rewritten to fix TW-8635.

    • Constructor Summary

      Constructors 
      Constructor Description
      HTMLFormatter()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addTransformLinkPattern()  
      static void addTransformLinkWithTextPattern()  
      static java.lang.String format​(java.lang.String text, javax.servlet.jsp.JspContext context)
      Searches for plain links in specified text and returns the same text with links transformed to HTML links (<a href=""></a>).
      static java.lang.String format​(java.lang.String text, WebContext context)
      Searches for plain links in specified text and returns the same text with links transformed to HTML links (<a href=""></a>).
      static java.lang.String formatMultiLine​(java.lang.String text)
      Escapes the text for HTML and transforms line feeds with <br>s.
      static java.lang.String formatMultiLine​(java.lang.String text, boolean escape)
      Transforms line feeds with <br>s.
      • Methods inherited from class java.lang.Object

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

      • HTMLFormatter

        public HTMLFormatter()
    • Method Detail

      • format

        public static java.lang.String format​(java.lang.String text,
                                              @NotNull
                                              javax.servlet.jsp.JspContext context)
        Searches for plain links in specified text and returns the same text with links transformed to HTML links (<a href=""></a>).
        Parameters:
        text - text containing links
        context - JSP context
        Returns:
        text with transformed links
      • format

        public static java.lang.String format​(java.lang.String text,
                                              @NotNull
                                              WebContext context)
        Searches for plain links in specified text and returns the same text with links transformed to HTML links (<a href=""></a>).
        Parameters:
        text - text containing links
        context - context for the transformation
        Returns:
        text with transformed links
        Since:
        2018.1
      • formatMultiLine

        @NotNull
        public static java.lang.String formatMultiLine​(@Nullable
                                                       java.lang.String text)
        Escapes the text for HTML and transforms line feeds with <br>s.
        Parameters:
        text - text to format
        Returns:
        a formatted text
        Since:
        7.0
      • formatMultiLine

        @NotNull
        public static java.lang.String formatMultiLine​(@Nullable
                                                       java.lang.String text,
                                                       boolean escape)
        Transforms line feeds with <br>s.
        Parameters:
        text - text to format
        escape - true if text should be escaped first
        Returns:
        a formatted text
        Since:
        7.1.2, 8.0
      • addTransformLinkWithTextPattern

        public static void addTransformLinkWithTextPattern()
      • addTransformLinkPattern

        public static void addTransformLinkPattern()