public class ServletUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
ServletUtil.ServletUtilAlternate
This interface is used internally by JCMS to provide custom behavior of
ServletUtil and should not be used elsewhere.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_DOMID_PREFIX |
static java.lang.String |
REVISION |
static java.lang.String |
UNIQUE_DOM_ID_COUNTER |
static int |
URL_INIT_SIZE
Buffer size used for when generating url using StrigBuffer (default is 200).
|
Modifier and Type | Method and 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 occurence 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.
|
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 |
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.
|
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(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 |
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 |
removeTrailingChars(java.lang.String url)
Return a String without the trailing chars.
|
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 |
unescapeAmpersand(java.lang.String str)
Replace all occurence of "&" by "&" in the given string
|
public static final java.lang.String REVISION
public static final int URL_INIT_SIZE
public static final java.lang.String DEFAULT_DOMID_PREFIX
public static final java.lang.String UNIQUE_DOM_ID_COUNTER
public static void setAlternateImpl(ServletUtil.ServletUtilAlternate alternate)
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.alternate
- the class to usepublic static ServletUtil.ServletUtilAlternate getAlternateImpl()
public static void backupAttribute(javax.servlet.jsp.PageContext pageContext, java.lang.String attribute)
public static void restoreAttribute(javax.servlet.jsp.PageContext pageContext, java.lang.String attribute)
pageContext
- attribute
- public static java.lang.String getBaseUrl(javax.servlet.http.HttpServletRequest request)
request
- the requestpublic static java.lang.String getContextPath(javax.servlet.http.HttpServletRequest request)
request
- the requestpublic static java.lang.String getJsp(javax.servlet.http.HttpServletRequest request)
getServletPath(HttpServletRequest)
, thus if the
jsp is accessed through a RequestDispatcher forward, this method will returned
the first servlet accessed.request
- the requestpublic static java.lang.String getResourcePath(javax.servlet.http.HttpServletRequest request)
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.request
- the requestpublic static java.lang.String getServletPath(javax.servlet.http.HttpServletRequest request)
request
- the request of which to retrieve the servlet pathpublic static java.lang.String getPathInfo(javax.servlet.http.HttpServletRequest request)
request
- the request of which to retrieve the servlet pathpublic static java.lang.String getUrl(javax.servlet.http.HttpServletRequest request)
request
- the requestpublic static java.lang.String getUrl(javax.servlet.http.HttpServletRequest request, boolean escapeAmpersand)
request
- the requestescapeAmpersand
- will use "&" if true, "&" if falsepublic static java.lang.String getQueryString(javax.servlet.http.HttpServletRequest request, boolean escapeAmpersand)
HttpServletRequest.getQueryString()
because
it rebuilds the querystring using all parameters of the given request.request
- the HttpRequestescapeAmpersand
- will use "&" if true, "&" if falsepublic static java.lang.String getUrlWithAddedParam(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String value)
request
- name
- value
- public static java.lang.String getUrlWithAddedParam(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String value, boolean escapeAmpersand)
request
- name
- value
- escapeAmpersand
- will use "&" if true, "&" if falsepublic static java.lang.String getUrlWithRemovedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] params, boolean escapeAmpersand)
request
- the HttpRequestparams
- the name of the parameters to be removedescapeAmpersand
- will use "&" if true, "&" if falsepublic static java.lang.String getUrlWithUpdatedParam(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String newValue)
request
- the HttpRequestname
- the name of the parameternewValue
- the value of the parameter (if newValue is null the param is removed)public static java.lang.String getAbsUrlWithRemovedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] params)
request
- the HttpRequestparams
- the name of the parameters to be removedpublic static java.lang.String getAbsUrlWithUpdatedParam(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String newValue)
request
- the HttpRequestname
- the name of the parameternewValue
- the value of the parameter (if newValue is null the param is removed)public static java.lang.String getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues)
request
- the HttpRequestnames
- an array of String which contains the name of the parametersnewValues
- an array of String which contains the values of
the parameters (if newValue[i] is null the names[i] parameter is
removed)public static java.lang.String getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues)
request
- the HttpRequestnames
- an array of String which contains the name of the parametersnewValues
- an array of String which contains the values of
the parameters (if newValue[i] is null the names[i] parameter is
removed)public static java.lang.String getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String removePattern)
request
- the HttpRequestnames
- an array of String which contains the name of the parametersnewValues
- 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' listpublic static java.lang.String getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns)
request
- the HttpRequestnames
- an array of String which contains the name of the parametersnewValues
- 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' listpublic static java.lang.String getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns, boolean escapeAmpersand)
request
- the HttpRequestnames
- an array of String which contains the name of the parametersnewValues
- 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' listescapeAmpersand
- will use "&" if true, "&" if falsepublic 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)
resourcePath
- the HttpRequest resource pathparameterMap
- the HttpRequest parameter mapnames
- an array of String which contains the name of the parametersnewValues
- 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' listescapeAmpersand
- will use "&" if true, "&" if falsepublic static java.lang.String getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String removePattern)
request
- the HttpRequestnames
- an array of String which contains the name of the parametersnewValues
- 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' listpublic static java.lang.String getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns)
request
- the HttpRequestnames
- an array of String which contains the name of the parametersnewValues
- 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' listpublic static java.lang.String getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns, boolean escapeAmpersand)
request
- the HttpRequestnames
- an array of String which contains the name of the parametersnewValues
- 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' listescapeAmpersand
- will use "& true, "&" if falsepublic static java.lang.String getUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues)
public static java.lang.String getUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String removePattern)
public static java.lang.String getUpdatedParams(javax.servlet.http.HttpServletRequest request, java.lang.String[] names, java.lang.String[] newValues, java.lang.String[] removePatterns)
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)
public static java.lang.String removeTrailingChars(java.lang.String url)
url
- an URL as Stringpublic static java.lang.String unescapeAmpersand(java.lang.String str)
str
- the string in which to find &public static java.lang.String escapeAmpersand(java.lang.String str)
str
- the string in which to find &public static java.lang.String decodeURL(java.lang.String str)
URLDecoder.decode(String, String)
str
- the string to url decodeURLDecoder.decode(String, String)
public static java.lang.String encodeURL(java.lang.String str)
URLEncoder.encode(String, String)
.
str
- the string to url encodeURLEncoder.encode(String, String)
public static java.util.Map<java.lang.String,java.lang.String[]> getOrderedParameterMap(javax.servlet.http.HttpServletRequest request)
request
- the requestpublic static java.util.Enumeration<java.lang.String> getOrderedParameterNames(javax.servlet.http.HttpServletRequest request)
request
- the requestpublic static java.lang.String getRequestId(javax.servlet.http.HttpServletRequest request)
This identifier can be used as a logging facility or as any other way to uniquely identify a request.
request
- an HttpServletRequest, must NOT be nullpublic static java.lang.String generateUniqueDOMId(javax.servlet.http.HttpServletRequest request, java.lang.String prefix)
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
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.public static java.util.SortedSet<java.lang.String> generateUniqueDOMIdCollection(javax.servlet.http.HttpServletRequest request, java.lang.String prefix, int size)
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.Copyright © 2001-2010 Jalios SA. All Rights Reserved.