Modifier and Type | Class and Description |
---|---|
static interface |
Servlets.ClientIdentifier
A plugin used to provide additional browser information for
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
Modifier and Type | Field and Description |
---|---|
static int |
APPEND_PARAM
Whether to append params if both uri and params contain the same
parameter.
|
static int |
IGNORE_PARAM
Whether to ignore params if both uri and params contain the same
parameter.
|
static int |
OVERWRITE_URI
Whether to overwrite uri if both uri and params contain the same
parameter.
|
static int |
PASS_THRU_ATTR
Whether the specified parameters shall be passed thru the request
attribute called arg.
|
Modifier | Constructor and Description |
---|---|
protected |
Servlets()
Utilities; no instantiation required.
|
Modifier and Type | Method and Description |
---|---|
static ExtendletContext |
addExtendletContext(javax.servlet.ServletContext ctx,
java.lang.String name,
ExtendletContext extctx)
Adds an extended context.
|
static void |
forward(javax.servlet.ServletContext ctx,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.String uri)
A shortcut of forward(request, response, uri, null, 0).
|
static void |
forward(javax.servlet.ServletContext ctx,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.String uri,
java.util.Map params,
int mode)
Forward to the specified URI.
|
static java.lang.String |
generateURI(java.lang.String uri,
java.util.Map params,
int mode)
Generates URI by appending the parameters.
|
static java.lang.String |
getBrowser(javax.servlet.ServletRequest request)
Returns the name of the browser, or null if not identifiable.
|
static java.lang.Double |
getBrowser(javax.servlet.ServletRequest request,
java.lang.String name)
Returns the version of the given browser name, or null if the client
is not the given browsers.
|
static java.lang.String |
getBrowser(java.lang.String userAgent)
Returns the name of the browser, or null if not identifiable.
|
static java.lang.Double |
getBrowser(java.lang.String userAgent,
java.lang.String name)
Returns the version of the given browser name, or null if the client
is not the given browsers.
|
static Servlets.ClientIdentifier |
getClientIdentifier()
Returns the client identifier, or null if no such plugin.
|
static java.util.List<java.lang.String> |
getContextPaths()
Returns a list of context paths (e.g., "/abc") that this application
has.
|
static java.lang.String |
getDetail(javax.servlet.ServletRequest request)
Returns the request detail infomation.
|
static ExtendletContext |
getExtendletContext(javax.servlet.ServletContext ctx,
java.lang.String name)
Returns the extended context of the specified name.
|
static java.lang.String |
getExtension(java.lang.String path)
Returns the file/path extension of the specified path (excluding dot),
or null if no extension at all.
|
static java.lang.String |
getExtension(java.lang.String path,
boolean lastOnly)
Returns the file/path extension of the specified path (excluding dot),
or null if no extension at all.
|
static double[] |
getIECompatibilityInfo(javax.servlet.ServletRequest request)
Returns the IE compatibility information.
|
static java.lang.String |
getLimitTimeOffer()
Returns a token to represent a limit-time offer.
|
static java.lang.String |
getNormalPath(java.lang.String path)
Returns the normal path; that is, will elminate the double dots
".."
|
static javax.servlet.RequestDispatcher |
getRequestDispatcher(javax.servlet.ServletContext ctx,
javax.servlet.ServletRequest request,
java.lang.String uri,
java.util.Map params,
int mode)
Returns the request dispatch of the specified URI.
|
static java.net.URL |
getResource(javax.servlet.ServletContext ctx,
java.lang.String uri)
Returns the resource of the specified uri.
|
static java.io.InputStream |
getResourceAsStream(javax.servlet.ServletContext ctx,
java.lang.String uri)
Returns the resource stream of the specified uri.
|
static java.lang.String |
getUserAgent(javax.servlet.ServletRequest req)
Returns the user-agent header, which indicates what the client is,
or an empty string if not available.
|
static void |
include(javax.servlet.ServletContext ctx,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.String uri)
A shortcut of include(request, response, uri, null, 0).
|
static void |
include(javax.servlet.ServletContext ctx,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.String uri,
java.util.Map params,
int mode)
Includes the resource at the specified URI.
|
static boolean |
isBrowser(javax.servlet.ServletRequest req,
java.lang.String type)
Returns whether the client is a browser of the specified type.
|
static boolean |
isBrowser(java.lang.String userAgent,
java.lang.String type)
Returns whether the user agent is a browser of the specified type.
|
static boolean |
isExplorer(javax.servlet.ServletRequest req)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isExplorer(java.lang.String userAgent)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isExplorer7(javax.servlet.ServletRequest req)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isExplorer7(java.lang.String userAgent)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isForwarded(javax.servlet.ServletRequest request)
Tests whether this page is forwarded by another page.
|
static boolean |
isGecko(javax.servlet.ServletRequest req)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isGecko(java.lang.String userAgent)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isGecko3(javax.servlet.ServletRequest req)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isGecko3(java.lang.String userAgent)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isHilDevice(javax.servlet.ServletRequest req)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isHilDevice(java.lang.String userAgent)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isIncluded(javax.servlet.ServletRequest request)
Tests whether this page is included by another page.
|
static boolean |
isOfferExpired(java.lang.String lto,
int timeout)
Returns whether a token returned by getLimitTimeOffer expired.
|
static boolean |
isOpera(javax.servlet.ServletRequest req)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isOpera(java.lang.String userAgent)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isRobot(javax.servlet.ServletRequest req)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isRobot(java.lang.String userAgent)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isSafari(javax.servlet.ServletRequest req)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isSafari(java.lang.String userAgent)
Deprecated.
As of release 6.0.0, replaced with
getBrowser(javax.servlet.ServletRequest, java.lang.String) . |
static boolean |
isServlet23()
Returns whether the current Web server supports Servlet 2.3 or above.
|
static boolean |
isServlet24()
Returns whether the current Web server supports Servlet 2.4 or above.
|
static boolean |
isServlet3()
Returns whether the current Web server supports Servlet 3.0 or above.
|
static boolean |
isUniversalURL(java.lang.String uri)
Returns whether a URL starts with xxx://, mailto:, about:,
javascript:, data:
|
static java.lang.String |
locate(javax.servlet.ServletContext ctx,
javax.servlet.ServletRequest request,
java.lang.String pgpath,
Locator locator)
Locates a page based on the current Locale.
|
static ExtendletContext |
removeExtendletContext(javax.servlet.ServletContext ctx,
java.lang.String name)
Removes an extended context of the specified name.
|
static void |
setClientIdentifier(Servlets.ClientIdentifier clientId)
Sets the client identifier that is used to assist
isBrowser(javax.servlet.ServletRequest, java.lang.String)
to identify a client. |
public static final int OVERWRITE_URI
generateURI(java.lang.String, java.util.Map, int)
public static final int IGNORE_PARAM
generateURI(java.lang.String, java.util.Map, int)
public static final int APPEND_PARAM
generateURI(java.lang.String, java.util.Map, int)
public static final int PASS_THRU_ATTR
public static final boolean isUniversalURL(java.lang.String uri)
public static final boolean isServlet3()
public static final boolean isServlet24()
public static final boolean isServlet23()
isServlet24()
returns true, isServlet23()
must return true, too.public static final java.lang.String locate(javax.servlet.ServletContext ctx, javax.servlet.ServletRequest request, java.lang.String pgpath, Locator locator) throws javax.servlet.ServletException
Notice that it cannot resolve a path starting with '~', and containing '*', because it cannot access the content of the other servlet context.
If an URI contains "*", it will be replaced with a proper Locale. For example, if the current Locale is zh_TW and the resource is named "ab*.cd", then it searches "ab_zh_TW.cd", "ab_zh.cd" and then "ab.cd", until any of them is found.
Note: "*" must be right before ".", or the last character. For example, "ab*.cd" and "ab*" are both correct, while "ab*cd" and "ab*\/cd" are ignored.
If an URI contains two "*", the first "*" will be replaced with a browser code and the second with a proper locale. The browser code depends on what browser the user are used to visit the web site. Currently, the code for Internet Explorer is "ie", Safari is "saf", Opera is "opr" and all others are "moz". Thus, in the above example, if the resource is named "ab**.cd" and Firefox is used, then it searches "abmoz_zh_TW.cd", "abmoz_zh.cd" and then "abmoz.cd", until any of them is found.
Note: it assumes the path as name_lang_cn_var.ext where ".ext" is optional. Example, my_zh_tw.html.jsp.
ctx
- the servlet context to locate pagespgpath
- the page path excluding servlet name. It is OK to have
the query string. It might contain "*" for current browser code and Locale.locator
- the locator used to locate resource. If null, ctx
is assumed.pgpath
, otherwise
never nulljavax.servlet.ServletException
Locales.getCurrent()
public static void setClientIdentifier(Servlets.ClientIdentifier clientId)
isBrowser(javax.servlet.ServletRequest, java.lang.String)
to identify a client.
Notice that the client identifier must be thread-safe.
clientId
- the client identifier. If null, only the default types
are recognized.Servlets.ClientIdentifier
public static Servlets.ClientIdentifier getClientIdentifier()
Servlets.ClientIdentifier
public static java.lang.Double getBrowser(javax.servlet.ServletRequest request, java.lang.String name)
Notice that, after this method is called, an attribute named zk
will be stored to the request, such that you can retrieve
the browser information by use of EL, such as
${zk.ie > 7}
.
request
- the request.name
- the browser's name. It includes "ie", "ff", "gecko",
"webkit", "safari", "opera", "android", "mobile", "ios", "iphone", "ipad"
and "ipod".
And, "ff" is the same as "gecko", and "webkit" is the same as "safari".public static java.lang.String getBrowser(javax.servlet.ServletRequest request)
public static java.lang.Double getBrowser(java.lang.String userAgent, java.lang.String name)
Notice that, after this method is called, an attribute named zk
will be stored to the request, such that you can retrieve
the browser information by use of EL, such as
${zk.ie > 7}
.
userAgent
- the user agent (i.e., the user-agent header in HTTP).name
- the browser's name. It includes "ie", "ff", "gecko",
"webkit", "safari", "opera", "android", "mobile", "ios", "iphone", "ipad"
and "ipod".
And, "ff" is the same as "gecko", and "webit" is the same as "safari".public static java.lang.String getBrowser(java.lang.String userAgent)
userAgent
- the user agent (i.e., the user-agent header in HTTP).public static boolean isBrowser(javax.servlet.ServletRequest req, java.lang.String type)
getUserAgent(ServletRequest)
instead.type
- the type of the browser.
The syntax: <browser-name>[<version-number>];[-]
.ie9
means Internet Explorer 9 and later, while
ie6-
means Internet Explorer 6 (not prior, nor later).public static boolean isBrowser(java.lang.String userAgent, java.lang.String type)
getUserAgent(ServletRequest)
instead.userAgent
- represents a client.
For HTTP clients, It is the user-agent header.type
- the type of the browser, or a list of types separated by comma.<browser-name>[<version-number>];[-]
.ie9
means Internet Explorer 9 and later, while
ie6-
means Internet Explorer 6 (not prior, nor later).ie6-,ie7-
),
this method returns true if any of them matches (i.e., OR condition).public static final boolean isRobot(javax.servlet.ServletRequest req)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.Because there are too many robots, it returns true if the user-agent is not recognized.
public static final boolean isRobot(java.lang.String userAgent)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.Because there are too many robots, it returns true if the user-agent is not recognized.
userAgent
- represents a client.
For HTTP clients, It is the user-agent header.public static final boolean isExplorer(javax.servlet.ServletRequest req)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.isExplorer7(javax.servlet.ServletRequest)
is true.public static final boolean isExplorer(java.lang.String userAgent)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.isExplorer7(javax.servlet.ServletRequest)
is true.userAgent
- represents a client.
For HTTP clients, It is the user-agent header.public static final boolean isExplorer7(javax.servlet.ServletRequest req)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.public static final boolean isExplorer7(java.lang.String userAgent)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.userAgent
- represents a client.
For HTTP clients, It is the user-agent header.public static final boolean isGecko(javax.servlet.ServletRequest req)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.isGecko3(javax.servlet.ServletRequest)
is true.public static final boolean isGecko(java.lang.String userAgent)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.isGecko3(javax.servlet.ServletRequest)
is true.userAgent
- represents a client.
For HTTP clients, It is the user-agent header.public static final boolean isGecko3(javax.servlet.ServletRequest req)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.public static final boolean isGecko3(java.lang.String userAgent)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.userAgent
- represents a client.
For HTTP clients, It is the user-agent header.public static final boolean isSafari(javax.servlet.ServletRequest req)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.public static final boolean isSafari(java.lang.String userAgent)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.userAgent
- represents a client.
For HTTP clients, It is the user-agent header.public static final boolean isOpera(javax.servlet.ServletRequest req)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.public static final boolean isOpera(java.lang.String userAgent)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.userAgent
- represents a client.
For HTTP clients, It is the user-agent header.public static final boolean isHilDevice(javax.servlet.ServletRequest req)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.public static final boolean isHilDevice(java.lang.String userAgent)
getBrowser(javax.servlet.ServletRequest, java.lang.String)
.userAgent
- represents a client.
For HTTP clients, It is the user-agent header.public static double[] getIECompatibilityInfo(javax.servlet.ServletRequest request)
request
- public static final java.lang.String getUserAgent(javax.servlet.ServletRequest req)
Note: it doesn't return null, so it is easy to test what
the client is with String.indexOf(int)
.
public static final boolean isIncluded(javax.servlet.ServletRequest request)
public static final boolean isForwarded(javax.servlet.ServletRequest request)
public static final void forward(javax.servlet.ServletContext ctx, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String uri, java.util.Map params, int mode) throws java.io.IOException, javax.servlet.ServletException
NOTE: don't include query parameters in uri.
ctx
- the servlet context. If null, uri cannot be foreign URI.
It is ignored if URI is relevant (neither starts with '/' nor '~').uri
- the URI to include. It is OK to relevant (without leading
'/'). If starts with "/", the context path of request is assumed.
To reference to foreign context, use "~ctx" where ctx is the
context path of the foreign context (without leading '/').
If it could be any context path recognized by the Web container or
any name registered with addExtendletContext(javax.servlet.ServletContext, java.lang.String, org.zkoss.web.util.resource.ExtendletContext)
.
uri
could contain
'*' (to denote locale and browser). Refer to locate(javax.servlet.ServletContext, javax.servlet.ServletRequest, java.lang.String, org.zkoss.util.resource.Locator)
.params
- the parameter map; null to ignoremode
- one of OVERWRITE_URI
, IGNORE_PARAM
,
and APPEND_PARAM
. It defines how to handle if both uri
and params contains the same parameter.java.io.IOException
javax.servlet.ServletException
public static final void forward(javax.servlet.ServletContext ctx, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String uri) throws java.io.IOException, javax.servlet.ServletException
java.io.IOException
javax.servlet.ServletException
public static final void include(javax.servlet.ServletContext ctx, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String uri, java.util.Map params, int mode) throws java.io.IOException, javax.servlet.ServletException
NOTE: don't include query parameters in uri.
ctx
- the servlet context. If null, uri cannot be foreign URI.
It is ignored if URI is relevant (neither starts with '/' nor '~').uri
- the URI to include. It is OK to relevant (without leading
'/'). If starts with "/", the context path of request is assumed.
To reference to foreign context, use "~ctx/" where ctx is the
context path of the foreign context (without leading '/').
uri
could contain
'*' (to denote locale and browser). Refer to locate(javax.servlet.ServletContext, javax.servlet.ServletRequest, java.lang.String, org.zkoss.util.resource.Locator)
.params
- the parameter map; null to ignoremode
- one of OVERWRITE_URI
, IGNORE_PARAM
,
and APPEND_PARAM
. It defines how to handle if both uri
and params contains the same parameter.java.io.IOException
javax.servlet.ServletException
public static final void include(javax.servlet.ServletContext ctx, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String uri) throws java.io.IOException, javax.servlet.ServletException
java.io.IOException
javax.servlet.ServletException
public static final javax.servlet.RequestDispatcher getRequestDispatcher(javax.servlet.ServletContext ctx, javax.servlet.ServletRequest request, java.lang.String uri, java.util.Map params, int mode) throws javax.servlet.ServletException
ctx
- the servlet context. If null, uri cannot be foreign URI.
It is ignored if uri is relevant (neither starts with '/' nor '~').request
- the request. If null, uri cannot be relevant.
It is used only if uri is relevant.uri
- the URI to include. It is OK to relevant (without leading
'/'). If starts with "/", the context path of request is assumed.
To reference to foreign context, use "~ctx/" where ctx is the
context path of the foreign context (without leading '/').params
- the parameter map; null to ignoremode
- one of OVERWRITE_URI
, IGNORE_PARAM
,
and APPEND_PARAM
. It defines how to handle if both uri
and params contains the same parameter.javax.servlet.ServletException
public static final java.net.URL getResource(javax.servlet.ServletContext ctx, java.lang.String uri) throws java.io.UnsupportedEncodingException
getRequestDispatcher(javax.servlet.ServletContext, javax.servlet.ServletRequest, java.lang.String, java.util.Map, int)
did.
Since 5.0.7, file://, http://, https:// and ftp:// are supported.
java.io.UnsupportedEncodingException
public static final java.io.InputStream getResourceAsStream(javax.servlet.ServletContext ctx, java.lang.String uri) throws java.io.IOException
getRequestDispatcher(javax.servlet.ServletContext, javax.servlet.ServletRequest, java.lang.String, java.util.Map, int)
did.
Since 5.0.7, file://, http://, https:// and ftp:// are supported.
java.io.IOException
public static final java.lang.String generateURI(java.lang.String uri, java.util.Map params, int mode)
params
- the parameters to apend to the query stringmode
- one of OVERWRITE_URI
, IGNORE_PARAM
,
APPEND_PARAM
and PASS_THRU_ATTR
.
It defines how to handle if both uri and params contains the same
parameter.
mode is used only if both uri contains query string and params is
not empty.Encodes.encodeURL(ServletContext, ServletRequest, ServletResponse, String)
public static final java.util.List<java.lang.String> getContextPaths()
public static final java.lang.String getLimitTimeOffer()
isOfferExpired(java.lang.String, int)
.public static final boolean isOfferExpired(java.lang.String lto, int timeout)
timeout
- how long the office shall expire, unit: seconds.public static final ExtendletContext addExtendletContext(javax.servlet.ServletContext ctx, java.lang.String name, ExtendletContext extctx)
public static final ExtendletContext removeExtendletContext(javax.servlet.ServletContext ctx, java.lang.String name)
public static final ExtendletContext getExtendletContext(javax.servlet.ServletContext ctx, java.lang.String name)
public static final java.lang.String getExtension(java.lang.String path)
Note: the extension is converted to the lower case.
path
- the path. If path is null, null is returned.getExtension(String, boolean)
public static final java.lang.String getExtension(java.lang.String path, boolean lastOnly)
Note: the extension is converted to the lower case.
The result is the same for both getExtension(String)
and getExtension(String, boolean)
, if the path
has only one dot. However, if there are more than one dot, e.g.,
/a/b.c.d, then getExtension(String)
retrieves the last
extension, that is, d in this example.
On the other hand, if you invoke getExtension(path, false),
it returns the complete extension, that is, c.d in this example.
path
- the path. If path is null, null is returned.lastOnly
- whether to return the last portion of extensioin
if there are two or more dots.
In other wors, getExtension(path) is the same as
getExtension(path, true).public static java.lang.String getDetail(javax.servlet.ServletRequest request)
public static java.lang.String getNormalPath(java.lang.String path)
Note that if found no way to navigate the path, it is deemed as an illegal path. e.g. /../abc or /../../abc is deemed as illegal path since we don't know how to continue doing the normalize.
Copyright © 2005-2018 Potix Corporation. All Rights Reserved.