Search in sources :

Example 1 with ELContextImpl

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

the class JspApplicationContextImpl method createELContext.

public ELContextImpl createELContext(JspContext context) {
    if (context == null) {
        throw new IllegalArgumentException("JspContext was null");
    }
    // create ELContext for JspContext
    ELResolver r = this.createELResolver();
    ELContextImpl ctx = new ELContextImpl(r);
    ctx.putContext(JspContext.class, context);
    // alert all ELContextListeners
    ELContextEvent event = new ELContextEvent(ctx);
    for (int i = 0; i < this.contextListeners.size(); i++) {
        this.contextListeners.get(i).contextCreated(event);
    }
    return ctx;
}
Also used : ListELResolver(javax.el.ListELResolver) BeanELResolver(javax.el.BeanELResolver) ELResolver(javax.el.ELResolver) ImplicitObjectELResolver(javax.servlet.jsp.el.ImplicitObjectELResolver) ResourceBundleELResolver(javax.el.ResourceBundleELResolver) MapELResolver(javax.el.MapELResolver) ArrayELResolver(javax.el.ArrayELResolver) CompositeELResolver(javax.el.CompositeELResolver) ScopedAttributeELResolver(javax.servlet.jsp.el.ScopedAttributeELResolver) ELContextImpl(org.apache.sling.scripting.jsp.jasper.el.ELContextImpl) ELContextEvent(javax.el.ELContextEvent)

Example 2 with ELContextImpl

use of org.apache.sling.scripting.jsp.jasper.el.ELContextImpl 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

ELContextImpl (org.apache.sling.scripting.jsp.jasper.el.ELContextImpl)2 IOException (java.io.IOException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayELResolver (javax.el.ArrayELResolver)1 BeanELResolver (javax.el.BeanELResolver)1 CompositeELResolver (javax.el.CompositeELResolver)1 ELContextEvent (javax.el.ELContextEvent)1 ELResolver (javax.el.ELResolver)1 ExpressionFactory (javax.el.ExpressionFactory)1 ListELResolver (javax.el.ListELResolver)1 MapELResolver (javax.el.MapELResolver)1 ResourceBundleELResolver (javax.el.ResourceBundleELResolver)1 ValueExpression (javax.el.ValueExpression)1 ServletException (javax.servlet.ServletException)1 JspException (javax.servlet.jsp.JspException)1 ELException (javax.servlet.jsp.el.ELException)1 ImplicitObjectELResolver (javax.servlet.jsp.el.ImplicitObjectELResolver)1 ScopedAttributeELResolver (javax.servlet.jsp.el.ScopedAttributeELResolver)1 SlingPageException (org.apache.sling.scripting.jsp.SlingPageException)1