| java.lang.Object org.opencms.util.CmsRequestUtil
CmsRequestUtil | final public class CmsRequestUtil (Code) | | Provides utility functions for dealing with values a
HttpServletRequest .
author: Alexander Kandzior version: $Revision: 1.27 $ since: 6.0.0 |
Method Summary | |
public static String | appendParameter(String url, String paramName, String paramValue) | public static String | appendParameters(String url, Map params, boolean encode) | public static Map | createParameterMap(Map params) | public static Map | createParameterMap(String query) Parses the parameters of the given request query part and creates a parameter map out of them.
Please note: This does not parse a full request URI/URL, only the query part that
starts after the "?". | public 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. | public static String | encodeParamsWithUri(String uri, HttpServletRequest req) | public 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 .
Please note: If possible, use
CmsRequestUtil.forwardRequest(String,Map,HttpServletRequest,HttpServletResponse)
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.
The parsing of parameters will likely fail for "large values" (e.g. | public static void | forwardRequest(String target, Map params, HttpServletRequest req, HttpServletResponse res) Forwards the response to the given target, with the provided parameter map.
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[] . | public static String | getCookieValue(CmsJspActionElement jsp, String name) | public static String | getNotEmptyDecodedParameter(HttpServletRequest request, String paramName) | public static String | getNotEmptyParameter(HttpServletRequest request, String paramName) | public static Object | getSessionValue(HttpServletRequest request, String key) Reads an object from the session of the given HTTP request.
A session will be initialized if the request does not currently have a session. | public static List | readMultipartFileItems(HttpServletRequest request) Parses a request of the form multipart/form-data . | public static Map | readParameterMapFromMultiPart(String encoding, List multiPartFileItems) | public static void | redirectPermanently(CmsJspActionElement jsp, String target) | public static void | redirectRequestSecure(CmsJspActionElement jsp, String target) | public static void | removeSessionValue(HttpServletRequest request, String key) Removes an object from the session of the given http request.
A session will be initialized if the request does not currently have a session. | public static void | setCookieValue(CmsJspActionElement jsp, String name, String value) Sets the value of a specific cookie.
If no cookie exists with the value, a new cookie will be created. | public static void | setNoCacheHeaders(HttpServletResponse res) | public static void | setSessionValue(HttpServletRequest request, String key, Object value) Adds an object to the session of the given HTTP request.
A session will be initialized if the request does not currently have a session. |
ATTRIBUTE_ERRORCODE | final public static String ATTRIBUTE_ERRORCODE(Code) | | Request attribute that contains the original error code.
|
HEADER_ACCEPT_CHARSET | final public static String HEADER_ACCEPT_CHARSET(Code) | | HTTP Accept-Charset Header for internal requests used during static export.
|
HEADER_ACCEPT_LANGUAGE | final public static String HEADER_ACCEPT_LANGUAGE(Code) | | HTTP Accept-Language Header for internal requests used during static export.
|
HEADER_CACHE_CONTROL | final public static String HEADER_CACHE_CONTROL(Code) | | HTTP Header "Cache-Control".
|
HEADER_CONNECTION | final public static String HEADER_CONNECTION(Code) | | HTTP Header "Connection".
|
HEADER_CONTENT_DISPOSITION | final public static String HEADER_CONTENT_DISPOSITION(Code) | | The "Content-Disposition" http header.
|
HEADER_CONTENT_TYPE | final public static String HEADER_CONTENT_TYPE(Code) | | The "Content-Type" http header.
|
HEADER_EXPIRES | final public static String HEADER_EXPIRES(Code) | | HTTP Header "Expires".
|
HEADER_IF_MODIFIED_SINCE | final public static String HEADER_IF_MODIFIED_SINCE(Code) | | HTTP Header "If-Modified-Since".
|
HEADER_JSESSIONID | final public static String HEADER_JSESSIONID(Code) | | The Header that stores the session id (used by OpenCms upload applet).
|
HEADER_LAST_MODIFIED | final public static String HEADER_LAST_MODIFIED(Code) | | HTTP Header "Last-Modified".
|
HEADER_LOCATION | final public static String HEADER_LOCATION(Code) | | HTTP Header "Location".
|
HEADER_OPENCMS_EXPORT | final public static String HEADER_OPENCMS_EXPORT(Code) | | HTTP Header for internal requests used during static export.
|
HEADER_PRAGMA | final public static String HEADER_PRAGMA(Code) | | HTTP Header "Pragma".
|
HEADER_SERVER | final public static String HEADER_SERVER(Code) | | HTTP Header "Server".
|
HEADER_USER_AGENT | final public static String HEADER_USER_AGENT(Code) | | HTTP Header "user-agent".
|
HEADER_VALUE_MAX_AGE | final public static String HEADER_VALUE_MAX_AGE(Code) | | HTTP Header value "max-age=" (for "Cache-Control").
|
HEADER_VALUE_MUST_REVALIDATE | final public static String HEADER_VALUE_MUST_REVALIDATE(Code) | | HTTP Header value "must-revalidate" (for "Cache-Control").
|
HEADER_VALUE_NO_CACHE | final public static String HEADER_VALUE_NO_CACHE(Code) | | HTTP Header value "no-cache" (for "Cache-Control").
|
HEADER_WWW_AUTHENTICATE | final public static String HEADER_WWW_AUTHENTICATE(Code) | | HTTP Header "WWW-Authenticate".
|
HEADER_X_FORWARDED_FOR | final public static String HEADER_X_FORWARDED_FOR(Code) | | Identifier for x-forwarded-for (i.e. proxied) request headers.
|
PARAMETER_ASSIGNMENT | final public static String PARAMETER_ASSIGNMENT(Code) | | Assignment char between parameter name and values.
|
PARAMETER_DELIMITER | final public static String PARAMETER_DELIMITER(Code) | | Delimiter char between parameters.
|
URL_DELIMITER | final public static String URL_DELIMITER(Code) | | Delimiter char between url and query.
|
appendParameter | public static String appendParameter(String url, String paramName, String paramValue)(Code) | | Appends a request parameter to the given URL.
This method takes care about the adding the parameter as an additional
parameter (appending ¶m=value ) or as the first parameter
(appending ?param=value ).
Parameters: url - the URL where to append the parameter to Parameters: paramName - the paramter name to append Parameters: paramValue - the parameter value to append the URL with the given parameter appended |
appendParameters | public static String appendParameters(String url, Map params, boolean encode)(Code) | | Appends a map of request parameters to the given URL.
The map can contains 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 ).
Parameters: url - the URL where to append the parameter to Parameters: params - the parameters to append Parameters: encode - if true , the parameter values are encoded before they are appended the URL with the given parameter appended |
createParameterMap | public static Map createParameterMap(Map params)(Code) | | Creates a valid request parameter map from the given map,
most notably changing the values form String
to String[] if required.
If the given parameter map is null , then null is returned.
Parameters: params - the map of parameters to create a parameter map from the created parameter map, all values will be instances of String[] |
createParameterMap | public static Map createParameterMap(String query)(Code) | | Parses the parameters of the given request query part and creates a parameter map out of them.
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.
Parameters: query - the query to parse the parameter map created from the query |
encodeParams | public static String encodeParams(HttpServletRequest req)(Code) | | Returns all parameters of the given request
as a request parameter URL String, that is in the form key1=value1&key2=value2 etc.
The result will be encoded using the
CmsEncoder.encode(String) function.
Parameters: req - the request to read the parameters from all initialized parameters of the given request as request parameter URL String |
encodeParamsWithUri | public static String encodeParamsWithUri(String uri, HttpServletRequest req)(Code) | | Encodes the given URI, with all parameters from the given request appended.
The result will be encoded using the
CmsEncoder.encode(String) function.
Parameters: req - the request where to read the parameters from Parameters: uri - the URI to encode the encoded URI, with all parameters from the given request appended |
forwardRequest | public static void forwardRequest(String target, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException(Code) | | Forwards the response to the given target, which may contain parameters appended like for example ?a=b&c=d .
Please note: If possible, use
CmsRequestUtil.forwardRequest(String,Map,HttpServletRequest,HttpServletResponse)
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.
The parsing of parameters will likely 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 relatively short and have no encoding or line break issues.
Parameters: target - the target to forward to (may contain parameters like ?a=b&c=d ) Parameters: req - the request to forward Parameters: res - the response to forward throws: IOException - in case the forwarding fails throws: ServletException - in case the forwarding fails |
forwardRequest | public static void forwardRequest(String target, Map params, HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException(Code) | | Forwards the response to the given target, with the provided parameter map.
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
CmsRequestUtil.createParameterMap(Map) before calling this method to make sure
all values are actually of the required array type.
Parameters: target - the target to forward to (may NOT contain parameters like ?a=b&c=d ) Parameters: params - the parameter map (the values must be of type String[] Parameters: req - the request to forward Parameters: res - the response to forward throws: IOException - in case the forwarding fails throws: ServletException - in case the forwarding fails |
getCookieValue | public static String getCookieValue(CmsJspActionElement jsp, String name)(Code) | | Returns the value of the cookie with the given name.
Parameters: jsp - the CmsJspActionElement to use Parameters: name - the name of the cookie the value of the cookie with the given name or null, if no cookie exists with the name |
getNotEmptyDecodedParameter | public static String getNotEmptyDecodedParameter(HttpServletRequest request, String paramName)(Code) | | Reads value from the request parameters,
will return null if the value is not available or only white space.
The value of the request will also be decoded using
CmsEncoder.decode(String)
and also trimmed using
String.trim .
Parameters: request - the request to read the parameter from Parameters: paramName - the parameter name to read the request parameter value for the given parameter |
getNotEmptyParameter | public static String getNotEmptyParameter(HttpServletRequest request, String paramName)(Code) | | Reads value from the request parameters,
will return null if the value is not available or only white space.
Parameters: request - the request to read the parameter from Parameters: paramName - the parameter name to read the request parameter value for the given parameter |
getSessionValue | public static Object getSessionValue(HttpServletRequest request, String key)(Code) | | Reads an object from the session of the given HTTP request.
A session will be initialized if the request does not currently have a session.
As a result, the request will always have a session after this method has been called.
Will return null if no corresponding object is found in the session.
Parameters: request - the request to get the session from Parameters: key - the key of the object to read from the session the object received form the session, or null |
readMultipartFileItems | public static List readMultipartFileItems(HttpServletRequest request)(Code) | | Parses a request of the form 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.
Parameters: request - the HTTP servlet request to parse the list of FileItem extracted from the multipart request,or null if the request was not of type multipart/form-data |
readParameterMapFromMultiPart | public static Map readParameterMapFromMultiPart(String encoding, List multiPartFileItems)(Code) | | Creates a "standard" request parameter map from the values of a
multipart/form-data request.
Parameters: encoding - the encoding to use when creating the values Parameters: multiPartFileItems - the list of parsed multi part file items a map containing all non-file request parameters See Also: CmsRequestUtil.readMultipartFileItems(HttpServletRequest) |
redirectPermanently | public static void redirectPermanently(CmsJspActionElement jsp, String target)(Code) | | Redirects the response to the target link using a "301 - Moved Permanently" header.
This implementation will work only on JSP pages in OpenCms that use the default JSP loader implementation.
Parameters: jsp - the OpenCms JSP context Parameters: target - the target link |
removeSessionValue | public static void removeSessionValue(HttpServletRequest request, String key)(Code) | | Removes an object from the session of the given http request.
A session will be initialized if the request does not currently have a session.
As a result, the request will always have a session after this method has been called.
Parameters: request - the request to get the session from Parameters: key - the key of the object to be removed from the session |
setCookieValue | public static void setCookieValue(CmsJspActionElement jsp, String name, String value)(Code) | | Sets the value of a specific cookie.
If no cookie exists with the value, a new cookie will be created.
Parameters: jsp - the CmsJspActionElement to use Parameters: name - the name of the cookie Parameters: value - the value of the cookie |
setNoCacheHeaders | public static void setNoCacheHeaders(HttpServletResponse res)(Code) | | Sets headers to the given response to prevent client side caching.
The following headers are set:
Cache-Control: max-age=0
Cache-Control: must-revalidate
Pragma: no-cache
Parameters: res - the request where to set the no-cache headers |
setSessionValue | public static void setSessionValue(HttpServletRequest request, String key, Object value)(Code) | | Adds an object to the session of the given HTTP request.
A session will be initialized if the request does not currently have a session.
As a result, the request will always have a session after this method has been called.
Parameters: request - the request to get the session from Parameters: key - the key of the object to be stored in the session Parameters: value - the object to be stored in the session |
|
|