Class LangProperties

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,​java.lang.String>

    public class LangProperties
    extends JProperties
    See Also:
    Serialized Form
    • Field Detail

      • defaultLangPrefix

        protected java.lang.String defaultLangPrefix
      • localizedLangList

        protected java.util.List<java.lang.String> localizedLangList
      • ENCRYPTED_EXTENSION

        protected java.lang.String ENCRYPTED_EXTENSION
    • Constructor Detail

      • LangProperties

        public LangProperties()
    • Method Detail

      • setDefaultLangPrefix

        public void setDefaultLangPrefix​(java.lang.String langPrefix)
        Define the default lang prefix to use when looking for a language property.
        Parameters:
        langPrefix - an ISO-639 language code (without any '.')
      • setLocalizedLanguageList

        public void setLocalizedLanguageList​(java.util.List<java.lang.String> langList)
        Set a list of languages in which this properties are localized.

        This list is used as a fallback when a property could not be found in the default language

        Parameters:
        langList - a List of ISO-639 language code.
      • getLangProperty

        public java.lang.String getLangProperty​(java.lang.String name,
                                                java.lang.Object... formArgs)
        Resolve the given property name using the default language prefix.
        Parameters:
        name - the property name to resolve
        formArgs - an array of parameters to use to for the format of property
        Returns:
        the resolved property
      • getExplicitLangProperty

        public java.lang.String getExplicitLangProperty​(LangProperty prop,
                                                        java.lang.String language)
        Resolve the given property name using the given language.
        Parameters:
        prop - the LangProperty instance corresponding to the property you want to resolve.
        language - the ISO-639 code language to use to retrieve this property
        Returns:
        the resolved property
      • getExplicitLangProperty

        public java.lang.String getExplicitLangProperty​(java.lang.String name,
                                                        java.lang.String language,
                                                        java.lang.Object[] formArgs)
        Resolve the given property name using the given language.

        Example :

          String i18nStr = getExplicitLangProperty("ui.com.lbl.byte", "en", 6);
         
        Parameters:
        name - the property name to resolve
        language - the language prefix used before the property name, usually an ISO-639 language code, if null, the default lang prefix is used.
        formArgs - an array of parameters to use to for the format of property
        Returns:
        the resolved property
      • getExplicitLangProperty

        public java.lang.String getExplicitLangProperty​(java.lang.String name,
                                                        java.lang.String language,
                                                        java.util.Map<java.lang.String,​java.lang.String> paramMap)
        Resolve the given property name using the given language.

        Example :

         
          Map<String,String> paramMap = new HashMap<String,String>();
          paramMap.put("firstName", "John");
          paramMap.put("lastName", "Doe");
          String i18nStr = getExplicitLangProperty("my.property", "en", paramMap);
          
         
        with the given property:
         my.property: Hello {firstName} {lastName}
         
        Parameters:
        name - the property name to resolve
        language - the language prefix used before the property name, usually an ISO-639 language code, if null, the default lang prefix is used.
        paramMap - the map of parameters
        Returns:
        the resolved property
      • getLangStringArrayProperty

        public java.lang.String[] getLangStringArrayProperty​(java.lang.String name,
                                                             java.lang.String[] defaultValue)
      • getProperties

        public JProperties getProperties​(java.lang.String prefix)
        Returns a new property set of properties with key matching a given prefix.
        Overrides:
        getProperties in class JProperties
        Parameters:
        prefix - the prefix the properties must match to be added to the return LangProperties instance, if null, all properties are added.
        Returns:
        a new property set of properties with key matching a given prefix.
      • format

        public java.lang.String format​(java.lang.String format,
                                       java.lang.Object[] objects)
        This is a temporary implementation waiting for a more powerful Format.
        The extensions of format compared to MessageFormat are
        - the ability to use context properties {property} - the ability to use more than 10 parameters - '...' is not an escape sequence for the expension
        Parameters:
        format - the string containing the pattern to be replaced
        objects - an array of objects to be formatted and substituted.
        Returns:
        the formated string
      • format

        public java.lang.String format​(java.lang.String format,
                                       java.lang.Object[] objects,
                                       java.lang.String language)
        This is a temporary implementation waiting for a more powerful Format.
        The extensions of format compared to MessageFormat are
        - the ability to use context properties {property} - the ability to use more than 10 parameters - '...' is not an escape sequence for the expension
        Parameters:
        format - the string containing the pattern to be replaced
        objects - an array of objects to be formatted and substituted.
        language - the language in which the string is being renderrd, used for recursive property such as "Hello {some.other.property}! "
        Returns:
        the formated string
      • popLastFormatException

        public java.lang.Exception popLastFormatException()
        Retrieve and clear the last Exception which occured while trying to formatting.

        This method is not thread safe and is only meant to be used for testing purpose

        Returns:
        the last exception catched during a formatting, or null if no exception occured since last pop
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface java.util.Map<K,​V>
        Overrides:
        put in class java.util.Hashtable<K,​V>
      • remove

        public V remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
        Overrides:
        remove in class java.util.Hashtable<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
        Overrides:
        clear in class java.util.Hashtable<K,​V>
      • getProtectedKeySet

        public java.util.Set<java.lang.String> getProtectedKeySet()
      • addProtectedKeys

        public void addProtectedKeys​(java.util.Collection<java.lang.String> col)