@Override public String resolveStringValue(String strVal) throws BeansException { return this.helper.replacePlaceholders(strVal, this.resolver); } }
@Test(expected = IllegalArgumentException.class) public void testUnresolvedPlaceholderAsError() { String text = "foo=${foo},bar=${bar}"; Properties props = new Properties(); props.setProperty("foo", "bar"); PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}", null, false); assertEquals("foo=bar,bar=${bar}", helper.replacePlaceholders(text, props)); }
int endIndex = findPlaceholderEndIndex(result, startIndex); if (endIndex != -1) { String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex); placeholder = parseStringValue(placeholder, placeholderResolver, visitedPlaceholders); propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders); result.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal); if (logger.isTraceEnabled()) {
public StaticStringValueResolver(final Map<String, String> values) { this.helper = new PropertyPlaceholderHelper("${", "}", ":", false); this.resolver = values::get; }
/** * Replaces all placeholders of format {@code ${name}} with the value returned * from the supplied {@link PlaceholderResolver}. * @param value the value containing the placeholders to be replaced * @param placeholderResolver the {@code PlaceholderResolver} to use for replacement * @return the supplied value with placeholders replaced inline */ public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) { Assert.notNull(value, "'value' must not be null"); return parseStringValue(value, placeholderResolver, new HashSet<>()); }
private PropertyPlaceholderHelper createPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) { return new PropertyPlaceholderHelper(this.placeholderPrefix, this.placeholderSuffix, this.valueSeparator, ignoreUnresolvablePlaceholders); }
/** * Replaces all placeholders of format {@code ${name}} with the value returned * from the supplied {@link PlaceholderResolver}. * @param value the value containing the placeholders to be replaced * @param placeholderResolver the {@code PlaceholderResolver} to use for replacement * @return the supplied value with placeholders replaced inline */ public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) { Assert.notNull(value, "'value' must not be null"); return parseStringValue(value, placeholderResolver, new HashSet<>()); }
public String expandTemplateVars(String destination) { return placeholderHelper.replacePlaceholders(destination, this.placeholderResolver); } }
/** * 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); }
private PropertyPlaceholderHelper createPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) { return new PropertyPlaceholderHelper(this.placeholderPrefix, this.placeholderSuffix, this.valueSeparator, ignoreUnresolvablePlaceholders); }
int endIndex = findPlaceholderEndIndex(result, startIndex); if (endIndex != -1) { String placeholder = result.substring(startIndex + this.placeholderPrefix.length(), endIndex); placeholder = parseStringValue(placeholder, placeholderResolver, visitedPlaceholders); propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders); result.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal); if (logger.isTraceEnabled()) {
/** * Replaces all placeholders of format <code>${name}</code> with the value returned from the supplied * {@link PlaceholderResolver}. * @param value the value containing the placeholders to be replaced. * @param placeholderResolver the <code>PlaceholderResolver</code> to use for replacement. * @return the supplied value with placeholders replaced inline. */ public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) { Assert.notNull(value, "Argument 'value' must not be null."); return parseStringValue(value, placeholderResolver, new HashSet<String>()); }
private String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper) { return helper.replacePlaceholders(text, this::getPropertyAsRawString); }
private static String replacePlaceholder(Properties properties, String value) { PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}"); return helper.replacePlaceholders(value, properties); }
public PropertySourcesPlaceholdersResolver(Iterable<PropertySource<?>> sources, PropertyPlaceholderHelper helper) { this.sources = sources; this.helper = (helper != null) ? helper : new PropertyPlaceholderHelper(SystemPropertyUtils.PLACEHOLDER_PREFIX, SystemPropertyUtils.PLACEHOLDER_SUFFIX, SystemPropertyUtils.VALUE_SEPARATOR, true); }
int endIndex = findPlaceholderEndIndex(buf, startIndex); if (endIndex != -1) { String placeholder = buf.substring(startIndex + this.placeholderPrefix.length(), endIndex); placeholder = parseStringValue(placeholder, placeholderResolver, visitedPlaceholders); propVal = parseStringValue(propVal, placeholderResolver, visitedPlaceholders); buf.replace(startIndex, endIndex + this.placeholderSuffix.length(), propVal); if (logger.isTraceEnabled()) {
/** * Replaces all placeholders of format {@code ${name}} with the value returned * from the supplied {@link PlaceholderResolver}. * @param value the value containing the placeholders to be replaced * @param placeholderResolver the {@code PlaceholderResolver} to use for replacement * @return the supplied value with placeholders replaced inline */ public String replacePlaceholders(String value, PlaceholderResolver placeholderResolver) { Assert.notNull(value, "'value' must not be null"); return parseStringValue(value, placeholderResolver, new HashSet<>()); }
/** * Replaces all placeholders of format {@code ${name}} with the corresponding * property from the supplied {@link Properties}. * @param value the value containing the placeholders to be replaced * @param properties the {@code Properties} to use for replacement * @return the supplied value with placeholders replaced inline */ public String replacePlaceholders(String value, final Properties properties) { Assert.notNull(properties, "'properties' must not be null"); return replacePlaceholders(value, properties::getProperty); }
private static String replacePlaceholder(Properties properties, String value) { PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}"); return helper.replacePlaceholders(value, properties); }
public PlaceholderResolvingStringValueResolver(Properties props) { this.helper = new PropertyPlaceholderHelper( placeholderPrefix, placeholderSuffix, valueSeparator, ignoreUnresolvablePlaceholders); this.resolver = new PropertyPlaceholderConfigurerResolver(props); }