use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class TestTMLJson method testClockTime.
@Test
public void testClockTime() throws Exception {
Navajo n = NavajoFactory.getInstance().createNavajo(getClass().getResourceAsStream("message2.xml"));
JSONTML json = JSONTMLFactory.getInstance();
Property prop = NavajoFactory.getInstance().createProperty(n, "clockTimeProp", "", "", "");
prop.setAnyValue(new ClockTime("11:12:12"));
n.getMessage("SimpleMessage").addProperty(prop);
Writer sw = new StringWriter();
json.format(n, sw, true);
String result = sw.toString();
Assert.assertEquals("{\n \"clockTimeProp\" : \"11:12:00\"\n}", result);
}
use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class DateAdd method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() > 2) {
java.util.Date datum = (java.util.Date) this.getOperands().get(0);
Integer arg = (Integer) this.getOperands().get(1);
String field = (String) this.getOperands().get(2);
Calendar cal = Calendar.getInstance();
cal.setTime(datum);
if (field.equals("YEAR")) {
cal.add(Calendar.YEAR, arg.intValue());
} else if (field.equals("MONTH")) {
cal.add(Calendar.MONTH, arg.intValue());
} else if (field.equals("DAY")) {
cal.add(Calendar.DAY_OF_YEAR, arg.intValue());
} else if (field.equals("WEEK")) {
cal.add(Calendar.WEEK_OF_YEAR, arg.intValue());
} else if (field.equals("HOUR")) {
cal.add(Calendar.HOUR_OF_DAY, arg.intValue());
} else if (field.equals("MINUTE")) {
cal.add(Calendar.MINUTE, arg.intValue());
} else if (field.equals("SECOND")) {
cal.add(Calendar.SECOND, arg.intValue());
}
return cal.getTime();
}
java.util.Date datum = (java.util.Date) this.getOperands().get(0);
ClockTime arg = (ClockTime) this.getOperands().get(1);
Calendar cal = Calendar.getInstance();
cal.setTime(datum);
cal.set(Calendar.HOUR_OF_DAY, arg.getHours());
cal.set(Calendar.MINUTE, arg.getMinutes());
cal.set(Calendar.SECOND, arg.getSeconds());
return cal.getTime();
}
use of com.dexels.navajo.document.types.ClockTime 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.document.types.ClockTime in project navajo by Dexels.
the class ToClockTime method main.
public static void main(String[] args) throws Exception {
// Tests.
ToClockTime cct = new ToClockTime();
cct.reset();
cct.insertStringOperand("12");
System.out.println("cct = " + cct.evaluate());
String expr = "ToClockTime('09:00') + ToClockTime('10')";
Operand o = Expression.evaluate(expr, null);
System.out.println("9:00 > 10:00 ? " + o.value + ", ToClockTime('25:88') = " + new ClockTime("25:88").toString());
expr = "ToClockTime('9') >= ToClockTime('9')";
Operand o2 = Expression.evaluate(expr, null);
System.out.println("9:00 >= 9:00 ? " + o2.value);
expr = "ToClockTime('9') < ToClockTime('12')";
Operand o3 = Expression.evaluate(expr, null);
System.out.println("9:00 < 12:00 ? " + o3.value);
}
use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.
the class DateAppendClockTime method testValidArguements.
@Test
public void testValidArguements() throws Exception {
Date date = new Date();
ClockTime cTime = new ClockTime("11:28");
System.out.println(" ------ Running Valid Parameters case ------ ");
System.out.println("Sending Date :: " + date);
System.out.println("Sending ClockTime :: " + cTime);
da.reset();
da.insertDateOperand(date);
da.insertClockTimeOperand(cTime);
System.out.println(da.evaluate());
Object o = da.evaluate();
assertEquals(o.getClass(), java.util.Date.class);
}
Aggregations