Search in sources :

Example 16 with Date

use of net.fortuna.ical4j.model.Date in project bw-calendar-engine by Bedework.

the class RecurUtil method getLastDate.

/* Return the highest possible start date from this recurrence or null
   * if no count or until date specified
   */
private static Date getLastDate(final Recur r, Date start, final Date maxRangeEnd) {
    Date seed = start;
    Date until = r.getUntil();
    if (until != null) {
        return until;
    }
    int count = r.getCount();
    if (count < 1) {
        return null;
    }
    Dur days100 = new Dur(100, 0, 0, 0);
    int counted = 0;
    while ((counted < count) && (start.before(maxRangeEnd))) {
        Date end = new DateTime(days100.getTime(start));
        DateList dl = r.getDates(seed, start, end, Value.DATE_TIME);
        int sz = dl.size();
        counted += sz;
        if (sz != 0) {
            until = (Date) dl.get(sz - 1);
        }
        start = end;
    }
    return until;
}
Also used : Dur(net.fortuna.ical4j.model.Dur) DateList(net.fortuna.ical4j.model.DateList) RDate(net.fortuna.ical4j.model.property.RDate) Date(net.fortuna.ical4j.model.Date) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime)

Example 17 with Date

use of net.fortuna.ical4j.model.Date in project bw-calendar-engine by Bedework.

the class VEventUtil method makeDlp.

private static void makeDlp(final BwEvent val, final boolean exdt, final Collection<BwDateTime> dts, final PropertyList pl) throws Throwable {
    if ((dts == null) || (dts.isEmpty())) {
        return;
    }
    TimeZone tz = null;
    if (!val.getForceUTC()) {
        BwDateTime dtstart = val.getDtstart();
        if ((dtstart != null) && !dtstart.isUTC()) {
            DtStart ds = dtstart.makeDtStart();
            tz = ds.getTimeZone();
        }
    }
    /* Generate as one date per property - matches up to other vendors better */
    for (BwDateTime dt : dts) {
        DateList dl = null;
        /* Always use the UTC values */
        boolean dateType = false;
        if (dt.getDateType()) {
            dl = new DateList(Value.DATE);
            dl.setUtc(true);
            dateType = true;
            dl.add(new Date(dt.getDtval()));
        } else {
            dl = new DateList(Value.DATE_TIME);
            if (tz == null) {
                dl.setUtc(true);
                DateTime dtm = new DateTime(dt.getDate());
                dtm.setUtc(true);
                dl.add(dtm);
            } else {
                dl.setTimeZone(tz);
                DateTime dtm = new DateTime(dt.getDate());
                dtm.setTimeZone(tz);
                dl.add(dtm);
            }
        }
        DateListProperty dlp;
        if (exdt) {
            dlp = new ExDate(dl);
        } else {
            dlp = new RDate(dl);
        }
        if (tz != null) {
            dlp.setTimeZone(tz);
        }
        if (dateType) {
            dlp.getParameters().add(Value.DATE);
        }
        pl.add(dlp);
    }
}
Also used : TimeZone(net.fortuna.ical4j.model.TimeZone) DtStart(net.fortuna.ical4j.model.property.DtStart) RDate(net.fortuna.ical4j.model.property.RDate) BwDateTime(org.bedework.calfacade.BwDateTime) DateListProperty(net.fortuna.ical4j.model.property.DateListProperty) ExDate(net.fortuna.ical4j.model.property.ExDate) DateList(net.fortuna.ical4j.model.DateList) Date(net.fortuna.ical4j.model.Date) RDate(net.fortuna.ical4j.model.property.RDate) ExDate(net.fortuna.ical4j.model.property.ExDate) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime)

Example 18 with Date

use of net.fortuna.ical4j.model.Date in project bw-calendar-engine by Bedework.

the class VEventUtil method makeZonedDt.

private static Date makeZonedDt(final BwEvent val, final String dtval) throws Throwable {
    BwDateTime dtstart = val.getDtstart();
    Date dt = new DateTime(dtval);
    if (dtstart.getDateType()) {
        // RECUR - fix all day recurrences sometime
        if (dtval.length() > 8) {
            // Try to fix up bad all day recurrence ids. - assume a local timezone
            ((DateTime) dt).setTimeZone(null);
            return new Date(dt.toString().substring(0, 8));
        }
        return dt;
    }
    if (val.getForceUTC()) {
        return dt;
    }
    if ((dtstart != null) && !dtstart.isUTC()) {
        DtStart ds = dtstart.makeDtStart();
        ((DateTime) dt).setTimeZone(ds.getTimeZone());
    }
    return dt;
}
Also used : DtStart(net.fortuna.ical4j.model.property.DtStart) BwDateTime(org.bedework.calfacade.BwDateTime) Date(net.fortuna.ical4j.model.Date) RDate(net.fortuna.ical4j.model.property.RDate) ExDate(net.fortuna.ical4j.model.property.ExDate) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime)

Example 19 with Date

use of net.fortuna.ical4j.model.Date in project zm-mailbox by Zimbra.

the class TestUserServlet method testIcsImportExport.

/**
 * Test that can import into a new calendar from ICALENDAR containing an inline ATTACHment.
 * Test that it is possible to export calendar entry with an attachment with the attachment
 * inlined if icalAttach=inline or ignoring the attachment if icalAttach=none
 * @throws Exception
 */
