类 PlaceholderParser

java.lang.Object
cn.taketoday.util.PlaceholderParser

final class PlaceholderParser extends Object
Parser for Strings that have placeholder values in them. In its simplest form, a placeholder takes the form of ${name}, where name is the key that can be resolved using a PlaceholderResolver, ${ the prefix, and } the suffix.

A placeholder can also have a default value if its key does not represent a known property. The default value is separated from the key using a separator. For instance ${name:John} resolves to John if the placeholder resolver does not provide a value for the name property.

Placeholders can also have a more complex structure, and the resolution of a given key can involve the resolution of nested placeholders. Default values can also have placeholders.

For situations where the syntax of a valid placeholder matches a String that must be rendered as is, the placeholder can be escaped using an escape character. For instance \${name} resolves as ${name}.

The prefix, suffix, separator, and escape characters are configurable. Only the prefix and suffix are mandatory, and the support for default values or escaping is conditional on providing non-null values for them.

This parser makes sure to resolves placeholders as lazily as possible.

从以下版本开始:
4.0
作者:
Stephane Nicoll, Harry Yang
  • 字段详细资料

    • logger

      private static final Logger logger
    • wellKnownSimplePrefixes

      private static final Map<String,String> wellKnownSimplePrefixes
    • prefix

      private final String prefix
    • suffix

      private final String suffix
    • simplePrefix

      private final String simplePrefix
    • separator

      @Nullable private final String separator
    • ignoreUnresolvablePlaceholders

      private final boolean ignoreUnresolvablePlaceholders
    • escape

      @Nullable private final Character escape
    • placeholderPrefixLength

      private final int placeholderPrefixLength
    • placeholderSuffixLength

      private final int placeholderSuffixLength
  • 构造器详细资料

    • PlaceholderParser

      PlaceholderParser(String prefix, String suffix, @Nullable String separator, @Nullable Character escape, boolean ignoreUnresolvablePlaceholders)
      Create an instance using the specified input for the parser.
      参数:
      prefix - the prefix that denotes the start of a placeholder
      suffix - the suffix that denotes the end of a placeholder
      separator - the separating character between the placeholder variable and the associated default value, if any
      escape - the character to use at the beginning of a placeholder prefix or separator to escape it and render it as is
      ignoreUnresolvablePlaceholders - whether unresolvable placeholders should be ignored (true) or cause an exception (false)
  • 方法详细资料