|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.opencms.i18n.CmsLocaleManager
Manages the locales configured for this OpenCms installation.
Locale configuration is done in opencms.xml.
| Field Summary | |
static String |
LOCALE_HANDLER
Runtime property name for locale handler. |
static String |
PARAMETER_ENCODING
Request parameter to force encoding selection. |
static String |
PARAMETER_LOCALE
Request parameter to force locale selection. |
| Constructor Summary | |
CmsLocaleManager()
Initializes a new CmsLocaleManager, called from the configuration. |
|
CmsLocaleManager(Locale defaultLocale)
Initializes a new CmsLocaleManager, used for OpenCms runlevel 1 (unit tests) only. |
|
| Method Summary | |
void |
addAvailableLocale(String localeName)
Adds a locale to the list of available locales. |
void |
addDefaultLocale(String localeName)
Adds a locale to the list of default locales. |
void |
cmsEvent(CmsEvent event)
Implements the CmsEvent interface, the locale manager the events to clear the list of cached keys . |
List |
getAvailableLocales()
Returns the list of available locales configured in. |
List |
getAvailableLocales(CmsObject cms,
String resourceName)
Returns an array of available locale names for the given resource. |
List |
getAvailableLocales(String names)
Returns a List of available locales from a comma separated string of locale names. |
Locale |
getBestMatchingLocale(Locale requestedLocale,
List locales,
Collection filter)
Returns the best matching locale from the given locales. |
static Locale |
getDefaultLocale()
Returns the default locale configured in opencms.properties. |
Locale |
getDefaultLocale(CmsObject cms,
String resourceName)
Returns the "best" default locale for the given resource. |
List |
getDefaultLocales()
Returns the list of default locale names configured in opencms.properties. |
List |
getDefaultLocales(CmsObject cms,
String resourceName)
Returns an array of default locales for the given resource. |
Locale |
getFirstMatchingLocale(List locales,
Collection filter)
Returns the first matching locale. |
CmsI18nInfo |
getI18nInfo(HttpServletRequest req,
CmsUser user,
CmsProject project,
String resource)
Returns the the appropriate locale/encoding for a request, using the "right" locale handler for the given resource. |
static Locale |
getLocale(String localeName)
Returns a locale created from the given full name. |
I_CmsLocaleHandler |
getLocaleHandler()
Returns the configured locale handler. |
static List |
getLocales(List localeNames)
Returns a List of locales from an array of locale names. |
static List |
getLocales(String localeNames)
Returns a List of locales from a comma-separated string of locale names. |
void |
initialize(CmsObject cms)
Initializes this locale manager with the OpenCms system configuration. |
boolean |
isInitialized()
Returns true if this locale manager is fully initialized. |
void |
setLocaleHandler(I_CmsLocaleHandler localeHandler)
Sets the configured locale handler. |
| 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_HANDLER
public static final String PARAMETER_ENCODING
public static final String PARAMETER_LOCALE
| Constructor Detail |
public CmsLocaleManager()
public CmsLocaleManager(Locale defaultLocale)
defaultLocale - the default locale to use| Method Detail |
public static Locale getDefaultLocale()
opencms.properties.The default locale is the first locale int the list of configured default locales.
public static Locale getLocale(String localeName)
The full name must consist of language code, country code(optional), variant(optional) separated by "_".
This method will always return a valid Locale! If the provided locale name is not valid (i.e. leads to an Exception when trying to create the Locale, then the configured default Locale is returned.
localeName - the full locale name
null if not availablepublic static List getLocales(List localeNames)
localeNames - array of locale names
public static List getLocales(String localeNames)
localeNames - a comma-separated string of locale names
public void addAvailableLocale(String localeName)
localeName - the locale to addpublic void addDefaultLocale(String localeName)
localeName - the locale to addpublic void cmsEvent(CmsEvent event)
cmsEvent in interface I_CmsEventListenerevent - CmsEvent that has occurredpublic List getAvailableLocales()
en, de
public List getAvailableLocales(CmsObject cms,
String resourceName)
cms - the current cms permission objectresourceName - the name of the resource
public List getAvailableLocales(String names)
All names are filtered against the allowed available locales
configured in opencms.properties.
names - a comma-separated String of locale names
public Locale getBestMatchingLocale(Locale requestedLocale,
List locales,
Collection filter)
The best matching locale is the first locale (eventually simplified) in the given list with the maximum number of parts similar to a (part of a) locale in the filter list. Example: getBestMatchingLocale([en_GB, de], {de, en, en_US} -> en since en_GB <> de = 0, en_GB <> en = 1, en_GB <> en_US = 1, de <> de = 1, de <> en = 0, de <> en_US = 0
requestedLocale - the originally requested localelocales - a list of locale namesfilter - a list of locale names to use as filter
public Locale getDefaultLocale(CmsObject cms,
String resourceName)
cms - the current cms permission objectresourceName - the name of the resource
getDefaultLocales(CmsObject, String)public List getDefaultLocales()
opencms.properties.
en, de
public List getDefaultLocales(CmsObject cms,
String resourceName)
Use this method in case you need to get all available default options for a resource,
if you just need the "best" default locale for a resource,
use .getDefaultLocale(CmsObject, String)
cms - the current cms permission objectresourceName - the name of the resource
getDefaultLocale(CmsObject, String)
public Locale getFirstMatchingLocale(List locales,
Collection filter)
locales - must be a ascending sourted list of locales in order of preferencefilter - the filter to check the locales agains
public CmsI18nInfo getI18nInfo(HttpServletRequest req,
CmsUser user,
CmsProject project,
String resource)
Certain system folders (like the Workplace) require a special locale handler different from the configured handler. Use this method if you want to resolve locales exactly like the system does for a request.
req - the current http requestuser - the current userproject - the current projectresource - the URI of the requested resource (with full site root added)
public I_CmsLocaleHandler getLocaleHandler()
This handler is used to derive the appropriate locale/encoding for a request.
public void initialize(CmsObject cms)
cms - an OpenCms context object that must have been initialized with "Admin" permissionspublic boolean isInitialized()
true if this locale manager is fully initialized.This is required to prevent errors during unit tests, simple unit tests will usually not have a fully initialized locale manager available.
public void setLocaleHandler(I_CmsLocaleHandler localeHandler)
localeHandler - the locale handler to set
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||