PropertyResourceBundle
s and Locales.
Allows to access a ResourceBundle
for a given locale multiple
times, without having to reload the Bundle each time. Also tries to keep
single copies of each Bundle (multiple locales may map to the same
ResourceBundle
object).
It can also be used to load the best bundle for a list of given locales:
instead of just probing one Locale and returning the default one when not
found, when getBundle()
is invoked with the array argument it
tries to find the best locale according the array of desired locales.
When this class is used with non-modular JDKs, the property resources are assumed to use UTF-8 encoding.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ResourceCache
createResourceCache
(String baseclass) Create a ResourceCache for a base resource, with the default ClassLoader.static ResourceCache
createResourceCache
(String baseclass, ClassLoader loader) Create a ResourceCache for a base resource, supplying a ClassLoader.static ResourceCache
createResourceCache
(String baseclass, ClassLoader loader, Locale deflocale) Create a ResourceCache for a base resource, supplying a ClassLoader and a default locale.static ResourceCache
createResourceCache
(String baseclass, ClassLoader loader, Locale deflocale, ResourceBundle.Control control) Deprecated.Retrieves the Bundle associated to default locale.getBundle
(Enumeration<Locale> locales) Retrieves the most appropriate Bundle according to an Enumeration of desired locales.Retrieves the best Bundle associated to a given Locale.Retrieves the most appropriate Bundle according to an array of desired locales.
-
Method Details
-
createResourceCache
@Deprecated public static ResourceCache createResourceCache(String baseclass, ClassLoader loader, Locale deflocale, ResourceBundle.Control control) Deprecated.Create a ResourceCache for a base resource, supplying a ClassLoader, a default locale and a Resource Control.- Parameters:
baseclass
- the base resource class name.loader
- the class loader.deflocale
- the default locale for the cache.control
- the resource control.- Returns:
- the ResourceCache.
- Throws:
MissingResourceException
- if no resources can be found at thebaseclass
.
-
createResourceCache
public static ResourceCache createResourceCache(String baseclass, ClassLoader loader, Locale deflocale) Create a ResourceCache for a base resource, supplying a ClassLoader and a default locale.- Parameters:
baseclass
- the base resource class name.loader
- the class loader.deflocale
- the default locale for the cache.- Returns:
- the ResourceCache.
- Throws:
MissingResourceException
- if no resources can be found at thebaseclass
.
-
createResourceCache
Create a ResourceCache for a base resource, supplying a ClassLoader.- Parameters:
baseclass
- the base resource class name.loader
- the class loader.- Returns:
- the ResourceCache.
- Throws:
MissingResourceException
- if no resources can be found at thebaseclass
.
-
createResourceCache
Create a ResourceCache for a base resource, with the default ClassLoader.- Parameters:
baseclass
- the base resource class name.- Returns:
- the ResourceCache.
- Throws:
MissingResourceException
- if no resources can be found at thebaseclass
.
-
getBundle
Retrieves the most appropriate Bundle according to an Enumeration of desired locales.If the list of locales is null, returns the default locale.
- Parameters:
locales
- the Enumeration of desired locales, in descending order of priority- Returns:
- the most appropriate Bundle for the given locale list
-
getBundle
Retrieves the most appropriate Bundle according to an array of desired locales.If the list of locales is null, returns the default locale.
- Parameters:
loc
- the array of desired locales, in descending order of priority- Returns:
- the most appropriate Bundle for the given locale list
-
getBundle
Retrieves the best Bundle associated to a given Locale.- Parameters:
loc
- the requested locale- Returns:
- the most appropriate Bundle for the given locale
-
getBundle
Retrieves the Bundle associated to default locale.- Returns:
- the most appropriate Bundle for the default locale
-
getObject
- Parameters:
name
- the key name- Returns:
- resource Object for name, for the default locale
- Throws:
MissingResourceException
- if no object for the given name can be found.
-
getString
- Parameters:
name
- the key name- Returns:
- resource String for name, for the default locale
- Throws:
MissingResourceException
- if no string for the given name can be found.
-
getObject
- Parameters:
name
- the key nameloc
- the requested locale- Returns:
- resource Object for name, for the given locale
- Throws:
MissingResourceException
- if no object for the given name can be found.
-
getString
- Parameters:
name
- the key nameloc
- the requested locale- Returns:
- resource String for name, for the requested locale
- Throws:
MissingResourceException
- if no string for the given name can be found.
-