本文整理汇总了Java中org.springframework.util.PropertyPlaceholderHelper类的典型用法代码示例。如果您正苦于以下问题:Java PropertyPlaceholderHelper类的具体用法?Java PropertyPlaceholderHelper怎么用?Java PropertyPlaceholderHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PropertyPlaceholderHelper类属于org.springframework.util包,在下文中一共展示了PropertyPlaceholderHelper类的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: DefaultConfigProvider
import org.springframework.util.PropertyPlaceholderHelper; //导入依赖的package包/类
/**
* @param properties
*/
public DefaultConfigProvider(Properties properties) {
if (properties == null) {
throw new IllegalArgumentException("properties 不能为null");
}
PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("${", "}", ":", true);
Properties replacedProperties = new Properties();
for (Map.Entry<?, ?> entry : properties.entrySet()) {
String key = (String) entry.getKey();
String value = (String) entry.getValue();
replacedProperties.setProperty(key, placeholderHelper.replacePlaceholders(value, properties));
}
this.properties = replacedProperties;
}
示例4: afterPropertiesSet
import org.springframework.util.PropertyPlaceholderHelper; //导入依赖的package包/类
/**
*
* {@inheritDoc}
*/
@Override
public void afterPropertiesSet()
{
if (this.propertyPrefix == null || this.propertyPrefix.trim().isEmpty())
{
throw new IllegalStateException("propertyPrefix has not been set");
}
if (this.beanTypes == null)
{
throw new IllegalStateException("beanTypes has not been set");
}
if (this.propertiesSource == null)
{
throw new IllegalStateException("propertiesSource has not been set");
}
this.placeholderHelper = new PropertyPlaceholderHelper(this.placeholderPrefix, this.placeholderSuffix, this.valueSeparator, true);
}
示例5: 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;
}
});
}
示例6: injectPropertiesFromContent
import org.springframework.util.PropertyPlaceholderHelper; //导入依赖的package包/类
private int injectPropertiesFromContent(PropertyPlaceholderHelper.PlaceholderResolver resolver)
throws RunBuildException {
String propertiesFileContent = getRunnerParameters().get("propertiesFileContent");
int propertiesCount = 0;
if (StringUtils.hasText(propertiesFileContent)) {
getLogger().message("Will use properties content string configured by user");
try (BufferedReader reader = new BufferedReader(new StringReader(propertiesFileContent))) {
propertiesCount = injectEnvironmentVars(reader, resolver);
} catch (IOException | RuntimeException e) {
getLogger().exception(e);
throw new RunBuildException("Exception occured reading/parsing given properties content. Message ["
+ e.getMessage() + "]");
}
getLogger().message("Plugin injected [" + propertiesCount + "] parameters from properties content");
}
return propertiesCount;
}
示例7: injectPropertiesFromFile
import org.springframework.util.PropertyPlaceholderHelper; //导入依赖的package包/类
private int injectPropertiesFromFile(PropertyPlaceholderHelper.PlaceholderResolver resolver)
throws RunBuildException {
String propertiesFilePath = getRunnerParameters().get("propertiesFilePath");
int propertiesCount = 0;
if (StringUtils.hasText(propertiesFilePath)) {
getLogger().message("Will use properties from file [" + propertiesFilePath + "]");
try (BufferedReader reader = newBufferedReader(Paths.get(propertiesFilePath), StandardCharsets.UTF_8)) {
propertiesCount = injectEnvironmentVars(reader, resolver);
} catch (IOException | RuntimeException e) {
throw new RunBuildException("Exception occured reading/parsing [" + propertiesFilePath
+ "]. Message [" + e.getMessage() + "]");
}
getLogger().message("Plugin injected [" + propertiesCount + "] parameters from ["
+ propertiesFilePath + "]");
}
return propertiesCount;
}
示例8: 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 "";
}
示例9: 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 "";
}
示例10: 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);
}
});
}
示例11: StaticStringValueResolver
import org.springframework.util.PropertyPlaceholderHelper; //导入依赖的package包/类
public StaticStringValueResolver(final Map<String, String> values) {
this.helper = new PropertyPlaceholderHelper("${", "}", ":", false);
this.resolver = new PlaceholderResolver() {
@Override
public String resolvePlaceholder(String placeholderName) {
return values.get(placeholderName);
}
};
}
示例12: SpelView
import org.springframework.util.PropertyPlaceholderHelper; //导入依赖的package包/类
public SpelView(String template) {
this.template = template;
this.prefix = new RandomValueStringGenerator().generate() + "{";
this.context.addPropertyAccessor(new MapAccessor());
this.resolver = new PropertyPlaceholderHelper.PlaceholderResolver() {
public String resolvePlaceholder(String name) {
Expression expression = parser.parseExpression(name);
Object value = expression.getValue(context);
return value == null ? null : value.toString();
}
};
}
示例13: 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);
}
示例14: processProperties
import org.springframework.util.PropertyPlaceholderHelper; //导入依赖的package包/类
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
super.processProperties(beanFactoryToProcess, props);
// store all the spring properties so we can refer to them later
properties.putAll(props);
// create helper
helper = new PropertyPlaceholderHelper(
configuredPlaceholderPrefix != null ? configuredPlaceholderPrefix : DEFAULT_PLACEHOLDER_PREFIX,
configuredPlaceholderSuffix != null ? configuredPlaceholderSuffix : DEFAULT_PLACEHOLDER_SUFFIX,
configuredValueSeparator != null ? configuredValueSeparator : DEFAULT_VALUE_SEPARATOR,
configuredIgnoreUnresolvablePlaceholders != null ? configuredIgnoreUnresolvablePlaceholders : false);
}
示例15: makeProgramCommandLine
import org.springframework.util.PropertyPlaceholderHelper; //导入依赖的package包/类
@NotNull
@Override
public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {
PropertyPlaceholderHelper.PlaceholderResolver resolver = new TeamcityPlaceholderResolver();
int envVarsFromFile = injectPropertiesFromFile(resolver);
int envVarsFromContent = injectPropertiesFromContent(resolver);
if (envVarsFromContent == 0 && envVarsFromFile == 0) {
getLogger().error("You have used the EnvInject plugin but not provided a properties file or content");
getLogger().error("This runner will effectively be a no-op");
}
return new SimpleProgramCommandLine(getRunnerContext(), "java", Collections.singletonList("-version"));
}