List of usage examples for org.apache.commons.jxpath CompiledExpression getValue
Object getValue(JXPathContext context);
From source file:org.apache.cocoon.generation.JXTemplateGenerator.java
static private Object getValue(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext, Boolean lenient) throws Exception { if (expr != null) { Object compiled = expr.compiledExpression; try {//from w w w. j a va 2 s . c o m if (compiled instanceof CompiledExpression) { CompiledExpression e = (CompiledExpression) compiled; boolean oldLenient = jxpathContext.isLenient(); if (lenient != null) { jxpathContext.setLenient(lenient.booleanValue()); } try { return e.getValue(jxpathContext); } finally { jxpathContext.setLenient(oldLenient); } } else if (compiled instanceof Expression) { Expression e = (Expression) compiled; return e.evaluate(jexlContext); } return compiled; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof Exception) { throw (Exception) t; } throw (Error) t; } } else { return null; } }
From source file:org.xchain.namespaces.core.TestUnknownFunction.java
@Ignore @Test//w ww .ja v a 2 s . c om public void testUnknownFunctionFromExpression() { try { CompiledExpression expression = JXPathContext.compile("unknown()"); expression.getValue(context); fail("Unknown function should have thrown an exception."); } catch (Exception e) { // success. } }