Class PropertyPlaceholder
- java.lang.Object
-
- cn.sliew.milky.common.parse.placeholder.PropertyPlaceholder
-
public class PropertyPlaceholder extends Object
Utility class for working with Strings that have placeholder values in them. A placeholder takes the form${name}. UsingPropertyPlaceholderthese placeholders can be substituted for user-supplied values. Values for substitution can be supplied using aPropertiesinstance or using aPropertyPlaceholder.PlaceholderResolver.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfacePropertyPlaceholder.PlaceholderResolverStrategy interface used to resolve replacement values for placeholders contained in Strings.
-
Constructor Summary
Constructors Constructor Description PropertyPlaceholder(Logger log, String placeholderPrefix, String placeholderSuffix)Creates a newPropertyPlaceholderHelperthat uses the supplied prefix and suffix.PropertyPlaceholder(Logger log, String placeholderPrefix, String placeholderSuffix, String valueSeparator, boolean ignoreUnresolvablePlaceholders)Creates a newPropertyPlaceholderHelperthat uses the supplied prefix and suffix.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringparseStringValue(String value, PropertyPlaceholder.PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders)StringreplacePlaceholders(String value, PropertyPlaceholder.PlaceholderResolver placeholderResolver)Replaces all placeholders of format${name}with the value returned from the suppliedPropertyPlaceholder.PlaceholderResolver.StringreplacePlaceholders(String value, Properties properties)Replaces all placeholders of format${name}with the corresponding property from the suppliedProperties.
-
-
-
Constructor Detail
-
PropertyPlaceholder
public PropertyPlaceholder(Logger log, String placeholderPrefix, String placeholderSuffix)
Creates a newPropertyPlaceholderHelperthat uses the supplied prefix and suffix. Unresolvable placeholders are ignored.- Parameters:
placeholderPrefix- the prefix that denotes the start of a placeholderplaceholderSuffix- the suffix that denotes the end of a placeholder
-
PropertyPlaceholder
public PropertyPlaceholder(Logger log, String placeholderPrefix, String placeholderSuffix, String valueSeparator, boolean ignoreUnresolvablePlaceholders)
Creates a newPropertyPlaceholderHelperthat uses the supplied prefix and suffix.- Parameters:
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)
-
-
Method Detail
-
replacePlaceholders
public String replacePlaceholders(String value, Properties properties)
Replaces all placeholders of format${name}with the corresponding property from the suppliedProperties.- Parameters:
value- the value containing the placeholders to be replacedproperties- thePropertiesto use for replacement- Returns:
- the supplied value with placeholders replaced inline
-
replacePlaceholders
public String replacePlaceholders(String value, PropertyPlaceholder.PlaceholderResolver placeholderResolver)
Replaces all placeholders of format${name}with the value returned from the suppliedPropertyPlaceholder.PlaceholderResolver.- Parameters:
value- the value containing the placeholders to be replaced.placeholderResolver- thePlaceholderResolverto use for replacement.- Returns:
- the supplied value with placeholders replaced inline.
- Throws:
NullPointerException- if value is null
-
parseStringValue
protected String parseStringValue(String value, PropertyPlaceholder.PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders)
-
-