| 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jalios.util.ServletUtil
public class ServletUtil
This class provides a set of static methods which perform various utility operations for Servlets.
| Nested Class Summary | |
|---|---|
static interface | 
ServletUtil.ServletUtilAlternate
This interface is used internally by JCMS to provide custom behavior of ServletUtil and should not be used elsewhere.  | 
| Field Summary | |
|---|---|
static String | 
DEFAULT_DOMID_PREFIX
 | 
static String | 
REVISION
 | 
static String | 
UNIQUE_DOM_ID_COUNTER
 | 
static int | 
URL_INIT_SIZE
Buffer size used for when generating url using StrigBuffer (default is 200).  | 
| Method Summary | |
|---|---|
static void | 
backupAttribute(javax.servlet.jsp.PageContext pageContext,
                String attribute)
Backup request attribute to page scope  | 
static String | 
decodeURL(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 String | 
encodeURL(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 String | 
escapeAmpersand(String str)
Replace all occurence of singles "&" by "&" in the given string Use a regular expression to prevent other entity to be changed  | 
static String | 
generateUniqueDOMId(javax.servlet.http.HttpServletRequest request,
                    String prefix)
Generates and returns an id, unique for one request.  | 
static SortedSet<String> | 
generateUniqueDOMIdCollection(javax.servlet.http.HttpServletRequest request,
                              String prefix,
                              int size)
Generates and returns a collection of unique id.  | 
static String | 
getAbsUrlWithRemovedParams(javax.servlet.http.HttpServletRequest request,
                           String[] params)
Returns an absolute URL with the given parameter removed  | 
static String | 
getAbsUrlWithUpdatedParam(javax.servlet.http.HttpServletRequest request,
                          String name,
                          String newValue)
Returns an absolute URL with the given parameter added or updated  | 
static String | 
getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                           String[] names,
                           String[] newValues)
Returns an absolute URL with the given parameters added or updated  | 
static String | 
getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                           String[] names,
                           String[] newValues,
                           String removePattern)
Returns an absolute URL with the given parameters added or updated  | 
static String | 
getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                           String[] names,
                           String[] newValues,
                           String[] removePatterns)
Returns an absolute URL with the given parameters added or updated  | 
static String | 
getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                           String[] names,
                           String[] newValues,
                           String[] removePatterns,
                           boolean escapeAmpersand)
Returns an absolute URL with the given parameters added or updated  | 
static ServletUtil.ServletUtilAlternate | 
getAlternateImpl()
 | 
static String | 
getBaseUrl(javax.servlet.http.HttpServletRequest request)
Returns the base URL of the given request.  | 
static String | 
getContextPath(javax.servlet.http.HttpServletRequest request)
Returns the portion of the request URI that indicates the context of the request.  | 
static String | 
getJsp(javax.servlet.http.HttpServletRequest request)
Returns the requested JSP.  | 
static Map<String,String[]> | 
getOrderedParameterMap(javax.servlet.http.HttpServletRequest request)
Returns a Map of the parameters of the request.  | 
static Enumeration<String> | 
getOrderedParameterNames(javax.servlet.http.HttpServletRequest request)
Returns an Enumeration of String objects containing the names of the parameters contained in the request.  | 
static 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 String | 
getQueryString(javax.servlet.http.HttpServletRequest request,
               boolean escapeAmpersand)
Return the queryString of the given request.  | 
static String | 
getResourcePath(javax.servlet.http.HttpServletRequest request)
Returns the path of the requested resource, without leading '/'.  | 
static String | 
getServletPath(javax.servlet.http.HttpServletRequest request)
Returns the part of the given request's URL that calls the servlet.  | 
static String | 
getUpdatedParams(javax.servlet.http.HttpServletRequest request,
                 String[] names,
                 String[] newValues)
 | 
static String | 
getUpdatedParams(javax.servlet.http.HttpServletRequest request,
                 String[] names,
                 String[] newValues,
                 String removePattern)
 | 
static String | 
getUpdatedParams(javax.servlet.http.HttpServletRequest request,
                 String[] names,
                 String[] newValues,
                 String[] removePatterns)
 | 
static String | 
getUpdatedParams(javax.servlet.http.HttpServletRequest request,
                 String[] names,
                 String[] newValues,
                 String[] removePatterns,
                 boolean escapeAmpersand)
 | 
static String | 
getUrl(javax.servlet.http.HttpServletRequest request)
Returns the absolute URL of the given request.  | 
static String | 
getUrl(javax.servlet.http.HttpServletRequest request,
       boolean escapeAmpersand)
Returns the absolute URL of the given request.  | 
static String | 
getUrlWithAddedParam(javax.servlet.http.HttpServletRequest request,
                     String name,
                     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 String | 
getUrlWithAddedParam(javax.servlet.http.HttpServletRequest request,
                     String name,
                     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 String | 
getUrlWithRemovedParams(javax.servlet.http.HttpServletRequest request,
                        String[] params,
                        boolean escapeAmpersand)
Returns a relative URL with the given parameter removed  | 
static String | 
getUrlWithUpdatedParam(javax.servlet.http.HttpServletRequest request,
                       String name,
                       String newValue)
Returns a relative URL with the given parameter added or updated  | 
static String | 
getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                        String[] names,
                        String[] newValues)
Returns a relative URL with the given parameters added or updated  | 
static String | 
getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                        String[] names,
                        String[] newValues,
                        String removePattern)
