public class PlaceholderResolver
extends java.lang.Object
example:
public static void main(String[] args) {
final Map placeholderVals = new HashMap(5);
placeholderVals.put("key1", "china");
placeholderVals.put("key2", "3");
placeholderVals.put("key3", "beijin");
String testStr = "hello ${key1}";
PlaceholderResolver resolver = new PlaceholderResolver(new PlaceholderResolved() {
public String doResolved(String placeholder) {
System.out.println("find placeholder:" + placeholder);
return placeholderVals.get(placeholder);
}
});
resolver.setPlaceholderPrefix("${");
resolver.setPlaceholderSuffix("}");
System.out.println(resolver.doParse(testStr));
testStr = "hello ${key${key2}}";
System.out.println(resolver.doParse(testStr));
}
| 限定符和类型 | 字段和说明 |
|---|---|
static java.lang.String |
DEFAULT_PLACEHOLDER_PREFIX
Default placeholder prefix: "${"
|
static java.lang.String |
DEFAULT_PLACEHOLDER_SUFFIX
Default placeholder suffix: "}"
|
| 构造器和说明 |
|---|
PlaceholderResolver(PlaceholderResolved resolvedInterceptor)
Constructor method
|
| 限定符和类型 | 方法和说明 |
|---|---|
java.lang.String |
doParse(java.lang.String strVal)
Do parser placeholder action.
|
boolean |
hasPlaceHolder(java.lang.String strVal)
test if target string contains placeholderPrefix
|
protected java.lang.String |
parseStringValue(java.lang.String strVal,
java.util.Set<java.lang.String> visitedPlaceholders)
Parse the given String value recursively, to be able to resolve nested
placeholders (when resolved property values in turn contain placeholders
again).
|
void |
setPlaceholderPrefix(java.lang.String placeholderPrefix) |
void |
setPlaceholderSuffix(java.lang.String placeholderSuffix) |
static boolean |
substringMatch(java.lang.CharSequence str,
int index,
java.lang.CharSequence substring)
Test whether the given string matches the given substring
at the given index.
|
public static final java.lang.String DEFAULT_PLACEHOLDER_PREFIX
public static final java.lang.String DEFAULT_PLACEHOLDER_SUFFIX
public PlaceholderResolver(PlaceholderResolved resolvedInterceptor)
resolvedInterceptor - PlaceholderResolved can not be null.public java.lang.String doParse(java.lang.String strVal)
strVal - target string to parserpublic boolean hasPlaceHolder(java.lang.String strVal)
strVal - target string to testprotected java.lang.String parseStringValue(java.lang.String strVal,
java.util.Set<java.lang.String> visitedPlaceholders)
strVal - the String value to parsevisitedPlaceholders - the placeholders that have already been visited
during the current resolution attempt (used to detect circular references
between placeholders). Only non-null if we're parsing a nested placeholder.public static boolean substringMatch(java.lang.CharSequence str,
int index,
java.lang.CharSequence substring)
str - the original string (or StringBuffer)index - the index in the original string to start matching againstsubstring - the substring to match at the given indexpublic void setPlaceholderPrefix(java.lang.String placeholderPrefix)
placeholderPrefix - the placeholderPrefix to setpublic void setPlaceholderSuffix(java.lang.String placeholderSuffix)
placeholderSuffix - the placeholderSuffix to setCopyright © 2015 Baidu, Inc.. All Rights Reserved.