use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetContextResource method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
java.io.File contextRoot = DispatcherFactory.getInstance().getNavajoConfig().getContextRoot();
java.io.File res = new java.io.File(contextRoot, "resources");
// input (ArrayList, Object).
if (this.getOperands().size() != 1)
throw new TMLExpressionException("GetContextResource(filename) expected");
Object a = this.getOperands().get(0);
if (!(a instanceof String)) {
throw new TMLExpressionException("GetContextResource(filename) expected");
}
java.io.File result = new java.io.File(res, (String) a);
// Security might be compromised if supplied with path like: ../../../root/somethingsecret
try {
return new Binary(result);
} catch (IOException e) {
throw new TMLExpressionException("Error constructing binary", e);
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class ForAll method evaluate.
@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
/**
*@todo Implement this com.dexels.navajo.parser.FunctionInterface abstract method
*/
Message arrayMessage = null;
String messagePath = null;
if (getOperand(0) instanceof Message) {
arrayMessage = (Message) getOperand(0);
} else {
messagePath = (String) getOperand(0);
}
String expression = (String) getOperand(1);
String filter = null;
if (getOperands().size() > 2) {
filter = (String) getOperand(2);
}
Message parent = getCurrentMessage();
Navajo doc = getNavajo();
// try {
try {
List<Message> arrayMsg = null;
if (arrayMessage != null) {
arrayMsg = arrayMessage.getAllMessages();
} else {
arrayMsg = (parent != null ? parent.getMessages(messagePath) : doc.getMessages(messagePath));
}
if (arrayMsg == null) {
throw new TMLExpressionException(this, "Empty or non existing array message: " + messagePath);
}
for (int i = 0; i < arrayMsg.size(); i++) {
Message current = arrayMsg.get(i);
try {
boolean evaluate = (filter != null ? Condition.evaluate(filter, doc, null, current, getAccess()) : true);
if (evaluate) {
Operand result = Expression.evaluate(expression, doc, null, current);
if (result == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
}
if (result.value == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
}
String res2 = "" + result.value;
Operand result2 = Expression.evaluate(res2, doc, null, current);
if (result2 == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
}
if (result2.value == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
}
boolean res = ((Boolean) result2.value).booleanValue();
if (!res) {
return Boolean.FALSE;
}
}
} catch (SystemException ex) {
logger.error("Error: ", ex);
}
}
} catch (NavajoException ex) {
throw new TMLExpressionException(this, "Error evaluating message path");
}
return Boolean.TRUE;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class FindElement method evaluate.
@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
Message in = null;
String propertyName = (String) getOperand(0);
Object propertyValue = getOperand(1);
if (getOperands().size() == 2) {
in = getCurrentMessage();
if (in == null) {
throw new TMLExpressionException("Can not FindElement: No supplied message and no currentMessage");
}
} else {
in = (Message) getOperand(2);
}
if (!Message.MSG_TYPE_ARRAY.equals(in.getType())) {
in = in.getArrayParentMessage();
}
if (in == null) {
throw new TMLExpressionException("Can not FindElement: Supplied message is not an array message or array element");
}
String type = in.getType();
if (!Message.MSG_TYPE_ARRAY.equals(type)) {
throw new TMLExpressionException("FindElement resolved message is still no array message (?)");
}
for (Message element : in.getAllMessages()) {
Property p = element.getProperty(propertyName);
if (p != null) {
if (propertyValue.equals(p.getTypedValue())) {
return element;
}
}
}
logger.debug("No property found in message. Property name: " + propertyName + " value: " + propertyValue);
return null;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetPropertyAttribute method getAttribute.
public Object getAttribute(Object operand, String attribute) throws com.dexels.navajo.expression.api.TMLExpressionException {
Property p = null;
if (operand instanceof Property) {
p = (Property) operand;
} else {
String propertyName = operand.toString();
p = (getCurrentMessage() != null ? getCurrentMessage().getProperty(propertyName) : this.getNavajo().getProperty(propertyName));
}
if (p == null) {
throw new TMLExpressionException(this, "Property " + operand.toString() + " not found");
}
if (attribute.equals("direction")) {
return p.getDirection();
}
if (attribute.equals("type")) {
return p.getType();
}
if (attribute.equals("cardinality")) {
return p.getCardinality();
}
try {
throw new TMLExpressionException(this, "attribute " + attribute + " not found for property " + p.getFullPropertyName());
} catch (NavajoException e) {
throw new TMLExpressionException(this, "attribute " + attribute + " not found for unknown property ");
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetPropertyValue method evaluate.
@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() != 2) {
throw new TMLExpressionException(this, "Invalid function call");
}
Object m = operand(0).value;
;
if (m == null) {
throw new TMLExpressionException(this, "Message or navajo argument expected. This one is null");
}
// Object o = getOperand(1);
// if (!(o instanceof String)) {
// throw new TMLExpressionException(this, "String argument expected");
// }
String propertyName = getStringOperand(1);
if (!(m instanceof Message) && !(m instanceof Navajo)) {
throw new TMLExpressionException(this, "Message or navajo argument expected");
}
if (m instanceof Navajo) {
Navajo n = (Navajo) m;
return n.getProperty(propertyName).getTypedValue();
}
if (m instanceof Message) {
Message message = (Message) m;
return message.getProperty(propertyName).getTypedValue();
}
return null;
}
Aggregations