Class LangResourceBundle


  • public class LangResourceBundle
    extends java.util.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.9" - b201903071030L
    Author:
    Julien Seinturier - COMEX S.A. - contact@jorigin.org - https://github.com/jorigin/jeometry
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.ResourceBundle

        java.util.ResourceBundle.Control
    • Field Summary

      • Fields inherited from class java.util.ResourceBundle

        parent
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsKey​(java.lang.String key)  
      static java.util.ArrayList<java.lang.String> getAvailableLocales()
      Get the available locales.
      static java.util.ResourceBundle getBundle​(java.lang.String baseName, java.util.Locale targetLocale, java.lang.ClassLoader loader, java.util.ResourceBundle.Control control)  
      static java.util.ResourceBundle getBundle​(java.util.Locale targetLocale)
      Get the resource bundle attached to the given locale.
      java.util.Enumeration<java.lang.String> getKeys()  
      java.util.Locale getLocale()  
      static java.lang.Object getResource​(java.lang.String key, java.lang.String param)
      Get a resource associated to a key.
      static java.lang.Object getResource​(java.lang.String key, java.lang.String[] params)
      Get a parametrized resource associated to a key.
      static java.lang.String getResourcePath()
      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.String getString​(java.lang.String key, java.lang.String[] aParams)
      Get a parametric resource into a String form.
      static java.lang.String getStringCap​(java.lang.String key)
      Get a resource into a String form.
      static java.lang.String getStringS​(java.lang.String key)
      Get a resource into a String form.
      protected java.lang.Object handleGetObject​(java.lang.String key)  
      protected java.util.Set<java.lang.String> handleKeySet()  
      java.util.Set<java.lang.String> keySet()  
      static void setLocale​(java.util.Locale locale)
      Set the locale of the lang resource.
      protected void setParent​(java.util.ResourceBundle parent)  
      static void setResourcePath​(java.lang.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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LangResourceBundle

        public LangResourceBundle()
    • Method Detail

      • getBundle

        public static java.util.ResourceBundle getBundle​(java.util.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 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:
        containsKey in class java.util.ResourceBundle
      • getKeys

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

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

        protected java.lang.Object handleGetObject​(java.lang.String key)
        Specified by:
        handleGetObject in class java.util.ResourceBundle
      • handleKeySet

        protected java.util.Set<java.lang.String> handleKeySet()
        Overrides:
        handleKeySet in class java.util.ResourceBundle
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Overrides:
        keySet in class java.util.ResourceBundle
      • setParent

        protected void setParent​(java.util.ResourceBundle parent)
        Overrides:
        setParent in class java.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 return
        param - 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 return
        params - 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 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 java.lang.String getStringCap​(java.lang.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 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 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.