Returns a relative URL with the given parameters added or updated  | 
static String | 
getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                        String[] names,
                        String[] newValues,
                        String[] removePatterns)
Returns a relative URL with the given parameters added or updated  | 
static String | 
getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                        String[] names,
                        String[] newValues,
                        String[] removePatterns,
                        boolean escapeAmpersand)
Returns a relative URL with the given parameters added or updated  | 
static String | 
getUrlWithUpdatedParams(String resourcePath,
                        Map<String,String[]> parameterMap,
                        String[] names,
                        String[] newValues,
                        String[] removePatterns,
                        boolean escapeAmpersand)
Returns a relative URL with the given parameters added or updated  | 
static String | 
removeTrailingChars(String url)
Return a String without the trailing chars.  | 
static void | 
restoreAttribute(javax.servlet.jsp.PageContext pageContext,
                 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 String | 
unescapeAmpersand(String str)
Replace all occurence of "&" 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 | 
|---|
public static final String REVISION
public static final int URL_INIT_SIZE
public static final String DEFAULT_DOMID_PREFIX
public static final String UNIQUE_DOM_ID_COUNTER
| Method Detail | 
|---|
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,
                                   String attribute)
public static void restoreAttribute(javax.servlet.jsp.PageContext pageContext,
                                    String attribute)
pageContext - attribute - public static String getBaseUrl(javax.servlet.http.HttpServletRequest request)
request - the request
public static String getContextPath(javax.servlet.http.HttpServletRequest request)
request - the request
public static 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 request
public static 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 request
public static String getServletPath(javax.servlet.http.HttpServletRequest request)
request - the request of which to retrieve the servlet path
public static String getPathInfo(javax.servlet.http.HttpServletRequest request)
request - the request of which to retrieve the servlet path
public static String getUrl(javax.servlet.http.HttpServletRequest request)
request - the request
public static String getUrl(javax.servlet.http.HttpServletRequest request,
                            boolean escapeAmpersand)
request - the requestescapeAmpersand - will use "&" if true, "&" if false
public static 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 false
public static String getUrlWithAddedParam(javax.servlet.http.HttpServletRequest request,
                                          String name,
                                          String value)
request - name - value - 
public static String getUrlWithAddedParam(javax.servlet.http.HttpServletRequest request,
                                          String name,
                                          String value,
                                          boolean escapeAmpersand)
request - name - value - escapeAmpersand - will use "&" if true, "&" if false
public static String getUrlWithRemovedParams(javax.servlet.http.HttpServletRequest request,
                                             String[] params,
                                             boolean escapeAmpersand)
request - the HttpRequestparams - the name of the parameters to be removedescapeAmpersand - will use "&" if true, "&" if false
public static String getUrlWithUpdatedParam(javax.servlet.http.HttpServletRequest request,
                                            String name,
                                            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 String getAbsUrlWithRemovedParams(javax.servlet.http.HttpServletRequest request,
                                                String[] params)
request - the HttpRequestparams - the name of the parameters to be removed
public static String getAbsUrlWithUpdatedParam(javax.servlet.http.HttpServletRequest request,
                                               String name,
                                               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 String getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                             String[] names,
                                             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 String getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                                String[] names,
                                                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 String getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                             String[] names,
                                             String[] newValues,
                                             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' list
public static String getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                             String[] names,
                                             String[] newValues,
                                             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' list
public static String getUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                             String[] names,
                                             String[] newValues,
                                             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 false
public static String getUrlWithUpdatedParams(String resourcePath,
                                             Map<String,String[]> parameterMap,
                                             String[] names,
                                             String[] newValues,
                                             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 false
public static String getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                                String[] names,
                                                String[] newValues,
                                                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' list
public static String getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                                String[] names,
                                                String[] newValues,
                                                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' list
public static String getAbsUrlWithUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                                String[] names,
                                                String[] newValues,
                                                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 false
public static String getUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                      String[] names,
                                      String[] newValues)
public static String getUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                      String[] names,
                                      String[] newValues,
                                      String removePattern)
public static String getUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                      String[] names,
                                      String[] newValues,
                                      String[] removePatterns)
public static String getUpdatedParams(javax.servlet.http.HttpServletRequest request,
                                      String[] names,
                                      String[] newValues,
                                      String[] removePatterns,
                                      boolean escapeAmpersand)
public static String removeTrailingChars(String url)
url - an URL as String
public static String unescapeAmpersand(String str)
str - the string in which to find &
public static String escapeAmpersand(String str)
str - the string in which to find &
public static String decodeURL(String str)
URLDecoder.decode(String, String)
 
str - the string to url decode
URLDecoder.decode(String, String)public static String encodeURL(String str)
URLEncoder.encode(String, String).
 
str - the string to url encode
URLEncoder.encode(String, String)public static Map<String,String[]> getOrderedParameterMap(javax.servlet.http.HttpServletRequest request)
request - the request
public static Enumeration<String> getOrderedParameterNames(javax.servlet.http.HttpServletRequest request)
request - the request
public static String generateUniqueDOMId(javax.servlet.http.HttpServletRequest request,
                                         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 SortedSet<String> generateUniqueDOMIdCollection(javax.servlet.http.HttpServletRequest request,
                                                              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.
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||