@Test public void testInterpolate() { Properties properties = new Properties(); properties.put("foo.x", "123"); properties.put("foo.y", "abc"); properties.put("foo.z", "bar"); InterpolationProperties props = new InterpolationProperties(properties); String result = props.interpolate( "123ajh${foo.z} akl ${foo.y}${foo.y} laskj ${foo.x}\n" + "foo.x${foo.x}${foo.x} ${foo.z}${foo.y}"); assertEquals("123ajhbar akl abcabc laskj 123\nfoo.x123123 barabc", result); }
public String interpolate(String input) { String result = input; Matcher matcher = PROPERTY_INTERPOLATION_PATTERN.matcher(result); while (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = (String) theProperties.get(propertyName); if (propertyValue == null) { throw new RuntimeException("Interpolation failed for missing property " + propertyName); } else { result = result.replace(matcher.group(), propertyValue).trim(); matcher.reset(result); } } return result; }
InterpolationProperties { public String interpolate(String input) { String result = input; Matcher matcher = PROPERTY_INTERPOLATION_PATTERN.matcher(result); while (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = (String) theProperties.get(propertyName); if (propertyValue == null) { throw new RuntimeException("Interpolation failed for missing property " + propertyName); } else { result = result.replace(matcher.group(), propertyValue).trim(); matcher.reset(result); } } return result; } }
InterpolationProperties { public String interpolate(String input) { String result = input; Matcher matcher = PROPERTY_INTERPOLATION_PATTERN.matcher(result); while (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = (String) theProperties.get(propertyName); if (propertyValue == null) { throw new RuntimeException("Interpolation failed for missing property " + propertyName); } else { result = result.replace(matcher.group(), propertyValue).trim(); matcher.reset(result); } } return result; } InterpolationProperties(Properties theProperties);  InterpolationProperties(String identifier);  InterpolationProperties(); }
InterpolationProperties { public String interpolate(String input) { String result = input; Matcher matcher = PROPERTY_INTERPOLATION_PATTERN.matcher(result); while (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = (String) theProperties.get(propertyName); if (propertyValue == null) { throw new RuntimeException("Interpolation failed for missing property " + propertyName); } else { result = result.replace(matcher.group(), propertyValue).trim(); matcher.reset(result); } } return result; } InterpolationProperties(Properties theProperties);  InterpolationProperties(String identifier);  InterpolationProperties(); void setProperty(String propName, String value); String getProperty(String propName); String interpolate(String input); static String readAll(InputStream input); }
InterpolationProperties { public String interpolate(String input) { String result = input; Matcher matcher = PROPERTY_INTERPOLATION_PATTERN.matcher(result); while (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = (String) theProperties.get(propertyName); if (propertyValue == null) { throw new RuntimeException("Interpolation failed for missing property " + propertyName); } else { result = result.replace(matcher.group(), propertyValue).trim(); matcher.reset(result); } } return result; } InterpolationProperties(Properties theProperties);  InterpolationProperties(String identifier);  InterpolationProperties(); void setProperty(String propName, String value); String getProperty(String propName); String interpolate(String input); static String readAll(InputStream input);  }