Search in sources :

Example 21 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project traccar by tananaev.

the class Calendar method setData.

public void setData(byte[] data) throws IOException, ParserException {
    CalendarBuilder builder = new CalendarBuilder();
    calendar = builder.build(new ByteArrayInputStream(data));
    this.data = data.clone();
}
Also used : CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 22 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project openolat by klemens.

the class CalendarImportTest method testImportFromFGiCal.

/*
	 * Why is this test not reliable???
	@Test(expected = ParserException.class)
	public void testImportRefresh() throws IOException, ParserException {
		InputStream in = CalendarImportTest.class.getResourceAsStream("Refresh.ics");
		CalendarBuilder builder = new CalendarBuilder();
		Calendar calendar = builder.build(in);
        assertNotNull(calendar);
	}
	*/
@Test
@Ignore
public void testImportFromFGiCal() throws IOException, ParserException {
    // default settings in olat
    System.setProperty(CompatibilityHints.KEY_RELAXED_UNFOLDING, "true");
    System.setProperty(CompatibilityHints.KEY_RELAXED_PARSING, "true");
    InputStream in = CalendarImportTest.class.getResourceAsStream("EMAIL.ics");
    CalendarBuilder builder = new CalendarBuilder();
    Calendar calendar = builder.build(in);
    assertNotNull(calendar);
}
Also used : CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) InputStream(java.io.InputStream) Calendar(net.fortuna.ical4j.model.Calendar) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project openolat by klemens.

the class CalendarImportTest method testImportOktoberFromOutlook.

@Test
public void testImportOktoberFromOutlook() throws IOException, ParserException {
    InputStream in = CalendarImportTest.class.getResourceAsStream("BB_Okt.ics");
    CalendarBuilder builder = new CalendarBuilder();
    Calendar calendar = builder.build(in);
    assertNotNull(calendar);
}
Also used : CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) InputStream(java.io.InputStream) Calendar(net.fortuna.ical4j.model.Calendar) Test(org.junit.Test)

Example 24 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project openolat by klemens.

the class CalendarImportTest method testImportFromOutlook.

@Test
public void testImportFromOutlook() throws IOException, ParserException {
    InputStream in = CalendarImportTest.class.getResourceAsStream("Hoffstedde.ics");
    CalendarBuilder builder = new CalendarBuilder();
    Calendar calendar = builder.build(in);
    assertNotNull(calendar);
}
Also used : CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) InputStream(java.io.InputStream) Calendar(net.fortuna.ical4j.model.Calendar) Test(org.junit.Test)

Example 25 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project openolat by klemens.

the class CalendarImportTest method testImportRecurringCal.

@Test
public void testImportRecurringCal() throws IOException, ParserException {
    InputStream in = CalendarImportTest.class.getResourceAsStream("RecurringEvent.ics");
    CalendarBuilder builder = new CalendarBuilder();
    Calendar calendar = builder.build(in);
    assertNotNull(calendar);
    VEvent rootEvent = null;
    VEvent exceptionEvent = null;
    for (Iterator<?> iter = calendar.getComponents().iterator(); iter.hasNext(); ) {
        Object comp = iter.next();
        if (comp instanceof VEvent) {
            VEvent vevent = (VEvent) comp;
            if (vevent.getRecurrenceId() == null) {
                rootEvent = vevent;
            } else {
                exceptionEvent = vevent;
            }
        }
    }
    assertNotNull(rootEvent);
    assertNotNull(exceptionEvent);
    java.util.Date startDate = CalendarUtils.getDate(2016, java.util.Calendar.OCTOBER, 10);
    DateTime start = new DateTime(startDate);
    java.util.Date endDate = CalendarUtils.getDate(2016, java.util.Calendar.NOVEMBER, 10);
    DateTime end = new DateTime(endDate);
    Period period = new Period(start, end);
    PeriodList pList = rootEvent.calculateRecurrenceSet(period);
    for (Object obj : pList) {
        Period p = (Period) obj;
        System.out.println("Period: " + p.getStart());
    }
    RecurrenceId recurrenceId = exceptionEvent.getRecurrenceId();
    Date recurrenceDate = recurrenceId.getDate();
    System.out.println("Recurrence: " + recurrenceDate);
    exceptionEvent.getSequence();
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) InputStream(java.io.InputStream) Date(java.util.Date) Calendar(net.fortuna.ical4j.model.Calendar) Period(net.fortuna.ical4j.model.Period) PeriodList(net.fortuna.ical4j.model.PeriodList) DateTime(net.fortuna.ical4j.model.DateTime) Date(java.util.Date) RecurrenceId(net.fortuna.ical4j.model.property.RecurrenceId) Test(org.junit.Test)

Aggregations

CalendarBuilder (net.fortuna.ical4j.data.CalendarBuilder)28 Calendar (net.fortuna.ical4j.model.Calendar)25 Test (org.junit.Test)15 InputStream (java.io.InputStream)14 URISyntaxException (java.net.URISyntaxException)7 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)6 BufferedReader (java.io.BufferedReader)5 IOException (java.io.IOException)5 InputStreamReader (java.io.InputStreamReader)5 ParserException (net.fortuna.ical4j.data.ParserException)5 FileNotFoundException (java.io.FileNotFoundException)4 ParseException (java.text.ParseException)4 Property (net.fortuna.ical4j.model.Property)4 VEvent (net.fortuna.ical4j.model.component.VEvent)4 Kalendar (org.olat.commons.calendar.model.Kalendar)4 Date (java.util.Date)3 Component (net.fortuna.ical4j.model.Component)3 DateTime (net.fortuna.ical4j.model.DateTime)3 Period (net.fortuna.ical4j.model.Period)3 PeriodList (net.fortuna.ical4j.model.PeriodList)3