public class UrlUtils extends Object
Collection of utilities to ease working with URLs.
Modifier and Type | Field and Description |
---|---|
static String |
FORWARD_QUERY_STRING_ATTRIBUTE |
static String |
FORWARD_REQUEST_URI_ATTRIBUTE |
static String |
INCLUDE_REQUEST_URI_ATTRIBUTE |
Constructor and Description |
---|
UrlUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addParameter(StringBuilder url,
String name) |
static void |
addParameter(StringBuilder url,
String name,
Object value) |
static boolean |
containsParameter(javax.servlet.http.HttpServletRequest request,
String parameterName) |
static boolean |
doesNotContainParamater(javax.servlet.http.HttpServletRequest request,
String parameterName) |
static String |
getBaseUrl(javax.servlet.http.HttpServletRequest request)
Returns the base URL, with the context path included by default.
|
static String |
getBaseUrl(javax.servlet.http.HttpServletRequest request,
boolean withContextPath)
Returns the base URL, containing the context path or not depending on the
withContextPath param. |
static StringBuilder |
getContext(javax.servlet.http.HttpServletRequest request) |
static StringBuilder |
getCurrentUri(javax.servlet.http.HttpServletRequest request)
Get the current URI with potentiel request parameters.
|
static StringBuilder |
getCurrentUrl(javax.servlet.http.HttpServletRequest request,
boolean preserveParameters)
Return the current URL, with or without query parameters, depending on the
perserveParameters parameter. |
static String |
getProcessedUrl(StringBuilder url,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
static String |
getProcessedUrl(String url,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
static boolean |
isAbsolute(String url)
Check whether the passed URL is absolute.
|
static boolean |
isContextRelative(String url,
javax.servlet.http.HttpServletRequest request) |
static boolean |
isProtocolRelative(String url) |
static boolean |
isServerRelative(String url) |
public static final String FORWARD_REQUEST_URI_ATTRIBUTE
public static final String FORWARD_QUERY_STRING_ATTRIBUTE
public static final String INCLUDE_REQUEST_URI_ATTRIBUTE
public static StringBuilder getCurrentUri(javax.servlet.http.HttpServletRequest request)
Get the current URI with potentiel request parameters.
request
- the request to extract the URI and parameters frompublic static StringBuilder getCurrentUrl(javax.servlet.http.HttpServletRequest request, boolean preserveParameters)
Return the current URL, with or without query parameters, depending on the
perserveParameters
parameter.
request
- The current HttpServletRequest
.preserveParameters
- preserve the url parameters.public static String getProcessedUrl(String url, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
public static String getProcessedUrl(StringBuilder url, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
public static boolean isAbsolute(String url)
Check whether the passed URL is absolute.
public static boolean isContextRelative(String url, javax.servlet.http.HttpServletRequest request)
public static boolean isServerRelative(String url)
public static boolean isProtocolRelative(String url)
public static StringBuilder getContext(javax.servlet.http.HttpServletRequest request)
public static void addParameter(StringBuilder url, String name)
public static void addParameter(StringBuilder url, String name, Object value)
public static boolean containsParameter(javax.servlet.http.HttpServletRequest request, String parameterName)
public static boolean doesNotContainParamater(javax.servlet.http.HttpServletRequest request, String parameterName)
public static String getBaseUrl(javax.servlet.http.HttpServletRequest request)
Returns the base URL, with the context path included by default.
For Example, for an URL like
http://domain.com:port/context/foo/bar
, this function returns
http://domain.com:port/context
.
request
- The HttpServletRequest
from which to extract the base
URL.public static String getBaseUrl(javax.servlet.http.HttpServletRequest request, boolean withContextPath)
Returns the base URL, containing the context path or not depending on the
withContextPath
param.
For Example, for an URL like
http://domain.com:port/context/foo/bar
, this function returns
http://domain.com:port/context
.
request
- The HttpServletRequest
from which to extract the base
URL.withContextPath
- true
to include the context path, false
otherwise.Copyright © 2013-2015 Dandelion Project. All Rights Reserved.