Class CmsResourceBundleLoader
The main reason for implementing this is that the Java default resource bundle loading mechanism
provided by ResourceBundle.getBundle(java.lang.String, java.util.Locale)
uses a
cache that can NOT be flushed by any standard means. This means for every simple change in a resource
bundle, the Java VM (and the webapp container that runs OpenCms) must be restarted.
This non-standard resource bundle loader avoids this by providing a flushable cache.
In case the requested bundle can not be found, a fallback mechanism to
ResourceBundle.getBundle(java.lang.String, java.util.Locale)
is used to look up
the resource bundle with the Java default resource bundle loading mechanism.
- Since:
- 6.2.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addBundleToCache
(String baseName, Locale locale, I_CmsResourceBundle bundle) Adds the specified resource bundle to the permanent cache.static void
Flushes the complete resource bundle cache.static void
flushBundleCache
(String baseName, boolean flushPermanent) Flushes all variations for the provided bundle from the cache.static void
flushPermanentCache
(String baseName) Removes bundles with the given base name from the permanent cache.static ResourceBundle
Get the appropriate ResourceBundle for the given locale.
-
Method Details
-
addBundleToCache
Adds the specified resource bundle to the permanent cache.- Parameters:
baseName
- the raw bundle name, without locale qualifierslocale
- the localebundle
- the bundle to cache
-
flushBundleCache
Flushes the complete resource bundle cache. -
flushBundleCache
Flushes all variations for the provided bundle from the cache.- Parameters:
baseName
- the bundle base name to flush the variations forflushPermanent
- if true, the cache for additional message bundles will be flushed, too
-
flushPermanentCache
Removes bundles with the given base name from the permanent cache.- Parameters:
baseName
- the bundle base name
-
getBundle
Get the appropriate ResourceBundle for the given locale. The following strategy is used:A sequence of candidate bundle names are generated, and tested in this order, where the suffix 1 means the string from the specified locale, and the suffix 2 means the string from the default locale:
- baseName + "_" + language1 + "_" + country1 + "_" + variant1
- baseName + "_" + language1 + "_" + country1
- baseName + "_" + language1
- baseName + "_" + language2 + "_" + country2 + "_" + variant2
- baseName + "_" + language2 + "_" + country2
- baseName + "_" + language2
- baseName
In the sequence, entries with an empty string are ignored. Next,
getBundle
tries to instantiate the resource bundle:- This implementation only resolves property based resource bundles. Class based resource bundles are nor found.
- A search is made for a property resource file, by replacing '.' with '/' and appending ".properties", and using ClassLoader.getResource(). If a file is found, then a PropertyResourceBundle is created from the file's contents.
If no resource bundle was found, the default resource bundle loader is used to look for the resource bundle. Class based resource bundles will be found now.
- Parameters:
baseName
- the name of the ResourceBundlelocale
- A locale- Returns:
- the desired resource bundle
-