|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.barracudamvc.plankton.l10n.Locales
Simple locale utilities. This class makes it easy to determine the target locale from an event context or a servlet request. You can also set the locale and ask the class to save the information for you (in a cookie and/or the session) so that the locale info will persist across muliple requests
Field Summary | |
static int |
COOKIES_AND_SESSION
|
static String |
COUNTRY_KEY
|
static String |
LANGAUGE_KEY
|
protected static org.apache.log4j.Logger |
logger
|
static int |
NONE
|
static int |
PERSIST_DEFAULT
|
static int |
SESSION
|
static String |
VARIANT_KEY
|
Constructor Summary | |
Locales()
|
Method Summary | |
static int |
findClosestLocale(Locale targetLocale,
Locale[] locales,
int defaultIndex)
This utility function will run through a list of Locales and return the index of the locale that matches most closely. |
static Locale |
getClientLocale(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Get the client locale from a ServletRequest using the default param keys and persist option |
static Locale |
getClientLocale(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
String languageKey,
String countryKey,
String variantKey,
int persistOption)
This method attempts to get the client locale. |
static void |
releaseClientLocale(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
Release a client locale (this effectively removes it from whereever it might have been persisted) |
static void |
releaseClientLocale(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
int persistOption)
Release a client locale (this effectively removes it from whereever it might have been persisted) |
static void |
saveClientLocale(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
Locale loc)
Here we actually force a locale to be saved using the default persist option. |
static void |
saveClientLocale(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
Locale loc,
int persistOption)
Here we actually force a locale to be saved. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static String LANGAUGE_KEY
public static String COUNTRY_KEY
public static String VARIANT_KEY
public static final int NONE
public static final int SESSION
public static final int COOKIES_AND_SESSION
public static int PERSIST_DEFAULT
protected static final org.apache.log4j.Logger logger
Constructor Detail |
public Locales()
Method Detail |
public static Locale getClientLocale(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
req
- the HttpServletRequest from which we'd like to determine Localeresp
- the HttpServletResponse (needed if we want to save Locale in a cookie
otherwise it may be null)
public static Locale getClientLocale(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String languageKey, String countryKey, String variantKey, int persistOption)
First we look to see if we can determine the locale by the req's form parameters (language, country, variant). If not, we look in the session to see if we can get the information from there. If that fails, we see if we can get the information from a client cookie (where the value is a comma delimited string containing language, country, and variant. If we still haven't got the locale information, we try and retrieve it from the servlet request, and if that fails, we use the default locale.
In each of these cases we save (depending on persistOption) the locale info in both the session and in a client cookie (so as to speed lookups on subsequent requests).
req
- the HttpServletRequest from which we'd like to determine Localeresp
- the HttpServletResponse (needed if we want to save Locale in a cookie
otherwise it may be null)languageKey
- the key to be used to look in the request for a
language paramtercountryKey
- the key to be used to look in the request for a
country paramtervariantKey
- the key to be used to look in the request for a
variant paramterpersistOption
- how we'd like to persist the Locale (by default, it will be stored
in the SESSION)
public static void saveClientLocale(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, Locale loc)
req
- the HttpServletRequest (needed to get the HttpSession)resp
- the HttpServletResponse (needed if we want to save Locale
in a cookie otherwise it may be null)loc
- the target client locale we'd like to setpublic static void saveClientLocale(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, Locale loc, int persistOption)
req
- the HttpServletRequest (needed to get the HttpSession)resp
- the HttpServletResponse (needed if we want to save Locale
in a cookie otherwise it may be null)loc
- the target client locale we'd like to setpersistOption
- the specific persistOption to be usedpublic static void releaseClientLocale(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
req
- the HttpServletRequest (needed to get the HttpSession)resp
- the HttpServletResponse (needed if we want to clear Locale
from a cookie otherwise it may be null)public static void releaseClientLocale(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, int persistOption)
req
- the HttpServletRequest (needed to get the HttpSession)resp
- the HttpServletResponse (needed if we want to clear Locale
from a cookie otherwise it may be null)persistOption
- the specific persistOption to be used (this tells us
where the locale info needs to be removed from)public static int findClosestLocale(Locale targetLocale, Locale[] locales, int defaultIndex)
targetLocale
- the target localelocales
- the array of locales to searchdefaultIndex
- the default index (if no match is found)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |