Class 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 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 locale
        resourceBundleFactory - 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 the Locale.ENGLISH. Two successive calls to this method may not return identical results since the returned LocalizedString is built using the bundles known by the manager.
        Parameters:
        key - the key to lookup in the bundles
        defaultValue - 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