Class LangProperties

All Implemented Interfaces:
Serializable, Cloneable, Map<String,String>

public class LangProperties extends JProperties
See Also:
  • Field Details

    • defaultLangPrefix

      protected String defaultLangPrefix
    • localizedLangList

      protected List<String> localizedLangList
    • ENCRYPTED_EXTENSION

      protected String ENCRYPTED_EXTENSION
      Suffix identifying a property whose value is encrypted, for example db.password.crypt. When such a key is written, its name without the suffix (db.password) is registered as a protected key. Subclasses may change it.
      See Also:
  • Constructor Details

    • LangProperties

      public LangProperties()
    • LangProperties

      protected LangProperties(JProperties jProperties)
  • Method Details

    • setDefaultLangPrefix

      public void setDefaultLangPrefix(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(List<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 String getLangProperty(String name, 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 String getExplicitLangProperty(LangProperty prop, 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 String getExplicitLangProperty(String name, String language, 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 String getExplicitLangProperty(String name, String language, Map<String,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 String[] getLangStringArrayProperty(String name, String[] defaultValue)
    • getProperties

      public JProperties getProperties(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 String format(String format, 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 String format(String format, Object[] objects, 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 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
    • getProtectedKeySet

      public Set<String> getProtectedKeySet()
      Returns the names of the protected properties, that is properties holding sensitive data whose value must be concealed when displayed or saved (see JProperties.isSensitiveProperty(String)).

      The set is filled automatically: each time a key ending with ENCRYPTED_EXTENSION is written (put, putAll, putIfAbsent, compute, computeIfAbsent, merge), the key without its last dot-separated part is added (db.password.crypt registers db.password). Keys can also be added explicitly with addProtectedKeys(Collection). Removing a property does not remove its protected key.

      The returned set is live and modifiable: changes made to it apply to this instance. It is thread-safe and can be iterated while other threads write, without ConcurrentModificationException. A clone() shares this set with the original (shallow copy).

      Returns:
      the set of protected property names, never null
      See Also:
    • addProtectedKeys

      public void addProtectedKeys(Collection<String> col)
      Registers additional protected property names, for keys that do not follow the ENCRYPTED_EXTENSION convention. The names are added as is (no suffix is removed) to the set returned by getProtectedKeySet().
      Parameters:
      col - the property names to protect; ignored if null
      See Also:
    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
      Overrides:
      size in class Hashtable<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
      Overrides:
      isEmpty in class Hashtable<K,V>
    • get

      public String get(Object key)
      Specified by:
      get in interface Map<K,V>
      Overrides:
      get in class Hashtable<K,V>
    • getOrDefault

      public String getOrDefault(Object key, String def)
      Specified by:
      getOrDefault in interface Map<K,V>
      Overrides:
      getOrDefault in class Hashtable<K,V>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
      Overrides:
      containsKey in class Hashtable<K,V>
    • containsValue

      public boolean containsValue(Object val)
      Specified by:
      containsValue in interface Map<K,V>
      Overrides:
      containsValue in class Hashtable<K,V>
    • contains

      public boolean contains(Object val)
      Overrides:
      contains in class Hashtable<K,V>
    • keys

      public Enumeration<String> keys()
      Overrides:
      keys in class Hashtable<K,V>
    • elements

      public Enumeration<String> elements()
      Overrides:
      elements in class Hashtable<K,V>
    • forEach

      public void forEach(BiConsumer<? super String,? super String> action)
      Specified by:
      forEach in interface Map<K,V>
      Overrides:
      forEach in class Hashtable<K,V>
    • keySet

      public Set<String> keySet()
      Specified by:
      keySet in interface Map<K,V>
      Overrides:
      keySet in class Hashtable<K,V>
    • values

      public Collection<String> values()
      Specified by:
      values in interface Map<K,V>
      Overrides:
      values in class Hashtable<K,V>
    • entrySet

      public Set<Map.Entry<String,String>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
      Overrides:
      entrySet in class Hashtable<K,V>
    • put

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

      public String remove(Object key)
      Specified by:
      remove in interface Map<K,V>
      Overrides:
      remove in class Hashtable<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
      Overrides:
      clear in class Hashtable<K,V>
    • putAll

      public void putAll(Map<? extends String,? extends String> m)
      Specified by:
      putAll in interface Map<K,V>
      Overrides:
      putAll in class Hashtable<K,V>
    • putIfAbsent

      public String putIfAbsent(String key, String value)
      Specified by:
      putIfAbsent in interface Map<K,V>
      Overrides:
      putIfAbsent in class Hashtable<K,V>
    • remove

      public boolean remove(Object key, Object value)
      Specified by:
      remove in interface Map<K,V>
      Overrides:
      remove in class Hashtable<K,V>
    • replace

      public boolean replace(String key, String oldValue, String newValue)
      Specified by:
      replace in interface Map<K,V>
      Overrides:
      replace in class Hashtable<K,V>
    • replace

      public String replace(String key, String value)
      Specified by:
      replace in interface Map<K,V>
      Overrides:
      replace in class Hashtable<K,V>
    • replaceAll

      public void replaceAll(BiFunction<? super String,? super String,? extends String> function)
      Specified by:
      replaceAll in interface Map<K,V>
      Overrides:
      replaceAll in class Hashtable<K,V>
    • computeIfAbsent

      public String computeIfAbsent(String key, Function<? super String,? extends String> function)
      Specified by:
      computeIfAbsent in interface Map<K,V>
      Overrides:
      computeIfAbsent in class Hashtable<K,V>
    • computeIfPresent

      public String computeIfPresent(String key, BiFunction<? super String,? super String,? extends String> function)
      Specified by:
      computeIfPresent in interface Map<K,V>
      Overrides:
      computeIfPresent in class Hashtable<K,V>
    • compute

      public String compute(String key, BiFunction<? super String,? super String,? extends String> function)
      Specified by:
      compute in interface Map<K,V>
      Overrides:
      compute in class Hashtable<K,V>
    • merge

      public String merge(String key, String value, BiFunction<? super String,? super String,? extends String> function)
      Specified by:
      merge in interface Map<K,V>
      Overrides:
      merge in class Hashtable<K,V>
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map<K,V>
      Overrides:
      equals in class Hashtable<K,V>
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<K,V>
      Overrides:
      hashCode in class Hashtable<K,V>
    • clone

      public Object clone()
      Overrides:
      clone in class Hashtable<K,V>