Search in sources :

Example 1 with FunctionMapperImpl

use of org.apache.sling.scripting.jsp.jasper.el.FunctionMapperImpl in project sling by apache.

the class PageContextImpl method proprietaryEvaluate.

/**
	 * Proprietary method to evaluate EL expressions. XXX - This method should
	 * go away once the EL interpreter moves out of JSTL and into its own
	 * project. For now, this is necessary because the standard machinery is too
	 * slow.
	 *
	 * @param expression
	 *            The expression to be evaluated
	 * @param expectedType
	 *            The expected resulting type
	 * @param pageContext
	 *            The page context
	 * @param functionMap
	 *            Maps prefix and name to Method
	 * @return The result of the evaluation
	 */
public static Object proprietaryEvaluate(final String expression, final Class expectedType, final PageContext pageContext, final ProtectedFunctionMapper functionMap, final boolean escape) throws ELException {
    Object retValue;
    final ExpressionFactory exprFactory = JspFactory.getDefaultFactory().getJspApplicationContext(pageContext.getServletContext()).getExpressionFactory();
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            retValue = AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws Exception {
                    ELContextImpl ctx = (ELContextImpl) pageContext.getELContext();
                    ctx.setFunctionMapper(new FunctionMapperImpl(functionMap));
                    ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
                    return ve.getValue(ctx);
                }
            });
        } catch (PrivilegedActionException ex) {
            Exception realEx = ex.getException();
            if (realEx instanceof ELException) {
                throw (ELException) realEx;
            } else {
                throw new ELException(realEx);
            }
        }
    } else {
        ELContextImpl ctx = (ELContextImpl) pageContext.getELContext();
        ctx.setFunctionMapper(new FunctionMapperImpl(functionMap));
        ValueExpression ve = exprFactory.createValueExpression(ctx, expression, expectedType);
        retValue = ve.getValue(ctx);
    }
    if (escape && retValue != null) {
        retValue = XmlEscape(retValue.toString());
    }
    return retValue;
}
Also used : FunctionMapperImpl(org.apache.sling.scripting.jsp.jasper.el.FunctionMapperImpl) ExpressionFactory(javax.el.ExpressionFactory) PrivilegedActionException(java.security.PrivilegedActionException) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.sling.scripting.jsp.jasper.el.ELContextImpl) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ELException(javax.servlet.jsp.el.ELException) ServletException(javax.servlet.ServletException) JspException(javax.servlet.jsp.JspException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) ELException(javax.servlet.jsp.el.ELException) SlingPageException(org.apache.sling.scripting.jsp.SlingPageException)

Aggregations

IOException (java.io.IOException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ExpressionFactory (javax.el.ExpressionFactory)1 ValueExpression (javax.el.ValueExpression)1 ServletException (javax.servlet.ServletException)1 JspException (javax.servlet.jsp.JspException)1 ELException (javax.servlet.jsp.el.ELException)1 SlingPageException (org.apache.sling.scripting.jsp.SlingPageException)1 ELContextImpl (org.apache.sling.scripting.jsp.jasper.el.ELContextImpl)1 FunctionMapperImpl (org.apache.sling.scripting.jsp.jasper.el.FunctionMapperImpl)1