public static String expand(String str, Configuration variables,
	    FacetList fl) {
	if (variables == null || str == null)
	    return str;

	String res = str;

	Pattern pattern = Pattern.compile("\\$\\{([^\\}]*)\\}");
	for (;;) {
	    Matcher m = pattern.matcher(res);
	    if (!m.find())
		break;

	    String varName = m.group(1);
	    String val;
	    if ("filename".equals(varName) && fl != null) {
		val = fl.getSource();
	    } else {
		val = variables.getParam(varName);
	    }
	    res = res.replace(m.group(0), (val == null) ? "" : val);
	}
	return res;
    }