Search in sources :

Example 11 with SimpleDateFormat

use of java.text.SimpleDateFormat in project camel by apache.

the class BeanIODataFormatComplexTest method createTestData.

private List<Object> createTestData(boolean skipB1header) throws ParseException {
    String source = "camel-beanio";
    List<Object> body = new ArrayList<Object>();
    Date date = new SimpleDateFormat("ddMMyy").parse("030808");
    Header hFirst = new Header("A1", date, "PRICE");
    Header hSecond = new Header("B1", date, "SECURITY");
    Separator headerEnd = new Separator("HEADER END");
    A1Record first = new A1Record("0001917", source, 12345.678900);
    A1Record second = new A1Record("0002374", source, 59303290.020);
    B1Record third = new B1Record("0015219", source, "SECURITY ONE");
    Separator sectionEnd = new Separator("END OF SECTION 1");
    A1Record fourth = new A1Record("0076647", source, 0.0000000001);
    A1Record fifth = new A1Record("0135515", source, 999999999999d);
    B1Record sixth = new B1Record("2000815", source, "SECURITY TWO");
    B1Record seventh = new B1Record("2207122", source, "SECURITY THR");
    body.add(hFirst);
    if (!skipB1header) {
        body.add(hSecond);
    }
    body.add(headerEnd);
    body.add(first);
    body.add(second);
    body.add(third);
    body.add(sectionEnd);
    body.add(fourth);
    body.add(fifth);
    body.add(sixth);
    body.add(seventh);
    Trailer trailer = new Trailer(7);
    body.add(trailer);
    return body;
}
Also used : ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 12 with SimpleDateFormat

use of java.text.SimpleDateFormat in project camel by apache.

the class TimerComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    TimerEndpoint answer = new TimerEndpoint(uri, this, remaining);
    // convert time from String to a java.util.Date using the supported patterns
    String time = getAndRemoveOrResolveReferenceParameter(parameters, "time", String.class);
    String pattern = getAndRemoveOrResolveReferenceParameter(parameters, "pattern", String.class);
    if (time != null) {
        SimpleDateFormat sdf;
        if (pattern != null) {
            sdf = new SimpleDateFormat(pattern);
        } else if (time.contains("T")) {
            sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        } else {
            sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
        Date date = sdf.parse(time);
        answer.setTime(date);
        answer.setPattern(pattern);
    }
    setProperties(answer, parameters);
    return answer;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 13 with SimpleDateFormat

use of java.text.SimpleDateFormat in project camel by apache.

the class FileProducerExpressionTest method testProducerDateByExpression.

public void testProducerDateByExpression() throws Exception {
    template.sendBody("file://target/filelanguage?fileName=myfile-${date:now:yyyyMMdd}.txt", "Hello World");
    String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
    assertFileExists("target/filelanguage/myfile-" + date + ".txt");
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 14 with SimpleDateFormat

use of java.text.SimpleDateFormat in project camel by apache.

the class FileLanguageTest method testDateUsingAlternativeStartToken.

public void testDateUsingAlternativeStartToken() throws Exception {
    String now = new SimpleDateFormat("yyyyMMdd").format(new Date());
    assertExpression("backup-$simple{date:now:yyyyMMdd}", "backup-" + now);
    String expected = new SimpleDateFormat("yyyyMMdd").format(new Date(file.lastModified()));
    assertExpression("backup-$simple{date:file:yyyyMMdd}", "backup-" + expected);
    assertExpression("backup-$simple{date:header.birthday:yyyyMMdd}", "backup-19740420");
    assertExpression("hello-$simple{date:out.header.special:yyyyMMdd}", "hello-20080808");
    try {
        this.assertExpression("nodate-$simple{date:header.xxx:yyyyMMdd}", null);
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 15 with SimpleDateFormat

use of java.text.SimpleDateFormat in project camel by apache.

the class MailConverters method toSearchTerm.

public static SearchTerm toSearchTerm(SimpleSearchTerm simple, TypeConverter typeConverter) throws ParseException, NoTypeConversionAvailableException {
    SearchTermBuilder builder = new SearchTermBuilder();
    if (simple.isUnseen()) {
        builder = builder.unseen();
    }
    if (simple.getSubjectOrBody() != null) {
        String text = simple.getSubjectOrBody();
        builder = builder.subject(text).body(SearchTermBuilder.Op.or, text);
    }
    if (simple.getSubject() != null) {
        builder = builder.subject(simple.getSubject());
    }
    if (simple.getBody() != null) {
        builder = builder.body(simple.getBody());
    }
    if (simple.getFrom() != null) {
        builder = builder.from(simple.getFrom());
    }
    if (simple.getTo() != null) {
        builder = builder.recipient(Message.RecipientType.TO, simple.getTo());
    }
    if (simple.getFromSentDate() != null) {
        String s = simple.getFromSentDate();
        if (s.startsWith("now")) {
            long offset = extractOffset(s, typeConverter);
            builder = builder.and(new NowSearchTerm(SearchTermBuilder.Comparison.GE.asNum(), true, offset));
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat(NOW_DATE_FORMAT);
            Date date = sdf.parse(s);
            builder = builder.sent(SearchTermBuilder.Comparison.GE, date);
        }
    }
    if (simple.getToSentDate() != null) {
        String s = simple.getToSentDate();
        if (s.startsWith("now")) {
            long offset = extractOffset(s, typeConverter);
            builder = builder.and(new NowSearchTerm(SearchTermBuilder.Comparison.LE.asNum(), true, offset));
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat(NOW_DATE_FORMAT);
            Date date = sdf.parse(s);
            builder = builder.sent(SearchTermBuilder.Comparison.LE, date);
        }
    }
    if (simple.getFromReceivedDate() != null) {
        String s = simple.getFromReceivedDate();
        if (s.startsWith("now")) {
            long offset = extractOffset(s, typeConverter);
            builder = builder.and(new NowSearchTerm(SearchTermBuilder.Comparison.GE.asNum(), false, offset));
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat(NOW_DATE_FORMAT);
            Date date = sdf.parse(s);
            builder = builder.received(SearchTermBuilder.Comparison.GE, date);
        }
    }
    if (simple.getToReceivedDate() != null) {
        String s = simple.getToReceivedDate();
        if (s.startsWith("now")) {
            long offset = extractOffset(s, typeConverter);
            builder = builder.and(new NowSearchTerm(SearchTermBuilder.Comparison.LE.asNum(), false, offset));
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat(NOW_DATE_FORMAT);
            Date date = sdf.parse(s);
            builder = builder.received(SearchTermBuilder.Comparison.LE, date);
        }
    }
    return builder.build();
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)2847 Date (java.util.Date)1590 ParseException (java.text.ParseException)463 DateFormat (java.text.DateFormat)425 Calendar (java.util.Calendar)307 Test (org.junit.Test)305 ArrayList (java.util.ArrayList)232 File (java.io.File)230 IOException (java.io.IOException)185 GregorianCalendar (java.util.GregorianCalendar)139 HashMap (java.util.HashMap)121 Locale (java.util.Locale)70 DateField (edu.uci.ics.textdb.api.field.DateField)64 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 IField (edu.uci.ics.textdb.api.field.IField)64 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)64 StringField (edu.uci.ics.textdb.api.field.StringField)63 TextField (edu.uci.ics.textdb.api.field.TextField)63 Map (java.util.Map)63 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)61