Package org.jorigin.lang
Class LangResourceBundle
- java.lang.Object
-
- java.util.ResourceBundle
-
- org.jorigin.lang.LangResourceBundle
-
public class LangResourceBundle extends java.util.ResourceBundleThis 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
- Author:
- Julien Seinturier - (c) 2009 - JOrigin project - http:/www.jorigin.org
-
-
Constructor Summary
Constructors Constructor Description LangResourceBundle()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsKey(java.lang.String key)static java.util.ArrayList<java.lang.String>getAvailableLocales()Get the available locales.static java.util.ResourceBundlegetBundle(java.lang.String baseName, java.util.Locale targetLocale, java.lang.ClassLoader loader, java.util.ResourceBundle.Control control)static java.util.ResourceBundlegetBundle(java.util.Locale targetLocale)Get theresource bundleattached to the givenlocale.java.util.Enumeration<java.lang.String>getKeys()java.util.LocalegetLocale()static java.lang.ObjectgetResource(java.lang.String key, java.lang.String param)Get a resource associated to a key.static java.lang.ObjectgetResource(java.lang.String key, java.lang.String[] params)Get a parametrized resource associated to a key.static java.lang.StringgetResourcePath()Set the root path of the resource language files.static java.util.HashMap<java.lang.String,java.lang.String>getResources()Get the map containing the lang resources.static java.lang.StringgetString(java.lang.String key, java.lang.String[] aParams)Get a parametric resource into a String form.static java.lang.StringgetStringCap(java.lang.String key)Get a resource into a String form.static java.lang.StringgetStringS(java.lang.String key)Get a resource into a String form.protected java.lang.ObjecthandleGetObject(java.lang.String key)protected java.util.Set<java.lang.String>handleKeySet()java.util.Set<java.lang.String>keySet()static voidsetLocale(java.util.Locale locale)Set the locale of the lang resource.protected voidsetParent(java.util.ResourceBundle parent)static voidsetResourcePath(java.lang.String path)Set the root path of the resource language files.
-
-
-
Method Detail
-
getBundle
public static java.util.ResourceBundle getBundle(java.util.Locale targetLocale)
Get theresource bundleattached to the givenlocale.- Parameters:
targetLocale- thelocaleto use.- Returns:
- the
resource bundleattached to the givenlocale.
-
getBundle
public static java.util.ResourceBundle getBundle(java.lang.String baseName, java.util.Locale targetLocale, java.lang.ClassLoader loader, java.util.ResourceBundle.Control control)
-
containsKey
public boolean containsKey(java.lang.String key)
- Overrides:
containsKeyin classjava.util.ResourceBundle
-
getKeys
public java.util.Enumeration<java.lang.String> getKeys()
- Specified by:
getKeysin classjava.util.ResourceBundle
-
getLocale
public java.util.Locale getLocale()
- Overrides:
getLocalein classjava.util.ResourceBundle
-
handleGetObject
protected java.lang.Object handleGetObject(java.lang.String key)
- Specified by:
handleGetObjectin classjava.util.ResourceBundle
-
handleKeySet
protected java.util.Set<java.lang.String> handleKeySet()
- Overrides:
handleKeySetin classjava.util.ResourceBundle
-
keySet
public java.util.Set<java.lang.String> keySet()
- Overrides:
keySetin classjava.util.ResourceBundle
-
setParent
protected void setParent(java.util.ResourceBundle parent)
- Overrides:
setParentin classjava.util.ResourceBundle
-
setLocale
public static void setLocale(java.util.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(java.lang.String path)
Set the root path of the resource language files.- Parameters:
path- the path of the resource language files root.
-
getResourcePath
public static java.lang.String getResourcePath()
Set the root path of the resource language files.- Returns:
- the path of the resource language files root.
-
getResources
public static java.util.HashMap<java.lang.String,java.lang.String> getResources()
Get the map containing the lang resources.- Returns:
- a hash map containing the lang resource.
-
getAvailableLocales
public static java.util.ArrayList<java.lang.String> getAvailableLocales()
Get the available locales.- Returns:
- a list of available locales.
-
getResource
public static java.lang.Object getResource(java.lang.String key, java.lang.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 java.lang.Object getResource(java.lang.String key, java.lang.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 java.lang.String getStringS(java.lang.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 java.lang.String getStringCap(java.lang.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 java.lang.String getString(java.lang.String key, java.lang.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.
-
-