in gshell-bootstrap/src/main/java/org/apache/geronimo/gshell/bootstrap/ExpressionEvaluator.java [54:105]
public static String evaluate(final String input, final Properties props) throws IllegalArgumentException {
StringBuffer sbuf = new StringBuffer();
int i = 0;
int j, k;
while (true) {
j = input.indexOf(DELIM_START, i);
if (j == -1) {
// no more variables
if (i == 0) { // this is a simple string
return input;
}
else { // add the tail string which contails no variables and return the result.
sbuf.append(input.substring(i, input.length()));
return sbuf.toString();
}
}
else {
sbuf.append(input.substring(i, j));
k = input.indexOf(DELIM_STOP, j);
if (k == -1) {
throw new IllegalArgumentException('"' + input + "\" has no closing brace. Opening brace at position " + j);
}
else {
j += DELIM_START_LEN;
String key = input.substring(j, k);
// first try in System properties
String replacement = getSystemProperty(key);
// then try props parameter
if (replacement == null && props != null) {
replacement = props.getProperty(key);
}
if (replacement != null) {
// Do variable substitution on the replacement string
// such that we can solve "Hello ${x2}" as "Hello p1"
// the where the properties are
// x1=p1
// x2=${x1}
String recursiveReplacement = evaluate(replacement, props);
sbuf.append(recursiveReplacement);
}
i = k + DELIM_STOP_LEN;
}
}
}
}