java.lang.Object
java.util.ResourceBundle
org.jorigin.lang.LangResourceBundle
This class represent a bundle of XML based language resources. The XML based language resource bundle behavior
is most the same that the classic
ResourceBundle.- Since:
- 1.0.0
- Version:
- "1.0.14" - b202111241200L
- Author:
- Julien SEINTURIER - Université de Toulon / CNRS LIS umr 7020 - github.com/jorigin/jcommon (contact@jorigin.org)
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.ResourceBundle
ResourceBundle.Control -
Field Summary
Fields inherited from class java.util.ResourceBundle
parent -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(String key) Get the available locales.static ResourceBundlegetBundle(String baseName, Locale targetLocale, ClassLoader loader, ResourceBundle.Control control) Get theresource bundleattached to the given parameters.static ResourceBundleGet theresource bundleattached to the givenlocale.getKeys()static ObjectgetResource(String key, String param) Get a resource associated to a key.static ObjectgetResource(String key, String[] params) Get a parametrized resource associated to a key.static StringSet the root path of the resource language files.Get the map containing the lang resources.static StringGet a parametric resource into a String form.static StringgetStringCap(String key) Get a resource into a String form.static StringgetStringS(String key) Get a resource into a String form.protected ObjecthandleGetObject(String key) keySet()static voidSet the locale of the lang resource.protected voidsetParent(ResourceBundle parent) static voidsetResourcePath(String path) Set the root path of the resource language files.Methods inherited from class java.util.ResourceBundle
clearCache, clearCache, getBaseBundleName, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getObject, getString, getStringArray
-
Constructor Details
-
LangResourceBundle
public LangResourceBundle()
-
-
Method Details
-
getBundle
Get theresource bundleattached to the givenlocale.- Parameters:
targetLocale- thelocaleto use.- Returns:
- the
resource bundleattached to the givenlocale.
-
getBundle
public static ResourceBundle getBundle(String baseName, Locale targetLocale, ClassLoader loader, ResourceBundle.Control control) Get theresource bundleattached to the given parameters.- Parameters:
baseName- the base nametargetLocale- the target localeloader- the class loader to usecontrol- the control to use- Returns:
- the resource bundle
-
containsKey
- Overrides:
containsKeyin classResourceBundle
-
getKeys
- Specified by:
getKeysin classResourceBundle
-
getLocale
- Overrides:
getLocalein classResourceBundle
-
handleGetObject
- Specified by:
handleGetObjectin classResourceBundle
-
handleKeySet
- Overrides:
handleKeySetin classResourceBundle
-
keySet
- Overrides:
keySetin classResourceBundle
-
setParent
- Overrides:
setParentin classResourceBundle
-
setLocale
Set the locale of the lang resource. When a locale is set, all lang resource file associated to the locale are loaded from the resource path.- Parameters:
locale- the new locale.
-
setResourcePath
Set the root path of the resource language files.- Parameters:
path- the path of the resource language files root.
-
getResourcePath
Set the root path of the resource language files.- Returns:
- the path of the resource language files root.
-
getResources
Get the map containing the lang resources.- Returns:
- a hash map containing the lang resource.
-
getAvailableLocales
Get the available locales.- Returns:
- a list of available locales.
-
getResource
Get a resource associated to a key. If the key does not correspond to any resource, the key itself is returned. The parameter given is applied to the resource if it accept parameter.- Parameters:
key- the key inditifying the resource to returnparam- the parameter to apply to the resource.- Returns:
- the resource or the key if no resource is available.
-
getResource
Get a parametrized resource associated to a key. If the key does not correspond to any resource, the key itself is returned. Parameters enable to caraterize the resource. Parameter are identified in a resource by a%followed by the parameter number. For example, if the resource is "Hello %1 and %2.", and parameters are"Fox"and"Dana", the object returned is"Hello Fox and Dana."- Parameters:
key- the key inditifying the resource to returnparams- the parameters of the resource.- Returns:
- the resource parametrized or the key if no resource is available.
-
getStringS
Get a resource into a String form. This method is simply a call ofgetResource(key).toString();.- Parameters:
key- the key inditifying the resource to return- Returns:
- the resource or the key if no resource is available.
-
getStringCap
Get a resource into a String form. This method call thegetString(key)and put in upper case the fisrt character of the string.- Parameters:
key- the key identifying the resource.- Returns:
- the resource or the key if no resource is available.
-
getString
Get a parametric resource into a String form. This method is simply a call ofgetResource(key, aParams).toString();on the current bundle.- Parameters:
key- the key referencing the resource.aParams- the parameters to use as replacements in the resource (if any).- Returns:
- the localized string with integrated parameters.
-