@Test
public void testIcsImportExport() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String calName = NAME_PREFIX + "2ndCalendar";
    String calUri = String.format("/%s?fmt=ics", calName);
    TestUtil.createFolder(mbox, calName, ZFolder.View.appointment);
    net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
    calendar.getProperties().add(new ProdId("-//ZimbraTest 1.0//EN"));
    calendar.getProperties().add(Version.VERSION_2_0);
    calendar.getProperties().add(CalScale.GREGORIAN);
    java.util.Calendar start = java.util.Calendar.getInstance();
    start.set(java.util.Calendar.MONTH, java.util.Calendar.SEPTEMBER);
    start.set(java.util.Calendar.DAY_OF_MONTH, 03);
    VEvent wwII = new VEvent(new Date(start.getTime()), NAME_PREFIX + " Declarations of war");
    wwII.getProperties().getProperty(Property.DTSTART).getParameters().add(Value.DATE);
    wwII.getProperties().add(new Uid("3-14159"));
    Attach attach = new Attach("Attachment.\nIsn't it short.".getBytes(MimeConstants.P_CHARSET_ASCII));
    attach.getParameters().add(new XParameter("X-APPLE-FILENAME", "short.txt"));
    attach.getParameters().add(new FmtType(MimeConstants.CT_TEXT_PLAIN));
    wwII.getProperties().add(attach);
    calendar.getComponents().add(wwII);
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    CalendarOutputter outputter = new CalendarOutputter();
    outputter.setValidating(false);
    outputter.output(calendar, buf);
    URI uri = mbox.getRestURI(calUri);
    HttpClient client = mbox.getHttpClient(uri);
    HttpPost post = new HttpPost(uri.toString());
    post.setEntity(new InputStreamEntity(new ByteArrayInputStream(buf.toByteArray()), ContentType.create(MimeConstants.CT_TEXT_CALENDAR)));
    ZimbraLog.test.info("testIcsImportExport:ICS to be imported:%s", new String(buf.toByteArray()));
    TestCalDav.HttpMethodExecutor.execute(client, post, HttpStatus.SC_OK);
    uri = mbox.getRestURI(calUri + "&icalAttach=inline");
    HttpGet get = new HttpGet(uri.toString());
    TestCalDav.HttpMethodExecutor executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
    String respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    ZimbraLog.test.info("testIcsImportExport:ICS exported (with icalAttach=inline):%s", respIcal);
    int attachNdx = respIcal.indexOf("ATTACH;");
    Assert.assertTrue("ATTACH should be present", -1 != attachNdx);
    String fromAttach = respIcal.substring(attachNdx);
    Assert.assertTrue("BINARY should be present", -1 != fromAttach.indexOf("VALUE=BINARY"));
    uri = mbox.getRestURI(calUri + "&icalAttach=none");
    get = new HttpGet(uri.toString());
    executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
    respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    ZimbraLog.test.debug("testIcsImportExport:ICS exported (with icalAttach=none):%s", respIcal);
    Assert.assertTrue("ATTACH should be present", -1 == respIcal.indexOf("ATTACH;"));
    uri = mbox.getRestURI(calUri);
    get = new HttpGet(uri.toString());
    executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
    respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
    ZimbraLog.test.debug("testIcsImportExport:ICS exported (default - same as icalAttach=none):%s", respIcal);
    Assert.assertTrue("ATTACH should be present", -1 == respIcal.indexOf("ATTACH;"));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpGet(org.apache.http.client.methods.HttpGet) ProdId(net.fortuna.ical4j.model.property.ProdId) URI(java.net.URI) ZMailbox(com.zimbra.client.ZMailbox) XParameter(net.fortuna.ical4j.model.parameter.XParameter) VEvent(net.fortuna.ical4j.model.component.VEvent) Attach(net.fortuna.ical4j.model.property.Attach) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Date(net.fortuna.ical4j.model.Date) InputStreamEntity(org.apache.http.entity.InputStreamEntity) Uid(net.fortuna.ical4j.model.property.Uid) ByteArrayInputStream(java.io.ByteArrayInputStream) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) HttpClient(org.apache.http.client.HttpClient) FmtType(net.fortuna.ical4j.model.parameter.FmtType) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter) Test(org.junit.Test)

Aggregations

Date (net.fortuna.ical4j.model.Date)19 BwDateTime (org.bedework.calfacade.BwDateTime)11 DateTime (net.fortuna.ical4j.model.DateTime)10 DtStart (net.fortuna.ical4j.model.property.DtStart)10 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)9 Dur (net.fortuna.ical4j.model.Dur)8 DtEnd (net.fortuna.ical4j.model.property.DtEnd)8 PropertyList (net.fortuna.ical4j.model.PropertyList)5 RDate (net.fortuna.ical4j.model.property.RDate)5 DateList (net.fortuna.ical4j.model.DateList)4 Parameter (net.fortuna.ical4j.model.Parameter)4 Period (net.fortuna.ical4j.model.Period)4 VEvent (net.fortuna.ical4j.model.component.VEvent)4 BwEvent (org.bedework.calfacade.BwEvent)4 ChangeTable (org.bedework.calfacade.util.ChangeTable)4 Iterator (java.util.Iterator)3 PeriodList (net.fortuna.ical4j.model.PeriodList)3 Recur (net.fortuna.ical4j.model.Recur)3 TimeZone (net.fortuna.ical4j.model.TimeZone)3 Duration (net.fortuna.ical4j.model.property.Duration)3