|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.enhydra.barracuda.core.util.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 java.lang.String |
COUNTRY_KEY
|
static java.lang.String |
LANGAUGE_KEY
|
protected static org.apache.log4j.Logger |
logger
|
static int |
NONE
|
static int |
PERSIST_DEFAULT
|
static int |
SESSION
|
static java.lang.String |
VARIANT_KEY
|
Constructor Summary | |
Locales()
|
Method Summary | |
static int |
findClosestLocale(java.util.Locale targetLocale,
java.util.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 java.util.Locale |
getClientLocale(EventContext ec)
Get the client locale from an EventContext using the default param keys and persist option. |
static java.util.Locale |
getClientLocale(EventContext ec,
java.lang.String languageKey,
java.lang.String countryKey,
java.lang.String variantKey,
int persistOption)
Get the client locale from an EventContext |
static java.util.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 java.util.Locale |
getClientLocale(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
java.lang.String languageKey,
java.lang.String countryKey,
java.lang.String variantKey,
int persistOption)
This method attempts to get the client locale. |
static void |
releaseClientLocale(EventContext ec)
Release the client locale using an EventContext (this effectively removes it from whereever it might have been persisted). |
static void |
releaseClientLocale(EventContext ec,
int persistOption)
Release the client locale using an EventContext (this effectively removes it from whereever it might have been persisted). |
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(EventContext ec,
java.util.Locale loc)
Save the client locale using an EventContext using the default persist option |
static void |
saveClientLocale(EventContext ec,
java.util.Locale loc,
int persistOption)
Save the client locale using an EventContext |
static void |
saveClientLocale(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
java.util.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,
java.util.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 java.lang.String LANGAUGE_KEY
public static java.lang.String COUNTRY_KEY
public static java.lang.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 org.apache.log4j.Logger logger
Constructor Detail |
public Locales()
Method Detail |
public static java.util.Locale getClientLocale(EventContext ec)
ec
- the EventContext from which we'd like to determine Locale
public static java.util.Locale getClientLocale(EventContext ec, java.lang.String languageKey, java.lang.String countryKey, java.lang.String variantKey, int persistOption)
ec
- the EventContext from which we'd like to determine LocalelanguageKey
- 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 java.util.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 java.util.Locale getClientLocale(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, java.lang.String languageKey, java.lang.String countryKey, java.lang.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(EventContext ec, java.util.Locale loc)
ec
- the EventContext in which we'd like to set Localeloc
- the target client locale we'd like to setpublic static void saveClientLocale(EventContext ec, java.util.Locale loc, int persistOption)
ec
- the EventContext in which we'd like to set Localeloc
- the target client locale we'd like to setpersistOption
- the specific persistOption to be usedpublic static void saveClientLocale(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, java.util.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, java.util.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(EventContext ec)
ec
- the EventContext in which we'd like to set Locale (this tells us
where the locale info needs to be removed from)public static void releaseClientLocale(EventContext ec, int persistOption)
ec
- the EventContext in which we'd like to set LocalepersistOption
- the specific persistOption to be used (this tells us
where the locale info needs to be removed from)public 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(java.util.Locale targetLocale, java.util.Locale[] locales, int defaultIndex)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |