Class ResourceLocator
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 Summary
Modifier and TypeMethodDescriptionstatic LocalizationBundlegetGeneralLocalizationBundle(String locale) Gets the Silverpeas general localized resource for the specified locale.static LocalizationBundlegetGeneralLocalizationBundle(Locale locale) Gets the Silverpeas general localized resource for the specified locale.static SettingBundleGets the Silverpeas general settings resource.static LocalizationBundlegetLocalizationBundle(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).static LocalizationBundlegetLocalizationBundle(String name, String locale) Gets the localized resource defined under the specified full qualified name and for the specified locale.static LocalizationBundlegetLocalizationBundle(String name, Locale locale) Gets the localized resource defined under the specified full qualified name and for the specified locale.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.static Optional<SettingBundle> Gets optionally the setting resource that is defined under the specified full qualified name.static SettingBundlegetSettingBundle(String name) Gets the setting resource that is defined under the specified full qualified name.static PropertiesGets setting resource that is defined under the specified full qualified name as aPropertiesinstance.static XmlSettingBundlegetXmlSettingBundle(String name) Gets the setting resource that is defined in an XML bundle under the specified full qualified name.static voidResets any caches used directly or indirectly by the ResourceLocator.static voidsaveSettingBundle(SettingBundle settings, Properties properties) Save the given properties forSettingBundleand refreshing its cache.
-
Method Details
-
getLocalizationBundle
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 aMissingResourceExceptionexception.- 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
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 aMissingResourceExceptionexception.- 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
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 aMissingResourceExceptionexception.- 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
Save the given properties forSettingBundleand refreshing its cache.- Parameters:
settings- a loaded setting bundle.properties- the properties, usually initialized fromSettingBundle.asProperties().
-
getXmlSettingBundle
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
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
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
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
Gets setting resource that is defined under the specified full qualified name as aPropertiesinstance. The properties gather all the settings used to configure the behaviour of a Silverpeas functionality. Instead of returning aSettingBundleor aXmlSettingBundlea basicPropertiesis just returned here; this method is useful for tiers code that requires aPropertiesto 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
Propertieswith 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
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
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.
-