use of javax.el.ELException in project tomcat70 by apache.
the class AstFunction method getType.
@Override
public Class<?> getType(EvaluationContext ctx) throws ELException {
FunctionMapper fnMapper = ctx.getFunctionMapper();
// quickly validate again for this request
if (fnMapper == null) {
throw new ELException(MessageFactory.get("error.fnMapper.null"));
}
Method m = fnMapper.resolveFunction(this.prefix, this.localName);
if (m == null) {
throw new ELException(MessageFactory.get("error.fnMapper.method", this.getOutputName()));
}
return m.getReturnType();
}
use of javax.el.ELException in project tomcat70 by apache.
the class AstFunction method getValue.
@Override
public Object getValue(EvaluationContext ctx) throws ELException {
FunctionMapper fnMapper = ctx.getFunctionMapper();
// quickly validate again for this request
if (fnMapper == null) {
throw new ELException(MessageFactory.get("error.fnMapper.null"));
}
Method m = fnMapper.resolveFunction(this.prefix, this.localName);
if (m == null) {
throw new ELException(MessageFactory.get("error.fnMapper.method", this.getOutputName()));
}
Class<?>[] paramTypes = m.getParameterTypes();
Object[] params = null;
Object result = null;
int inputParameterCount = this.jjtGetNumChildren();
int methodParameterCount = paramTypes.length;
if (inputParameterCount == 0 && methodParameterCount == 1 && m.isVarArgs()) {
params = new Object[] { null };
} else if (inputParameterCount > 0) {
params = new Object[methodParameterCount];
try {
for (int i = 0; i < methodParameterCount; i++) {
if (m.isVarArgs() && i == methodParameterCount - 1) {
if (inputParameterCount < methodParameterCount) {
params[i] = new Object[] { null };
} else if (inputParameterCount == methodParameterCount && paramTypes[i].isArray()) {
params[i] = this.jjtGetChild(i).getValue(ctx);
} else {
Object[] varargs = new Object[inputParameterCount - methodParameterCount + 1];
Class<?> target = paramTypes[i].getComponentType();
for (int j = i; j < inputParameterCount; j++) {
varargs[j - i] = this.jjtGetChild(j).getValue(ctx);
varargs[j - i] = coerceToType(varargs[j - i], target);
}
params[i] = varargs;
}
} else {
params[i] = this.jjtGetChild(i).getValue(ctx);
}
params[i] = coerceToType(params[i], paramTypes[i]);
}
} catch (ELException ele) {
throw new ELException(MessageFactory.get("error.function", this.getOutputName()), ele);
}
}
try {
result = m.invoke(null, params);
} catch (IllegalAccessException iae) {
throw new ELException(MessageFactory.get("error.function", this.getOutputName()), iae);
} catch (InvocationTargetException ite) {
Throwable cause = ite.getCause();
if (cause instanceof ThreadDeath) {
throw (ThreadDeath) cause;
}
if (cause instanceof VirtualMachineError) {
throw (VirtualMachineError) cause;
}
throw new ELException(MessageFactory.get("error.function", this.getOutputName()), cause);
}
return result;
}
use of javax.el.ELException in project tomcat70 by apache.
the class AstIdentifier method getMethodExpression.
private final MethodExpression getMethodExpression(EvaluationContext ctx) throws ELException {
Object obj = null;
// case A: ValueExpression exists, getValue which must
// be a MethodExpression
VariableMapper varMapper = ctx.getVariableMapper();
ValueExpression ve = null;
if (varMapper != null) {
ve = varMapper.resolveVariable(this.image);
if (ve != null) {
obj = ve.getValue(ctx);
}
}
// a MethodExpression to be able to invoke
if (ve == null) {
ctx.setPropertyResolved(false);
obj = ctx.getELResolver().getValue(ctx, null, this.image);
}
// finally provide helpful hints
if (obj instanceof MethodExpression) {
return (MethodExpression) obj;
} else if (obj == null) {
throw new MethodNotFoundException("Identity '" + this.image + "' was null and was unable to invoke");
} else {
throw new ELException("Identity '" + this.image + "' does not reference a MethodExpression instance, returned type: " + obj.getClass().getName());
}
}
use of javax.el.ELException in project tomcat70 by apache.
the class TestELParser method doTestParser.
private void doTestParser(String input, String expectedResult, String expectedBuilderOutput) throws JasperException {
ELException elException = null;
String elResult = null;
// Don't try and evaluate expressions that depend on variables or functions
if (expectedResult != null) {
try {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
ValueExpression ve = factory.createValueExpression(context, input, String.class);
elResult = ve.getValue(context).toString();
Assert.assertEquals(expectedResult, elResult);
} catch (ELException ele) {
elException = ele;
}
}
Nodes nodes = null;
try {
nodes = ELParser.parse(input, false);
Assert.assertNull(elException);
} catch (IllegalArgumentException iae) {
Assert.assertNotNull(elResult, elException);
// Not strictly true but enables us to report both
iae.initCause(elException);
throw iae;
}
TextBuilder textBuilder = new TextBuilder(false);
nodes.visit(textBuilder);
Assert.assertEquals(expectedBuilderOutput, textBuilder.getText());
}
use of javax.el.ELException in project tomcat70 by apache.
the class TestELEvaluation method testParserStringLiteral.
@Test
public void testParserStringLiteral() {
// Inspired by work on bug 45451, comments from kkolinko on the dev
// list and looking at the spec to find some edge cases
// The only characters that can be escaped inside a String literal
// are \ " and '. # and $ are not escaped inside a String literal.
Assert.assertEquals("\\", evaluateExpression("${'\\\\'}"));
Assert.assertEquals("\\", evaluateExpression("${\"\\\\\"}"));
Assert.assertEquals("\\\"'$#", evaluateExpression("${'\\\\\\\"\\'$#'}"));
Assert.assertEquals("\\\"'$#", evaluateExpression("${\"\\\\\\\"\\'$#\"}"));
// Trying to quote # or $ should throw an error
Exception e = null;
try {
evaluateExpression("${'\\$'}");
} catch (ELException el) {
e = el;
}
Assert.assertNotNull(e);
Assert.assertEquals("\\$", evaluateExpression("${'\\\\$'}"));
Assert.assertEquals("\\\\$", evaluateExpression("${'\\\\\\\\$'}"));
// Can use ''' inside '"' when quoting with '"' and vice versa without
// escaping
Assert.assertEquals("\\\"", evaluateExpression("${'\\\\\"'}"));
Assert.assertEquals("\"\\", evaluateExpression("${'\"\\\\'}"));
Assert.assertEquals("\\'", evaluateExpression("${'\\\\\\''}"));
Assert.assertEquals("'\\", evaluateExpression("${'\\'\\\\'}"));
Assert.assertEquals("\\'", evaluateExpression("${\"\\\\'\"}"));
Assert.assertEquals("'\\", evaluateExpression("${\"'\\\\\"}"));
Assert.assertEquals("\\\"", evaluateExpression("${\"\\\\\\\"\"}"));
Assert.assertEquals("\"\\", evaluateExpression("${\"\\\"\\\\\"}"));
}
Aggregations