|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.riotfamily.common.web.util.ServletUtils
public final class ServletUtils
Field Summary | |
---|---|
static String |
INCLUDE_URI_REQUEST_ATTRIBUTE
|
static String |
REFERER_HEADER
|
static String |
REQUESTED_WITH_HEADER
|
static String |
SCHEME_HTTP
|
static String |
SCHEME_HTTPS
|
static String |
USER_AGENT_HEADER
|
static String |
VALID_SCHEME_CHARS
Valid characters in a scheme. |
static String |
XML_HTTP_REQUEST
|
Method Summary | |
---|---|
static String |
addParameter(String url,
String name,
String value)
Returns an URL with the given parameter added to the given URL's query string. |
static String |
addRequestParameters(String url,
HttpServletRequest request)
Returns an URL with all of the given request's parameters added to the given URL's query string. |
static String |
addServletMapping(String path,
HttpServletRequest request)
Adds the mapping of the servlet that is mapped to the given request to the path. |
static void |
appendParameter(StringBuffer url,
String name,
String value)
Appends the given parameter to the given URL's query string. |
static void |
appendRequestParameters(StringBuffer url,
HttpServletRequest request)
Appends all of the given request's parameters to the given URL's query string. |
static StringBuffer |
getAbsoluteUrlPrefix(HttpServletRequest request)
Returns a StringBuffer containing an URL with the protocol, hostname and port (unless it's the protocol's default port) of the given request. |
static String |
getHost(String uri)
Returns the host of the given URI. |
static String |
getOriginatingContextPath(HttpServletRequest request)
Return the context path for the given request, detecting an include request URL if called within a RequestDispatcher include. |
static String |
getOriginatingPathWithinApplication(HttpServletRequest request)
Return the path within the web application for the given request. |
static String |
getOriginatingPathWithinServletMapping(HttpServletRequest request)
Return the path within the servlet mapping for the given request, i.e. the part of the request's URL beyond the part that called the servlet, or "" if the whole URL has been used to identify the servlet. |
static String |
getOriginatingPathWithoutServletMapping(HttpServletRequest request)
Returns the lookup-path for a given request. |
static String |
getOriginatingRequestUri(HttpServletRequest request)
Return the request URI for root of the given request. |
static String |
getOriginatingServletPath(HttpServletRequest request)
|
static String |
getPath(String uri)
Returns the path of the given URI. |
static String |
getPathWithinApplication(HttpServletRequest request)
Return the path within the web application for the given request. |
static String |
getPathWithoutServletMapping(HttpServletRequest request)
Returns the lookup-path for a given request. |
static String |
getReferer(HttpServletRequest request)
Convenience method to get the Referer header. |
static String |
getRequestUri(HttpServletRequest request)
Return the request URI for the given request, detecting an include request URL if called within a RequestDispatcher include. |
static String |
getRequestUrlWithQueryString(HttpServletRequest request)
|
static Long |
getRequiredLongAttribute(HttpServletRequest request,
String name)
|
static String |
getRequiredStringAttribute(HttpServletRequest request,
String name)
|
static String |
getRootPath(HttpServletRequest request)
Returns a String consisting of the context-path and the servlet-prefix for the given request. |
static String |
getServerNameAndPort(HttpServletRequest request)
Returns the serverName and port (if applicable) for the given request. |
static String |
getServletMapping(String servletName,
ServletContext servletContext)
Parses the web.xml deployment descriptor and returns the url-pattern for the given servlet-name, or null if no mapping is found. |
static String |
getServletPrefix(HttpServletRequest request)
Returns the servlet-mapping prefix for the given request or an empty String if the servlet is mapped by a suffix. |
static String |
getServletSuffix(HttpServletRequest request)
Returns the servlet-mapping suffix for the given request or an empty String if the servlet is mapped by a prefix. |
static Map<String,String> |
getSingularParameterMap(HttpServletRequest request)
Returns a map of request parameters. |
static String |
getUserAgent(HttpServletRequest request)
Convenience method to get the USER_AGENT_HEADER header. |
static boolean |
isAbsoluteUrl(String url)
Returns true if our current URL is absolute, false otherwise. |
static boolean |
isDirectRequest(HttpServletRequest request)
Returns whether the given request is a direct request, i.e. not dispatched by a RequestDispatcher. |
static boolean |
isHttpUrl(String url)
|
static boolean |
isMultipartRequest(HttpServletRequest request)
|
static boolean |
isXmlHttpRequest(HttpServletRequest request)
Returns whether the X-Requested-With header is set to
XMLHttpRequest as done by prototype.js. |
static String |
resolveAndEncodeUrl(String url,
HttpServletRequest request,
HttpServletResponse response)
|
static String |
resolveToAbsoluteUrl(String url,
HttpServletRequest request)
|
static String |
resolveUrl(String url,
HttpServletRequest request)
|
static void |
restoreAttributes(HttpServletRequest request,
Map<String,Object> attributesSnapshot)
Restores request attributes from the given map. |
static void |
setCacheHeaders(HttpServletResponse response,
String period)
Sets Expires and Cache-Control headers to allow caching for the given period. |
static void |
setFarFutureExpiresHeader(HttpServletResponse response)
Sets an far future Expires header. |
static void |
setNoCacheHeaders(HttpServletResponse response)
Sets Pragma, Expires and Cache-Control headers to prevent caching. |
static String |
setParameter(String url,
String name,
String value)
This method tries to replace the given parameter's value in the given URL's query string with the given new value or adds the parameter if it is not yet contained. |
static Map<String,Object> |
takeAttributesSnapshot(HttpServletRequest request)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String INCLUDE_URI_REQUEST_ATTRIBUTE
public static final String REFERER_HEADER
public static final String USER_AGENT_HEADER
public static final String REQUESTED_WITH_HEADER
public static final String XML_HTTP_REQUEST
public static final String SCHEME_HTTP
public static final String SCHEME_HTTPS
public static final String VALID_SCHEME_CHARS
Valid characters in a scheme.
RFC 1738 says the following:
Scheme names consist of a sequence of characters. The lower case letters "a"--"z", digits, and the characters plus ("+"), period ("."), and hyphen ("-") are allowed. For resiliency, programs interpreting URLs should treat upper case letters as equivalent to lower case in scheme names (e.g., allow "HTTP" as well as "http").
We treat as absolute any URL that begins with such a scheme name, followed by a colon.
Method Detail |
---|
public static String getOriginatingContextPath(HttpServletRequest request)
UrlPathHelper.getOriginatingContextPath(HttpServletRequest)
public static String getRequestUri(HttpServletRequest request)
UrlPathHelper.getRequestUri(HttpServletRequest)
public static String getOriginatingRequestUri(HttpServletRequest request)
UrlPathHelper.getOriginatingRequestUri(HttpServletRequest)
public static String getOriginatingServletPath(HttpServletRequest request)
public static String getPathWithinApplication(HttpServletRequest request)
UrlPathHelper.getPathWithinApplication(HttpServletRequest)
public static String getOriginatingPathWithinApplication(HttpServletRequest request)
request
- current HTTP request
public static String getOriginatingPathWithinServletMapping(HttpServletRequest request)
E.g.: servlet mapping = "/test/*"; request URI = "/test/a" -> "/a".
E.g.: servlet mapping = "/test"; request URI = "/test" -> "".
E.g.: servlet mapping = "/*.test"; request URI = "/a.test" -> "".
request
- current HTTP request
public static String getPathWithoutServletMapping(HttpServletRequest request)
public static String getOriginatingPathWithoutServletMapping(HttpServletRequest request)
public static String getServletPrefix(HttpServletRequest request)
public static String getServletSuffix(HttpServletRequest request)
public static String addServletMapping(String path, HttpServletRequest request)
public static String getRootPath(HttpServletRequest request)
public static boolean isAbsoluteUrl(String url)
public static boolean isHttpUrl(String url)
public static String resolveUrl(String url, HttpServletRequest request)
public static String resolveAndEncodeUrl(String url, HttpServletRequest request, HttpServletResponse response)
public static String resolveToAbsoluteUrl(String url, HttpServletRequest request)
public static Map<String,Object> takeAttributesSnapshot(HttpServletRequest request)
public static void restoreAttributes(HttpServletRequest request, Map<String,Object> attributesSnapshot)
public static Map<String,String> getSingularParameterMap(HttpServletRequest request)
ServletRequest.getParameterMap()
this method returns Strings
instead of String arrays. When more than one parameter with the same
name is present, only the first value is put into the map.
public static String getHost(String uri)
URI
internally to parse the given String. If the given string violates
RFC 2396 null
will be returned.
public static String getPath(String uri)
URI
internally to parse the given String. If the given string violates
RFC 2396 null
will be returned.
public static StringBuffer getAbsoluteUrlPrefix(HttpServletRequest request)
public static String getServerNameAndPort(HttpServletRequest request)
public static String getReferer(HttpServletRequest request)
Referer
header.
public static String getUserAgent(HttpServletRequest request)
USER_AGENT_HEADER
header.
public static boolean isXmlHttpRequest(HttpServletRequest request)
X-Requested-With
header is set to
XMLHttpRequest
as done by prototype.js.
public static boolean isMultipartRequest(HttpServletRequest request)
public static boolean isDirectRequest(HttpServletRequest request)
public static void setNoCacheHeaders(HttpServletResponse response)
public static void setCacheHeaders(HttpServletResponse response, String period)
FormatUtils.parseMillis(String)
public static void setFarFutureExpiresHeader(HttpServletResponse response)
public static String getServletMapping(String servletName, ServletContext servletContext)
null
if no mapping is found.
public static String setParameter(String url, String name, String value)
public static String addParameter(String url, String name, String value)
public static void appendParameter(StringBuffer url, String name, String value)
public static String addRequestParameters(String url, HttpServletRequest request)
public static void appendRequestParameters(StringBuffer url, HttpServletRequest request)
public static String getRequestUrlWithQueryString(HttpServletRequest request)
public static String getRequiredStringAttribute(HttpServletRequest request, String name)
public static Long getRequiredLongAttribute(HttpServletRequest request, String name)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |