com.baidu.jprotobuf.pbrpc.spring
类 PlaceholderResolver

java.lang.Object
  继承者 com.baidu.jprotobuf.pbrpc.spring.PlaceholderResolver

public class PlaceholderResolver
extends java.lang.Object

字符串占位符解析工作类.
例如: String testStr = "abc${ab}" 如果ab="ddd",则解析后结果为 abcddd

 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));
    }
    

从以下版本开始:
2.17
作者:
xiemalin

字段摘要
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.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

DEFAULT_PLACEHOLDER_PREFIX

public static final java.lang.String DEFAULT_PLACEHOLDER_PREFIX
Default placeholder prefix: "${"

另请参见:
常量字段值

DEFAULT_PLACEHOLDER_SUFFIX

public static final java.lang.String DEFAULT_PLACEHOLDER_SUFFIX
Default placeholder suffix: "}"

另请参见:
常量字段值
构造方法详细信息

PlaceholderResolver

public PlaceholderResolver(PlaceholderResolved resolvedInterceptor)
Constructor method

参数:
resolvedInterceptor - PlaceholderResolved can not be null.
方法详细信息

doParse

public java.lang.String doParse(java.lang.String strVal)
Do parser placeholder action.

参数:
strVal - target string to parser
返回:
target string after placeholder parse

hasPlaceHolder

public boolean hasPlaceHolder(java.lang.String strVal)
test if target string contains placeholderPrefix

参数:
strVal - target string to test
返回:
true if string contains placeholderPrefix

parseStringValue

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

参数:
strVal - the String value to parse
visitedPlaceholders - 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.

substringMatch

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

参数:
str - the original string (or StringBuffer)
index - the index in the original string to start matching against
substring - the substring to match at the given index

setPlaceholderPrefix

public void setPlaceholderPrefix(java.lang.String placeholderPrefix)
参数:
placeholderPrefix - the placeholderPrefix to set

setPlaceholderSuffix

public void setPlaceholderSuffix(java.lang.String placeholderSuffix)
参数:
placeholderSuffix - the placeholderSuffix to set


Copyright © 2015 Baidu, Inc.. All Rights Reserved.