Class HtmlUtil


  • public final class HtmlUtil
    extends Object
    • 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.
      • urlDecode

        public static String urlDecode​(String url,
                                       Charset encoding)
        Decodes URL percent encoded characters.
        Parameters:
        url - the URL to decode
        encoding - the character encoding to use while decoding
        Returns:
        the decoded string
        Since:
        8.7
      • resoluteUrlDecode

        public static String resoluteUrlDecode​(String encodedStr,
                                               Charset charset)
        Variant of URLCodec.decode(String, String) that ignores invalid encoded sequences and continues to decode the remainder of the String.

        Invalid sequences include those with invalid hex characters (%GG) and incomplete sequences (%A).

      • loopedUrlDecode

        public static String loopedUrlDecode​(String str,
                                             Charset charset)
        Repeatedly resolves URL-encoded sequences in a string until it remains constant.
      • 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

        @Deprecated
        public static String reencodeURL​(String originalUrl)
        Deprecated.
        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
      • reencodeURL

        public static String reencodeURL​(String originalUrl,
                                         Charset encoding)
        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
        Since:
        8.7