use of ognl.OgnlException in project entando-core by entando.
the class OgnlValidationRule method validate.
public AttributeFieldError validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
AttributeFieldError error = null;
String expression = this.getExpression();
if (null == expression || expression.trim().length() == 0) {
return null;
}
if (this.isEvalExpressionOnValuedAttribute() && attribute.getStatus().equals(AttributeInterface.Status.EMPTY)) {
return null;
}
try {
Object expr = Ognl.parseExpression(expression);
OgnlContext ctx = this.createContextForExpressionValidation(attribute, tracer, langManager);
Boolean value = (Boolean) Ognl.getValue(expr, ctx, attribute, Boolean.class);
if (!value) {
error = new AttributeFieldError(attribute, AttributeFieldError.OGNL_VALIDATION, tracer);
error.setMessage(this.getErrorMessage());
error.setMessageKey(this.getErrorMessageKey());
}
} catch (OgnlException oe) {
_logger.error("Error on evaluation of expression : {}", expression, oe);
} catch (Throwable t) {
_logger.error("Generic Error on evaluation Ognl Expression : {}", expression, t);
throw new RuntimeException("Generic Error on evaluation Ognl Expression", t);
}
return error;
}
Aggregations