Class ResourceLocator
- java.lang.Object
-
- org.silverpeas.core.util.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 theorg.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, ...) andorg.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 thejava.util.ResourceBundle
class). To have a glance of the policy adopted by theorg.silverpeas.core.util.SilverpeasBundle
concrete types, please read their corresponding documentation.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static LocalizationBundle
getGeneralLocalizationBundle(String locale)
Gets the Silverpeas general localized resource for the specified locale.static SettingBundle
getGeneralSettingBundle()
Gets the Silverpeas general settings resource.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).static LocalizationBundle
getLocalizationBundle(String name, String 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>
getOptionalSettingBundle(String name)
Gets optionally the setting resource that is defined under the specified full qualified name.static SettingBundle
getSettingBundle(String name)
Gets setting resource that is defined under the specified full qualified name.static Properties
getSettingsAsProperties(String name)
Gets setting resource that is defined under the specified full qualified name as aProperties
instance.static XmlSettingBundle
getXmlSettingBundle(String name)
Gets setting resource that is defined in an XML bundle under the specified full qualified name.static void
resetCache()
Resets any caches used directly or indirectly by the ResourceLocator.static void
saveSettingBundle(SettingBundle settings, Properties properties)
Save the given properties forSettingBundle
and refreshing its cache.
-
-
-
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 aMissingResourceException
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 aMissingResourceException
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 forSettingBundle
and refreshing its cache.- Parameters:
settings
- a loaded setting bundle.properties
- the properties, usually initialized fromSettingBundle.asProperties()
.
-
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 aProperties
instance. The properties gathers all the settings used to configure the behaviour of a Silverpeas functionality. Instead of returning aSettingBundle
or aXmlSettingBundle
a basicProperties
is just returned here; this method is useful for tiers code that requires aProperties
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.
-
-