public class PropertyPlaceholderHelper
extends java.lang.Object
${name}
. Using PropertyPlaceholderHelper
these placeholders can be substituted for
user-supplied values. Values for substitution can be supplied using a Properties
instance or
using a PropertyPlaceholderHelper.PlaceholderResolver
.
Modifier and Type | Class and Description |
---|---|
static interface |
PropertyPlaceholderHelper.PlaceholderResolver
Strategy interface used to resolve replacement values for placeholders contained in Strings.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
ignoreUnresolvablePlaceholders |
private static Log |
logger |
private java.lang.String |
placeholderPrefix |
private java.lang.String |
placeholderSuffix |
private java.lang.String |
simplePrefix |
private java.lang.String |
valueSeparator |
private static java.util.Map<java.lang.String,java.lang.String> |
wellKnownSimplePrefixes |
Constructor and Description |
---|
PropertyPlaceholderHelper(java.lang.String placeholderPrefix,
java.lang.String placeholderSuffix)
Creates a new
PropertyPlaceholderHelper that uses the supplied prefix and suffix. |
PropertyPlaceholderHelper(java.lang.String placeholderPrefix,
java.lang.String placeholderSuffix,
java.lang.String valueSeparator,
boolean ignoreUnresolvablePlaceholders)
Creates a new
PropertyPlaceholderHelper that uses the supplied prefix and suffix. |
Modifier and Type | Method and Description |
---|---|
private int |
findPlaceholderEndIndex(java.lang.CharSequence buf,
int startIndex) |
protected java.lang.String |
parseStringValue(java.lang.String strVal,
PropertyPlaceholderHelper.PlaceholderResolver placeholderResolver,
java.util.Set<java.lang.String> visitedPlaceholders) |
java.lang.String |
replacePlaceholders(java.lang.String value,
java.util.Properties properties)
Replaces all placeholders of format
${name} with the corresponding property
from the supplied Properties . |
java.lang.String |
replacePlaceholders(java.lang.String value,
PropertyPlaceholderHelper.PlaceholderResolver placeholderResolver)
Replaces all placeholders of format
${name} with the value returned from the supplied
PropertyPlaceholderHelper.PlaceholderResolver . |
private static final Log logger
private static final java.util.Map<java.lang.String,java.lang.String> wellKnownSimplePrefixes
private final java.lang.String placeholderPrefix
private final java.lang.String placeholderSuffix
private final java.lang.String simplePrefix
private final java.lang.String valueSeparator
private final boolean ignoreUnresolvablePlaceholders
public PropertyPlaceholderHelper(java.lang.String placeholderPrefix, java.lang.String placeholderSuffix)
PropertyPlaceholderHelper
that uses the supplied prefix and suffix.
Unresolvable placeholders are ignored.placeholderPrefix
- the prefix that denotes the start of a placeholder.placeholderSuffix
- the suffix that denotes the end of a placeholder.public PropertyPlaceholderHelper(java.lang.String placeholderPrefix, java.lang.String placeholderSuffix, java.lang.String valueSeparator, boolean ignoreUnresolvablePlaceholders)
PropertyPlaceholderHelper
that uses the supplied prefix and suffix.placeholderPrefix
- the prefix that denotes the start of a placeholderplaceholderSuffix
- the suffix that denotes the end of a placeholdervalueSeparator
- the separating character between the placeholder variable
and the associated default value, if anyignoreUnresolvablePlaceholders
- indicates whether unresolvable placeholders should be ignored
(true
) or cause an exception (false
).public java.lang.String replacePlaceholders(java.lang.String value, java.util.Properties properties)
${name}
with the corresponding property
from the supplied Properties
.value
- the value containing the placeholders to be replaced.properties
- the Properties
to use for replacement.public java.lang.String replacePlaceholders(java.lang.String value, PropertyPlaceholderHelper.PlaceholderResolver placeholderResolver)
${name}
with the value returned from the supplied
PropertyPlaceholderHelper.PlaceholderResolver
.value
- the value containing the placeholders to be replaced.placeholderResolver
- the PlaceholderResolver
to use for replacement.protected java.lang.String parseStringValue(java.lang.String strVal, PropertyPlaceholderHelper.PlaceholderResolver placeholderResolver, java.util.Set<java.lang.String> visitedPlaceholders)
private int findPlaceholderEndIndex(java.lang.CharSequence buf, int startIndex)