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