private String replace(String string, Properties table) { try { Pattern pattern = Pattern.compile("\\$\\{\\w+\\}"); Matcher matcher = pattern.matcher(string); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String group = matcher.group(); String key = group.substring(2, group.length() - 1).trim(); String repl = table.getProperty(key); if (repl == null) repl = matcher.quoteReplacement(group); matcher.appendReplacement(sb, repl); } matcher.appendTail(sb); return sb.toString(); } catch (Exception ex) { return string; } }
protected String getProperty(String key) { return properties.getProperty(key); }