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 ExpressionEvaluator.

This class will by default use standard evaluate calls. If your application server happens to be inefficient in that respect, consider setting Spring's "cacheJspExpressions" context-param in web.xml to "true", which will use parseExpression calls with cached Expression objects instead.

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.

Since:
11.07.2003
Author:
Juergen Hoeller, Alef Arendsen
See Also:
ExpressionEvaluator.evaluate(java.lang.String, java.lang.Class, javax.servlet.jsp.el.VariableResolver, javax.servlet.jsp.el.FunctionMapper), ExpressionEvaluator.parseExpression(java.lang.String, java.lang.Class, javax.servlet.jsp.el.FunctionMapper)

Field Summary
static java.lang.String EXPRESSION_CACHE_CONTEXT_PARAM
          JSP 2.0 expression cache parameter at the servlet context level (i.e.
static java.lang.String EXPRESSION_PREFIX
           
static java.lang.String EXPRESSION_SUFFIX
           
 
Constructor Summary
ExpressionEvaluationUtils()
           
 
Method Summary
static java.lang.Object evaluate(java.lang.String attrName, java.lang.String attrValue, java.lang.Class resultClass, javax.servlet.jsp.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, javax.servlet.jsp.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, javax.servlet.jsp.PageContext pageContext)
          Evaluate the given expression (be it EL or a literal String value) to a boolean.
static int evaluateInteger(java.lang.String attrName, java.lang.String attrValue, javax.servlet.jsp.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, javax.servlet.jsp.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXPRESSION_CACHE_CONTEXT_PARAM

public static final java.lang.String EXPRESSION_CACHE_CONTEXT_PARAM
JSP 2.0 expression cache parameter at the servlet context level (i.e. a context-param in web.xml): "cacheJspExpressions".

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

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,
                                        javax.servlet.jsp.PageContext pageContext)
                                 throws javax.servlet.jsp.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:
javax.servlet.jsp.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,
                                        javax.servlet.jsp.PageContext pageContext)
                                 throws javax.servlet.jsp.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:
javax.servlet.jsp.JspException - in case of parsing errors

evaluateString

public static java.lang.String evaluateString(java.lang.String attrName,
                                              java.lang.String attrValue,
                                              javax.servlet.jsp.PageContext pageContext)
                                       throws javax.servlet.jsp.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:
javax.servlet.jsp.JspException - in case of parsing errors

evaluateInteger

public static int evaluateInteger(java.lang.String attrName,
                                  java.lang.String attrValue,
                                  javax.servlet.jsp.PageContext pageContext)
                           throws javax.servlet.jsp.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:
javax.servlet.jsp.JspException - in case of parsing errors

evaluateBoolean

public static boolean evaluateBoolean(java.lang.String attrName,
                                      java.lang.String attrValue,
                                      javax.servlet.jsp.PageContext pageContext)
                               throws javax.servlet.jsp.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:
javax.servlet.jsp.JspException - in case of parsing errors