Class HtmlUtil


  • public final class HtmlUtil
    extends Object
    • Field Detail

      • HTML_ENCODE_FUNCTION

        public static final com.google.common.base.Function<String,​String> HTML_ENCODE_FUNCTION
        Function to apply htmlEncode(String).
    • Constructor Detail

      • HtmlUtil

        public HtmlUtil()
    • Method Detail

      • htmlEncode

        public static String htmlEncode​(Object object)
        Encodes the given Object to be HTML safe using entity escapes. If the object is a number, returns the string it in string format If the object is a string, returns htmlEncoded string For everything else returns an empty string
        Parameters:
        object - the object to encode.
        Returns:
        the encoded text.
      • htmlEncode

        public static String htmlEncode​(String text)
        Encodes the given text to be HTML safe using entity escapes.
        Parameters:
        text - the text to encode.
        Returns:
        the encoded text.
      • htmlEncodeAndReplaceSpaces

        public static String htmlEncodeAndReplaceSpaces​(String text)
        Encodes the given text to be HTML safe using entity escapes, and embedding non-breaking spaces in place of spaces.
        Parameters:
        text - the text to encode.
        Returns:
        the encoded text.
      • urlEncode

        public static String urlEncode​(String text,
                                       String encoding)
        Encodes HTTP form parameter/values. To encode entire URLs, use completeUrlEncode(java.lang.String) instead.
        Parameters:
        text - part of the url to encode
        encoding - the character encoding to use
        Returns:
        encoded url
        Since:
        5.3.3
      • urlDecode

        public static String urlDecode​(String url)
        Decodes URL percent encoded characters, using the character encoding as per GeneralUtil.getCharacterEncoding().
        Parameters:
        url - the URL to decode
        Returns:
        the decoded string
      • shouldUrlDecode

        public static boolean shouldUrlDecode​(String text)
        Checks if the given text should contains any percent encoded characters that should be decoded.
        Parameters:
        text - the text to check
        Returns:
        true, if the text should be decoded
      • reencodeURL

        public static String reencodeURL​(String originalUrl)
        Attempts to handle common encoding errors in hand-edited URLs, such as failing to URL encode quotes.
        Parameters:
        originalUrl - the url to re-encode.
        Returns:
        the re-encoded URL, or the original value if it cannot be