Class URLSupport


  • public class URLSupport
    extends java.lang.Object
    A utility class for working with URLs
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String decode​(java.lang.String s)
      URL decode the input string
      static java.lang.String getFirst​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> map, java.lang.String key)
      Get the first value of the list for the specified key from the provided multivalued map
      static java.lang.String getPath​(java.lang.String url)
      Get the path part of the provided URL
      static java.util.List<java.lang.String> getPathSegments​(java.lang.String url)
      Get a list containing the path segments from the provided URL
      static java.util.List<java.lang.String> getPathSegments​(java.lang.String url, boolean decode)
      Get a list containing the path segments from the provided URL
      static java.lang.String getQuery​(java.lang.String url)
      Get the query part of the provided URL
      static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getQueryParameters​(java.lang.String url)
      Get a multivalued map containing the query parameters for the provided URL
      static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getQueryParameters​(java.lang.String url, boolean decode)
      Get a multivalued map containing the query parameters for the provided URL
      static java.net.URL getURL​(java.lang.String url)
      Get a URL instance that represents the specified parameter
      static java.util.List<java.lang.String> parsePath​(java.lang.String path)
      Parse the provided path part into a List of path segments
      static java.util.List<java.lang.String> parsePath​(java.lang.String path, boolean decode)
      Parse the provided path part into a list of path segments
      static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> parseQuery​(java.lang.String query)
      Parse the provided query part into a multivalued map of query parameters
      static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> parseQuery​(java.lang.String query, boolean decode)
      Parse the provided query part into a multivalued map of query parameters
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • decode

        public static java.lang.String decode​(java.lang.String s)
        URL decode the input string
        Parameters:
        s - the string to URL decode
        Returns:
        the URL decoded string
      • getFirst

        public static java.lang.String getFirst​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> map,
                                                java.lang.String key)
        Get the first value of the list for the specified key from the provided multivalued map
        Parameters:
        map - the multivalued map
        key - the key
        Returns:
        the first value of the list for the specified key from the provided multivalued map or null if not exists
      • getPath

        public static java.lang.String getPath​(java.lang.String url)
        Get the path part of the provided URL
        Parameters:
        url - the url
        Returns:
        the path part or empty if not exists
        See Also:
        URL.getPath()
      • getPathSegments

        public static java.util.List<java.lang.String> getPathSegments​(java.lang.String url)
        Get a list containing the path segments from the provided URL

        The path segments are URL decoded

        Parameters:
        url - the url
        Returns:
        a list containing the path segments from the provided URL
      • getPathSegments

        public static java.util.List<java.lang.String> getPathSegments​(java.lang.String url,
                                                                       boolean decode)
        Get a list containing the path segments from the provided URL

        The path segments are URL decoded according to the specified parameter

        Parameters:
        url - the url
        decode - indicates whether to decode the path segments
        Returns:
        a list containing the path segments from the provided URL
      • getQuery

        public static java.lang.String getQuery​(java.lang.String url)
        Get the query part of the provided URL
        Parameters:
        url - the URL
        Returns:
        the query part of the provided URL or empty if not exists
        See Also:
        URL.getQuery()
      • getQueryParameters

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getQueryParameters​(java.lang.String url)
        Get a multivalued map containing the query parameters for the provided URL

        The keys and values of the multivalued map are URL decoded

        Parameters:
        url - the URL
        Returns:
        a multivalued map containing the query parameters for the provided URL
      • getQueryParameters

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getQueryParameters​(java.lang.String url,
                                                                                                                boolean decode)
        Get a multivalued map containing the query parameters for the provided URL

        The keys and values of the multivalued map are URL decoded according the specified parameter

        Parameters:
        url - the URL
        decode - indicates whether to decode the keys and values of the multivalued map should be decoded
        Returns:
        a multivalued map containing the query parameters for the provided URL
      • getURL

        public static java.net.URL getURL​(java.lang.String url)
        Get a URL instance that represents the specified parameter
        Parameters:
        url - the url
        Returns:
        a URL instance that represents the specified parameter
        See Also:
        URL
      • parsePath

        public static java.util.List<java.lang.String> parsePath​(java.lang.String path)
        Parse the provided path part into a List of path segments

        The path segments are URL decoded

        Parameters:
        path - the path part
        Returns:
        a list of path segments
      • parsePath

        public static java.util.List<java.lang.String> parsePath​(java.lang.String path,
                                                                 boolean decode)
        Parse the provided path part into a list of path segments

        The path segments are decoded according to the specified parameter

        Parameters:
        path - the path part
        decode - indicates whether the path segments should be URL decoded
        Returns:
        a list of path segments
      • parseQuery

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> parseQuery​(java.lang.String query)
        Parse the provided query part into a multivalued map of query parameters

        The keys and values of the multivalued map are URL decoded

        Parameters:
        query - the query part
        Returns:
        a multivalued map containing the query parameters for the provided URL
      • parseQuery

        public static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> parseQuery​(java.lang.String query,
                                                                                                        boolean decode)
        Parse the provided query part into a multivalued map of query parameters

        The keys and values of the multivalued map are URL decoded according to the specified parameter

        Parameters:
        query - the query part
        decode - indicates whether to decode the keys and values of the multivalued map should be decoded
        Returns:
        a multivalued map containing the query parameters for the provided URL