Class ResourceLocator

java.lang.Object
org.silverpeas.kernel.bundle.ResourceLocator

public class ResourceLocator extends Object
The resource locator gives access to the resource bundles (bundles of localized resources and of settings) that are located each of them into a particular directory. This directory can be the same location, the Silverpeas resources home directory. The location of the l10n resources is given by SilverpeasResourcesLocation.getL10nBundlesRootPath() and the one of the settings is given by SilverpeasResourcesLocation.getConfigurationFilesRootPath().

The mechanism used to access the files containing these resources is wrapped by this class. The resource bundles, according to the type of the resources, are represented by a concrete type implementing the SilverpeasBundle interface. For instance, three kinds of resources are handled by the ResourceLocator: LocalizationBundle for the l10n bundles (icons, messages, ...), SettingBundle for the configuration properties files, and XmlSettingBundle for XML configuration files.

The localization bundles and the settings aren't provided in a classical way (id est by resource getting from classpath) because they aren't carried into the Silverpeas archives as this should usually be done. Instead, they are located each of them into a peculiar directory so that administrators can easily modify them by hand. The access to the directories is handled by this class. If in the future, the mechanism requires to be modified, then this modification will be transparent for the rest of the code.

In order to keep stable the memory management with the resource bundles, ResourceLocator loads the resource bundles on the demand and uses a cache to keep them in memory for all the running time of Silverpeas so that they aren't collected by the garbage collector. Nevertheless, the policy on the bundle content loading is delegated to the SilverpeasBundle concrete types, so that advanced mechanism can be used to keep in memory the content itself with an expiration trigger (policy implemented by the ResourceBundle class). To have a glance of the policy adopted by the SilverpeasBundle concrete types, please read their corresponding documentation.

  • Method Details

    • getLocalizationBundle

      public static LocalizationBundle getLocalizationBundle(String name, String locale)
      Gets the localized resource defined under the specified full qualified name and for the specified locale. This resource can be a set of icons or of messages that are defined for the given locale. If the specified bundle doesn't exist, then any get of one of a localized property from the bundle will throw a MissingResourceException exception.
      Parameters:
      name - the full qualified name of the localized resource to return. It maps the path of the file in which the resource is stored (the path is relative to the Silverpeas resources home directory).
      locale - is an ISO 639-1 code identifying a language. If null, empty or missing, the default locale of the platform onto which Silverpeas is running will be taken into account.
      Returns:
      a resource bundle with the asked localized resources plus the general ones.
    • getLocalizationBundle

      public static LocalizationBundle getLocalizationBundle(String name, Locale locale)
      Gets the localized resource defined under the specified full qualified name and for the specified locale. This resource can be a set of icons or of messages that are defined for the given locale. If the specified bundle doesn't exist, then any get of one of a localized property from the bundle will throw a MissingResourceException exception.
      Parameters:
      name - the full qualified name of the localized resource to return. It maps the path of the file in which the resource is stored (the path is relative to the Silverpeas resources home directory).
      locale - the local for which tp get the bundle. If null the default locale of the platform onto which Silverpeas is running will be taken into account.
      Returns:
      a resource bundle with the asked localized resources plus the general ones.
    • getSettingBundle

      public static SettingBundle getSettingBundle(String name)
      Gets the setting resource that is defined under the specified full qualified name. This resource is a set of settings used to configure the behaviour of a Silverpeas functionality. If the specified bundle doesn't exist, then any get of one of a settings property from the bundle will throw a MissingResourceException exception.
      Parameters:
      name - the full qualified name of the resource to return. It maps the path of the file in which the resource is stored (the path is relative to the Silverpeas resources home directory).
      Returns:
      the bundle with the asked settings.
    • saveSettingBundle

      public static void saveSettingBundle(SettingBundle settings, Properties properties)
      Save the given properties for SettingBundle and refreshing its cache.
      Parameters:
      settings - a loaded setting bundle.
      properties - the properties, usually initialized from SettingBundle.asProperties().
    • getXmlSettingBundle

      public static XmlSettingBundle getXmlSettingBundle(String name)
      Gets the setting resource that is defined in an XML bundle under the specified full qualified name. This resource is set of settings to configure some behaviours of a Silverpeas functionality.

      To have a glance on the schema of the XML bundle, please see org.silverpeas.core.util.XmlSettingBundle.

      Parameters:
      name - the full qualified name of the resource to return. It maps the path of the file in which the resource is stored (the path is relative to the Silverpeas resources home directory).
      Returns:
      the XML bundle with the asked settings.
    • getGeneralLocalizationBundle

      public static LocalizationBundle getGeneralLocalizationBundle(String locale)
      Gets the Silverpeas general localized resource for the specified locale. If the locale is null or empty or missing, then the root locale is taken into account.
      Parameters:
      locale - the locale for which the bundle is returned.
      Returns:
      the bundle with the general localized resource.
    • getGeneralLocalizationBundle

      public static LocalizationBundle getGeneralLocalizationBundle(Locale locale)
      Gets the Silverpeas general localized resource for the specified locale. If the locale is null then the root locale is taken into account.
      Parameters:
      locale - the locale for which the bundle is returned.
      Returns:
      the bundle with the general localized resource.
    • getGeneralSettingBundle

      public static SettingBundle getGeneralSettingBundle()
      Gets the Silverpeas general settings resource. This resource is a set of general settings used to configure the common behaviour of Silverpeas.
      Returns:
      the bundle with the general settings.
    • getSettingsAsProperties

      public static Properties getSettingsAsProperties(String name)
      Gets setting resource that is defined under the specified full qualified name as a Properties instance. The properties gather all the settings used to configure the behaviour of a Silverpeas functionality. Instead of returning a SettingBundle or a XmlSettingBundle a basic Properties is just returned here; this method is useful for tiers code that requires a Properties to set up some of their functionality for Silverpeas.
      Parameters:
      name - the full qualified name of the localized resource to return. It maps the path of the file in which the resource is stored (the path is relative to the Silverpeas resources home directory).
      Returns:
      the Properties with the asked settings.
    • resetCache

      public static void resetCache()
      Resets any caches used directly or indirectly by the ResourceLocator. As consequence, the bundles will be reloaded when accessing.

      The cache containing the content of the bundles are usually expired at regularly time if a such time was defined in the system properties of Silverpeas. Otherwise, this method should be explicitly used to reset this cache and then to force the reloading of the bundles' content.

    • getOptionalSettingBundle

      public static Optional<SettingBundle> getOptionalSettingBundle(String name)
      Gets optionally the setting resource that is defined under the specified full qualified name. This resource is a set of settings used to configure the behaviour of a Silverpeas functionality.
      Parameters:
      name - the full qualified name of the resource to return. It maps the path of the file in which the resource is stored (the path is relative to the Silverpeas resources home directory).
      Returns:
      an optional bundle with the asked settings.
    • getOptionalLocalizationBundle

      public static Optional<LocalizationBundle> getOptionalLocalizationBundle(String name, String locale)
      Gets optionally the localized resource defined under the specified full qualified name and for the specified locale. This resource can be a set of icons or of messages that are defined for the given locale.
      Parameters:
      name - the full qualified name of the localized resource to return. It maps the path of the file in which the resource is stored (the path is relative to the Silverpeas resources home directory).
      locale - is an ISO 639-1 code identifying a language. If null, empty or missing, the default locale of the platform onto which Silverpeas is running will be taken into account.
      Returns:
      an optional resource bundle with the asked localized resources plus the general ones.
    • getLocalizationBundle

      public static LocalizationBundle getLocalizationBundle(String name)
      Gets the localized resource that is defined under the specified full qualified name and for the root locale (default locale when no one is specified or a locale is missing); the resources are provided by the bundle whose name matches exactly the bundle base name (id est without any locale extension). This resource can be a set of icons or of messages.
      Parameters:
      name - the full qualified name of the localized resource to return. It maps the path of the file in which the resource is stored (the path is relative to the Silverpeas resources home directory).
      Returns:
      the bundle with the asked localized resource plus the general one.