Search in sources :

Example 31 with ValueExpression

use of javax.el.ValueExpression in project jersey by jersey.

the class LinkELContextTest method testNestedExpression.

@Test
public void testNestedExpression() {
    System.out.println("Nested expression");
    ExpressionFactory factory = ExpressionFactory.newInstance();
    LinkELContext context = new LinkELContext(new OuterEntityBean(), null);
    ValueExpression expr = factory.createValueExpression(context, "${entity.inner.id}", String.class);
    Object value = expr.getValue(context);
    assertEquals(ID, value);
}
Also used : ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) Test(org.junit.Test)

Example 32 with ValueExpression

use of javax.el.ValueExpression in project sling by apache.

the class ExpressionEvaluatorImpl method parseExpression.

public Expression parseExpression(String expression, Class expectedType, FunctionMapper fMapper) throws ELException {
    try {
        ELContextImpl ctx = new ELContextImpl(ELResolverImpl.DefaultResolver);
        if (fMapper != null) {
            ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
        }
        ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
        return new ExpressionImpl(ve);
    } catch (javax.el.ELException e) {
        throw new ELParseException(e.getMessage());
    }
}
Also used : ValueExpression(javax.el.ValueExpression) ELParseException(javax.servlet.jsp.el.ELParseException)

Example 33 with ValueExpression

use of javax.el.ValueExpression 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)

Example 34 with ValueExpression

use of javax.el.ValueExpression in project oxCore by GluuFederation.

the class ValueExpressionAnalyzer method getValueReference.

public ValueReference getValueReference(ELContext elContext) {
    InterceptingResolver resolver = new InterceptingResolver(elContext.getELResolver());
    try {
        expression.setValue(decorateELContext(elContext, resolver), null);
    } catch (ELException ele) {
        return null;
    }
    ValueReference reference = resolver.getValueReference();
    if (reference != null) {
        Object base = reference.getBase();
        if (base instanceof CompositeComponentExpressionHolder) {
            ValueExpression ve = ((CompositeComponentExpressionHolder) base).getExpression((String) reference.getProperty());
            if (ve != null) {
                this.expression = ve;
                reference = getValueReference(elContext);
            }
        }
    }
    return reference;
}
Also used : CompositeComponentExpressionHolder(javax.faces.el.CompositeComponentExpressionHolder) ValueExpression(javax.el.ValueExpression) ELException(javax.el.ELException) ValueReference(javax.el.ValueReference)

Example 35 with ValueExpression

use of javax.el.ValueExpression in project oxCore by GluuFederation.

the class EnumConverter method getAsObjectImpl.

public Object getAsObjectImpl(FacesContext context, UIComponent comp, String value) throws ConverterException {
    ValueExpression expr = comp.getValueExpression("value");
    Class enumType = expr == null ? null : expr.getType(context.getELContext());
    if (enumType != null && enumType.isEnum()) {
        return Enum.valueOf(enumType, value);
    } else {
        for (Object child : comp.getChildren()) {
            if (child instanceof UIComponent) {
                UIComponent c = (UIComponent) child;
                expr = c.getValueExpression("value");
                Object val = expr == null ? null : expr.getValue(context.getELContext());
                if (val == null) {
                    throw new ConverterException("Cannot get items");
                }
                Class t = val.getClass();
                if (t.isArray() && t.getComponentType().isEnum()) {
                    return Enum.valueOf(t.getComponentType(), value);
                } else if (val instanceof Collection) {
                    Object firstItem = ((Collection) val).iterator().next();
                    if (firstItem instanceof Enum) {
                        t = ((Enum) firstItem).getDeclaringClass();
                    } else {
                        t = firstItem.getClass();
                    }
                    return Enum.valueOf(t, value);
                }
            }
        }
    }
    throw new ConverterException("Unable to find selectItems with enum values.");
}
Also used : ConverterException(javax.faces.convert.ConverterException) ValueExpression(javax.el.ValueExpression) UIComponent(javax.faces.component.UIComponent) Collection(java.util.Collection)

Aggregations

ValueExpression (javax.el.ValueExpression)59 Test (org.junit.Test)36 ExpressionFactory (javax.el.ExpressionFactory)33 ELContext (javax.el.ELContext)27 ELContextImpl (org.apache.jasper.el.ELContextImpl)17 VariableMapper (javax.el.VariableMapper)9 ELException (javax.el.ELException)7 ELProcessor (javax.el.ELProcessor)7 MethodExpression (javax.el.MethodExpression)7 PropertyNotFoundException (javax.el.PropertyNotFoundException)4 ValueReference (javax.el.ValueReference)4 SimpleContext (de.odysseus.el.util.SimpleContext)2 HashMap (java.util.HashMap)2 ELClass (javax.el.ELClass)2 FunctionMapper (javax.el.FunctionMapper)2 ELParseException (javax.servlet.jsp.el.ELParseException)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1