Class ConversionUtils


  • public class ConversionUtils
    extends Object
    General purpose conversion utilities related to HTTP/HTML
    • Constructor Detail

      • ConversionUtils

        public ConversionUtils()
    • Method Detail

      • getEncodingFromContentType

        public static String getEncodingFromContentType​(String contentType)
        Extract the encoding (charset) from the Content-Type, e.g. "text/html; charset=utf-8".
        Parameters:
        contentType - string from which the encoding should be extracted
        Returns:
        the charset encoding - or null, if none was found or the charset is not supported
        Throws:
        IllegalCharsetNameException - if the found charset is not supported
      • escapeIllegalURLCharacters

        public static String escapeIllegalURLCharacters​(String url)
                                                 throws Exception
        Parameters:
        url - String Url to escape
        Returns:
        String cleaned up url
        Throws:
        Exception - when given url leads to a malformed URL or URI
      • sanitizeUrl

        public static final URI sanitizeUrl​(URL url)
                                     throws URISyntaxException
        Checks a URL and encodes it if necessary, i.e. if it is not currently correctly encoded. Warning: it may not work on all unencoded URLs.
        Parameters:
        url - non-encoded URL
        Returns:
        URI which has been encoded as necessary
        Throws:
        URISyntaxException - if parts of the url form a non valid URI
      • removeSlashDotDot

        public static String removeSlashDotDot​(String url)
        collapses absolute or relative URLs containing '/..' converting http://host/path1/../path2 to http://host/path2 or /one/two/../three to /one/three
        Parameters:
        url - in which the '/..'s should be removed
        Returns:
        collapsed URL
        See Also:
        Bug 49083 - collapse /.. in redirect URLs