private String substituteVariables ( String template , String patternString , Map < String , String > variables ) { Pattern pattern = Pattern . compile ( patternString ) ; Matcher matcher = pattern . matcher ( template ) ; StringBuffer buffer = new StringBuffer ( ) ; while ( matcher . find ( ) ) { if ( variables . containsKey ( matcher . group ( 1 ) ) ) { String replacement = variables . get ( matcher . group ( 1 ) ) ; // quote to work properly with $ and {,} signs matcher . appendReplacement ( buffer , replacement != null ? Matcher . quoteReplacement ( replacement ) : "null" ) ; } } matcher . appendTail ( buffer ) ; return buffer . toString ( ) ; }
Replace variables with given pattern .