public static String subst(String string, Map dictionary)
    {
        LOGGER.entering(CLASS_NAME, "subst", new Object[]{string, dictionary});

        Pattern pattern = Pattern.compile(VARIABLE_PATTERN);
        Matcher matcher = pattern.matcher(string);

        while (matcher.find())
        {
            String value = (String)dictionary.get(matcher.group(1));

            if (value == null) value = "";

            string = string.replace(matcher.group(0), value);
            matcher.reset(string);
        }
        matcher.reset();

        LOGGER.exiting(CLASS_NAME, "subst", string);

        return string;
    }
public static String subst ( String string , Map dictionary ) { LOGGER . entering ( CLASS_NAME , "subst" , new Object [ ] { string , dictionary } ) ; Pattern pattern = Pattern . compile ( VARIABLE_PATTERN ) ; Matcher matcher = pattern . matcher ( string ) ; while ( matcher . find ( ) ) { String value = ( String ) dictionary . get ( matcher . group ( 1 ) ) ; if ( value == null ) value = "" ; string = string . replace ( matcher . group ( 0 ) , value ) ; matcher . reset ( string ) ; } matcher . reset ( ) ; LOGGER . exiting ( CLASS_NAME , "subst" , string ) ; return string ; }
Substitute variables surrounded by <code>${</code> and <code>}</code>.
The variables' values come from the dicionary that is also passed along.
Variables that have no values in the dictionary are removed from the
final string result.

@param string     the original string w/ variables
@param dictionary the dictionary with variables' values
@return the orginal string with variables substituted