|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.opencms.i18n.CmsLocaleManager
public class 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 defaults,
Collection available)
Tries to find the given requested locale (eventually simplified) in the collection of available locales, if the requested locale is not found it will return the first match from the given list of default locales. |
static Locale |
getDefaultLocale()
Returns the default locale configured in opencms-system.xml. |
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 available)
Returns the first matching locale (eventually simplified) from the available locales. |
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 String |
getLocaleNames(List localeNames)
Returns the locale names from the given List of locales as a comma separated String. |
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-system.xml.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 String getLocaleNames(List localeNames)
For example, if the input List contains and
Locale.ENGLISH, the result will be Locale.GERMANY"en, de_DE".
An empty String is returned if the input is null, or contains no elements.
localeNames - the locale names to generate a String from
public 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 defaults,
Collection available)
requestedLocale - the requested locale, if this (or a simplified version of it) is available it will be returneddefaults - a list of default locales to use in case the requested locale is not availableavailable - the available locales to find a match in
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 available)
locales - must be an ascending sorted list of locales in order of preferenceavailable - the available locales to find a match in
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 | |||||||||