Spring Framework

org.springframework.util
Class PropertyPlaceholderHelper

java.lang.Object
  extended by org.springframework.util.PropertyPlaceholderHelper

public class PropertyPlaceholderHelper
extends java.lang.Object

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 PropertyPlaceholderHelper.PlaceholderResolver.

Since:
3.0
Author:
Juergen Hoeller, Rob Harrop

Nested Class Summary
static interface PropertyPlaceholderHelper.PlaceholderResolver
          Strategy interface used to resolve replacement values for placeholders contained in Strings.
 
Constructor Summary
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.
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyPlaceholderHelper

public PropertyPlaceholderHelper(java.lang.String placeholderPrefix,
                                 java.lang.String placeholderSuffix)
Creates a new PropertyPlaceholderHelper that uses the supplied prefix and suffix. Unresolvable placeholders are ignored.

Parameters:
placeholderPrefix - the prefix that denotes the start of a placeholder.
placeholderSuffix - the suffix that denotes the end of a placeholder.

PropertyPlaceholderHelper

public 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.

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

replacePlaceholders

public 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.

Parameters:
value - the value containing the placeholders to be replaced.
properties - the Properties to use for replacement.
Returns:
the supplied value with placeholders replaced inline.

replacePlaceholders

public 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.

Parameters:
value - the value containing the placeholders to be replaced.
placeholderResolver - the PlaceholderResolver to use for replacement.
Returns:
the supplied value with placeholders replaced inline.

parseStringValue

protected java.lang.String parseStringValue(java.lang.String strVal,
                                            PropertyPlaceholderHelper.PlaceholderResolver placeholderResolver,
                                            java.util.Set<java.lang.String> visitedPlaceholders)

Spring Framework