Class LocalizationBundle

java.lang.Object
java.util.ResourceBundle
org.silverpeas.kernel.bundle.LocalizationBundle
All Implemented Interfaces:
SilverpeasBundle

public class LocalizationBundle extends ResourceBundle implements SilverpeasBundle
A resource bundle that contains the l10n resources defined under a fully qualified name in Silverpeas. These resources can be messages, icons, and so one.

It decorates ResourceBundle to suit the peculiar use of the resource bundles in Silverpeas. It wraps in a transparent way both the Silverpeas general resource bundle and any another peculiar resource bundle. The loading of the resources bundles in Silverpeas is managed by ResourceLocator itself. If no bundle exists with the given fully qualified name (the bundle base name) or if a given key isn't defined in the bundle, then a MissingResourceException exception is thrown as defined in the ResourceBundle contract.

To handle the general localized resources and those from the given bundle name it uses an instance of ResourceBundle for each of them. So, it profits then of the bundle content access policy implemented by this class: the content is cached in memory with an expiration trigger.

See Also:
API Note:
A general resource bundle is expected at GENERAL_BUNDLE_NAME
  • Field Details

    • GENERAL_BUNDLE_NAME

      public static final String GENERAL_BUNDLE_NAME
      The Silverpeas l10n bundle for general translations. It is both the default and base bundle that is always loaded along any other specific bundles. This Bundle has to be provided and available for Silverpeas.
      See Also:
  • Constructor Details

  • Method Details

    • keySet

      @NonNull public Set<String> keySet()
      Returns a Set of all keys contained in this ResourceBundle and its parent bundles.
      Specified by:
      keySet in interface SilverpeasBundle
      Overrides:
      keySet in class ResourceBundle
      Returns:
      a Set of all keys contained in this ResourceBundle and its parent bundles.
      Since:
      1.6
    • specificKeySet

      public Set<String> specificKeySet()
      Returns a Set of the specific keys contained in this ResourceBundle. The keys from the general resource bundle aren't taken into account.
      Returns:
      a Set of specific keys contained in this ResourceBundle.
    • containsKey

      public boolean containsKey(@NonNull String key)
      Determines whether the given key is contained in this ResourceBundle or its parent bundles.
      Specified by:
      containsKey in interface SilverpeasBundle
      Overrides:
      containsKey in class ResourceBundle
      Parameters:
      key - the resource key
      Returns:
      true if the given key is contained in this ResourceBundle or its parent bundles; false otherwise.
      Throws:
      NullPointerException - if key is null
      Since:
      1.6
    • getBaseBundleName

      public String getBaseBundleName()
      Returns the base name of this bundle, if known, or null if unknown.

      If not null, then this is the value of the baseName parameter that was passed to the ResourceBundle.getBundle(String) method when the resource bundle was loaded.

      Specified by:
      getBaseBundleName in interface SilverpeasBundle
      Overrides:
      getBaseBundleName in class ResourceBundle
      Returns:
      The base name of the resource bundle, as provided to and expected by the ResourceBundle.getBundle(...) methods.
      Since:
      1.8
      See Also:
    • getLocale

      public Locale getLocale()
      Returns the actual locale of this resource bundle. This method can be used to determine whether the resource bundle returned really corresponds to the requested locale or is a fallback to the default locale.
      Overrides:
      getLocale in class ResourceBundle
      Returns:
      the locale of this resource bundle
    • getKeys

      @NonNull public Enumeration<String> getKeys()
      Specified by:
      getKeys in class ResourceBundle
    • getSpecificKeys

      public Enumeration<String> getSpecificKeys()
      Gets the specific keys of this bundle. The keys from the general resource bundle aren't taken into account.
      Returns:
      an enumaration with the specific keys of this bundle.
    • changeLocale

      public void changeLocale(String locale)
      Changes the locale of this localization bundle. The bundle content will be loaded for the specified locale.
      Parameters:
      locale - the new locale.
    • changeLocale

      public void changeLocale(Locale locale)
      Changes the locale of this localization bundle. The bundle content will be loaded for the specified locale.
      Parameters:
      locale - the new locale.
    • exists

      public boolean exists()
      Is this bundle exists?
      Specified by:
      exists in interface SilverpeasBundle
      Returns:
      true if this bundle exists, false otherwise.
    • getStringWithParams

      public String getStringWithParams(String resName, Object... params)
    • handleGetObject

      protected Object handleGetObject(@NonNull String key)
      Specified by:
      handleGetObject in class ResourceBundle