Class LangProperties
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,String>
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected StringSuffix identifying a property whose value is encrypted, for exampledb.password.crypt.Fields inherited from class com.jalios.util.JProperties
listenerSet, PREFIX_PROPERTIES_CACHE_MAX_ENTRIES, prefixPropertiesCache, propertyNameAsDefaultValue, SENSITIVE_KEYWORD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddProtectedKeys(Collection<String> col) Registers additional protected property names, for keys that do not follow theENCRYPTED_EXTENSIONconvention.voidclear()clone()computeIfAbsent(String key, Function<? super String, ? extends String> function) computeIfPresent(String key, BiFunction<? super String, ? super String, ? extends String> function) booleanbooleancontainsKey(Object key) booleancontainsValue(Object val) elements()entrySet()booleanvoidforEach(BiConsumer<? super String, ? super String> action) This is a temporary implementation waiting for a more powerful Format.This is a temporary implementation waiting for a more powerful Format.getExplicitLangProperty(LangProperty prop, String language) Resolve the given property name using the given language.getExplicitLangProperty(String name, String language, Object[] formArgs) Resolve the given property name using the given language.Resolve the given property name using the given language.getLangProperty(String name, Object... formArgs) Resolve the given property name using the default language prefix.String[]getLangStringArrayProperty(String name, String[] defaultValue) getOrDefault(Object key, String def) getProperties(String prefix) Returns a new property set of properties with key matching a given prefix.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)).inthashCode()booleanisEmpty()keys()keySet()merge(String key, String value, BiFunction<? super String, ? super String, ? extends String> function) Retrieve and clear the last Exception which occured while trying to formatting.voidputIfAbsent(String key, String value) booleanbooleanvoidreplaceAll(BiFunction<? super String, ? super String, ? extends String> function) voidsetDefaultLangPrefix(String langPrefix) Define the default lang prefix to use when looking for a language property.voidsetLocalizedLanguageList(List<String> langList) Set a list of languages in which this properties are localized.intsize()values()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
-
Field Details
-
defaultLangPrefix
-
localizedLangList
-
ENCRYPTED_EXTENSION
Suffix identifying a property whose value is encrypted, for exampledb.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
-
-
Method Details
-
setDefaultLangPrefix
Define the default lang prefix to use when looking for a language property.- Parameters:
langPrefix- an ISO-639 language code (without any '.')
-
setLocalizedLanguageList
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
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
Resolve the given property name using the given language.- Parameters:
prop- theLangPropertyinstance 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
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
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
-
getProperties
Returns a new property set of properties with key matching a given prefix.- Overrides:
getPropertiesin 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
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
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
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
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_EXTENSIONis written (put, putAll, putIfAbsent, compute, computeIfAbsent, merge), the key without its last dot-separated part is added (db.password.cryptregistersdb.password). Keys can also be added explicitly withaddProtectedKeys(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
Registers additional protected property names, for keys that do not follow theENCRYPTED_EXTENSIONconvention. The names are added as is (no suffix is removed) to the set returned bygetProtectedKeySet().- Parameters:
col- the property names to protect; ignored if null- See Also:
-
size
public int size() -
isEmpty
public boolean isEmpty() -
get
-
getOrDefault
- Specified by:
getOrDefaultin interfaceMap<K,V> - Overrides:
getOrDefaultin classHashtable<K,V>
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classHashtable<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classHashtable<K,V>
-
contains
-
keys
-
elements
-
forEach
-
keySet
-
values
-
entrySet
-
put
-
remove
-
clear
public void clear() -
putAll
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceMap<K,V> - Overrides:
putIfAbsentin classHashtable<K,V>
-
remove
-
replace
-
replace
-
replaceAll
- Specified by:
replaceAllin interfaceMap<K,V> - Overrides:
replaceAllin classHashtable<K,V>
-
computeIfAbsent
- Specified by:
computeIfAbsentin interfaceMap<K,V> - Overrides:
computeIfAbsentin classHashtable<K,V>
-
computeIfPresent
public String computeIfPresent(String key, BiFunction<? super String, ? super String, ? extends String> function) - Specified by:
computeIfPresentin interfaceMap<K,V> - Overrides:
computeIfPresentin classHashtable<K,V>
-
compute
-
merge
-
equals
-
hashCode
public int hashCode() -
clone
-