Top Description Inners Fields Constructors Methods
org.springframework.util

public Class PropertyPlaceholderHelper

extends Object
Class Inheritance
Imports
java.util.HashMap, .HashSet, .Map, .Properties, .Set, org.apache.commons.logging.Log, .LogFactory, org.springframework.lang.Nullable

Utility class for working with Strings that have placeholder values in them. A placeholder takes the form ${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 PlaceholderResolver.

Authors
Juergen Hoeller, Rob Harrop
Since
3.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
PropertyPlaceholderHelper.PlaceholderResolver

Strategy interface used to resolve replacement values for placeholders contained in Strings.

Field Summary

Modifier and TypeField and Description
private final boolean
private static final Log
private final String
private final String
private final String
private final String
private static final Map<String, String>

Constructor Summary

AccessConstructor and Description
public
PropertyPlaceholderHelper(String
the prefix that denotes the start of a placeholder
placeholderPrefix
,
String
the suffix that denotes the end of a placeholder
placeholderSuffix
)

Creates a new PropertyPlaceholderHelper that uses the supplied prefix and suffix.

public
PropertyPlaceholderHelper(String
the prefix that denotes the start of a placeholder
placeholderPrefix
,
String
the suffix that denotes the end of a placeholder
placeholderSuffix
,
String
the separating character between the placeholder variable and the associated default value, if any
valueSeparator
,
boolean
indicates whether unresolvable placeholders should be ignored (true) or cause an exception (false)
ignoreUnresolvablePlaceholders
)

Creates a new PropertyPlaceholderHelper that uses the supplied prefix and suffix.

Method Summary

Modifier and TypeMethod and Description
private int
protected String
parseStringValue(String value, PropertyPlaceholderHelper.PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders)

public String

Returns:

the supplied value with placeholders replaced inline
replacePlaceholders
(String
the value containing the placeholders to be replaced
value
,
final Properties
the Properties to use for replacement
properties
)

Replaces all placeholders of format ${name} with the corresponding property from the supplied Properties.

public String

Returns:

the supplied value with placeholders replaced inline
replacePlaceholders
(String
the value containing the placeholders to be replaced
value
,
PropertyPlaceholderHelper.PlaceholderResolver
the PlaceholderResolver to use for replacement
placeholderResolver
)

Replaces all placeholders of format ${name} with the value returned from the supplied PlaceholderResolver.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ignoreUnresolvablePlaceholdersback to summary
private final boolean ignoreUnresolvablePlaceholders
loggerback to summary
private static final Log logger
placeholderPrefixback to summary
private final String placeholderPrefix
placeholderSuffixback to summary
private final String placeholderSuffix
simplePrefixback to summary
private final String simplePrefix
valueSeparatorback to summary
private final String valueSeparator
Annotations
@Nullable
wellKnownSimplePrefixesback to summary
private static final Map<String, String> wellKnownSimplePrefixes

Constructor Detail

PropertyPlaceholderHelperback to summary
public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix)

Creates a new PropertyPlaceholderHelper that uses the supplied prefix and suffix. Unresolvable placeholders are ignored.

Parameters
placeholderPrefix:String

the prefix that denotes the start of a placeholder

placeholderSuffix:String

the suffix that denotes the end of a placeholder

PropertyPlaceholderHelperback to summary
public PropertyPlaceholderHelper(String placeholderPrefix, String placeholderSuffix, String valueSeparator, boolean ignoreUnresolvablePlaceholders)

Creates a new PropertyPlaceholderHelper that uses the supplied prefix and suffix.

Parameters
placeholderPrefix:String

the prefix that denotes the start of a placeholder

placeholderSuffix:String

the suffix that denotes the end of a placeholder

valueSeparator:String

the separating character between the placeholder variable and the associated default value, if any

ignoreUnresolvablePlaceholders:boolean

indicates whether unresolvable placeholders should be ignored (true) or cause an exception (false)

Method Detail

findPlaceholderEndIndexback to summary
private int findPlaceholderEndIndex(CharSequence buf, int startIndex)
parseStringValueback to summary
protected String parseStringValue(String value, PropertyPlaceholderHelper.PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders)
replacePlaceholdersback to summary
public String replacePlaceholders(String value, final Properties properties)

Replaces all placeholders of format ${name} with the corresponding property from the supplied Properties.

Parameters
value:String

the value containing the placeholders to be replaced

properties:Properties

the Properties to use for replacement

Returns:String

the supplied value with placeholders replaced inline

replacePlaceholdersback to summary
public String replacePlaceholders(String value, PropertyPlaceholderHelper.PlaceholderResolver placeholderResolver)

Replaces all placeholders of format ${name} with the value returned from the supplied PlaceholderResolver.

Parameters
value:String

the value containing the placeholders to be replaced

placeholderResolver:PropertyPlaceholderHelper.PlaceholderResolver

the PlaceholderResolver to use for replacement

Returns:String

the supplied value with placeholders replaced inline

org.springframework.util back to summary

public Interface PropertyPlaceholderHelper.PlaceholderResolver

Known Direct Implementers
org.springframework.util.SystemPropertyUtils.SystemPropertyPlaceholderResolver
Annotations
@FunctionalInterface

Strategy interface used to resolve replacement values for placeholders contained in Strings.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the replacement value, or null if no replacement is to be made
resolvePlaceholder
(String
the name of the placeholder to resolve
placeholderName
)

Resolve the supplied placeholder name to the replacement value.

Method Detail

resolvePlaceholderback to summary
public String resolvePlaceholder(String placeholderName)

Resolve the supplied placeholder name to the replacement value.

Parameters
placeholderName:String

the name of the placeholder to resolve

Returns:String

the replacement value, or null if no replacement is to be made

Annotations
@Nullable