Class WebEncodeHelper


  • public class WebEncodeHelper
    extends Object
    Utility class to encode special string or characters to be compliant with the web (HTML and Javascript). Useful to format text in HTML but not to encode unsafe text in HTML or Javascript. To encode unsafe text, please use instead Encode.
    Version:
    1.0
    Author:
    lloiseau
    • Method Detail

      • javaStringToJsString

        public static String javaStringToJsString​(String input)
        Convert a java string to a javascript string. Replace \,\n,\r and "
        Parameters:
        input - Java string to encode
        Returns:
        javascript string encoded
      • javaStringToHtmlString

        public static String javaStringToHtmlString​(String input)
        Convert a java string to a html text for textArea value. Replace ", >, <, & and \n
        Parameters:
        input - Java string to encode
        Returns:
        html string encoded
      • escapeXml

        public static String escapeXml​(String input)
      • convertBlanksForHtml

        public static String convertBlanksForHtml​(String input)
        Convert a text, possibly an HTML one, by replacing any blank tokens (tab and line-feeds) by their counterpart in HTML.
        Parameters:
        input - a text in which blank tokens are converted in HTML.
        Returns:
        an HTML text
      • javaStringToHtmlParagraphe

        public static String javaStringToHtmlParagraphe​(String input)
        Convert a java string to a html string for HTML paragraph. Replace ", >, <, & and \n
        Parameters:
        input - Java string to encode
        Returns:
        html string encoded
      • htmlStringToJavaString

        public static String htmlStringToJavaString​(String input)
        Convert a html string to a java string. Replace "
        Parameters:
        input - HTML text to encode
        Returns:
        html string JAVA encoded
      • convertHTMLEntities

        public static String convertHTMLEntities​(String text)
      • encodeFilename

        public static String encodeFilename​(String filename)
        Encode a UTF-8 filename in Base64 for the content-disposition header according to RFC2047.
        Parameters:
        filename - the UTF-8 filename to be encoded.
        Returns:
        the filename to be inserted in the content-disposition header.