Search in sources :

Example 11 with ParserException

use of net.fortuna.ical4j.data.ParserException in project bw-calendar-engine by Bedework.

the class IcalTranslator method fromIcal.

/**
 * Convert the Icalendar reader to a Collection of Calendar objects
 *
 * @param col      collection the entities will live in - possibly null
 * @param rdr
 * @param contentType
 * @param diff     True if we should assume we are updating existing events.
 * @param mergeAttendees True if we should only update our own attendee.
 * @return Icalendar
 * @throws CalFacadeException
 */
public Icalendar fromIcal(final BwCalendar col, final Reader rdr, final String contentType, final boolean diff, final boolean mergeAttendees) throws CalFacadeException {
    try {
        Icalendar ic = new Icalendar();
        setSystemProperties();
        Calendar cal;
        if ((contentType != null) && contentType.equals("application/calendar+xml")) {
            XmlCalendarBuilder bldr = new XmlCalendarBuilder(ic);
            cal = bldr.build(rdr);
        } else if ((contentType != null) && contentType.equals("application/calendar+json")) {
            JsonCalendarBuilder bldr = new JsonCalendarBuilder(ic);
            cal = bldr.build(rdr);
        } else {
            CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
            UnfoldingReader ufrdr = new UnfoldingReader(rdr, true);
            cal = bldr.build(ufrdr);
        }
        return makeIc(col, ic, cal, diff, mergeAttendees);
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (ParserException pe) {
        if (debug) {
            error(pe);
        }
        throw new IcalMalformedException(pe.getMessage());
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : ParserException(net.fortuna.ical4j.data.ParserException) CalendarParserImpl(net.fortuna.ical4j.data.CalendarParserImpl) JsonCalendarBuilder(org.bedework.util.calendar.JsonCalendarBuilder) JsonCalendarBuilder(org.bedework.util.calendar.JsonCalendarBuilder) XmlCalendarBuilder(org.bedework.util.calendar.XmlCalendarBuilder) BwCalendar(org.bedework.calfacade.BwCalendar) Calendar(net.fortuna.ical4j.model.Calendar) UnfoldingReader(net.fortuna.ical4j.data.UnfoldingReader) XmlCalendarBuilder(org.bedework.util.calendar.XmlCalendarBuilder) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 12 with ParserException

use of net.fortuna.ical4j.data.ParserException in project bw-calendar-engine by Bedework.

the class IcalUtil method parseVpollVvoters.

/**
 * @param poll the poll entity
 * @return Parsed VVOTER components map - key is voter cua.
 * @throws Throwable
 */
public static Map<String, VVoter> parseVpollVvoters(final BwEvent poll) throws Throwable {
    final StringBuilder sb = new StringBuilder();
    // Better if ical4j supported sub-component parsing
    sb.append("BEGIN:VCALENDAR\n");
    sb.append("PRODID://Bedework.org//BedeWork V3.9//EN\n");
    sb.append("VERSION:2.0\n");
    sb.append("BEGIN:VPOLL\n");
    sb.append("UID:0123\n");
    if (!Util.isEmpty(poll.getVvoters())) {
        for (final String s : poll.getVvoters()) {
            sb.append(s);
        }
    }
    sb.append("END:VPOLL\n");
    sb.append("END:VCALENDAR\n");
    try {
        final StringReader sr = new StringReader(sb.toString());
        final Icalendar ic = new Icalendar();
        final CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
        final UnfoldingReader ufrdr = new UnfoldingReader(sr, true);
        final Calendar ical = bldr.build(ufrdr);
        final Map<String, VVoter> voters = new HashMap<>();
        /* Should be one vpoll object */
        final VPoll vpoll = (VPoll) ical.getComponent(Component.VPOLL);
        for (final Object o : vpoll.getVoters()) {
            final VVoter vvoter = (VVoter) o;
            final Voter v = (Voter) vvoter.getProperty(Property.VOTER);
            if (v == null) {
                continue;
            }
            voters.put(v.getValue(), vvoter);
        }
        return voters;
    } catch (final ParserException pe) {
        throw new IcalMalformedException(pe.getMessage());
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : ParserException(net.fortuna.ical4j.data.ParserException) CalendarParserImpl(net.fortuna.ical4j.data.CalendarParserImpl) VVoter(net.fortuna.ical4j.model.component.VVoter) HashMap(java.util.HashMap) UnfoldingReader(net.fortuna.ical4j.data.UnfoldingReader) Calendar(net.fortuna.ical4j.model.Calendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) VPoll(net.fortuna.ical4j.model.component.VPoll) StringReader(java.io.StringReader) Voter(net.fortuna.ical4j.model.property.Voter) VVoter(net.fortuna.ical4j.model.component.VVoter)

Example 13 with ParserException

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

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)

Aggregations

ParserException (net.fortuna.ical4j.data.ParserException)13 IOException (java.io.IOException)8 Calendar (net.fortuna.ical4j.model.Calendar)6 CalendarBuilder (net.fortuna.ical4j.data.CalendarBuilder)4 ValidationException (net.fortuna.ical4j.model.ValidationException)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 URISyntaxException (java.net.URISyntaxException)3 URL (java.net.URL)3 VTimeZone (net.fortuna.ical4j.model.component.VTimeZone)3 Conference (com.github.lantoine.lamsadetools.conferences.Conference)2 GoogleItineraryMap (com.github.lantoine.lamsadetools.map.GoogleItineraryMap)2 UserDetails (com.github.lantoine.lamsadetools.setCoordinates.UserDetails)2 SardineException (com.github.sardine.impl.SardineException)2 StringReader (java.io.StringReader)2 SQLException (java.sql.SQLException)2 LocalDate (java.time.LocalDate)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 DateTimeParseException (java.time.format.DateTimeParseException)2 Date (java.util.Date)2