@Test public void testPlaceholderUtil_replaceVariables() { String hostName = "host1"; String ip = "127.0.0.1"; String clusterName = "test-cluster"; HashMap<String, String> contextParam = new HashMap<String, String>(); contextParam.put("host", hostName); contextParam.put("ip", ip); contextParam.put("cluster", clusterName); String resultStr = PlaceholderUtil.replaceVariables("$CLUSTER/logfeeder/$HOST-$IP/logs", contextParam); String expectedStr = clusterName + "/logfeeder/" + hostName + "-" + ip + "/logs"; assertEquals("Result string :" + resultStr + " is not equal to exptected string :" + expectedStr, resultStr, expectedStr); }
public static String replaceVariables(String inputStr, HashMap<String, String> contextParam) { Matcher m = placeHolderPattern.matcher(inputStr); String output = new String(inputStr); while (m.find()) { String placeholder = m.group(); if (placeholder != null && !placeholder.isEmpty()) { String key = placeholder.replace("$","").toLowerCase(); String replacement = getFromContext(contextParam, placeholder, key); output = output.replace(placeholder, replacement); } } return output; }
PlaceholderUtil { public static String replaceVariables(String inputStr, HashMap<String, String> contextParam) { Matcher m = placeHolderPattern.matcher(inputStr); String output = new String(inputStr); while (m.find()) { String placeholder = m.group(); if (placeholder != null && !placeholder.isEmpty()) { String key = placeholder.replace("$","").toLowerCase(); String replacement = getFromContext(contextParam, placeholder, key); output = output.replace(placeholder, replacement); } } return output; } }
PlaceholderUtil { public static String replaceVariables(String inputStr, HashMap<String, String> contextParam) { Matcher m = placeHolderPattern.matcher(inputStr); String output = new String(inputStr); while (m.find()) { String placeholder = m.group(); if (placeholder != null && !placeholder.isEmpty()) { String key = placeholder.replace("$","").toLowerCase(); String replacement = getFromContext(contextParam, placeholder, key); output = output.replace(placeholder, replacement); } } return output; } private  PlaceholderUtil(); }
PlaceholderUtil { public static String replaceVariables(String inputStr, HashMap<String, String> contextParam) { Matcher m = placeHolderPattern.matcher(inputStr); String output = new String(inputStr); while (m.find()) { String placeholder = m.group(); if (placeholder != null && !placeholder.isEmpty()) { String key = placeholder.replace("$","").toLowerCase(); String replacement = getFromContext(contextParam, placeholder, key); output = output.replace(placeholder, replacement); } } return output; } private  PlaceholderUtil(); static String replaceVariables(String inputStr, HashMap<String, String> contextParam); }
PlaceholderUtil { public static String replaceVariables(String inputStr, HashMap<String, String> contextParam) { Matcher m = placeHolderPattern.matcher(inputStr); String output = new String(inputStr); while (m.find()) { String placeholder = m.group(); if (placeholder != null && !placeholder.isEmpty()) { String key = placeholder.replace("$","").toLowerCase(); String replacement = getFromContext(contextParam, placeholder, key); output = output.replace(placeholder, replacement); } } return output; } private  PlaceholderUtil(); static String replaceVariables(String inputStr, HashMap<String, String> contextParam);  }