Search in sources :

Example 96 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class GetBinary method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    if (getOperands().size() != 1) {
        throw new TMLExpressionException(this, "Invalid number of operands");
    }
    if (!(getOperand(0) instanceof String)) {
        throw new TMLExpressionException(this, "Invalid operand: " + getOperand(0));
    }
    Binary b = null;
    String id = (String) getOperand(0);
    SharedStoreInterface mss = SharedStoreFactory.getInstance();
    try {
        InputStream is = mss.getStream(PARENT_LOCATION, id);
        b = new Binary(is);
        is.close();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new TMLExpressionException(this, e.getMessage());
    }
    return b;
}
Also used : InputStream(java.io.InputStream) SharedStoreInterface(com.dexels.navajo.sharedstore.SharedStoreInterface) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 97 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class GetCents method evaluate.

@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    final Object op = this.getOperands().get(0);
    if (op == null) {
        return ("");
    }
    if (!(op instanceof Money)) {
        throw new TMLExpressionException(this, "Money argument expected");
    }
    Money mo = (Money) op;
    return MoneyToCents(mo);
}
Also used : Money(com.dexels.navajo.document.types.Money) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 98 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class FormatDate method evaluate.

@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (this.getOperands().size() < 2 || this.getOperands().size() > 3)
        throw new TMLExpressionException(this.usage());
    if (getOperands().get(0) == null) {
        return "";
    }
    java.util.Date date = null;
    if (getOperands().get(0) instanceof ClockTime) {
        date = ((ClockTime) getOperands().get(0)).dateValue();
    } else if (getOperands().get(0) instanceof java.util.Date) {
        date = (java.util.Date) getOperands().get(0);
    } else {
        throw new TMLExpressionException(this, "Type mismatch");
    }
    String format = (String) this.getOperands().get(1);
    if (format == null)
        throw new TMLExpressionException("FormatDate: format cannot be null");
    java.text.SimpleDateFormat formatter = null;
    if (this.getOperands().size() > 2) {
        final String loc = (String) this.getOperands().get(2);
        if (loc != null && loc.length() > 0) {
            final Locale l = new Locale(loc);
            formatter = new java.text.SimpleDateFormat(format, l);
        }
    } else if (getAccess() != null && getAccess().getInDoc() != null) {
        String localeheader = getAccess().getInDoc().getHeader().getHeaderAttribute("locale");
        if (localeheader != null) {
            final Locale l = new Locale(localeheader);
            formatter = new java.text.SimpleDateFormat(format, l);
        }
    }
    if (formatter == null) {
        // fallback
        formatter = new java.text.SimpleDateFormat(format);
    }
    return formatter.format(date);
}
Also used : Locale(java.util.Locale) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) ClockTime(com.dexels.navajo.document.types.ClockTime)

Example 99 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class EvaluateParameters method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    if (getOperands().size() != 1) {
        throw new TMLExpressionException("Wrong number of arguments");
    }
    Message currentMessage = this.getCurrentMessage();
    String expression = (String) getOperand(0);
    logger.debug("input: {} ", expression);
    String result = "";
    StringTokenizer tok = new StringTokenizer(expression, "[");
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        logger.debug("token: {}", token);
        if (token.indexOf("]") > 0) {
            String property = token.substring(0, token.indexOf("]"));
            String value = property;
            logger.debug("Property: {}", property);
            if (currentMessage != null) {
                if (currentMessage.getProperty(property) != null) {
                    value = currentMessage.getProperty(property).getValue();
                }
            } else {
                if (inMessage.getProperty(property) != null) {
                    value = inMessage.getProperty(property).getValue();
                }
            }
            result += value;
            if (token.indexOf("]") < token.length() - 1) {
                result += token.substring(token.indexOf("]") + 1);
            }
        } else {
            result += token;
        }
    }
    return result;
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(com.dexels.navajo.document.Message) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 100 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class GetMessage method evaluate.

@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() == 1) {
        return getMessageFromNavajo(getStringOperand(0));
    }
    if (getOperands().size() != 2) {
        throw new TMLExpressionException(this, "Invalid function call");
    }
    Object m = operand(0).value;
    if (m == null) {
        throw new TMLExpressionException(this, "Message argument expected. This one is null");
    }
    if (!(m instanceof Message)) {
        throw new TMLExpressionException(this, "Message argument expected");
    }
    Integer index = getIntegerOperand(1);
    Message message = (Message) m;
    return message.getMessage(index.intValue());
}
Also used : Message(com.dexels.navajo.document.Message) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

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