Class 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 into a particular directory, the Silverpeas resources home directory. 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 org.silverpeas.core.util.SilverpeasBundle interface. For instance, two kinds of resources are handled by ResourceLocator: org.silverpeas.core.util.LocalizationBundle for the localized resources (icons, messages, ...) and org.silverpeas.core.util.SettingBundle for the configuration parameters.

    The localization bundles and the settings aren't provided in a classical way (id est by injection point) because they aren't carried into the Silverpeas archive as it should usually be done. Instead, they are located into a peculiar directory in the Silverpeas home directory so that administrators can easily modify them by hand. The access to this directory 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 org.silverpeas.core.util.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 java.util.ResourceBundle class). To have a glance of the policy adopted by the org.silverpeas.core.util.SilverpeasBundle concrete types, please read their corresponding documentation.

    • Method Detail

      • 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.
      • getSettingBundle

        public static SettingBundle getSettingBundle​(String name)
        Gets 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.
      • getXmlSettingBundle

        public static XmlSettingBundle getXmlSettingBundle​(String name)
        Gets 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.
      • 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 gathers 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 reload 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.