1 18 19 package org.apache.roller.util; 20 21 import java.util.Map ; 22 import java.util.regex.Matcher ; 23 import java.util.regex.Pattern ; 24 25 32 public class PropertyExpander { 33 private PropertyExpander() { 34 } 35 36 private static final Pattern EXPANSION_PATTERN = Pattern.compile("(\\$\\{([^}]+?)\\})", java.util.regex.Pattern.MULTILINE); 38 39 55 public static String expandProperties(String input, Map props) { 56 if (input == null) return null; 57 58 Matcher matcher = EXPANSION_PATTERN.matcher(input); 59 60 StringBuffer expanded = new StringBuffer (input.length()); 61 while (matcher.find()) { 62 String propName = matcher.group(2); 63 String value = (String ) props.get(propName); 64 if (value == null) value = matcher.group(0); 66 matcher.appendReplacement(expanded, ""); 68 expanded.append(value); 69 } 70 matcher.appendTail(expanded); 71 72 return expanded.toString(); 73 } 74 75 83 public static String expandSystemProperties(String input) { 84 return expandProperties(input, System.getProperties()); 85 } 86 } 87 | Popular Tags |