类 PlaceholderParser
${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
-
嵌套类概要
嵌套类修饰符和类型类说明(专用程序包) static final recordAPlaceholderParser.Partimplementation that represents a single placeholder containing nested placeholders.(专用程序包) static final recordA representation of the parsing of an input string.(专用程序包) static interfaceA part is a section of a String containing placeholders to replace.(专用程序包) static classProvide the necessary context to handle and resolve underlying placeholders.(专用程序包) static final recordAPlaceholderParser.Partimplementation that represents a single placeholder with a hard-coded fallback.(专用程序包) static final recordAPlaceholderParser.Partimplementation that does not contain a valid placeholder. -
字段概要
字段 -
构造器概要
构造器构造器说明PlaceholderParser(String prefix, String suffix, String separator, Character escape, boolean ignoreUnresolvablePlaceholders) Create an instance using the specified input for the parser. -
方法概要
修饰符和类型方法说明private static voidaddText(String value, int start, int end, LinkedList<PlaceholderParser.Part> parts) createNestedPlaceholderPart(String text, List<PlaceholderParser.Part> parts) private booleanprivate intnextStartPrefix(String value, int index) private intnextValidEndPrefix(String value, int startIndex) Parse the specified value.private List<PlaceholderParser.Part>replacePlaceholders(String value, PlaceholderResolver placeholderResolver) Replace all placeholders of format${name}with the value returned from the suppliedPlaceholderResolver.private String[]splitKeyAndDefault(String value)
-
字段详细资料
-
logger
-
wellKnownSimplePrefixes
-
prefix
-
suffix
-
simplePrefix
-
separator
-
ignoreUnresolvablePlaceholders
private final boolean ignoreUnresolvablePlaceholders -
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 placeholdersuffix- the suffix that denotes the end of a placeholderseparator- the separating character between the placeholder variable and the associated default value, if anyescape- the character to use at the beginning of a placeholder prefix or separator to escape it and render it as isignoreUnresolvablePlaceholders- whether unresolvable placeholders should be ignored (true) or cause an exception (false)
-
-
方法详细资料
-
replacePlaceholders
Replace all placeholders of format${name}with the value returned from the suppliedPlaceholderResolver.- 参数:
value- the value containing the placeholders to be replacedplaceholderResolver- thePlaceholderResolverto use for replacement- 返回:
- the supplied value with placeholders replaced inline
-
parse
Parse the specified value.- 参数:
value- the value containing the placeholders to be replaced- 返回:
- the different parts that have been identified
-
parse
-
createSimplePlaceholderPart
-
createNestedPlaceholderPart
private PlaceholderParser.NestedPlaceholderPart createNestedPlaceholderPart(String text, List<PlaceholderParser.Part> parts) -
splitKeyAndDefault
-
addText
private static void addText(String value, int start, int end, LinkedList<PlaceholderParser.Part> parts) -
nextStartPrefix
-
nextValidEndPrefix
-
isEscaped
-