public class DefaultLocalePicker extends Object implements LocalePicker
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.
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
DefaultLocalePicker() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
public static final String LOCALE_LIST
protected Configuration configuration
protected List<Locale> locales
public void init(Configuration configuration) throws Exception
init in interface ConfigurableComponentconfiguration - Exceptionpublic Locale pickLocale(HttpServletRequest request)
pickLocale in interface LocalePickerrequest - the request being processedpublic String pickCharacterEncoding(HttpServletRequest request, Locale locale)
pickCharacterEncoding in interface LocalePickerrequest - the current requestlocale - the locale picked for the request© Copyright 2005-2006, Stripes Development Team.