Created
March 18, 2009 15:39
-
-
Save raykrueger/81197 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TokenReplacement { | |
private static final Logger log = | |
LoggerFactory.getLogger(TokenReplacement.class); | |
private static final Pattern TOKEN_PATTERN = Pattern.compile("\\$\\{(.*?)\\}"); | |
public static String replaceTokens(final String input, Properties props) { | |
Matcher matcher = TOKEN_PATTERN.matcher(input); | |
StringBuilder output = new StringBuilder(); | |
while (matcher.find()) { | |
if (log.isDebugEnabled()) { | |
log.debug("Found the text \"{}\" starting at " + | |
"index {} and ending at index {}", | |
new Object[]{matcher.group(), matcher.start(), matcher.end()}); | |
} | |
matcher.appendReplacement(output, props.getProperty(matcher.group(1))); | |
} | |
matcher.appendTail(output); | |
return output.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment