|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.stripes.localization.DefaultLocalePicker
public class DefaultLocalePicker
Default locale picker that uses a comma separated list of locales in the servlet init parameters to determine the set of locales that are supported by the application. Then at request time matches the user's preference order list as specified by the headers included in the request until it finds one of those locales in the system list. If a match cannot be found, the first locale in the system list will be picked. If there is no list of configured locales then the picker will default the list to a one entry list containing the system locale.
Locales are hierarchical, with up to three levels designating language, country and variant. Only the first level (language) is required. To provide the best match possible the DefaultLocalePicker tracks the one-level matches, two-level matches and three-level matches. If a three level match is found, it will be returned. If not the first two-level match will be returned if one was found. If not, the first one-level match will be returned. If not even a one-level match is found, the first locale supported by the system is returned.
Field Summary | |
---|---|
protected Configuration |
configuration
Stores a reference to the configuration passed in at initialization. |
protected Map<Locale,String> |
encodings
Contains a map of Locale to preferred character encoding. |
static String |
LOCALE_LIST
The configuration parameter that is used to lookup a comma separated list of locales that the system supports. |
protected List<Locale> |
locales
Stores the configured set of Locales that the system supports, looked up at init time. |
Constructor Summary | |
---|---|
DefaultLocalePicker()
|
Method Summary | |
---|---|
void |
init(Configuration configuration)
Attempts to read the |
String |
pickCharacterEncoding(HttpServletRequest request,
Locale locale)
Returns the character encoding to use for the request and locale if one has been specified in the configuration. |
Locale |
pickLocale(HttpServletRequest request)
Uses a preference matching algorithm to pick a Locale for the user's request. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String LOCALE_LIST
protected Configuration configuration
protected List<Locale> locales
protected Map<Locale,String> encodings
Constructor Detail |
---|
public DefaultLocalePicker()
Method Detail |
---|
public void init(Configuration configuration) throws Exception
init
in interface ConfigurableComponent
configuration
-
Exception
public Locale pickLocale(HttpServletRequest request)
pickLocale
in interface LocalePicker
request
- the request being processed
public String pickCharacterEncoding(HttpServletRequest request, Locale locale)
pickCharacterEncoding
in interface LocalePicker
request
- the current requestlocale
- the locale picked for the request
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |