Class ServletUtil


  • public class ServletUtil
    extends java.lang.Object
    This class provides a set of static methods which perform various utility operations for Servlets.
    Version:
    $Revision: 111286 $
    Author:
    Olivier Dedieu
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  ServletUtil.ServletUtilAlternate
      This interface is used internally by JCMS to provide custom behavior of ServletUtil and should not be used elsewhere.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void backupAttribute​(javax.servlet.jsp.PageContext pageContext, java.lang.String attribute)
      Backup request attribute to page scope
      static java.lang.String decodeURL​(java.lang.String str)
      Convenient method to avoid the need to specify "UTF-8" encoding and catching of exception in call to URLDecoder.decode(String, String)
      Because URLDecoder.decode is quite slow, this methods caches the decoded url in a LRU containing 500 entries.
      static java.lang.String encodeURL​(java.lang.String str)
      Convenient method to avoid the need to specify "UTF-8" encoding and catching of exception in call to URLEncoder.encode(String, String).
      static java.lang.String escapeAmpersand​(java.lang.String str)
      Replace all occurrence of singles "&" by "&" in the given string Use a regular expression to prevent other entity to be changed
      static java.lang.String generateUniqueDOMId​(javax.servlet.http.HttpServletRequest request, java.lang.String prefix)
      Generates and returns an id, unique for one request.
      static java.util.SortedSet<java.lang.String> generateUniqueDOMIdCollection​(javax.servlet.http.HttpServletRequest request, java.lang.String prefix, int size)
      Generates and returns a collection of unique id.
      static java.lang.String getAbsUrlWithRemovedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] params)
      Returns an absolute URL with the given parameter removed
      static java.lang.String getAbsUrlWithUpdatedParam​(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String newValue)
      Returns an absolute URL with the given parameter added or updated
      static java.lang.String getAbsUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues)
      Returns an absolute URL with the given parameters added or updated
      static java.lang.String getAbsUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String removePattern)
      Returns an absolute URL with the given parameters added or updated
      static java.lang.String getAbsUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns)
      Returns an absolute URL with the given parameters added or updated
      static java.lang.String getAbsUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns, boolean escapeAmpersand)
      Returns an absolute URL with the given parameters added or updated
      static ServletUtil.ServletUtilAlternate getAlternateImpl()  
      static java.lang.String getBaseUrl​(javax.servlet.http.HttpServletRequest request)
      Returns the base URL of the given request.
      static java.lang.String getContextPath​(javax.servlet.http.HttpServletRequest request)
      Returns the portion of the request URI that indicates the context of the request.
      static java.lang.String getJsp​(javax.servlet.http.HttpServletRequest request)
      Returns the requested JSP.
      e.g: For the URL http://host/webapp/subdir/my.jsp?x=y, it returns my.jsp.
      static java.util.Map<java.lang.String,​java.lang.String[]> getOrderedParameterMap​(javax.servlet.http.HttpServletRequest request)
      Returns a Map of the parameters of the request.
      static java.util.Enumeration<java.lang.String> getOrderedParameterNames​(javax.servlet.http.HttpServletRequest request)
      Returns an Enumeration of String objects containing the names of the parameters contained in the request.
      static java.lang.String getOriginalUrl​(javax.servlet.http.HttpServletRequest request)
      When invoked during an ajax request, this method returns the absolute URL of the original request.
      static java.lang.String getPathInfo​(javax.servlet.http.HttpServletRequest request)
      Returns any extra path information associated with the URL the client sent when it made this request.
      static java.lang.String getQueryString​(javax.servlet.http.HttpServletRequest request, boolean escapeAmpersand)
      Return the queryString of the given request.

      The query String does not contain the "?".
      static java.lang.String getRequestId​(javax.servlet.http.HttpServletRequest request)
      Return unique identifier for the specified request, constant during all the duration of this request and unique accross application lifecyle.
      static java.lang.String getResourcePath​(javax.servlet.http.HttpServletRequest request)
      Returns the path of the requested resource, without leading '/'.
      static java.lang.String getServletPath​(javax.servlet.http.HttpServletRequest request)
      Returns the part of the given request's URL that calls the servlet.
      static java.lang.String getUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues)  
      static java.lang.String getUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String removePattern)  
      static java.lang.String getUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns)  
      static java.lang.String getUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns, boolean escapeAmpersand)  
      static java.lang.String getUrl​(javax.servlet.http.HttpServletRequest request)
      Returns the absolute URL of the given request.
      static java.lang.String getUrl​(javax.servlet.http.HttpServletRequest request, boolean escapeAmpersand)
      Returns the absolute URL of the given request.
      static java.lang.String getUrlWithAddedParam​(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String value)
      Returns a relative URL with the given parameter added even if already present (in case of an array of parameters having the same name).
      static java.lang.String getUrlWithAddedParam​(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String value, boolean escapeAmpersand)
      Returns a relative URL with the given parameter added even if already present (in case of an array of parameters having the same name).
      static java.lang.String getUrlWithRemovedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] params, boolean escapeAmpersand)
      Returns a relative URL with the given parameter removed
      static java.lang.String getUrlWithUpdatedParam​(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String newValue)
      Returns a relative URL with the given parameter added or updated
      static java.lang.String getUrlWithUpdatedParams​(java.lang.String resourcePath, java.util.Map<java.lang.String,​java.lang.String[]> parameterMap, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns, boolean escapeAmpersand)
      Returns a relative URL with the given parameters added or updated
      static java.lang.String getUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues)
      Returns a relative URL with the given parameters added or updated
      static java.lang.String getUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String removePattern)
      Returns a relative URL with the given parameters added or updated
      static java.lang.String getUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns)
      Returns a relative URL with the given parameters added or updated
      static java.lang.String getUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns, boolean escapeAmpersand)
      Returns a relative URL with the given parameters added or updated
      static java.lang.String removeTrailingChars​(java.lang.String url)
      Return a String without the trailing chars. I.e. '&' or '?'.
      static void restoreAttribute​(javax.servlet.jsp.PageContext pageContext, java.lang.String attribute)
      Restore request attribute from page scope
      static void setAlternateImpl​(ServletUtil.ServletUtilAlternate alternate)
      Define the ServletUtil.ServletUtilAlternate class to use to provide custom behavior for ServletUtil methods.
      static java.lang.String toAbsoluteUrl​(javax.servlet.http.HttpServletRequest request, java.lang.String path)
      Convert a relative URL into a full URL.
      static java.lang.String unescapeAmpersand​(java.lang.String str)
      Replace all occurence of "&amp;" by "&" in the given string
      • Methods inherited from class java.lang.Object

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

      • URL_INIT_SIZE

        public static final int URL_INIT_SIZE
        Buffer size used for when generating url using StrigBuffer (default is 200).
        See Also:
        Constant Field Values
      • DEFAULT_DOMID_PREFIX

        public static final java.lang.String DEFAULT_DOMID_PREFIX
        See Also:
        Constant Field Values
      • UNIQUE_DOM_ID_COUNTER

        public static final java.lang.String UNIQUE_DOM_ID_COUNTER
        See Also:
        Constant Field Values
    • Method Detail

      • setAlternateImpl

        public static void setAlternateImpl​(ServletUtil.ServletUtilAlternate alternate)
        Define the ServletUtil.ServletUtilAlternate class to use to provide custom behavior for ServletUtil methods. Warning: calling this override any previous alternate class as only one alternate class can be use at the same time.
        Parameters:
        alternate - the class to use
      • getAlternateImpl

        public static ServletUtil.ServletUtilAlternate getAlternateImpl()
        Returns:
        the current alternate class being registered in ServletUtil to provide a custom behavior.
      • backupAttribute

        public static void backupAttribute​(javax.servlet.jsp.PageContext pageContext,
                                           java.lang.String attribute)
        Backup request attribute to page scope
      • restoreAttribute

        public static void restoreAttribute​(javax.servlet.jsp.PageContext pageContext,
                                            java.lang.String attribute)
        Restore request attribute from page scope
        Parameters:
        pageContext -
        attribute -
        Since:
        jcms-4.0
      • getBaseUrl

        public static java.lang.String getBaseUrl​(javax.servlet.http.HttpServletRequest request)
        Returns the base URL of the given request. Rebuild this URL from the request attributes (serverName, serverPort and contextPath). The base URL contains a trailing '/'. The return value may be forced by request's attribute "baseUrl". For example, if the requested url is http://mysite.com:8080/dir/webapp/subdir/my.jsp?param=value returns http://mysite.com:8080/dir/webapp/
        Parameters:
        request - the request
        Returns:
        the base URL of the request
      • getContextPath

        public static java.lang.String getContextPath​(javax.servlet.http.HttpServletRequest request)
        Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". May be forced by request's attribute "contextPath" (usefull when using reverseProxy).
        Parameters:
        request - the request
        Returns:
        the contextPath of the request
      • getJsp

        public static java.lang.String getJsp​(javax.servlet.http.HttpServletRequest request)
        Returns the requested JSP.
        e.g: For the URL http://host/webapp/subdir/my.jsp?x=y, it returns my.jsp.
        Computed from the value returned by getServletPath(HttpServletRequest), thus if the jsp is accessed through a RequestDispatcher forward, this method will returned the first servlet accessed.
        Parameters:
        request - the request
        Returns:
        the requested JSP
        Since:
        jcms-4.0
      • getResourcePath

        public static java.lang.String getResourcePath​(javax.servlet.http.HttpServletRequest request)
        Returns the path of the requested resource, without leading '/'.
        Examples:
        "http://host/mywebapp/subdir/my.jsp?x=y" ==> "subdir/my.jsp"
        "http://host/mywebapp/subdir/images/test.gif" ==> "subdir/images/test.gif"
        "http://host/mywebapp/MyServlet/action?x=y" ==> "MyServlet/action"

        Equivalent to the requestURI minus the contextPath. From section 4.4 of the Java Servlet Specification 2.3: The following equation is always true: requestURI = contextPath + servletPath + pathInfo
        The returned value is computed from the value returned by getServletPath(HttpServletRequest) and getPathInfo(HttpServletRequest), thus if the method is called from a servlet accessed through a RequestDispatcher forward, this method will returned the value for the first servlet accessed.
        Parameters:
        request - the request
        Returns:
        a String with the requested resource (jsp, static file, servlet)
        Since:
        jcms-4.0
      • getServletPath

        public static java.lang.String getServletPath​(javax.servlet.http.HttpServletRequest request)
        Returns the part of the given request's URL that calls the servlet. This path starts with a "/" character and includes either the servlet name or a path to the servlet, but does not include any extra path.

        This method will check for attribute "javax.servlet.forward.servlet_path" that may have been added when calling a servlet using the forward method of a RequestDispatcher.
        Parameters:
        request - the request of which to retrieve the servlet path
        Returns:
        a String containing the name or path of the servlet being called, as specified in the request URL, decoded, or an empty string if the servlet used to process the request is matched using the "/*" pattern.
      • getPathInfo

        public static java.lang.String getPathInfo​(javax.servlet.http.HttpServletRequest request)
        Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string and will start with a "/" character.

        This method returns null if there was no extra path information.
        Same as the value of the CGI variable PATH_INFO.

        This method will check for attribute "javax.servlet.forward.path_info" that may have been added when calling a servlet using the forward method of a RequestDispatcher.
        Parameters:
        request - the request of which to retrieve the servlet path
        Returns:
        a String, decoded by the web container, specifying extra path information that comes after the servlet path but before the query string in the request URL; or null if the URL does not have any extra path information
      • getUrl

        public static java.lang.String getUrl​(javax.servlet.http.HttpServletRequest request)
        Returns the absolute URL of the given request. Rebuild this URL from the request attributes (baseUrl + servletPath + queryString).
        Parameters:
        request - the request
        Returns:
        the URL of the request
      • getUrl

        public static java.lang.String getUrl​(javax.servlet.http.HttpServletRequest request,
                                              boolean escapeAmpersand)
        Returns the absolute URL of the given request. Rebuild this URL from the request attributes (baseUrl + servletPath + queryString).
        Parameters:
        request - the request
        escapeAmpersand - will use "&amp;" if true, "&" if false
        Returns:
        the URL of the request
      • getOriginalUrl

        public static java.lang.String getOriginalUrl​(javax.servlet.http.HttpServletRequest request)
        When invoked during an ajax request, this method returns the absolute URL of the original request.

        Implementation detail : it uses the referrer sent by the browser, and default to getUrl(HttpServletRequest, boolean).

        Parameters:
        request - the current Ajax request
        Returns:
        the URL of the request (in which ampersand are not encoded for HTML)
        Since:
        JCMS-6567
      • getQueryString

        public static java.lang.String getQueryString​(javax.servlet.http.HttpServletRequest request,
                                                      boolean escapeAmpersand)
        Return the queryString of the given request.

        The query String does not contain the "?". As stated in the rfc 1738, section 3.3. : In an URL with the form: http://{host}:{port}/{path}?{searchpart} {searchpart} is a query string.

        This methods differs from the method HttpServletRequest.getQueryString() because it rebuilds the querystring using all parameters of the given request.
        Thus, calling this method in a servlet called through RequestDispatcher.forward will gives you all the parameters (from the "original" servlet request and from the forwarded servlet).
        For example, if a servlet 1 accessed using "/servlet1/view/id?a=b&c=d" forward to a servlet 2 "/servlet2?view=id". The computed querystring will be "view=id&a=b&c=d".
        Parameters:
        request - the HttpRequest
        escapeAmpersand - will use "&amp;" if true, "&" if false
        Returns:
        the queryString of the given request.
      • getUrlWithAddedParam

        public static java.lang.String getUrlWithAddedParam​(javax.servlet.http.HttpServletRequest request,
                                                            java.lang.String name,
                                                            java.lang.String value)
        Returns a relative URL with the given parameter added even if already present (in case of an array of parameters having the same name).
        Parameters:
        request -
        name -
        value -
        Returns:
        the new URL
      • getUrlWithAddedParam

        public static java.lang.String getUrlWithAddedParam​(javax.servlet.http.HttpServletRequest request,
                                                            java.lang.String name,
                                                            java.lang.String value,
                                                            boolean escapeAmpersand)
        Returns a relative URL with the given parameter added even if already present (in case of an array of parameters having the same name).
        Parameters:
        request -
        name -
        value -
        escapeAmpersand - will use "&amp;" if true, "&" if false
        Returns:
        the new URL
      • getUrlWithRemovedParams

        public static java.lang.String getUrlWithRemovedParams​(javax.servlet.http.HttpServletRequest request,
                                                               java.lang.String[] params,
                                                               boolean escapeAmpersand)
        Returns a relative URL with the given parameter removed
        Parameters:
        request - the HttpRequest
        params - the name of the parameters to be removed
        escapeAmpersand - will use "&amp;" if true, "&" if false
        Returns:
        the new URL
        Since:
        jcms-5.5.0
      • getUrlWithUpdatedParam

        public static java.lang.String getUrlWithUpdatedParam​(javax.servlet.http.HttpServletRequest request,
                                                              java.lang.String name,
                                                              java.lang.String newValue)
        Returns a relative URL with the given parameter added or updated
        Parameters:
        request - the HttpRequest
        name - the name of the parameter
        newValue - the value of the parameter (if newValue is null the param is removed)
        Returns:
        the new URL
      • getAbsUrlWithRemovedParams

        public static java.lang.String getAbsUrlWithRemovedParams​(javax.servlet.http.HttpServletRequest request,
                                                                  java.lang.String[] params)
        Returns an absolute URL with the given parameter removed
        Parameters:
        request - the HttpRequest
        params - the name of the parameters to be removed
        Returns:
        the new URL
        Since:
        jcms-5.5.0
      • getAbsUrlWithUpdatedParam

        public static java.lang.String getAbsUrlWithUpdatedParam​(javax.servlet.http.HttpServletRequest request,
                                                                 java.lang.String name,
                                                                 java.lang.String newValue)
        Returns an absolute URL with the given parameter added or updated
        Parameters:
        request - the HttpRequest
        name - the name of the parameter
        newValue - the value of the parameter (if newValue is null the param is removed)
        Returns:
        the new URL
      • getUrlWithUpdatedParams

        public static java.lang.String getUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                               java.lang.String[] names,
                                                               java.lang.String[] newValues)
        Returns a relative URL with the given parameters added or updated
        Parameters:
        request - the HttpRequest
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        Returns:
        the new URL
      • getAbsUrlWithUpdatedParams

        public static java.lang.String getAbsUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                                  java.lang.String[] names,
                                                                  java.lang.String[] newValues)
        Returns an absolute URL with the given parameters added or updated
        Parameters:
        request - the HttpRequest
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        Returns:
        the new URL
      • getUrlWithUpdatedParams

        public static java.lang.String getUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                               java.lang.String[] names,
                                                               java.lang.String[] newValues,
                                                               java.lang.String removePattern)
        Returns a relative URL with the given parameters added or updated
        Parameters:
        request - the HttpRequest
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        removePattern - any parameter name containing the given String will be removed from the parameters' list
        Returns:
        the new URL
      • getUrlWithUpdatedParams

        public static java.lang.String getUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                               java.lang.String[] names,
                                                               java.lang.String[] newValues,
                                                               java.lang.String[] removePatterns)
        Returns a relative URL with the given parameters added or updated
        Parameters:
        request - the HttpRequest
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        removePatterns - any parameter name containing one of the given Strings will be removed from the parameters' list
        Returns:
        the new URL
      • getUrlWithUpdatedParams

        public static java.lang.String getUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                               java.lang.String[] names,
                                                               java.lang.String[] newValues,
                                                               java.lang.String[] removePatterns,
                                                               boolean escapeAmpersand)
        Returns a relative URL with the given parameters added or updated
        Parameters:
        request - the HttpRequest
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        removePatterns - any parameter name containing one of the given Strings will be removed from the parameters' list
        escapeAmpersand - will use "&amp;" if true, "&" if false
        Returns:
        the new URL
      • getUrlWithUpdatedParams

        public static java.lang.String getUrlWithUpdatedParams​(java.lang.String resourcePath,
                                                               java.util.Map<java.lang.String,​java.lang.String[]> parameterMap,
                                                               java.lang.String[] names,
                                                               java.lang.String[] newValues,
                                                               java.lang.String[] removePatterns,
                                                               boolean escapeAmpersand)
        Returns a relative URL with the given parameters added or updated
        Parameters:
        resourcePath - the HttpRequest resource path
        parameterMap - the HttpRequest parameter map
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        removePatterns - any parameter name containing one of the given Strings will be removed from the parameters' list
        escapeAmpersand - will use "&amp;" if true, "&" if false
        Returns:
        the new URL
      • getAbsUrlWithUpdatedParams

        public static java.lang.String getAbsUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                                  java.lang.String[] names,
                                                                  java.lang.String[] newValues,
                                                                  java.lang.String removePattern)
        Returns an absolute URL with the given parameters added or updated
        Parameters:
        request - the HttpRequest
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        removePattern - any parameter name containing the given String will be removed from the parameters' list
        Returns:
        the new URL
      • getAbsUrlWithUpdatedParams

        public static java.lang.String getAbsUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                                  java.lang.String[] names,
                                                                  java.lang.String[] newValues,
                                                                  java.lang.String[] removePatterns)
        Returns an absolute URL with the given parameters added or updated
        Parameters:
        request - the HttpRequest
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        removePatterns - any parameter name containing one of the given Strings will be removed from the parameters' list
        Returns:
        the new URL
      • getAbsUrlWithUpdatedParams

        public static java.lang.String getAbsUrlWithUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                                  java.lang.String[] names,
                                                                  java.lang.String[] newValues,
                                                                  java.lang.String[] removePatterns,
                                                                  boolean escapeAmpersand)
        Returns an absolute URL with the given parameters added or updated
        Parameters:
        request - the HttpRequest
        names - an array of String which contains the name of the parameters
        newValues - an array of String which contains the values of the parameters (if newValue[i] is null the names[i] parameter is removed)
        removePatterns - any parameter name containing one of the given Strings will be removed from the parameters' list
        escapeAmpersand - will use "&amp; true, "&" if false
        Returns:
        the new URL
      • getUpdatedParams

        public static java.lang.String getUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                        java.lang.String[] names,
                                                        java.lang.String[] newValues)
      • getUpdatedParams

        public static java.lang.String getUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                        java.lang.String[] names,
                                                        java.lang.String[] newValues,
                                                        java.lang.String removePattern)
      • getUpdatedParams

        public static java.lang.String getUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                        java.lang.String[] names,
                                                        java.lang.String[] newValues,
                                                        java.lang.String[] removePatterns)
      • getUpdatedParams

        public static java.lang.String getUpdatedParams​(javax.servlet.http.HttpServletRequest request,
                                                        java.lang.String[] names,
                                                        java.lang.String[] newValues,
                                                        java.lang.String[] removePatterns,
                                                        boolean escapeAmpersand)
      • removeTrailingChars

        public static java.lang.String removeTrailingChars​(java.lang.String url)
        Return a String without the trailing chars. I.e. '&' or '?'.
        Parameters:
        url - an URL as String
        Returns:
        the URL stripped of trailing chars '&' or '?' if any
      • unescapeAmpersand

        public static java.lang.String unescapeAmpersand​(java.lang.String str)
        Replace all occurence of "&amp;" by "&" in the given string
        Parameters:
        str - the string in which to find &amp;
        Returns:
        a new string with all replacement being done.
      • escapeAmpersand

        public static java.lang.String escapeAmpersand​(java.lang.String str)
        Replace all occurrence of singles "&" by "&amp;" in the given string Use a regular expression to prevent other entity to be changed
        Parameters:
        str - the string in which to find &
        Returns:
        a new string with all replacement being done.
      • decodeURL

        public static java.lang.String decodeURL​(java.lang.String str)
        Convenient method to avoid the need to specify "UTF-8" encoding and catching of exception in call to URLDecoder.decode(String, String)
        Because URLDecoder.decode is quite slow, this methods caches the decoded url in a LRU containing 500 entries.
        Parameters:
        str - the string to url decode
        Returns:
        the decoded URL
        See Also:
        URLDecoder.decode(String, String)
      • encodeURL

        public static java.lang.String encodeURL​(java.lang.String str)
        Convenient method to avoid the need to specify "UTF-8" encoding and catching of exception in call to URLEncoder.encode(String, String).
        Because URLEncoder.encode is quite slow, this methods caches the encoded url in a LRU containing 2000 entries.
        Parameters:
        str - the string to url encode
        Returns:
        the encoded URL
        See Also:
        URLEncoder.encode(String, String)
      • getOrderedParameterMap

        public static java.util.Map<java.lang.String,​java.lang.String[]> getOrderedParameterMap​(javax.servlet.http.HttpServletRequest request)
        Returns a Map of the parameters of the request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
        Parameters:
        request - the request
        Returns:
        an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array. Parameter are order in the way they were sent to the server
      • getOrderedParameterNames

        public static java.util.Enumeration<java.lang.String> getOrderedParameterNames​(javax.servlet.http.HttpServletRequest request)
        Returns an Enumeration of String objects containing the names of the parameters contained in the request. If the request has no parameters, the method returns an empty Enumeration.
        Parameters:
        request - the request
        Returns:
        an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if the request has no parameters. Parameter names are order in the way they were sent to the server
      • getRequestId

        public static java.lang.String getRequestId​(javax.servlet.http.HttpServletRequest request)
        Return unique identifier for the specified request, constant during all the duration of this request and unique accross application lifecyle.

        This identifier can be used as a logging facility or as any other way to uniquely identify a request.

        Parameters:
        request - an HttpServletRequest, must NOT be null
        Returns:
        a non null identifier
      • generateUniqueDOMId

        public static java.lang.String generateUniqueDOMId​(javax.servlet.http.HttpServletRequest request,
                                                           java.lang.String prefix)
        Generates and returns an id, unique for one request.

        This id embed the current date, not to be equals to an id, already used in a cache. You may use your own prefix, to set a human readable part in the id.

        As of current implementation, the returned id will match the pattern required by the scriptaculous javascript API, "{prefix}_{identifier}" : http://wiki.script.aculo.us/scriptaculous/show/Sortable.serialize

        Parameters:
        request - the current HttpServletRequest. Required, must be not null.
        prefix - a custom prefix, if null the default prefix "generateddomid" will be used. Use only alphanumeric characters.
        Returns:
        a unique identifier (or null if request is null).
      • generateUniqueDOMIdCollection

        public static java.util.SortedSet<java.lang.String> generateUniqueDOMIdCollection​(javax.servlet.http.HttpServletRequest request,
                                                                                          java.lang.String prefix,
                                                                                          int size)
        Generates and returns a collection of unique id.
        Parameters:
        request - the current HttpServletRequest. Required, must be not null.
        prefix - a custom prefix, if null the default prefix "generateddomid" will be used. Use only alphanumeric characters.
        size - Size of the Set to return.
        Returns:
        a SortedSet of unique identifiers (or null if request is null).
      • toAbsoluteUrl

        public static java.lang.String toAbsoluteUrl​(javax.servlet.http.HttpServletRequest request,
                                                     java.lang.String path)
        Convert a relative URL into a full URL.

        If the specified path is already an absolute URL the path is returned unmodified.
        If the specified request is null the path is returned unmodified.

        Parameters:
        path - a path relative to the webapp root directory (without leading slash), eg "css/custom/myfile.css"
        Returns:
        an absolute URL using current request base URL.
        Since:
        JCMS-6621