org.springframework.web.util
Class ExpressionEvaluationUtils

java.lang.Object
  extended by org.springframework.web.util.ExpressionEvaluationUtils

public abstract class ExpressionEvaluationUtils
extends java.lang.Object

Convenience methods for accessing JSP 2.0's javax.servlet.jsp.el.ExpressionEvaluator.

The evaluation methods check if the value contains "${" before invoking the EL evaluator, treating the value as "normal" expression (i.e. a literal String value) else.

See isSpringJspExpressionSupportActive(PageContext) for guidelines on when to use Spring's JSP expression support as opposed to the built-in expression support in JSP 2.0+ containers.

Since:
11.07.2003
Author:
Juergen Hoeller, Alef Arendsen
See Also:
javax.servlet.jsp.el.ExpressionEvaluator#evaluate

Field Summary
static java.lang.String EXPRESSION_PREFIX
           
static java.lang.String EXPRESSION_SUFFIX
           
static java.lang.String EXPRESSION_SUPPORT_CONTEXT_PARAM
          Expression support parameter at the servlet context level (i.e.
 
Constructor Summary
ExpressionEvaluationUtils()
           
 
Method Summary
private static java.lang.Object doEvaluate(java.lang.String attrName, java.lang.String attrValue, java.lang.Class resultClass, PageContext pageContext)
          Actually evaluate the given expression (be it EL or a literal String value) to an Object of a given type.
static java.lang.Object evaluate(java.lang.String attrName, java.lang.String attrValue, java.lang.Class resultClass, PageContext pageContext)
          Evaluate the given expression (be it EL or a literal String value) to an Object of a given type,
static java.lang.Object evaluate(java.lang.String attrName, java.lang.String attrValue, PageContext pageContext)
          Evaluate the given expression (be it EL or a literal String value) to an Object.
static boolean evaluateBoolean(java.lang.String attrName, java.lang.String attrValue, PageContext pageContext)
          Evaluate the given expression (be it EL or a literal String value) to a boolean.
private static java.lang.Object evaluateExpression(java.lang.String exprValue, java.lang.Class resultClass, PageContext pageContext)
           
static int evaluateInteger(java.lang.String attrName, java.lang.String attrValue, PageContext pageContext)
          Evaluate the given expression (be it EL or a literal String value) to an integer.
static java.lang.String evaluateString(java.lang.String attrName, java.lang.String attrValue, PageContext pageContext)
          Evaluate the given expression (be it EL or a literal String value) to a String.
static boolean isExpressionLanguage(java.lang.String value)
          Check if the given expression value is an EL expression.
static boolean isSpringJspExpressionSupportActive(PageContext pageContext)
          Check whether Spring's JSP expression support is actually active.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXPRESSION_SUPPORT_CONTEXT_PARAM

public static final java.lang.String EXPRESSION_SUPPORT_CONTEXT_PARAM
Expression support parameter at the servlet context level (i.e. a context-param in web.xml): "springJspExpressionSupport".

See Also:
Constant Field Values

EXPRESSION_PREFIX

public static final java.lang.String EXPRESSION_PREFIX
See Also:
Constant Field Values

EXPRESSION_SUFFIX

public static final java.lang.String EXPRESSION_SUFFIX
See Also:
Constant Field Values
Constructor Detail

ExpressionEvaluationUtils

public ExpressionEvaluationUtils()
Method Detail

isSpringJspExpressionSupportActive

public static boolean isSpringJspExpressionSupportActive(PageContext pageContext)
Check whether Spring's JSP expression support is actually active.

Note that JSP 2.0+ containers come with expression support themselves: However, it will only be active for web applications declaring Servlet 2.4 or higher in their web.xml deployment descriptor.

If a web.xml context-param named "springJspExpressionSupport" is found, its boolean value will be taken to decide whether this support is active. If not found, the default is for expression support to be inactive on Servlet 3.0 containers with web applications declaring Servlet 2.4 or higher in their web.xml. For backwards compatibility, Spring's expression support will remain active for applications declaring Servlet 2.3 or earlier. However, on Servlet 2.4/2.5 containers, we can't find out what the application has declared, so we'll also fall back to keeping expression support active in such a case.

Recommendations: Explicitly set "springJspExpressionSupport" to "false" in order to prevent double evaluation for Servlet 2.4+ based applications. On Servlet 3.0 containers, this will be done for you by default by the framework. If for some reason you nevertheless want Spring's JSP expression support to be active, explicitly set the "springJspExpressionSupport" context-param to "true".

Parameters:
pageContext - current JSP PageContext
Returns:
true if active (ExpressionEvaluationUtils will actually evaluate expressions); false if not active (ExpressionEvaluationUtils will return given values as-is, relying on the JSP container pre-evaluating values before passing them to JSP tag attributes)

isExpressionLanguage

public static boolean isExpressionLanguage(java.lang.String value)
Check if the given expression value is an EL expression.

Parameters:
value - the expression to check
Returns:
true if the expression is an EL expression, false otherwise

evaluate

public static java.lang.Object evaluate(java.lang.String attrName,
                                        java.lang.String attrValue,
                                        java.lang.Class resultClass,
                                        PageContext pageContext)
                                 throws JspException
Evaluate the given expression (be it EL or a literal String value) to an Object of a given type,

Parameters:
attrName - name of the attribute (typically a JSP tag attribute)
attrValue - value of the attribute
resultClass - class that the result should have (String, Integer, Boolean)
pageContext - current JSP PageContext
Returns:
the result of the evaluation
Throws:
JspException - in case of parsing errors, also in case of type mismatch if the passed-in literal value is not an EL expression and not assignable to the result class

evaluate

public static java.lang.Object evaluate(java.lang.String attrName,
                                        java.lang.String attrValue,
                                        PageContext pageContext)
                                 throws JspException
Evaluate the given expression (be it EL or a literal String value) to an Object.

Parameters:
attrName - name of the attribute (typically a JSP tag attribute)
attrValue - value of the attribute
pageContext - current JSP PageContext
Returns:
the result of the evaluation
Throws:
JspException - in case of parsing errors

evaluateString

public static java.lang.String evaluateString(java.lang.String attrName,
                                              java.lang.String attrValue,
                                              PageContext pageContext)
                                       throws JspException
Evaluate the given expression (be it EL or a literal String value) to a String.

Parameters:
attrName - name of the attribute (typically a JSP tag attribute)
attrValue - value of the attribute
pageContext - current JSP PageContext
Returns:
the result of the evaluation
Throws:
JspException - in case of parsing errors

evaluateInteger

public static int evaluateInteger(java.lang.String attrName,
                                  java.lang.String attrValue,
                                  PageContext pageContext)
                           throws JspException
Evaluate the given expression (be it EL or a literal String value) to an integer.

Parameters:
attrName - name of the attribute (typically a JSP tag attribute)
attrValue - value of the attribute
pageContext - current JSP PageContext
Returns:
the result of the evaluation
Throws:
JspException - in case of parsing errors

evaluateBoolean

public static boolean evaluateBoolean(java.lang.String attrName,
                                      java.lang.String attrValue,
                                      PageContext pageContext)
                               throws JspException
Evaluate the given expression (be it EL or a literal String value) to a boolean.

Parameters:
attrName - name of the attribute (typically a JSP tag attribute)
attrValue - value of the attribute
pageContext - current JSP PageContext
Returns:
the result of the evaluation
Throws:
JspException - in case of parsing errors

doEvaluate

private static java.lang.Object doEvaluate(java.lang.String attrName,
                                           java.lang.String attrValue,
                                           java.lang.Class resultClass,
                                           PageContext pageContext)
                                    throws JspException
Actually evaluate the given expression (be it EL or a literal String value) to an Object of a given type. Supports concatenated expressions, for example: "${var1}text${var2}"

Parameters:
attrName - name of the attribute
attrValue - value of the attribute
resultClass - class that the result should have
pageContext - current JSP PageContext
Returns:
the result of the evaluation
Throws:
JspException - in case of parsing errors

evaluateExpression

private static java.lang.Object evaluateExpression(java.lang.String exprValue,
                                                   java.lang.Class resultClass,
                                                   PageContext pageContext)
                                            throws ELException
Throws:
ELException