Search in sources :

Example 1 with XmlCalendarBuilder

use of org.bedework.util.calendar.XmlCalendarBuilder 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)

Aggregations

CalendarParserImpl (net.fortuna.ical4j.data.CalendarParserImpl)1 ParserException (net.fortuna.ical4j.data.ParserException)1 UnfoldingReader (net.fortuna.ical4j.data.UnfoldingReader)1 Calendar (net.fortuna.ical4j.model.Calendar)1 BwCalendar (org.bedework.calfacade.BwCalendar)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 JsonCalendarBuilder (org.bedework.util.calendar.JsonCalendarBuilder)1 XmlCalendarBuilder (org.bedework.util.calendar.XmlCalendarBuilder)1