use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class DecryptString method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
String result = null;
String key = (String) getOperand(0);
String message = (String) getOperand(1);
try {
Security s = new Security(key);
result = s.decrypt(message);
} catch (Exception e) {
throw new TMLExpressionException(e.getMessage(), e);
}
return result;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class Exists 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.TRUE;
}
}
} catch (SystemException ex) {
logger.error("Error: ", ex);
}
}
} catch (NavajoException ex) {
throw new TMLExpressionException(this, "Error evaluating message path");
}
return Boolean.FALSE;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class ExistsSelectionValue method evaluate.
@Override
@SuppressWarnings("unchecked")
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() != 2) {
throw new TMLExpressionException(this, "Invalid function call, need two parameters");
}
Object o = getOperand(0);
if (o == null) {
throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter null");
}
Object v = getOperand(1);
if (v == null) {
throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: Second parameter null");
}
if (!(v instanceof String)) {
throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: Second parameter not a string");
}
if (o instanceof Property) {
Property p = (Property) o;
try {
Selection s = p.getSelectionByValue((String) v);
return !s.getValue().equals(Selection.DUMMY_ELEMENT);
} catch (NavajoException ne) {
throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter not a selection property");
}
}
if (!(o instanceof List)) {
throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter not a selection property");
}
List<Selection> l = (List<Selection>) o;
for (Selection selection : l) {
if (v.equals(selection.getValue())) {
return true;
}
}
return false;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetSelectedValues method evaluate.
@Override
@SuppressWarnings("unchecked")
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() > 2) {
throw new TMLExpressionException(this, "Invalid function call, need one or two parameters");
}
Object o = operand(0).value;
if (o == null) {
throw new TMLExpressionException(this, "Invalid function call in GetSelectedValues: Parameter null");
}
boolean outputAsStringList = false;
if (getOperands().size() > 1) {
outputAsStringList = getBooleanOperand(1);
}
List<Object> values = new ArrayList<Object>();
if (o instanceof Property) {
Property p = (Property) o;
if (p.getSelected() != null) {
if (p.getAllSelectedSelections().size() > 0) {
values.add(p.getAllSelectedSelections());
}
}
} else if (o instanceof String) {
values.add(o);
} else {
if (!(o instanceof List)) {
throw new TMLExpressionException(this, "Invalid function call in GetSelectedValues: Not a selection property");
}
if (((List<Object>) o).size() != 0) {
List<Object> l = (List<Object>) o;
if (outputAsStringList) {
for (Object selection : l) {
values.add(selection.toString());
}
} else {
values.add(l);
}
}
}
// Outputtype...
if (outputAsStringList && values.size() != 0) {
String output = "";
for (Object item : values) {
output += item.toString() + ";";
}
return output;
} else {
return values;
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetUrlTime method evaluate.
@Override
public final Object evaluate() throws TMLExpressionException {
// input (ArrayList, Object).
if (this.getOperands().size() != 1)
throw new TMLExpressionException("GetUrlTime(String) expected");
Object a = this.getOperands().get(0);
if (a == null) {
return null;
}
if (!(a instanceof String))
throw new TMLExpressionException("GetUrlTime(String) expected");
URL u;
try {
u = new URL((String) a);
} catch (MalformedURLException e) {
throw new TMLExpressionException("CheckUrl: bad url: " + a);
}
return getUrlTime(u);
}
Aggregations