|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.opencms.util.CmsRequestUtil
public final class CmsRequestUtil
Provides utility functions for dealing with values a .HttpServletRequest
| Field Summary | |
|---|---|
static String |
ATTRIBUTE_ERRORCODE
Request attribute that contains the original error code. |
static String |
HEADER_ACCEPT_CHARSET
HTTP Accept-Charset Header for internal requests used during static export. |
static String |
HEADER_ACCEPT_LANGUAGE
HTTP Accept-Language Header for internal requests used during static export. |
static String |
HEADER_CACHE_CONTROL
HTTP Header "Cache-Control". |
static String |
HEADER_CONTENT_DISPOSITION
The "Content-Disposition" http header. |
static String |
HEADER_CONTENT_TYPE
The "Content-Type" http header. |
static String |
HEADER_EXPIRES
HTTP Header "Expires". |
static String |
HEADER_IF_MODIFIED_SINCE
HTTP Header "If-Modified-Since". |
static String |
HEADER_JSESSIONID
The Header that stores the session id (used by OpenCms upload applet). |
static String |
HEADER_LAST_MODIFIED
HTTP Header "Last-Modified". |
static String |
HEADER_OPENCMS_EXPORT
HTTP Header for internal requests used during static export. |
static String |
HEADER_PRAGMA
HTTP Header "Pragma". |
static String |
HEADER_SERVER
HTTP Header "Server". |
static String |
HEADER_USER_AGENT
HTTP Header "user-agent". |
static String |
HEADER_VALUE_MAX_AGE
HTTP Header value "max-age=" (for "Cache-Control"). |
static String |
HEADER_VALUE_MUST_REVALIDATE
HTTP Header value "must-revalidate" (for "Cache-Control"). |
static String |
HEADER_VALUE_NO_CACHE
HTTP Header value "no-cache" (for "Cache-Control"). |
static String |
HEADER_WWW_AUTHENTICATE
HTTP Header "WWW-Authenticate". |
static String |
HEADER_X_FORWARDED_FOR
Identifier for x-forwarded-for (i.e. |
| Method Summary | |
|---|---|
static String |
appendParameter(String url,
String paramName,
String paramValue)
Appends a request parameter to the given URL. |
static String |
appendParameters(String url,
Map params,
boolean encode)
Appends a map of request parameters to the given URL. |
static Map |
createParameterMap(Map params)
Creates a valid request parameter map from the given map, most notably changing the values form String
to String[] if required. |
static Map |
createParameterMap(String query)
Parses the parameters of the given request query part and creaes a parameter map out of them. |
static String |
encodeParams(HttpServletRequest req)
Returns all parameters of the given request as a request parameter URL String, that is in the form key1=value1&key2=value2 etc. |
static String |
encodeParamsWithUri(String uri,
HttpServletRequest req)
Encodes the given uri, with all parameters from the given request appended. |
static void |
forwardRequest(String target,
HttpServletRequest req,
HttpServletResponse res)
Forwards the response to the given target, which may contain parameters appended like for example ?a=b&c=d. |
static void |
forwardRequest(String target,
Map params,
HttpServletRequest req,
HttpServletResponse res)
Forwards the response to the given target, with the provided parameter map. |
static String |
getNotEmptyDecodedParameter(HttpServletRequest request,
String paramName)
Reads value from the request parameters, will return null if the value is not available or only white space. |
static String |
getNotEmptyParameter(HttpServletRequest request,
String paramName)
Reads value from the request parameters, will return null if the value is not available or only white space. |
static List |
readMultipartFileItems(HttpServletRequest request)
Parses a request of the form multipart/form-data. |
static Map |
readParameterMapFromMultiPart(String encoding,
List multiPartFileItems)
Creates a "standard" request parameter map from the values of a multipart/form-data request. |
static void |
setNoCacheHeaders(HttpServletResponse res)
Sets headers to the given response to prevent client side caching. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String ATTRIBUTE_ERRORCODE
public static final String HEADER_ACCEPT_CHARSET
public static final String HEADER_ACCEPT_LANGUAGE
public static final String HEADER_CACHE_CONTROL
public static final String HEADER_CONTENT_DISPOSITION
public static final String HEADER_CONTENT_TYPE
public static final String HEADER_EXPIRES
public static final String HEADER_IF_MODIFIED_SINCE
public static final String HEADER_JSESSIONID
public static final String HEADER_LAST_MODIFIED
public static final String HEADER_OPENCMS_EXPORT
public static final String HEADER_PRAGMA
public static final String HEADER_SERVER
public static final String HEADER_USER_AGENT
public static final String HEADER_VALUE_MAX_AGE
public static final String HEADER_VALUE_MUST_REVALIDATE
public static final String HEADER_VALUE_NO_CACHE
public static final String HEADER_WWW_AUTHENTICATE
public static final String HEADER_X_FORWARDED_FOR
| Method Detail |
|---|
public static String appendParameter(String url,
String paramName,
String paramValue)
This method takes care about the adding the parameter as an additional
parameter (appending ¶m=value) or as the first parameter
(appending ?param=value).
url - the URL where to append the parameter toparamName - the paramter name to appendparamValue - the parameter value to append
public static String appendParameters(String url,
Map params,
boolean encode)
The map can cointains values of String[] or
simple String values.
This method takes care about the adding the parameter as an additional
parameter (appending ¶m=value) or as the first parameter
(appending ?param=value).
url - the URL where to append the parameter toparams - the paramters to appendencode - if true, the parameter values are encoded before they are appended
public static Map createParameterMap(Map params)
String
to String[] if required.
If the given parameter map is null, then null is returned.
params - the map of parameters to create a parameter map from
String[]public static Map createParameterMap(String query)
Please note: This does not parse a full request URI/URL, only the query part that
starts after the "?". For example, in the URI /system/index.html?a=b&c=d,
the query part is a=b&c=d.
If the given String is empty, an empty map is returned.
query - the query to parse
public static String encodeParams(HttpServletRequest req)
key1=value1&key2=value2 etc.
The result will be encoded using the CmsEncoder.encode(String) function.
req - the request to read the parameters from
public static String encodeParamsWithUri(String uri,
HttpServletRequest req)
The result will be encoded using the function.CmsEncoder.encode(String)
req - the request where to read the parameters fromuri - the uri to encode
public static void forwardRequest(String target,
HttpServletRequest req,
HttpServletResponse res)
throws IOException,
ServletException
?a=b&c=d.
Please note: If possible, use
where the parameters are passed as a map, since the parsing of the parameters may introduce issues with encoding
and is in general much less effective.forwardRequest(String, Map, HttpServletRequest, HttpServletResponse)
The parsing of parameters will likley fail for "large values" (e.g. full blown web forms with <textarea> elements etc. Use this method only if you know that the target will just contain up to 3 parameters which are relativly short and have no encoding or linebreak issues.
target - the target to forward to (may contain parameters like ?a=b&c=d)req - the request to forwardres - the response to forward
IOException - in case the forwarding fails
ServletException - in case the forwarding fails
public static void forwardRequest(String target,
Map params,
HttpServletRequest req,
HttpServletResponse res)
throws IOException,
ServletException
The target uri must NOT have parameters appended like for example ?a=b&c=d.
The values in the provided map must be of type String[]. If required, use
before calling this method to make sure
all values are actually of the required array type.createParameterMap(Map)
target - the target to forward to (may NOT contain parameters like ?a=b&c=d)params - the parameter map (the values must be of type String[]req - the request to forwardres - the response to forward
IOException - in case the forwarding fails
ServletException - in case the forwarding fails
public static String getNotEmptyDecodedParameter(HttpServletRequest request,
String paramName)
null if the value is not available or only white space.
The value of the request will also be decoded using
and also trimmed using CmsEncoder.decode(String).String.trim()
request - the request to read the parameter fromparamName - the parameter name to read
public static String getNotEmptyParameter(HttpServletRequest request,
String paramName)
null if the value is not available or only white space.
request - the request to read the parameter fromparamName - the parameter name to read
public static List readMultipartFileItems(HttpServletRequest request)
multipart/form-data.
The result list will contain items of type FileItem.
If the request is not of type multipart/form-data, then null is returned.
request - the HTTP servlet request to parse
FileItem extracted from the multipart request,
or null if the request was not of type multipart/form-data
public static Map readParameterMapFromMultiPart(String encoding,
List multiPartFileItems)
multipart/form-data request.
encoding - the encoding to use when creating the valuesmultiPartFileItems - the list of parsed multi part file items
readMultipartFileItems(HttpServletRequest)public static void setNoCacheHeaders(HttpServletResponse res)
The following headers are set:
Cache-Control: max-age=0
Cache-Control: must-revalidate
Pragma: no-cache
res - the request where to set the no-cache headers
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||