Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@42 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
1 changed files with 1 additions and 1 deletions
@ -1 +1 @@
@@ -1 +1 @@
|
||||
package org.springframework.expression.common;
import java.util.LinkedList;
import java.util.List;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.ParseException;
import org.springframework.expression.ParserContext;
/**
* An expression parser that understands templates. It can be subclassed by expression parsers that do not offer first
* class support for templating.
*
* @author Keith Donald
* @author Andy Clement
*/
/**
* An expression parser that understands templates. It can be subclassed by expression parsers that do not offer first
* class support for templating.
*
* @author Keith Donald
* @author Andy Clement
*/
* @author Keith Donald
/**
private Expression parseTemplate(String expressionString, ParserContext context) throws ParseException {
// TODO what about zero length expressions?
Expression[] expressions = parseExpressions(expressionString, context);
if (expressions.length == 1) {
return expressions[0];
} else {
return new CompositeStringExpression(expressionString, expressions);
* @author Keith Donald
/**
// helper methods
/**
* Helper that parses given expression string using the configured parser. The expression string can contain any
* number of expressions all contained in "${...}" markers. For instance: "foo${expr0}bar${expr1}". The static
* pieces of text will also be returned as Expressions that just return that static piece of text. As a result,
* evaluating all returned expressions and concatenating the results produces the complete evaluated string.
* Unwrapping is only done of the outermost delimiters found, so the string 'hello ${foo${abc}}' would break into
* the pieces 'hello ' and 'foo${abc}'. This means that expression languages that used ${..} as part of their
* functionality are supported without any problem
*
* @param expressionString the expression string
* @return the parsed expressions
* @throws ParseException when the expressions cannot be parsed
*/
private final Expression[] parseExpressions(String expressionString, ParserContext context)
throws ParseException {
// TODO this needs to handle nested delimiters for cases where the expression uses the delim chars
List<Expression> expressions = new LinkedList<Expression>();
int startIdx = 0;
String prefix = context.getExpressionPrefix();
String suffix = context.getExpressionSuffix();
* class support for templating.
* class support for templating.
if (prefixIndex >= startIdx) {
// a inner expression was found - this is a composite
if (prefixIndex > startIdx) {
expressions.add(new LiteralExpression(expressionString.substring(startIdx, prefixIndex)));
* class support for templating.
*
}
int nextPrefixIndex = expressionString.indexOf(prefix, prefixIndex + prefix.length());
int suffixIndex;
*
*
suffixIndex = expressionString.lastIndexOf(suffix);
} else {
*
* class support for templating.
suffixIndex = expressionString.lastIndexOf(suffix, nextPrefixIndex);
}
if (suffixIndex < (prefixIndex + prefix.length())) {
throw new ParseException(expressionString, "No ending suffix '" + suffix
+ "' for expression starting at character " + prefixIndex + ": "
+ expressionString.substring(prefixIndex), null);
* @author Keith Donald
* @author Keith Donald
+ suffix + "' at character " + prefixIndex, null);
} else {
String expr = expressionString.substring(prefixIndex + prefix.length(), suffixIndex);
expressions.add(doParseExpression(expr, context));
startIdx = suffixIndex +suffix.length();
}
} else {
if (startIdx == 0) {
expressions.add(doParseExpression(expressionString, context));
} else {
// no more ${expressions} found in string, add rest as static text
expressions.add(new LiteralExpression(expressionString.substring(startIdx)));
}
startIdx = expressionString.length();
}
}
return expressions.toArray(new Expression[expressions.size()]);
}
protected abstract Expression doParseExpression(String expressionString, ParserContext context)
throws ParseException;
} |
||||
package org.springframework.expression.common;
import java.util.LinkedList;
import java.util.List;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.ParseException;
import org.springframework.expression.ParserContext;
/**
* An expression parser that understands templates. It can be subclassed by expression parsers that do not offer first
* class support for templating.
* @author Andy Clement
* @author Andy Clement
* @author Andy Clement
/**
* @author Andy Clement
* An expression parser that understands templates. It can be subclassed by expression parsers that do not offer first
* @author Andy Clement
* class support for templating.
* @author Andy Clement
*
* @author Andy Clement
* @author Keith Donald
* @author Andy Clement
* @author Andy Clement
* @author Andy Clement
*/
*/
if (context == null) {
*/
}
if (context.isTemplate()) {
return parseTemplate(expressionString, context);
} else {
return doParseExpression(expressionString, context);
}
}
private Expression parseTemplate(String expressionString, ParserContext context) throws ParseException {
if (expressionString.length() == 0) {
}
/**
* An expression parser that understands templates. It can be subclassed by expression parsers that do not offer first
} else {
* class support for templating.
}
}
*
* @author Keith Donald
* @author Andy Clement
*/
public Expression parseExpression(String expressionString) throws ParseException {
* pieces of text will also be returned as Expressions that just return that static piece of text. As a result,
public Expression parseExpression(String expressionString) throws ParseException {
/**
public final Expression parseExpression(String expressionString, ParserContext context) throws ParseException {
* functionality are supported without any problem
*
public Expression parseExpression(String expressionString) throws ParseException {
* @author Keith Donald
if (context.isTemplate()) {
* @throws ParseException when the expressions cannot be parsed
private final Expression[] parseExpressions(String expressionString, ParserContext context) throws ParseException {
private Expression parseTemplate(String expressionString, ParserContext context) throws ParseException {
// TODO what about zero length expressions?
Expression[] expressions = parseExpressions(expressionString, context);
if (expressions.length == 1) {
return expressions[0];
* @author Keith Donald
// helper methods
/**
* Helper that parses given expression string using the configured parser. The expression string can contain any
* number of expressions all contained in "${...}" markers. For instance: "foo${expr0}bar${expr1}". The static
* pieces of text will also be returned as Expressions that just return that static piece of text. As a result,
* evaluating all returned expressions and concatenating the results produces the complete evaluated string.
* Unwrapping is only done of the outermost delimiters found, so the string 'hello ${foo${abc}}' would break into
* the pieces 'hello ' and 'foo${abc}'. This means that expression languages that used ${..} as part of their
* functionality are supported without any problem
*
* @param expressionString the expression string
* @return the parsed expressions
* @throws ParseException when the expressions cannot be parsed
*/
}
private final Expression[] parseExpressions(String expressionString, ParserContext context)
throws ParseException {
// TODO this needs to handle nested delimiters for cases where the expression uses the delim chars
List<Expression> expressions = new LinkedList<Expression>();
int startIdx = 0;
String prefix = context.getExpressionPrefix();
String suffix = context.getExpressionSuffix();
public final Expression parseExpression(String expressionString, ParserContext context) throws ParseException {
* class support for templating.
* class support for templating.
if (context == null) {
suffix.length();
}
} else {
if (startIdx == 0) {
expressions.add(doParseExpression(expressionString, context));
} else {
// no more ${expressions} found in string, add rest as static text
expressions.add(new LiteralExpression(expressionString.substring(startIdx)));
}
startIdx = expressionString.length();
}
}
return expressions.toArray(new Expression[expressions.size()]);
}
protected abstract Expression doParseExpression(String expressionString, ParserContext context)
throws ParseException;
} |
||||
Loading…
Reference in new issue