本文整理汇总了Java中org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyPlaceholderHelper.replacePlaceholders方法的具体用法?Java PropertyPlaceholderHelper.replacePlaceholders怎么用?Java PropertyPlaceholderHelper.replacePlaceholders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.PropertyPlaceholderHelper
的用法示例。
在下文中一共展示了PropertyPlaceholderHelper.replacePlaceholders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processProperties
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
PropertyPlaceholderHelper helper =
new PropertyPlaceholderHelper(DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, false);
for (Entry<Object, Object> entry : props.entrySet()) {
String stringKey = String.valueOf(entry.getKey());
String stringValue = String.valueOf(entry.getValue());
if ((stringKey.contains(DEFAULT_PLACEHOLDER_PREFIX) && stringKey.contains(DEFAULT_PLACEHOLDER_SUFFIX)
&& (stringKey.indexOf(DEFAULT_PLACEHOLDER_PREFIX) < stringKey.indexOf(DEFAULT_PLACEHOLDER_SUFFIX)))) {
stringKey = getReplacedStringKey(stringKey, helper, props);
}
stringValue = helper.replacePlaceholders(stringValue, props);
//
if (stringKey.startsWith(this.appPropertiesPrefix)) {
FileCloudPropertyConfigurer.appProperties.put(stringKey, stringValue);
}
properties.put(stringKey, stringValue);
}
super.processProperties(beanFactoryToProcess, props);
}
示例2: getReplacedStringKey
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
public String getReplacedStringKey(String stringKey, PropertyPlaceholderHelper helper, Properties props) {
if (stringKey.contains(DEFAULT_PLACEHOLDER_PREFIX) && stringKey.contains(DEFAULT_PLACEHOLDER_SUFFIX)
&& (stringKey.indexOf(DEFAULT_PLACEHOLDER_PREFIX) < stringKey.indexOf(DEFAULT_PLACEHOLDER_SUFFIX))) {
// before of target
String prefix = stringKey.substring(0, stringKey.indexOf(DEFAULT_PLACEHOLDER_PREFIX));
// replace
String refString =
stringKey.substring(stringKey.indexOf(DEFAULT_PLACEHOLDER_PREFIX), stringKey.indexOf(DEFAULT_PLACEHOLDER_SUFFIX) + 1);
// after of target
String suffix = stringKey.substring(stringKey.indexOf(DEFAULT_PLACEHOLDER_SUFFIX) + 1);
// get target from props data
String refStringValue = helper.replacePlaceholders(refString, props);
// build a new local key
String newKey = prefix + refStringValue + suffix;
// while until the key not contains of ${}
return getReplacedStringKey(newKey, helper, props);
}
return stringKey;
}
示例3: replacePlaceholders
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
/**
* Replaces each occurence of ${SOME_VALUE} with the varible SOME_VALUE in 'variables'
* If any error occures during parsing, i.e: variable doesn't exist, bad syntax, etc...
* a {@link PlaceholderResolutionException} is thrown, otherwise the new string after all replacements have been
* made will be returned.
*
* @param variables The variables map to match placeholders against
* @param value the string, possibly containing placeholders
* @return the value after placeholder replacement have been made
* @throws PlaceholderResolutionException if an empty placeholder is found
* or a place holder with no suitable value in 'variables'
*/
public static String replacePlaceholders(final Map<String, String> variables, final String value) throws PlaceholderResolutionException {
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${","}");
return helper.replacePlaceholders(value, new PlaceholderResolver() {
public String resolvePlaceholder(String key) {
if (key.isEmpty()) {
throw new PlaceholderResolutionException("Placeholder in '" + value + "' has to have a length of at least 1");
}
String result = variables.get(key);
if (result == null) {
throw new PlaceholderResolutionException("Missing value for placeholder: '" + key + "' in '" + value + "'");
}
return result;
}
});
}
示例4: replaceValuesAndGetTemplateValue
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
/**
*
* @param templateResourcePath
* @param templateProperties
* @return
*/
private String replaceValuesAndGetTemplateValue(String templateResourcePath,
Properties templateProperties,RestResponse response) {
InputStream gradleInitTemplateStream = null;
try {
gradleInitTemplateStream = getClass().getResourceAsStream(templateResourcePath);
String gradleTemplate = IOUtils.toString(gradleInitTemplateStream);
PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper("${", "}");
return propertyPlaceholderHelper.replacePlaceholders(gradleTemplate, templateProperties);
} catch (IOException e) {
String errorMessage = "An error occurred while preparing the Gradle Init Script template: ";
response.error(errorMessage + e.getMessage());
log.error(errorMessage, e);
} finally {
IOUtils.closeQuietly(gradleInitTemplateStream);
}
return "";
}
示例5: replaceValuesAndGetTemplateValue
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
private String replaceValuesAndGetTemplateValue(String templateResourcePath, Properties templateProperties) {
InputStream gradleInitTemplateStream = null;
try {
gradleInitTemplateStream = getClass().getResourceAsStream(templateResourcePath);
String gradleTemplate = IOUtils.toString(gradleInitTemplateStream);
PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper("${", "}");
return propertyPlaceholderHelper.replacePlaceholders(gradleTemplate, templateProperties);
} catch (IOException e) {
String errorMessage = "An error occurred while preparing the Gradle Init Script template: ";
error(errorMessage + e.getMessage());
log.error(errorMessage, e);
} finally {
IOUtils.closeQuietly(gradleInitTemplateStream);
}
return "";
}
示例6: doResolvePlaceholders
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
private String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper) {
return helper.replacePlaceholders(text, new PropertyPlaceholderHelper.PlaceholderResolver() {
@Override
public String resolvePlaceholder(String placeholderName) {
return getPropertyAsRawString(placeholderName);
}
});
}
示例7: render
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
throws Exception {
Map<String, Object> map = new HashMap<String, Object>(model);
String path = ServletUriComponentsBuilder.fromContextPath(request).build()
.getPath();
map.put("path", (Object) path==null ? "" : path);
context.setRootObject(map);
String maskedTemplate = template.replace("${", prefix);
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(prefix, "}");
String result = helper.replacePlaceholders(maskedTemplate, resolver);
result = result.replace(prefix, "${");
response.setContentType(getContentType());
response.getWriter().append(result);
}
示例8: injectEnvironmentVars
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
protected int injectEnvironmentVars(BufferedReader reader, PropertyPlaceholderHelper.PlaceholderResolver resolver)
throws IOException, RunBuildException {
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("{", "}");
String line;
int propertiesCount = 0;
while ((line = reader.readLine()) != null) {
addDebugMessage("Read line [%s]", line);
if (!line.contains("=")) {
throw new RunBuildException("The line [" + line + "] does contain property of the form key=value");
}
String[] split = line.split("=", 2);
addDebugMessage("Will use key [%s] and value [%s]", split[0], split[1]);
String finalValue = helper.replacePlaceholders(split[1], resolver);
addDebugMessage("Resolved value of [%s] is [%s]", split[1], finalValue);
if (split[0].startsWith(ENV_VAR_PREFIX)) {
addDebugMessage("Will set environment variable");
getAgentConfiguration().addEnvironmentVariable(split[0].replace(ENV_VAR_PREFIX, ""), finalValue);
} else if (split[0].startsWith(SYSTEM_VAR_PREFIX)) {
addDebugMessage("Will set system property");
getAgentConfiguration().addSystemProperty(split[0].replace(SYSTEM_VAR_PREFIX, ""), finalValue);
} else {
addDebugMessage("Will set configuration property");
getAgentConfiguration().addConfigurationParameter(split[0], finalValue);
}
propertiesCount++;
}
return propertiesCount;
}
示例9: replacePlaceholders
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
private String replacePlaceholders(String value, Properties properties) {
if (value.contains("$")) {
LOGGER.debug("replacing placeholders in " + value);
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}");
String newValue = helper.replacePlaceholders(value, properties);
LOGGER.debug("after replacement: " + newValue);
return newValue;
} else {
return value;
}
}
示例10: replaceProperties
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
private String replaceProperties(String uri) {
if (uri == null) {
return null;
}
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}", ":", true);
return helper.replacePlaceholders(uri, new PropertyPlaceholderHelper.PlaceholderResolver() {
@Override
public String resolvePlaceholder(String placeholderName) {
return propertyResolver.getProperty(placeholderName);
}
});
}
示例11: doResolvePlaceholders
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
private String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper) {
return helper.replacePlaceholders(text, new PropertyPlaceholderHelper.PlaceholderResolver() {
public String resolvePlaceholder(String placeholderName) {
return getPropertyAsRawString(placeholderName);
}
});
}
示例12: loadJsonFile
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
/**
* Load the JSON template and perform string substitution on the ${...} tokens
* @param is
* @return
* @throws IOException
*/
@SuppressWarnings("unchecked")
Map<String, Object> loadJsonFile(InputStream is, Properties sliProps) throws IOException {
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
String template = writer.toString();
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}");
template = helper.replacePlaceholders(template, sliProps);
return (Map<String, Object>) JSON.parse(template);
}
示例13: getFilteredContent
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
public String getFilteredContent(String s, Properties properties) {
PropertyPlaceholderHelper pph = new PropertyPlaceholderHelper(PREFIX, SUFFIX);
String filtered = pph.replacePlaceholders(s, properties);
return filtered;
}
示例14: parseStringValue
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
/**
* Parse the given String value for placeholder resolution.
* @param strVal the String value to parse
* @param props the Properties to resolve placeholders against
* @param visitedPlaceholders the placeholders that have already been visited
* during the current resolution attempt (ignored in this version of the code)
* @deprecated as of Spring 3.0, in favor of using {@link #resolvePlaceholder}
* with {@link org.springframework.util.PropertyPlaceholderHelper}.
* Only retained for compatibility with Spring 2.5 extensions.
*/
@Deprecated
protected String parseStringValue(String strVal, Properties props, Set<?> visitedPlaceholders) {
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(
placeholderPrefix, placeholderSuffix, valueSeparator, ignoreUnresolvablePlaceholders);
PlaceholderResolver resolver = new PropertyPlaceholderConfigurerResolver(props);
return helper.replacePlaceholders(strVal, resolver);
}
示例15: parseStringValue
import org.springframework.util.PropertyPlaceholderHelper; //导入方法依赖的package包/类
/**
* Parse the given String with Placeholder "${...}" and returns the result.
* <p>
* Placeholders will be resolved with Settings4j.
* </p>
*
* @param strVal
* the String with the Paceholders
* @param prefix
* for all placehodlers.
* @param props
* The default Properties if no Value where found
* @return the parsed String
* @throws BeanDefinitionStoreException
* if invalid values are encountered (Placeholders where no values where found).
*/
public static String parseStringValue(final String strVal, final String prefix, final Properties props)
throws BeanDefinitionStoreException {
final PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(DEFAULT_PLACEHOLDER_PREFIX,
DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, false);
return helper.replacePlaceholders(strVal, new Settings4jPlaceholderConfigurerResolver(prefix, props));
}