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));
}
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);
}
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);
}
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);
}
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;
}
Aggregations