Class LangResourceBundle

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 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)
  • Constructor Details

    • LangResourceBundle

      public LangResourceBundle()
  • Method Details

    • getBundle

      public static ResourceBundle getBundle(Locale targetLocale)
      Get the resource bundle attached to the given locale.
      Parameters:
      targetLocale - the locale to use.
      Returns:
      the resource bundle attached to the given locale.
    • getBundle

      public static ResourceBundle getBundle(String baseName, Locale targetLocale, ClassLoader loader, ResourceBundle.Control control)
      Get the resource bundle attached to the given parameters.
      Parameters:
      baseName - the base name
      targetLocale - the target locale
      loader - the class loader to use
      control - the control to use
      Returns:
      the resource bundle
    • containsKey

      public boolean containsKey(String key)
      Overrides:
      containsKey in class ResourceBundle
    • getKeys

      public Enumeration<String> getKeys()
      Specified by:
      getKeys in class ResourceBundle
    • getLocale

      public Locale getLocale()
      Overrides:
      getLocale in class ResourceBundle
    • handleGetObject

      protected Object handleGetObject(String key)
      Specified by:
      handleGetObject in class ResourceBundle
    • handleKeySet

      protected Set<String> handleKeySet()
      Overrides:
      handleKeySet in class ResourceBundle
    • keySet

      public Set<String> keySet()
      Overrides:
      keySet in class ResourceBundle
    • setParent

      protected void setParent(ResourceBundle parent)
      Overrides:
      setParent in class ResourceBundle
    • 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 return
      param - 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 return
      params - 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 of getResource(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 the getString(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 of getResource(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.