public class VariableString
extends java.lang.Object
Invocation of the toString() method will resolve the embedded
variables using the Java system properties.
By using the toString(Map) method you can specify which
dictionary to use.
In both cases, the following holds: If a non-existing (or null-value)
variable is encountered, it will either a) be resolved to the empty string,
or b) an exception will be thrown. This depends on the boolean flag lenient.
Note:
Relationship between PreparedString
and VariableString:
PreparedString uses positional
parameters to replace placeholders with the elements of a string array.
VariableString uses named
parameters to replace placeholders with values from a map.
| Modifier and Type | Class and Description |
|---|---|
static interface |
VariableString.IResolver |
static class |
VariableString.UnresolvableException |
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
lenient |
protected java.lang.String |
source |
| Constructor and Description |
|---|
VariableString(java.lang.String source)
Constructs an instance with the given source, and a lenient way
of dealing with unresolvable variables.
|
VariableString(java.lang.String source,
boolean lenient)
Constructs an instance with the given source.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getSource()
Returns the non-resolved (source) version of this instance.
|
protected java.lang.String |
resolveVariables(VariableString.IResolver res,
java.lang.String value)
Performs the replacement of embedded variable names, recursively.
|
java.lang.String |
toString()
Returns a resolved version of this instance,
resolving is done using the Java system properties.
|
java.lang.String |
toString(java.util.Map<?,java.lang.Object> map)
Returns a resolved version of this instance,
resolving is done using the specified map.
|
java.lang.String |
toString(VariableString.IResolver map)
Returns a resolved version of this instance,
resolving is done using the specified IResolver.
|
public VariableString(java.lang.String source)
source - string, e.g. "${user.home}/config/${policydir}".public VariableString(java.lang.String source,
boolean lenient)
source - string, e.g. "${user.home}/config/${policydir}".lenient - whether unresolvable variables will provoke an exceptionpublic java.lang.String getSource()
public java.lang.String toString()
throws VariableString.UnresolvableException
toString in class java.lang.ObjectVariableString.UnresolvableException - if variables cannot be resolved and we are non-lenientpublic java.lang.String toString(java.util.Map<?,java.lang.Object> map)
throws VariableString.UnresolvableException
VariableString.UnresolvableException - if variables cannot be resolved and we are non-lenientpublic java.lang.String toString(VariableString.IResolver map) throws VariableString.UnresolvableException
VariableString.UnresolvableException - if variables cannot be resolved and we are non-lenientprotected java.lang.String resolveVariables(VariableString.IResolver res, java.lang.String value) throws VariableString.UnresolvableException
lenient.