use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class Contains method evaluate.
@Override
public final Object evaluate() throws TMLExpressionException {
// input (ArrayList, Object).
if (this.getOperands().size() != 2)
throw new TMLExpressionException("Contains(ArrayList, Object) expected");
Object a = this.getOperands().get(0);
if (!(a instanceof List))
throw new TMLExpressionException("Contains(ArrayList, Object) expected");
Object b = this.getOperands().get(1);
return (contains((List<?>) a, b));
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class EncryptBinary method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
String result = null;
String key = (String) getOperand(0);
Binary image = (Binary) getOperand(1);
try {
Security s = new Security(key);
result = s.encrypt(image).replace("\n", "");
} catch (Exception e) {
throw new TMLExpressionException(e.getMessage());
}
return result;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class EvaluateExpression method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() != 1 && getOperands().size() != 3) {
throw new TMLExpressionException("Wrong number of arguments");
}
Navajo currentNavajo = this.getNavajo();
Message currentMessage = this.getCurrentMessage();
Operand result = null;
boolean conditional = (this.getOperands().size() == 3);
if (!conditional) {
String expression = (String) getOperand(0);
try {
result = Expression.evaluate(expression, currentNavajo, null, currentMessage, null, null, null, null);
} catch (TMLExpressionException ex) {
logger.error("Error: ", ex);
}
} else {
String condition = (String) getOperand(0);
String exp1 = (String) getOperand(1);
String exp2 = (String) getOperand(2);
try {
if (Condition.evaluate(condition, currentNavajo, null, currentMessage, getAccess())) {
result = Expression.evaluate(exp1, currentNavajo, null, currentMessage, null, null, null, null);
} else {
result = Expression.evaluate(exp2, currentNavajo, null, currentMessage, null, null, null, null);
}
} catch (SystemException ex1) {
logger.error("Error: ", ex1);
throw new TMLExpressionException(this, ex1.getMessage());
} catch (TMLExpressionException ex1) {
logger.error("Error: ", ex1);
throw new TMLExpressionException(this, ex1.getMessage());
}
}
if (result != null) {
return result.value;
} else {
return null;
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class DateTime method evaluate.
@Override
public final String evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
String pattern;
DateTimeFormatter dtf;
if (this.getOperands().isEmpty()) {
// Getting Default Pattern
System.out.println("Getting Default Parser");
pattern = "dd-MM-yyyy HH:mm:ss";
} else {
if (this.getOperands().size() == 1) {
pattern = this.getStringOperand(0);
} else
throw new TMLExpressionException(this, "error: can take 0 or 1 arguments ");
}
try {
dtf = DateTimeFormatter.ofPattern(pattern);
} catch (Exception e) {
// Pattern not found. Setting default Pattern
System.out.println("Pattern not found. Setting default pattern : dd-MM-yyyy HH:mm:ss");
dtf = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
}
LocalDateTime now = LocalDateTime.now();
System.out.println(dtf.format(now));
return dtf.format(now);
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class CheckUrl method evaluate.
@Override
public final Object evaluate() throws TMLExpressionException {
// input (ArrayList, Object).
if (this.getOperands().size() != 1)
throw new TMLExpressionException("CheckUrl(String) expected");
Object a = this.getOperands().get(0);
if (a == null) {
return Boolean.FALSE;
}
if (!(a instanceof String))
throw new TMLExpressionException("CheckUrl(String) expected");
URL u;
try {
u = new URL((String) a);
} catch (MalformedURLException e) {
throw new TMLExpressionException("CheckUrl: bad url: " + a);
}
return Boolean.valueOf(check(u));
}
Aggregations