@Test public void test() { Properties p = new Properties(); p.put("foo", "bar"); p.put("car", "cdr"); assert "This is a bar test".equals(Utils.subst("This is a ${foo} test", p)); assert "This is a bar cdr test".equals(Utils.subst("This is a ${foo} ${car} ${oops}test", p)); assert "This is a bar cdr tes${t".equals(Utils.subst("This is a ${foo} ${car} ${oops}tes${t", p)); }
public static String subst(String string, Map dictionary) { LOGGER.entering(CLASS_NAME, "subst", new Object[]{string, dictionary}); Pattern pattern = Pattern.compile(VARIABLE_PATTERN); Matcher matcher = pattern.matcher(string); while (matcher.find()) { String value = (String)dictionary.get(matcher.group(1)); if (value == null) value = ""; string = string.replace(matcher.group(0), value); matcher.reset(string); } matcher.reset(); LOGGER.exiting(CLASS_NAME, "subst", string); return string; }
Utils { public static String subst(String string, Map dictionary) { LOGGER.entering(CLASS_NAME, "subst", new Object[]{string, dictionary}); Pattern pattern = Pattern.compile(VARIABLE_PATTERN); Matcher matcher = pattern.matcher(string); while (matcher.find()) { String value = (String)dictionary.get(matcher.group(1)); if (value == null) value = ""; string = string.replace(matcher.group(0), value); matcher.reset(string); } matcher.reset(); LOGGER.exiting(CLASS_NAME, "subst", string); return string; } }
Utils { public static String subst(String string, Map dictionary) { LOGGER.entering(CLASS_NAME, "subst", new Object[]{string, dictionary}); Pattern pattern = Pattern.compile(VARIABLE_PATTERN); Matcher matcher = pattern.matcher(string); while (matcher.find()) { String value = (String)dictionary.get(matcher.group(1)); if (value == null) value = ""; string = string.replace(matcher.group(0), value); matcher.reset(string); } matcher.reset(); LOGGER.exiting(CLASS_NAME, "subst", string); return string; } private  Utils(); }
Utils { public static String subst(String string, Map dictionary) { LOGGER.entering(CLASS_NAME, "subst", new Object[]{string, dictionary}); Pattern pattern = Pattern.compile(VARIABLE_PATTERN); Matcher matcher = pattern.matcher(string); while (matcher.find()) { String value = (String)dictionary.get(matcher.group(1)); if (value == null) value = ""; string = string.replace(matcher.group(0), value); matcher.reset(string); } matcher.reset(); LOGGER.exiting(CLASS_NAME, "subst", string); return string; } private  Utils(); static String subst(String string, Map dictionary); static Map<String, String> toMap(ServiceReference reference); }
Utils { public static String subst(String string, Map dictionary) { LOGGER.entering(CLASS_NAME, "subst", new Object[]{string, dictionary}); Pattern pattern = Pattern.compile(VARIABLE_PATTERN); Matcher matcher = pattern.matcher(string); while (matcher.find()) { String value = (String)dictionary.get(matcher.group(1)); if (value == null) value = ""; string = string.replace(matcher.group(0), value); matcher.reset(string); } matcher.reset(); LOGGER.exiting(CLASS_NAME, "subst", string); return string; } private  Utils(); static String subst(String string, Map dictionary); static Map<String, String> toMap(ServiceReference reference);  }