- All Implemented Interfaces:
Serializable
,Cloneable
,Map<Object,
Object>
With this variant of Properties, you can do things like the following:
name=myname path=/path/to/${name}
- See Also:
-
Field Summary
Fields inherited from class java.util.Properties
defaults
-
Constructor Summary
ConstructorDescriptionCreates an empty environ list with no default values.EnvironProperties
(Properties defaults) Creates an empty environ list with the specified defaults. -
Method Summary
Modifier and TypeMethodDescriptiongetProperty
(String key) Gets a property attempting environment-variable style substitution.Searches for the property with the specified key in this property list.Attempts to parse the contents of a line and perform a variable substitution when an environ-style entry (${property-key}
) is found.protected String
Attempts to parse the contents of a line and perform a variable substitution when an environ-style entry (${property-key}
) is found.void
setKeyPrefix
(String prefix) Set a key prefix to be prepended to all keys used.void
setParse
(boolean doparsing) Turns on/off parsing when calling getProperty method.void
setRecursionLevel
(int max) Sets the maximum recursion level in case there is a loop in property evaluations (for examplea=${b}, b=${a}
).Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, getProperty, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, put, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Constructor Details
-
EnvironProperties
public EnvironProperties()Creates an empty environ list with no default values. -
EnvironProperties
Creates an empty environ list with the specified defaults.- Parameters:
defaults
- the defaults.
-
-
Method Details
-
setRecursionLevel
public void setRecursionLevel(int max) Sets the maximum recursion level in case there is a loop in property evaluations (for examplea=${b}, b=${a}
).The default value will work for most cases.
- Parameters:
max
- the maximum recursion level.
-
parse
Attempts to parse the contents of a line and perform a variable substitution when an environ-style entry (${property-key}
) is found.Any occurrence of
${property-key}
is replaced by the value of that property key.In order to avoid possible infinite loops, while property evaluation is recursive, loops are limited to what is set by
setRecursionLevel
. Default value should be appropriate for most uses.- Parameters:
line
- the line to be parsed.- Returns:
- the line after the variable substitution(s).
- Throws:
ParsingException
- if a syntax error is found.
-
parse
Attempts to parse the contents of a line and perform a variable substitution when an environ-style entry (${property-key}
) is found.Any occurrence of
${property-key}
is replaced by the value of that property key.In order to avoid possible infinite loops, while property evaluation is recursive, loops are limited to what is set by
setRecursionLevel
. Default value should be appropriate for most uses.- Parameters:
line
- the line to be parsed.indirection_level
- the current recursion level.- Returns:
- the line after the variable substitution(s).
- Throws:
ParsingException
- if a syntax error is found.
-
setParse
public void setParse(boolean doparsing) Turns on/off parsing when calling getProperty method. By default, does parsing.- Parameters:
doparsing
- true to activate parsing, false to deactivate.
-
getProperty
Gets a property attempting environment-variable style substitution. Any occurrence of${property-key}
in thekey
property value is, in turn, replaced by the value of that property-key.If a parsing error occurs, returns the unparsed value.
Property evaluation is recursive.
- Overrides:
getProperty
in classProperties
- Parameters:
key
- the property key.- Returns:
- the value in this property list with the specified key value, attempting a variable substitution.
-
getUnparsedProperty
Searches for the property with the specified key in this property list.Does not attempt to do any variable substitution.
- Parameters:
key
- the property key.- Returns:
- the value in this property list with the specified key value.
-
setKeyPrefix
Set a key prefix to be prepended to all keys used.For example, if a "myapp" prefix is set, and the property file looks like:
myapp.key1=value1 myapp.key2=value2 myapp.otherkey=othervalue
Then getting, for example, the "key1" property will return "value1".This is useful when you want to keep several property sets in a single file.
- Parameters:
prefix
- the prefix to be prepended (together with a dot). If null, no prefix will be used.
-