类 PropertyPlaceholderHandler

java.lang.Object
cn.taketoday.util.PropertyPlaceholderHandler

public class PropertyPlaceholderHandler extends Object
Utility class for working with Strings that have placeholder values in them. A placeholder takes the form ${name}. Using PropertyPlaceholderHandler these placeholders can be substituted for user-supplied values.

Values for substitution can be supplied using a Properties instance or using a PlaceholderResolver.

从以下版本开始:
4.0
作者:
Juergen Hoeller, Rob Harrop, TODAY 2021/9/28 22:26
  • 字段详细资料

    • log

      private static final Logger log
    • PLACEHOLDER_SUFFIX

      public static final String PLACEHOLDER_SUFFIX
      Suffix for property placeholders: "}".
      另请参阅:
    • PLACEHOLDER_PREFIX

      public static final String PLACEHOLDER_PREFIX
      Prefix for property placeholders: "${".
      另请参阅:
    • VALUE_SEPARATOR

      public static final String VALUE_SEPARATOR
      Value separator for property placeholders: ":".
      另请参阅:
    • wellKnownSimplePrefixes

      private static final HashMap<String,String> wellKnownSimplePrefixes
    • strict

      public static final PropertyPlaceholderHandler strict
    • nonStrict

      public static final PropertyPlaceholderHandler nonStrict
    • simplePrefix

      private final String simplePrefix
    • placeholderPrefix

      private final String placeholderPrefix
    • placeholderSuffix

      private final String placeholderSuffix
    • placeholderPrefixLength

      private final int placeholderPrefixLength
    • placeholderSuffixLength

      private final int placeholderSuffixLength
    • valueSeparator

      @Nullable private final String valueSeparator
    • ignoreUnresolvablePlaceholders

      private final boolean ignoreUnresolvablePlaceholders
  • 构造器详细资料

    • PropertyPlaceholderHandler

      public PropertyPlaceholderHandler(String placeholderPrefix, String placeholderSuffix)
      Creates a new PropertyPlaceholderHandler 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
    • PropertyPlaceholderHandler

      public PropertyPlaceholderHandler(String placeholderPrefix, String placeholderSuffix, @Nullable String valueSeparator, boolean ignoreUnresolvablePlaceholders)
      Creates a new PropertyPlaceholderHandler that uses the supplied prefix and suffix.
      参数:
      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)
  • 方法详细资料

    • replacePlaceholders

      public String replacePlaceholders(String value, Properties properties)
      Replaces all placeholders of format ${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
      返回:
      the supplied value with placeholders replaced inline
    • replacePlaceholders

      public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver)
      Replaces all placeholders of format ${name} with the value returned from the supplied PlaceholderResolver.
      参数:
      value - the value containing the placeholders to be replaced
      placeholderResolver - the PlaceholderResolver to use for replacement
      返回:
      the supplied value with placeholders replaced inline
    • parseStringValue

      protected String parseStringValue(String value, PlaceholderResolver placeholderResolver, @Nullable Set<String> visitedPlaceholders)
    • findPlaceholderEndIndex

      private int findPlaceholderEndIndex(CharSequence buf, int startIndex)
    • shared

      @NonNull public static PropertyPlaceholderHandler shared(boolean ignoreUnresolvablePlaceholders)