|
|
|
@ -1,7 +1,5 @@
|
|
|
|
|
package com.java3y.austin.support.utils;
|
|
|
|
|
|
|
|
|
|
import org.springframework.context.expression.MapAccessor;
|
|
|
|
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
|
|
|
|
import org.springframework.util.PropertyPlaceholderHelper;
|
|
|
|
|
|
|
|
|
|
import java.text.MessageFormat;
|
|
|
|
@ -25,20 +23,11 @@ public class ContentHolderUtil {
|
|
|
|
|
*/
|
|
|
|
|
private static final String PLACE_HOLDER_SUFFIX = "}";
|
|
|
|
|
|
|
|
|
|
private static final StandardEvaluationContext EVALUATION_CONTEXT;
|
|
|
|
|
private static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper(PLACE_HOLDER_PREFIX, PLACE_HOLDER_SUFFIX);
|
|
|
|
|
|
|
|
|
|
private static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper(
|
|
|
|
|
PLACE_HOLDER_PREFIX, PLACE_HOLDER_SUFFIX);
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
EVALUATION_CONTEXT = new StandardEvaluationContext();
|
|
|
|
|
EVALUATION_CONTEXT.addPropertyAccessor(new MapAccessor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String replacePlaceHolder(final String template, final Map<String, String> paramMap) {
|
|
|
|
|
String replacedPushContent = PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders(template,
|
|
|
|
|
new CustomPlaceholderResolver(template, paramMap));
|
|
|
|
|
return replacedPushContent;
|
|
|
|
|
return PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders(template, new CustomPlaceholderResolver(template, paramMap));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class CustomPlaceholderResolver implements PropertyPlaceholderHelper.PlaceholderResolver {
|
|
|
|
@ -55,8 +44,7 @@ public class ContentHolderUtil {
|
|
|
|
|
public String resolvePlaceholder(String placeholderName) {
|
|
|
|
|
String value = paramMap.get(placeholderName);
|
|
|
|
|
if (null == value) {
|
|
|
|
|
String errorStr = MessageFormat.format("template:{0} require param:{1},but not exist! paramMap:{2}",
|
|
|
|
|
template, placeholderName, paramMap.toString());
|
|
|
|
|
String errorStr = MessageFormat.format("template:{0} require param:{1},but not exist! paramMap:{2}", template, placeholderName, paramMap.toString());
|
|
|
|
|
throw new IllegalArgumentException(errorStr);
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|