Search in sources :

Example 11 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project OpenOLAT by OpenOLAT.

the class ICalServlet method getOutlookVTimeZone.

/**
 * Load the VTimeZone for Outlook. ical4j use a static map to reuse the TimeZone objects, we need to load
 * and save our specialized TimeZone in a separate map.
 */
private VTimeZone getOutlookVTimeZone(final String id) throws IOException, ParserException {
    return outlookVTimeZones.computeIfAbsent(id, (timeZoneId) -> {
        try {
            URL resource = ResourceLoader.getResource("zoneinfo-outlook/" + id + ".ics");
            CalendarBuilder builder = new CalendarBuilder();
            Calendar calendar = builder.build(resource.openStream());
            VTimeZone vTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE);
            return vTimeZone;
        } catch (Exception e) {
            log.error("", e);
            return null;
        }
    });
}
Also used : CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) Calendar(net.fortuna.ical4j.model.Calendar) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) URL(java.net.URL) ValidationException(net.fortuna.ical4j.model.ValidationException) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ParserException(net.fortuna.ical4j.data.ParserException) IOException(java.io.IOException)

Example 12 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project zm-mailbox by Zimbra.

the class ZoneInfo2iCalendar method makeOldTimeZonesMap.

private static Map<String, VTimeZone> makeOldTimeZonesMap(Params params) {
    Map<String, VTimeZone> oldTimeZones = Maps.newHashMap();
    if (null != params.oldTimezonesFileName) {
        try (FileInputStream fin = new FileInputStream(params.oldTimezonesFileName)) {
            CalendarBuilder builder = new CalendarBuilder();
            net.fortuna.ical4j.model.Calendar calendar = builder.build(fin, "UTF-8");
            for (Iterator i = calendar.getComponents().iterator(); i.hasNext(); ) {
                Component component = (Component) i.next();
                if (Component.VTIMEZONE.equals(component.getName())) {
                    VTimeZone vtz = (VTimeZone) component;
                    Property tzprop = vtz.getProperties().getProperty(Property.TZID);
                    if (null != tzprop) {
                        oldTimeZones.put(tzprop.getValue(), vtz);
                    }
                }
            }
        } catch (IOException | ParserException e) {
            System.err.println("Problem loading old timezones.ics - ignoring it.  " + e.getMessage());
        }
    }
    return oldTimeZones;
}
Also used : ParserException(net.fortuna.ical4j.data.ParserException) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Iterator(java.util.Iterator) Component(net.fortuna.ical4j.model.Component) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property)

Example 13 with CalendarBuilder

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

the class CalendarImportTest method testImportWeekFromOutlook.

@Test
public void testImportWeekFromOutlook() throws IOException, ParserException {
    InputStream in = CalendarImportTest.class.getResourceAsStream("BB_7.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 14 with CalendarBuilder

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

the class CalendarImportTest method testImportAllFromOutlook.

@Test
public void testImportAllFromOutlook() throws IOException, ParserException {
    InputStream in = CalendarImportTest.class.getResourceAsStream("BB_Alles.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 15 with CalendarBuilder

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

the class CalendarImportTest method testImportMonthFromOutlook.

@Test
public void testImportMonthFromOutlook() throws IOException, ParserException {
    InputStream in = CalendarImportTest.class.getResourceAsStream("BB_30.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)

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