@Override public String resolveStringValue(String strVal) throws BeansException { return this.helper.replacePlaceholders(strVal, this.resolver); } }
public String expandTemplateVars(String destination) { return placeholderHelper.replacePlaceholders(destination, this.placeholderResolver); } }
private String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper) { return helper.replacePlaceholders(text, this::getPropertyAsRawString); }
/** * 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 String doResolvePlaceholders(String text, PropertyPlaceholderHelper helper) { return helper.replacePlaceholders(text, this::getPropertyAsRawString); }
@Override @Nullable public String resolveStringValue(String strVal) throws BeansException { String resolved = this.helper.replacePlaceholders(strVal, this.resolver); if (trimValues) { resolved = resolved.trim(); } return (resolved.equals(nullValue) ? null : resolved); } }
@Override public Object resolvePlaceholders(Object value) { if (value != null && value instanceof String) { return this.helper.replacePlaceholders((String) value, this::resolvePlaceholder); } return value; }
/** * 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); }
/** * Resolve {@code ${...}} placeholders in the given text, replacing them with * corresponding system property values. Unresolvable placeholders with no default * value are ignored and passed through unchanged if the flag is set to {@code true}. * @param text the String to resolve * @param ignoreUnresolvablePlaceholders whether unresolved placeholders are to be ignored * @return the resolved String * @throws IllegalArgumentException if there is an unresolvable placeholder * @see #PLACEHOLDER_PREFIX * @see #PLACEHOLDER_SUFFIX * and the "ignoreUnresolvablePlaceholders" flag is {@code false} */ public static String resolvePlaceholders(String text, boolean ignoreUnresolvablePlaceholders) { PropertyPlaceholderHelper helper = (ignoreUnresolvablePlaceholders ? nonStrictHelper : strictHelper); return helper.replacePlaceholders(text, new SystemPropertyPlaceholderResolver(text)); }
@Override public String resolveStringValue(String strVal) throws BeansException { String value = this.helper.replacePlaceholders(strVal, this.resolver); return (value.equals("") ? null : value); } }
@Override @Nullable public String resolveStringValue(String strVal) throws BeansException { String resolved = this.helper.replacePlaceholders(strVal, this.resolver); if (trimValues) { resolved = resolved.trim(); } return (resolved.equals(nullValue) ? null : resolved); } }
/** * Resolve ${...} placeholders in the given text, replacing them with corresponding * servlet context init parameter or system property values. Unresolvable placeholders * with no default value are ignored and passed through unchanged if the flag is set to true. * @param text the String to resolve * @param servletContext the servletContext to use for lookups. * @param ignoreUnresolvablePlaceholders flag to determine is unresolved placeholders are ignored * @return the resolved String * @throws IllegalArgumentException if there is an unresolvable placeholder and the flag is false * @see SystemPropertyUtils#PLACEHOLDER_PREFIX * @see SystemPropertyUtils#PLACEHOLDER_SUFFIX * @see SystemPropertyUtils#resolvePlaceholders(String, boolean) */ public static String resolvePlaceholders(String text, ServletContext servletContext, boolean ignoreUnresolvablePlaceholders) { PropertyPlaceholderHelper helper = (ignoreUnresolvablePlaceholders ? nonStrictHelper : strictHelper); return helper.replacePlaceholders(text, new ServletContextPlaceholderResolver(text, servletContext)); }
/** * Resolve {@code ${...}} placeholders in the given text, replacing them with * corresponding system property values. Unresolvable placeholders with no default * value are ignored and passed through unchanged if the flag is set to {@code true}. * @param text the String to resolve * @param ignoreUnresolvablePlaceholders whether unresolved placeholders are to be ignored * @return the resolved String * @throws IllegalArgumentException if there is an unresolvable placeholder * @see #PLACEHOLDER_PREFIX * @see #PLACEHOLDER_SUFFIX * and the "ignoreUnresolvablePlaceholders" flag is {@code false} */ public static String resolvePlaceholders(String text, boolean ignoreUnresolvablePlaceholders) { PropertyPlaceholderHelper helper = (ignoreUnresolvablePlaceholders ? nonStrictHelper : strictHelper); return helper.replacePlaceholders(text, new SystemPropertyPlaceholderResolver(text)); }
@Test public void testWithMultipleProperties() { String text = "foo=${foo},bar=${bar}"; Properties props = new Properties(); props.setProperty("foo", "bar"); props.setProperty("bar", "baz"); assertEquals("foo=bar,bar=baz", this.helper.replacePlaceholders(text, props)); }
@Test public void testRecurseInProperty() { String text = "foo=${bar}"; Properties props = new Properties(); props.setProperty("bar", "${baz}"); props.setProperty("baz", "bar"); assertEquals("foo=bar", this.helper.replacePlaceholders(text, props)); }
@Test public void testRecurseInPlaceholder() { String text = "foo=${b${inner}}"; Properties props = new Properties(); props.setProperty("bar", "bar"); props.setProperty("inner", "ar"); assertEquals("foo=bar", this.helper.replacePlaceholders(text, props)); text = "${top}"; props = new Properties(); props.setProperty("top", "${child}+${child}"); props.setProperty("child", "${${differentiator}.grandchild}"); props.setProperty("differentiator", "first"); props.setProperty("first.grandchild", "actualValue"); assertEquals("actualValue+actualValue", this.helper.replacePlaceholders(text, props)); }
@Test public void testUnresolvedPlaceholderIsIgnored() { String text = "foo=${foo},bar=${bar}"; Properties props = new Properties(); props.setProperty("foo", "bar"); assertEquals("foo=bar,bar=${bar}", this.helper.replacePlaceholders(text, props)); }
@Test public void testWithProperties() { String text = "foo=${foo}"; Properties props = new Properties(); props.setProperty("foo", "bar"); assertEquals("foo=bar", this.helper.replacePlaceholders(text, props)); }
@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)); }
@Test public void testWithResolver() { String text = "foo=${foo}"; assertEquals("foo=bar", this.helper.replacePlaceholders(text, new PropertyPlaceholderHelper.PlaceholderResolver() { @Override public String resolvePlaceholder(String placeholderName) { if ("foo".equals(placeholderName)) { return "bar"; } else { return null; } } })); }