- java.lang.Object
-
- java.util.ResourceBundle
-
- org.jorigin.lang.LangResourceBundle
-
public class LangResourceBundle extends ResourceBundle
This class represent a bundle of XML based language resources. The XML based language resource bundle behavior is most the same that the classicResourceBundle.- 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 Constructor Description LangResourceBundle()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsKey(String key)static ArrayList<String>getAvailableLocales()Get the available locales.static ResourceBundlegetBundle(String baseName, Locale targetLocale, ClassLoader loader, ResourceBundle.Control control)Get theresource bundleattached to the given parameters.static ResourceBundlegetBundle(Locale targetLocale)Get theresource bundleattached to the givenlocale.Enumeration<String>getKeys()LocalegetLocale()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 StringgetResourcePath()Set the root path of the resource language files.static HashMap<String,String>getResources()Get the map containing the lang resources.static StringgetString(String key, String[] aParams)Get 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)protected Set<String>handleKeySet()Set<String>keySet()static voidsetLocale(Locale locale)Set 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
-
-
-
-
Method Detail
-
getBundle
public static ResourceBundle getBundle(Locale targetLocale)
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
public boolean containsKey(String key)
- Overrides:
containsKeyin classResourceBundle
-
getKeys
public Enumeration<String> getKeys()
- Specified by:
getKeysin classResourceBundle
-
getLocale
public Locale getLocale()
- Overrides:
getLocalein classResourceBundle
-
handleGetObject
protected Object handleGetObject(String key)
- Specified by:
handleGetObjectin classResourceBundle
-
handleKeySet
protected Set<String> handleKeySet()
- Overrides:
handleKeySetin classResourceBundle
-
keySet
public Set<String> keySet()
- Overrides:
keySetin classResourceBundle
-
setParent
protected void setParent(ResourceBundle parent)
- Overrides:
setParentin classResourceBundle
-
setLocale
public static void setLocale(Locale locale)
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
public static void setResourcePath(String path)
Set the root path of the resource language files.- Parameters:
path- the path of the resource language files root.
-
getResourcePath
public static String getResourcePath()
Set the root path of the resource language files.- Returns:
- the path of the resource language files root.
-
getResources
public static HashMap<String,String> getResources()
Get the map containing the lang resources.- Returns:
- a hash map containing the lang resource.
-
getAvailableLocales
public static ArrayList<String> getAvailableLocales()
Get the available locales.- Returns:
- a list of available locales.
-
getResource
public static Object getResource(String key, String param)
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
public static Object getResource(String key, String[] params)
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
public static String getStringS(String key)
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
public static String getStringCap(String key)
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
public static String getString(String key, String[] aParams)
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.
-
-