use of javax.el.ExpressionFactory 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.ExpressionFactory in project camel by apache.
the class JuelTest method testJuel.
@Test
public void testJuel() throws Exception {
ExpressionFactory factory = new ExpressionFactoryImpl();
ELContext context = new SimpleContext();
ValueExpression valueExpression = factory.createValueExpression(context, "${123 * 2}", Object.class);
Object value = valueExpression.getValue(context);
assertEquals("Result is a Long object", 246L, value);
}
use of javax.el.ExpressionFactory in project camel by apache.
the class DozerEndpoint method initELEngine.
public void initELEngine() {
String elprop = System.getProperty("javax.el.ExpressionFactory");
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
ClassLoader appcl = getCamelContext().getApplicationContextClassLoader();
ClassLoader auxcl = appcl != null ? appcl : DozerEndpoint.class.getClassLoader();
Thread.currentThread().setContextClassLoader(auxcl);
try {
Class<?> clazz = auxcl.loadClass("com.sun.el.ExpressionFactoryImpl");
ExpressionFactory factory = (ExpressionFactory) clazz.newInstance();
System.setProperty("javax.el.ExpressionFactory", factory.getClass().getName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
LOG.debug("Cannot load glasfish expression engine, using default");
}
ELEngine engine = new ELEngine();
engine.init();
BeanContainer.getInstance().setElEngine(engine);
ElementReader reader = new ExpressionElementReader(engine);
BeanContainer.getInstance().setElementReader(reader);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
if (elprop != null) {
System.setProperty("javax.el.ExpressionFactory", elprop);
} else {
System.clearProperty("javax.el.ExpressionFactory");
}
}
}
use of javax.el.ExpressionFactory in project core by weld.
the class ELResolverTest method testResolveBeanPropertyOfProducerBean.
/**
* Test that the WeldELResolver only works to resolve the base of an EL
* expression, in this case from a producer method. Once the base is
* resolved, the remainder of the expression should be delegated to the
* standard chain of property resolvers. If the WeldELResolver oversteps
* its bounds by trying to resolve the property against the Weld
* namespace, the test will fail.
*/
@Test
public void testResolveBeanPropertyOfProducerBean() {
ELContext elContext = EL.createELContext(beanManager);
ExpressionFactory exprFactory = EL.EXPRESSION_FACTORY;
Object value = exprFactory.createValueExpression(elContext, "#{beerOnTap.style}", String.class).getValue(elContext);
Assert.assertEquals("IPA", value);
}
use of javax.el.ExpressionFactory in project core by weld.
the class WeldApplication method init.
private void init() {
ExpressionFactory expressionFactory = this.expressionFactory;
BeanManager beanManager = null;
if (expressionFactory == null && (expressionFactory = super.getExpressionFactory()) != null && (beanManager = beanManager()) != null) {
elResolver.beanManagerReady(beanManager);
this.expressionFactory = beanManager.wrapExpressionFactory(expressionFactory);
}
}
Aggregations