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;
}
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);
}
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);
}
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;
}
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());
}
Aggregations