Search in sources :

Example 26 with ExpressionFactory

use of javax.el.ExpressionFactory in project tomcat70 by apache.

the class TestValueExpressionImpl method testBug51177ObjectMap.

@Test
public void testBug51177ObjectMap() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    Object o1 = "String value";
    Object o2 = Integer.valueOf(32);
    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put("key1", o1);
    map.put("key2", o2);
    ValueExpression var = factory.createValueExpression(map, Map.class);
    context.getVariableMapper().setVariable("map", var);
    ValueExpression ve1 = factory.createValueExpression(context, "${map.key1}", Object.class);
    ve1.setValue(context, o2);
    Assert.assertEquals(o2, ve1.getValue(context));
    ValueExpression ve2 = factory.createValueExpression(context, "${map.key2}", Object.class);
    ve2.setValue(context, o1);
    Assert.assertEquals(o1, ve2.getValue(context));
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) HashMap(java.util.HashMap) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) Test(org.junit.Test)

Example 27 with ExpressionFactory

use of javax.el.ExpressionFactory in project tomcat70 by apache.

the class TestELParser method testJavaKeyWordSuffix.

@Test
public void testJavaKeyWordSuffix() {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    TesterBeanA beanA = new TesterBeanA();
    beanA.setInt("five");
    ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class);
    context.getVariableMapper().setVariable("beanA", var);
    // Should fail
    Exception e = null;
    try {
        factory.createValueExpression(context, "${beanA.int}", String.class);
    } catch (ELException ele) {
        e = ele;
    }
    Assert.assertNotNull(e);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl) ELException(javax.el.ELException) ELException(javax.el.ELException) Test(org.junit.Test)

Example 28 with ExpressionFactory

use of javax.el.ExpressionFactory in project tomcat70 by apache.

the class TestELParser method testExpression.

private void testExpression(String expression, String expected) {
    ExpressionFactory factory = ExpressionFactory.newInstance();
    ELContext context = new ELContextImpl();
    ValueExpression ve = factory.createValueExpression(context, expression, String.class);
    String result = (String) ve.getValue(context);
    Assert.assertEquals(expected, result);
}
Also used : ELContext(javax.el.ELContext) ExpressionFactory(javax.el.ExpressionFactory) ValueExpression(javax.el.ValueExpression) ELContextImpl(org.apache.jasper.el.ELContextImpl)

Example 29 with ExpressionFactory

use of javax.el.ExpressionFactory in project ysoserial by frohoff.

the class Myfaces1 method makeExpressionPayload.

public static Object makeExpressionPayload(String expr) throws IllegalArgumentException, IllegalAccessException, Exception {
    FacesContextImpl fc = new FacesContextImpl((ServletContext) null, (ServletRequest) null, (ServletResponse) null);
    ELContext elContext = new FacesELContext(new CompositeELResolver(), fc);
    Reflections.getField(FacesContextImplBase.class, "_elContext").set(fc, elContext);
    ExpressionFactory expressionFactory = ExpressionFactory.newInstance();
    ValueExpression ve1 = expressionFactory.createValueExpression(elContext, expr, Object.class);
    ValueExpressionMethodExpression e = new ValueExpressionMethodExpression(ve1);
    ValueExpression ve2 = expressionFactory.createValueExpression(elContext, "${true}", Object.class);
    ValueExpressionMethodExpression e2 = new ValueExpressionMethodExpression(ve2);
    return Gadgets.makeMap(e2, e);
}
Also used : FacesELContext(org.apache.myfaces.el.unified.FacesELContext) FacesELContext(org.apache.myfaces.el.unified.FacesELContext) ELContext(javax.el.ELContext) CompositeELResolver(org.apache.myfaces.el.CompositeELResolver) FacesContextImpl(org.apache.myfaces.context.servlet.FacesContextImpl) ExpressionFactory(javax.el.ExpressionFactory) ValueExpressionMethodExpression(org.apache.myfaces.view.facelets.el.ValueExpressionMethodExpression) FacesContextImplBase(org.apache.myfaces.context.servlet.FacesContextImplBase) ValueExpression(javax.el.ValueExpression)

Example 30 with ExpressionFactory

use of javax.el.ExpressionFactory in project rubia-forums by flashboss.

the class ACLRenderingController method aclCheck.

public boolean aclCheck(String fragment, String contextData, ForumsACLProvider forumsACLProvider, UserModule userModule, FaceletContext ctx) {
    boolean isAccessAllowed;
    // resourcesetup
    try {
        Object[] runtime = null;
        FacesContext facesContext = ctx.getFacesContext();
        if (contextData != null && contextData.trim().length() > 0) {
            StringTokenizer st = new StringTokenizer(contextData, ",");
            runtime = new Object[st.countTokens()];
            int i = 0;
            while (st.hasMoreTokens()) {
                String parameter = st.nextToken();
                Object parameterValue = null;
                // evaluate this expression to a value
                ExpressionFactory f = ctx.getExpressionFactory();
                ValueExpression expr = f.createValueExpression(ctx, parameter, Object.class);
                parameterValue = expr.getValue(facesContext.getELContext());
                runtime[i++] = parameterValue;
            }
        }
        // check access here
        UIContext securityContext = new UIContext(getUser(userModule));
        securityContext.setFragment(fragment);
        securityContext.setContextData(runtime);
        isAccessAllowed = forumsACLProvider.hasAccess(securityContext);
    } catch (NoSuchMethodException nsme) {
        throw new FacesException(nsme);
    } catch (Exception e) {
        throw new FacesException(e);
    }
    // access should be granted or not
    return isAccessAllowed;
}
Also used : FacesContext(javax.faces.context.FacesContext) ExpressionFactory(javax.el.ExpressionFactory) FacesException(javax.faces.FacesException) FacesException(javax.faces.FacesException) StringTokenizer(java.util.StringTokenizer) ValueExpression(javax.el.ValueExpression)

Aggregations

ExpressionFactory (javax.el.ExpressionFactory)39 ValueExpression (javax.el.ValueExpression)28 Test (org.junit.Test)24 ELContext (javax.el.ELContext)22 ELContextImpl (org.apache.jasper.el.ELContextImpl)15 ELException (javax.el.ELException)4 ValueReference (javax.el.ValueReference)3 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 FacesException (javax.faces.FacesException)2 FacesContext (javax.faces.context.FacesContext)2 ExpressionFactoryImpl (de.odysseus.el.ExpressionFactoryImpl)1 SimpleContext (de.odysseus.el.util.SimpleContext)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ELResolver (javax.el.ELResolver)1 ServletContextEvent (javax.servlet.ServletContextEvent)1