restored default ognl behavior

This commit is contained in:
Keith Donald
2008-01-18 16:36:23 +00:00
parent b535dc7522
commit 166ba72062
5 changed files with 44 additions and 11 deletions

View File

@@ -72,6 +72,7 @@ public class ELExpressionParser implements ExpressionParser {
}
public Expression parseExpression(String expressionString, ParserContext context) throws ParserException {
Assert.notNull(expressionString, "The expression string to parse is required");
if (context == null) {
context = NullParserContext.INSTANCE;
}

View File

@@ -31,9 +31,6 @@ import org.springframework.util.Assert;
/**
* Evaluates a parsed Ognl expression.
* <p>
* IMPLEMENTATION NOTE: Ognl 2.6.7 expression objects do not respect equality properly, so the equality operations
* defined within this class do not function properly.
*
* @author Keith Donald
*/
@@ -65,8 +62,6 @@ class OgnlExpression implements Expression {
if (!(o instanceof OgnlExpression)) {
return false;
}
// as late as Ognl 2.6.7, their expression objects don't implement equals
// so this always returns false
OgnlExpression other = (OgnlExpression) o;
return expression.equals(other.expression);
}
@@ -106,7 +101,6 @@ class OgnlExpression implements Expression {
ExpressionVariable var = variables[i];
variableMap.put(var.getName(), var.getValue());
}
System.out.println(variableMap);
return variableMap;
} else {
return Collections.EMPTY_MAP;

View File

@@ -81,10 +81,23 @@ public abstract class AbstractExpressionParser implements ExpressionParser {
}
public boolean isDelimitedExpression(String string) {
return string.startsWith(expressionPrefix) && string.endsWith(expressionSuffix);
int prefixIndex = string.indexOf(getExpressionPrefix());
if (prefixIndex == -1) {
return false;
}
int suffixIndex = string.indexOf(getExpressionSuffix(), prefixIndex);
if (suffixIndex == -1) {
return false;
} else {
// make sure there is actually something inside the ${}
if (suffixIndex == prefixIndex + getExpressionPrefix().length()) {
return false;
} else {
return true;
}
}
}
// TODO - add back 1.0 and 2.0 m1 semantics
public Expression parseExpression(String expressionString, ParserContext context) throws ParserException {
Assert.notNull(expressionString, "The expression string to parse is required");
Expression[] expressions = parseExpressions(expressionString, context);
@@ -110,7 +123,7 @@ public abstract class AbstractExpressionParser implements ExpressionParser {
while (startIdx < expressionString.length()) {
int prefixIndex = expressionString.indexOf(getExpressionPrefix(), startIdx);
if (prefixIndex >= startIdx) {
// an expression was found
// a inner expression was found - this is a composite
if (prefixIndex > startIdx) {
expressions.add(new StaticExpression(expressionString.substring(startIdx, prefixIndex)));
startIdx = prefixIndex;
@@ -138,8 +151,13 @@ public abstract class AbstractExpressionParser implements ExpressionParser {
startIdx = suffixIndex + 1;
}
} else {
// no more evaluatable ${expressions} found in string
expressions.add(new StaticExpression(expressionString.substring(startIdx)));
if (startIdx == 0) {
// treat the entire string as one expression
expressions.add(doParseExpression(expressionString, context));
} else {
// no more ${expressions} found in string, add rest as static text
expressions.add(new StaticExpression(expressionString.substring(startIdx)));
}
startIdx = expressionString.length();
}
}