@Test public void testReplaceProperty() throws Exception { String s = ConfigUtils.replaceProperty("1${a.b.c}2${a.b.c}3", Collections.singletonMap("a.b.c", "ABC")); assertEquals(s, "1ABC2ABC3"); s = ConfigUtils.replaceProperty("1${a.b.c}2${a.b.c}3", Collections.<String, String>emptyMap()); assertEquals(s, "123"); }
public static String replaceProperty(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0 || expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = System.getProperty(key); if (value == null && params != null) { value = params.get(key); } if (value == null) { value = ""; } matcher.appendReplacement(sb, Matcher.quoteReplacement(value)); } matcher.appendTail(sb); return sb.toString(); }
ConfigUtils { public static String replaceProperty(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0 || expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = System.getProperty(key); if (value == null && params != null) { value = params.get(key); } if (value == null) { value = ""; } matcher.appendReplacement(sb, Matcher.quoteReplacement(value)); } matcher.appendTail(sb); return sb.toString(); } }
ConfigUtils { public static String replaceProperty(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0 || expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = System.getProperty(key); if (value == null && params != null) { value = params.get(key); } if (value == null) { value = ""; } matcher.appendReplacement(sb, Matcher.quoteReplacement(value)); } matcher.appendTail(sb); return sb.toString(); } private  ConfigUtils(); }
ConfigUtils { public static String replaceProperty(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0 || expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = System.getProperty(key); if (value == null && params != null) { value = params.get(key); } if (value == null) { value = ""; } matcher.appendReplacement(sb, Matcher.quoteReplacement(value)); } matcher.appendTail(sb); return sb.toString(); } private  ConfigUtils(); static boolean isNotEmpty(String value); static boolean isEmpty(String value); static boolean isDefault(String value); static List<String> mergeValues(Class<?> type, String cfg, List<String> def); static String replaceProperty(String expression, Map<String, String> params); static Properties getProperties(); static void setProperties(Properties properties); static void addProperties(Properties properties); static String getProperty(String key); @SuppressWarnings({"unchecked", "rawtypes"}) static String getProperty(String key, String defaultValue); static String getSystemProperty(String key); static Properties loadProperties(String fileName); static Properties loadProperties(String fileName, boolean allowMultiFile); static Properties loadProperties(String fileName, boolean allowMultiFile, boolean optional); static int getPid(); @SuppressWarnings("deprecation") static int getServerShutdownTimeout(); }
ConfigUtils { public static String replaceProperty(String expression, Map<String, String> params) { if (expression == null || expression.length() == 0 || expression.indexOf('$') < 0) { return expression; } Matcher matcher = VARIABLE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String key = matcher.group(1); String value = System.getProperty(key); if (value == null && params != null) { value = params.get(key); } if (value == null) { value = ""; } matcher.appendReplacement(sb, Matcher.quoteReplacement(value)); } matcher.appendTail(sb); return sb.toString(); } private  ConfigUtils(); static boolean isNotEmpty(String value); static boolean isEmpty(String value); static boolean isDefault(String value); static List<String> mergeValues(Class<?> type, String cfg, List<String> def); static String replaceProperty(String expression, Map<String, String> params); static Properties getProperties(); static void setProperties(Properties properties); static void addProperties(Properties properties); static String getProperty(String key); @SuppressWarnings({"unchecked", "rawtypes"}) static String getProperty(String key, String defaultValue); static String getSystemProperty(String key); static Properties loadProperties(String fileName); static Properties loadProperties(String fileName, boolean allowMultiFile); static Properties loadProperties(String fileName, boolean allowMultiFile, boolean optional); static int getPid(); @SuppressWarnings("deprecation") static int getServerShutdownTimeout();  }