Search in sources :

Example 86 with TMLExpressionException

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));
}
Also used : List(java.util.List) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 87 with TMLExpressionException

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;
}
Also used : Binary(com.dexels.navajo.document.types.Binary) Security(com.dexels.navajo.functions.security.Security) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 88 with TMLExpressionException

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;
    }
}
Also used : Message(com.dexels.navajo.document.Message) SystemException(com.dexels.navajo.script.api.SystemException) Operand(com.dexels.navajo.document.Operand) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 89 with TMLExpressionException

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) DateTimeFormatter(java.time.format.DateTimeFormatter) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 90 with TMLExpressionException

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));
}
Also used : MalformedURLException(java.net.MalformedURLException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) URL(java.net.URL)

Aggregations

TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)129 Message (com.dexels.navajo.document.Message)26 Navajo (com.dexels.navajo.document.Navajo)26 Binary (com.dexels.navajo.document.types.Binary)23 Property (com.dexels.navajo.document.Property)17 ArrayList (java.util.ArrayList)16 Operand (com.dexels.navajo.document.Operand)15 List (java.util.List)13 NavajoException (com.dexels.navajo.document.NavajoException)12 IOException (java.io.IOException)12 Selection (com.dexels.navajo.document.Selection)11 Access (com.dexels.navajo.script.api.Access)10 Calendar (java.util.Calendar)10 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)9 Test (org.junit.Test)9 Money (com.dexels.navajo.document.types.Money)8 SystemException (com.dexels.navajo.script.api.SystemException)8 StringTokenizer (java.util.StringTokenizer)8 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)7 ClockTime (com.dexels.navajo.document.types.ClockTime)7