Package com.jalios.util
Class LangProperties
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<K,V>
-
- com.jalios.util.JProperties
-
- com.jalios.util.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 Summary
Fields Modifier and Type Field Description protected java.lang.String
defaultLangPrefix
protected java.lang.String
ENCRYPTED_EXTENSION
protected java.util.List<java.lang.String>
localizedLangList
static java.lang.String
REVISION
-
Fields inherited from class com.jalios.util.JProperties
listenerSet, PREFIX_PROPERTIES_CACHE_MAX_ENTRIES, prefixPropertiesCache, propertyNameAsDefaultValue, SENSITIVE_KEYWORD
-
-
Constructor Summary
Constructors Constructor Description LangProperties()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProtectedKeys(java.util.Collection<java.lang.String> col)
void
clear()
java.lang.String
format(java.lang.String format, java.lang.Object[] objects)
This is a temporary implementation waiting for a more powerful Format.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.java.lang.String
getExplicitLangProperty(LangProperty prop, java.lang.String language)
Resolve the given property name using the given language.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.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.java.lang.String
getLangProperty(java.lang.String name, java.lang.Object... formArgs)
Resolve the given property name using the default language prefix.java.lang.String[]
getLangStringArrayProperty(java.lang.String name, java.lang.String[] defaultValue)
JProperties
getProperties(java.lang.String prefix)
Returns a new property set of properties with key matching a given prefix.java.util.Set<java.lang.String>
getProtectedKeySet()
java.lang.Exception
popLastFormatException()
Retrieve and clear the last Exception which occured while trying to formatting.V
put(K key, V value)
V
remove(java.lang.Object key)
void
setDefaultLangPrefix(java.lang.String langPrefix)
Define the default lang prefix to use when looking for a language property.void
setLocalizedLanguageList(java.util.List<java.lang.String> langList)
Set a list of languages in which this properties are localized.-
Methods inherited from class com.jalios.util.JProperties
addProperties, addProperties, addPropertiesListener, buildArrayFromString, checkCacheGetProperties, clearProperties, containsProperty, firePropertiesChange, getBooleanProperty, getDoubleProperty, getFloatProperty, getIntArrayProperty, getIntegerProperty, getListenerSet, getLoadedFiles, getLongProperty, getProperty, getProperty, getStringArrayProperty, getSubProperties, invalidateCacheGetProperties, isSensitiveProperty, load, load, load, load, parse, putCacheGetProperties, removePropertiesListener, setListenerSet, setProperty, toString, updateAndSave
-
Methods inherited from class java.util.Hashtable
clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, putAll, putIfAbsent, rehash, remove, replace, replace, replaceAll, size, values
-
-
-
-
Field Detail
-
REVISION
public static final java.lang.String REVISION
- See Also:
- Constant Field Values
-
defaultLangPrefix
protected java.lang.String defaultLangPrefix
-
localizedLangList
protected java.util.List<java.lang.String> localizedLangList
-
ENCRYPTED_EXTENSION
protected java.lang.String ENCRYPTED_EXTENSION
-
-
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 resolveformArgs
- 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
- theLangProperty
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 resolvelanguage
- 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 resolvelanguage
- 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 classJProperties
- 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 replacedobjects
- 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 replacedobjects
- 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 interfacejava.util.Map<K,V>
- Overrides:
put
in classjava.util.Hashtable<K,V>
-
remove
public V remove(java.lang.Object key)
- Specified by:
remove
in interfacejava.util.Map<K,V>
- Overrides:
remove
in classjava.util.Hashtable<K,V>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Map<K,V>
- Overrides:
clear
in classjava.util.Hashtable<K,V>
-
getProtectedKeySet
public java.util.Set<java.lang.String> getProtectedKeySet()
-
addProtectedKeys
public void addProtectedKeys(java.util.Collection<java.lang.String> col)
-
-