public class Charsets
extends java.lang.Object
Constructor and Description |
---|
Charsets() |
Modifier and Type | Method and Description |
---|---|
static void |
cleanup(javax.servlet.ServletRequest request,
java.lang.Object old)
Cleans up what has been set in
setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String) . |
static java.util.Locale |
getPreferredLocale(javax.servlet.http.HttpSession sess,
javax.servlet.ServletRequest request)
Returns the preferred locale of the specified request.
|
static java.util.Locale |
getPreferredLocale(javax.servlet.ServletRequest request)
Returns the preferred locale of the specified request.
|
static java.lang.String |
getURICharset()
Returns the charset used to encode URI and query string.
|
static boolean |
hasSetup(javax.servlet.ServletRequest request)
Returns whether the specified request has been set up, i.e.,
setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String) is called
It is rarely needed to call this method, because it is called
automatically by setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String) . |
static void |
markSetup(javax.servlet.ServletRequest request,
boolean setup)
Marks the specified request whether it has been set up, i.e.,
setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String) is called. |
static void |
setPreferredLocale(javax.servlet.http.HttpSession hsess,
java.util.Locale locale)
Sets the preferred locale for the specified session.
|
static void |
setPreferredLocale(javax.servlet.ServletContext ctx,
java.util.Locale locale)
Sets the preferred locale for the specified servlet context.
|
static java.lang.Object |
setup(javax.servlet.http.HttpSession sess,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.String charset)
Sets up the charset for the request and response based on
getPreferredLocale(HttpSession,ServletRequest) . |
static java.lang.Object |
setup(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
java.lang.String charset)
Sets up the charset for the request and response based on
getPreferredLocale(HttpSession,ServletRequest) . |
public static final java.lang.String getURICharset()
public static final java.lang.Object setup(javax.servlet.http.HttpSession sess, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String charset)
getPreferredLocale(HttpSession,ServletRequest)
. After setting up, you shall invoke
cleanup(javax.servlet.ServletRequest, java.lang.Object)
before exiting.
final Object old = setup(request, response, null);
try {
....
} finally {
cleanup(request, old);
}
It is OK to call this method multiple time, since it is smart
enough to ignore redundant calls.
CharsetFilter
actually use this method to setup
the proper charset and locale. By mapping CharsetFilter
to
all servlets, the encoding charset could be prepared correctly.
However, if you are writing libraries to be as independent of
web.xml as possible, you might choose to invoke this method directly.
sess
- the session to look for the preferred locale. Ignored if null.charset
- the response's charset. If null or empty,
response.setCharacterEncoding won't be called, i.e., the container's
default is used.cleanup(javax.servlet.ServletRequest, java.lang.Object)
public static final java.lang.Object setup(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String charset)
getPreferredLocale(HttpSession,ServletRequest)
.
It is the same as setup(request.getSession(false), request, response, charset);public static final void cleanup(javax.servlet.ServletRequest request, java.lang.Object old)
setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String)
.
Some invocation are not undo-able, so this method only does the basic
cleanups.old
- the value must be the one returned by the last call to
setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String)
.public static final boolean hasSetup(javax.servlet.ServletRequest request)
setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String)
is called
It is rarely needed to call this method, because it is called
automatically by setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String)
.
public static final void markSetup(javax.servlet.ServletRequest request, boolean setup)
setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String)
is called.
It is rarely needed to call this method, because it is called
automatically by setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String)
.
public static final java.util.Locale getPreferredLocale(javax.servlet.http.HttpSession sess, javax.servlet.ServletRequest request)
setup(javax.servlet.http.HttpSession, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String)
.
Attributes.PREFERRED_LOCALE
. If so, return it.Attributes.PREFERRED_LOCALE
. If so, return it.Attributes.PREFERRED_LOCALE
is defined. If so, return it.sess
- the session to look for the preferred locale. Ignored if null.public static final java.util.Locale getPreferredLocale(javax.servlet.ServletRequest request)
public static final void setPreferredLocale(javax.servlet.http.HttpSession hsess, java.util.Locale locale)
Default: null (no preferred locale -- depending on browser's setting).
locale
- the preferred Locale. If null, it means no preferred localegetPreferredLocale(HttpSession,ServletRequest)
public static final void setPreferredLocale(javax.servlet.ServletContext ctx, java.util.Locale locale)
Default: null (no preferred locale -- depending on browser's setting).
locale
- the preferred Locale. If null, it means no preferred localegetPreferredLocale(HttpSession,ServletRequest)
Copyright © 2005-2018 Potix Corporation. All Rights Reserved.