Package org.gatein.pc.portlet.impl.info
Class ResourceBundleManager
- java.lang.Object
-
- org.gatein.pc.portlet.impl.info.ResourceBundleManager
-
public class ResourceBundleManager extends Object
Manage a set of resource bundles. Obtention of bundles is delegated to a ResourceBundleFactory. A bundle obtained successfully is cached in order to avoid the potential expensive cost of the bundle retrieval.
The manager can also be used to build LocalizedString object from the loaded bundles.
- Version:
- $Revision: 7228 $
- Author:
- Julien Viet, Thomas Heute
-
-
Constructor Summary
Constructors Constructor Description ResourceBundleManager(ResourceBundle defaultBundle, org.gatein.common.i18n.ResourceBundleFactory resourceBundleFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.gatein.common.i18n.LocalizedStringgetLocalizedValue(String key, String defaultValue)Return a localized value constructed from the various resource bundles.ResourceBundlegetResourceBundle(Locale locale)Return a bundle for the given locale.
-
-
-
Constructor Detail
-
ResourceBundleManager
public ResourceBundleManager(ResourceBundle defaultBundle, org.gatein.common.i18n.ResourceBundleFactory resourceBundleFactory) throws IllegalArgumentException
- Parameters:
defaultBundle- the default bundle returned when no bundle has been obtained for the localeresourceBundleFactory- the resource bundle factory- Throws:
IllegalArgumentException- IllegalArgumentException if the resource bundle factory is null
-
-
Method Detail
-
getLocalizedValue
public org.gatein.common.i18n.LocalizedString getLocalizedValue(String key, String defaultValue) throws IllegalArgumentException
Return a localized value constructed from the various resource bundles. The supported locales of the manager are used in combination with the specified key. The default value is used if no value is found for theLocale.ENGLISH. Two successive calls to this method may not return identical results since the returnedLocalizedStringis built using the bundles known by the manager.- Parameters:
key- the key to lookup in the bundlesdefaultValue- the default value- Returns:
- the localized string
- Throws:
IllegalArgumentException- if the key of the default value is null
-
getResourceBundle
public ResourceBundle getResourceBundle(Locale locale) throws IllegalArgumentException
Return a bundle for the given locale. If the complete locale (language + country + variant) does not exist then it falls back to (language + country) or (language) or the default file. When the resource bundle object is found and was not in the global map, it put it in that map with a copy on write.- Parameters:
locale- the locale we want a bundle for- Returns:
- a bundle for the locale or null if not suitable bundle is found.
- Throws:
IllegalArgumentException- if the locale is null
-
-