use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class Trunc method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
java.util.Date date = getDateOperand(0);
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
try {
date = formatter.parse(formatter.format(date));
} catch (ParseException ex) {
throw new TMLExpressionException(this, "Invalid date format: " + date + " for given date pattern: " + "yyyy-MM-dd");
}
return date;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class WeekDay method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
Object o = null;
try {
o = getOperand(0);
} catch (Exception e) {
o = new java.util.Date();
}
java.util.Date day = null;
if (o == null) {
// take today
day = Calendar.getInstance(locale).getTime();
} else if (o instanceof java.util.Date) {
day = (java.util.Date) o;
} else if (o instanceof String) {
java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd");
try {
day = format.parse((String) o);
} catch (Exception e) {
throw new TMLExpressionException("Invalid date format: " + (String) o);
}
} else {
throw new TMLExpressionException("Invalid date: " + o);
}
return new SimpleDateFormat("EEE", locale).format(day).toUpperCase();
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class URLEncode method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
String stringToEncode = getStringOperand(0);
boolean space_as_plus = false;
if (getOperands().size() > 1) {
space_as_plus = getBooleanOperand(1);
}
String encoded;
try {
encoded = URLEncoder.encode(stringToEncode, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new TMLExpressionException(this, "Can not parse URL: " + stringToEncode, e);
}
if (!space_as_plus) {
encoded = encoded.replace("+", "%20");
}
return encoded;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class ToPattern method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
String s = (String) this.getOperands().get(0);
if (s == null)
return null;
int options = 0;
if (this.getOperands().size() > 1) {
String soptions = (String) this.getOperands().get(1);
if (soptions.indexOf('i') > -1) {
options = options | Pattern.CASE_INSENSITIVE;
}
}
try {
return Pattern.compile(s, options);
} catch (PatternSyntaxException e) {
throw new TMLExpressionException("Invalid regex!");
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class Round method evaluate.
@Override
public final Object evaluate() throws TMLExpressionException {
Object a = getOperands().get(0);
Object b = getOperands().get(1);
try {
Double value = (Double) a;
Integer digits = (Integer) b;
value = (int) Math.signum(value) * ((int) (0.5 + Math.abs(value) * Math.pow(10.0, digits))) / Math.pow(10.0, digits);
return Double.valueOf(value);
} catch (Exception e) {
throw new TMLExpressionException(this, "Illegal type specified in Round() function: " + e.getMessage());
}
}
Aggregations