public class DefaultLocalePicker extends java.lang.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 java.util.Map<java.util.Locale,java.lang.String> |
encodings
Contains a map of Locale to preferred character encoding.
|
static java.lang.String |
LOCALE_LIST
The configuration parameter that is used to lookup a comma separated list of locales that
the system supports.
|
protected java.util.List<java.util.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
|
java.lang.String |
pickCharacterEncoding(javax.servlet.http.HttpServletRequest request,
java.util.Locale locale)
Returns the character encoding to use for the request and locale if one has been
specified in the configuration.
|
java.util.Locale |
pickLocale(javax.servlet.http.HttpServletRequest request)
Uses a preference matching algorithm to pick a Locale for the user's request.
|
public static final java.lang.String LOCALE_LIST
protected Configuration configuration
protected java.util.List<java.util.Locale> locales
protected java.util.Map<java.util.Locale,java.lang.String> encodings
public void init(Configuration configuration) throws java.lang.Exception
init
in interface ConfigurableComponent
configuration
- java.lang.Exception
public java.util.Locale pickLocale(javax.servlet.http.HttpServletRequest request)
pickLocale
in interface LocalePicker
request
- the request being processedpublic java.lang.String pickCharacterEncoding(javax.servlet.http.HttpServletRequest request, java.util.Locale locale)
pickCharacterEncoding
in interface LocalePicker
request
- the current requestlocale
- the locale picked for the request? Copyright 2005-2006, Stripes Development Team.