| java.lang.Object org.zkoss.web.servlet.Charsets
Charsets | public class Charsets (Code) | | Utilities to handle characters
author: tomyeh |
Method Summary | |
final public static void | cleanup(ServletRequest request, Object old) Cleans up what has been set in
Charsets.setup . | final public static Locale | getPreferredLocale(ServletRequest request) Returns the preferred locale of the specified request.
You rarely need to invoke this method directly, because it is done
automatically by
Charsets.setup .
- It checks whether any attribute stored in HttpSession called
Attributes.PREFERRED_LOCALE .
| final public static String | getURICharset() Returns the charset used to encode URI and query string. | final public static boolean | hasSetup(ServletRequest request) Returns whether the specified request has been set up, i.e.,
Charsets.setup is called
It is rarely needed to call this method, because it is called
automatically by
Charsets.setup . | final public static void | markSetup(ServletRequest request, boolean setup) Marks the specified request whether it has been set up, i.e.,
Charsets.setup is called. | final public static void | setPreferredLocale(ServletRequest request, Locale locale) Sets the preferred locale for the current session of the specified
request.
Parameters: locale - the preferred Locale. | final public static Object | setup(ServletRequest request, ServletResponse response, String charset) Sets up the charset for the request and response based on
Charsets.getPreferredLocale . |
cleanup | final public static void cleanup(ServletRequest request, Object old)(Code) | | Cleans up what has been set in
Charsets.setup .
Some invocation are not undo-able, so this method only does the basic
cleanups.
Parameters: old - the value must be the one returned by the last call toCharsets.setup. |
getPreferredLocale | final public static Locale getPreferredLocale(ServletRequest request)(Code) | | Returns the preferred locale of the specified request.
You rarely need to invoke this method directly, because it is done
automatically by
Charsets.setup .
- It checks whether any attribute stored in HttpSession called
Attributes.PREFERRED_LOCALE . If so, return it.
- Otherwise, use ServletRequest.getLocale().
|
getURICharset | final public static String getURICharset()(Code) | | Returns the charset used to encode URI and query string.
|
hasSetup | final public static boolean hasSetup(ServletRequest request)(Code) | | Returns whether the specified request has been set up, i.e.,
Charsets.setup is called
It is rarely needed to call this method, because it is called
automatically by
Charsets.setup .
|
markSetup | final public static void markSetup(ServletRequest request, boolean setup)(Code) | | Marks the specified request whether it has been set up, i.e.,
Charsets.setup is called.
It is rarely needed to call this method, because it is called
automatically by
Charsets.setup .
|
setPreferredLocale | final public static void setPreferredLocale(ServletRequest request, Locale locale)(Code) | | Sets the preferred locale for the current session of the specified
request.
Parameters: locale - the preferred Locale. If null, it means no preferredlocale (and then Charsets.getPreferredLocale use request.getLocaleinstead). |
setup | final public static Object setup(ServletRequest request, ServletResponse response, String charset)(Code) | | Sets up the charset for the request and response based on
Charsets.getPreferredLocale . After setting up, you shall invoke
Charsets.cleanup 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 redudant 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.
Parameters: charset - the response's charset. If null or empty,response.setCharacterEncoding won't be called, i.e., the container'sdefault is used. an object that must be passed to Charsets.cleanup
|
|
|