Class URLUtil


  • public abstract class URLUtil
    extends java.lang.Object
    Utility class for URL related actions.
    Since:
    8.1.0
    Version:
    $Revision$ $Date$
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String buildQueryString​(java.util.Map<java.lang.String,​java.util.Collection<java.lang.String>> values)
      Returns a query string created with the given parameters.
      static PageWebResource getFirstPageWebResource​(ChannelWebResource cwr)
      Returns the page web resource for the first page whithin the channel of the given channel web resource.
      static java.lang.String getHost​(java.net.URI uri)
      Returns the host of the given URI or null if none could be inferred.
      static java.lang.String getQueryStringFromUri​(java.lang.String uri)
      Given a URI, extract its query string.
      static java.util.Map<java.lang.String,​java.util.Collection<java.lang.String>> getQueryStringParametersMap​(java.lang.String uri)
      Returns the query string parameters map.
      static java.lang.String getQueryStringParameterValue​(java.lang.String paramName, java.lang.String uri)
      Returns the first non-empty query string parameter value.
      static java.util.Collection<java.lang.String> getQueryStringParameterValues​(java.lang.String paramName, java.lang.String uri)
      Returns the query string parameter values.
      static java.lang.String getRefererPath​(java.lang.String referer, IWebsiteBaseURL baseURL, javax.servlet.http.HttpServletRequest request)
      Get the Web Resource path from the given URL
      static java.lang.String getRefererRelativeUri​(java.lang.String referer, IWebsiteBaseURL baseURL, javax.servlet.http.HttpServletRequest request)
      Returns the URI relative to the application root, without the mode root path, including the query string.
      static java.util.Optional<WebResource> getWebResource​(java.lang.String location, javax.servlet.http.HttpServletRequest currentRequest)
      Returns the web resource related to the given location.
      static java.lang.String processURL​(java.lang.String uri, PageWebResource pageWR, javax.servlet.http.HttpServletRequest req)
      Process the given URL.
      static java.net.URI removeDefaultPort​(java.net.URI uri)
      Remove default port of the given URI.
      It removes the port if:
      The scheme is http and the port is 80; or The scheme is https and the port is 443
      If the given URI is not absolute, is opaque or doesn't fit the above rule, the original URI will be returned.
      static java.net.URI removeQueryString​(java.net.URI uri)
      Removes the query string from the given URI.
      • Methods inherited from class java.lang.Object

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

      • getRefererPath

        public static java.lang.String getRefererPath​(java.lang.String referer,
                                                      IWebsiteBaseURL baseURL,
                                                      javax.servlet.http.HttpServletRequest request)
        Get the Web Resource path from the given URL
        Parameters:
        referer - The URL to get the path from
        baseURL - The WebsiteBaseURL
        request - The HttpServletRequest
        Returns:
        A string corresponding to the web resource path of the URL
        Since:
        8.1.0
      • getRefererRelativeUri

        public static java.lang.String getRefererRelativeUri​(java.lang.String referer,
                                                             IWebsiteBaseURL baseURL,
                                                             javax.servlet.http.HttpServletRequest request)
        Returns the URI relative to the application root, without the mode root path, including the query string.
        Parameters:
        referer - The URL to get the path from
        baseURL - The WebsiteBaseURL
        request - The HttpServletRequest
        Returns:
        A string corresponding to the relative uri.
        Since:
        10.4.0
      • getFirstPageWebResource

        public static PageWebResource getFirstPageWebResource​(ChannelWebResource cwr)
                                                       throws PortalException
        Returns the page web resource for the first page whithin the channel of the given channel web resource.

        This method requires a current session and a current transaction.

        Parameters:
        cwr - the channel web resource.
        Returns:
        the page web resource for the first page whithin the channel of the given channel web resource.
        Throws:
        PortalException
        Since:
        10.3.0
      • getHost

        public static java.lang.String getHost​(java.net.URI uri)
        Returns the host of the given URI or null if none could be inferred.
        Parameters:
        uri - the URI.
        Returns:
        the host of the given URI or null if none could be inferred.
        Since:
        10.3.0
      • removeDefaultPort

        public static java.net.URI removeDefaultPort​(java.net.URI uri)
        Remove default port of the given URI.
        It removes the port if:
        • The scheme is http and the port is 80; or
        • The scheme is https and the port is 443

        If the given URI is not absolute, is opaque or doesn't fit the above rule, the original URI will be returned.
        Parameters:
        uri - the URI to have its default port removed.
        Returns:
        the given URI without the default port (if any).
        Throws:
        java.lang.NullPointerException - if the given URI is null.
        Since:
        10.4.0
      • getQueryStringFromUri

        public static java.lang.String getQueryStringFromUri​(java.lang.String uri)
        Given a URI, extract its query string.
        Parameters:
        uri - the URI
        Returns:
        the query string (or an empty string if there's no query string)
        Since:
        14.2.0
      • getQueryStringParametersMap

        public static java.util.Map<java.lang.String,​java.util.Collection<java.lang.String>> getQueryStringParametersMap​(java.lang.String uri)
        Returns the query string parameters map.
        Parameters:
        uri - the URI
        Returns:
        the query string parameters map.
        Since:
        14.2.0
      • getQueryStringParameterValue

        public static java.lang.String getQueryStringParameterValue​(java.lang.String paramName,
                                                                    java.lang.String uri)
        Returns the first non-empty query string parameter value.
        Parameters:
        paramName - the desired parameter name
        uri - the URI
        Returns:
        the first non-empty query string parameter value.
        Since:
        14.2.0
      • getQueryStringParameterValues

        public static java.util.Collection<java.lang.String> getQueryStringParameterValues​(java.lang.String paramName,
                                                                                           java.lang.String uri)
        Returns the query string parameter values.
        Parameters:
        paramName - the parameter name
        uri - the URI
        Returns:
        the query string parameter values.
        Since:
        14.2.0
      • buildQueryString

        public static java.lang.String buildQueryString​(java.util.Map<java.lang.String,​java.util.Collection<java.lang.String>> values)
        Returns a query string created with the given parameters.
        Parameters:
        values - the parameter values
        Returns:
        a query string created with the given parameters.
        Since:
        14.2.0
      • processURL

        public static java.lang.String processURL​(java.lang.String uri,
                                                  PageWebResource pageWR,
                                                  javax.servlet.http.HttpServletRequest req)
                                           throws PortalException
        Process the given URL.
        Parameters:
        uri - the URI
        pageWR - the Page Web Resource
        req - the request
        Returns:
        the processed URL
        Throws:
        PortalException
        Since:
        15.0.0
      • getWebResource

        public static java.util.Optional<WebResource> getWebResource​(java.lang.String location,
                                                                     javax.servlet.http.HttpServletRequest currentRequest)
                                                              throws PortalException
        Returns the web resource related to the given location.
        Parameters:
        location - the location
        currentRequest - current request
        Returns:
        the web resource related to the given location.
        Throws:
        PortalException
        Since:
        16.0.0
      • removeQueryString

        public static java.net.URI removeQueryString​(java.net.URI uri)
        Removes the query string from the given URI.
        Parameters:
        uri - the URI
        Returns:
        the cleaned URI
        Since:
        17.0.0