Search in sources :

Example 46 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class IcalTranslator method toIcal.

/**
 * Turn a collection of events into a calendar
 *
 * @param vals
 * @param methodType    int value fromIcalendar
 * @return Calendar
 * @throws CalFacadeException
 */
public Calendar toIcal(final Collection vals, final int methodType) throws CalFacadeException {
    Calendar cal = newIcal(methodType);
    if ((vals == null) || (vals.size() == 0)) {
        return cal;
    }
    TreeSet<String> added = new TreeSet<String>();
    try {
        Iterator it = vals.iterator();
        while (it.hasNext()) {
            Object o = it.next();
            if (o instanceof EventInfo) {
                addToCalendar(cal, (EventInfo) o, added);
            } else {
                // XXX implement
                warn("Unimplemented toIcal for " + o.getClass().getName());
                continue;
            }
        }
        return cal;
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : EventInfo(org.bedework.calfacade.svc.EventInfo) TreeSet(java.util.TreeSet) BwCalendar(org.bedework.calfacade.BwCalendar) Calendar(net.fortuna.ical4j.model.Calendar) Iterator(java.util.Iterator) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 47 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class IcalTranslator method xmlComponent.

private void xmlComponent(final XmlEmit xml, final Component val) throws CalFacadeException {
    try {
        QName tag = openTag(xml, val.getName());
        PropertyList pl = val.getProperties();
        if (pl.size() > 0) {
            xml.openTag(XcalTags.properties);
            for (Object po : pl) {
                xmlProperty(xml, (Property) po);
            }
            xml.closeTag(XcalTags.properties);
        }
        ComponentList cl = null;
        if (val instanceof VTimeZone) {
            cl = ((VTimeZone) val).getObservances();
        } else if (val instanceof VEvent) {
            cl = ((VEvent) val).getAlarms();
        } else if (val instanceof VToDo) {
            cl = ((VToDo) val).getAlarms();
        }
        if ((cl != null) && (cl.size() > 0)) {
            xml.openTag(XcalTags.components);
            for (Object o : cl) {
                xmlComponent(xml, (Component) o);
            }
            xml.closeTag(XcalTags.components);
        }
        xml.closeTag(tag);
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) PropertyList(net.fortuna.ical4j.model.PropertyList) QName(javax.xml.namespace.QName) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) ComponentList(net.fortuna.ical4j.model.ComponentList) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) VToDo(net.fortuna.ical4j.model.component.VToDo)

Example 48 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class IcalTranslator method doTimeZone.

private TimeZoneInfo doTimeZone(final VTimeZone vtz) throws CalFacadeException {
    TzId tzid = vtz.getTimeZoneId();
    if (tzid == null) {
        throw new CalFacadeException("Missing tzid property");
    }
    String id = tzid.getValue();
    try {
        TimeZone tz = Timezones.getTz(id);
        String tzSpec = null;
        if (tz == null) {
            tz = new TimeZone(vtz);
            tzSpec = vtz.toString();
        }
        return new TimeZoneInfo(id, tz, tzSpec);
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : TimeZone(net.fortuna.ical4j.model.TimeZone) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) TimeZoneInfo(org.bedework.icalendar.Icalendar.TimeZoneInfo) TzId(net.fortuna.ical4j.model.property.TzId) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 49 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class IcalTranslator method xmlParameter.

private void xmlParameter(final XmlEmit xml, final Parameter val) throws CalFacadeException {
    try {
        ParameterInfoIndex pii = ParameterInfoIndex.lookupPname(val.getName());
        QName ptype = XcalTags.textVal;
        if (pii != null) {
            DataType dtype = pii.getPtype();
            if (dtype != null) {
                ptype = dtype.getXcalType();
            }
        }
        if (ptype.equals(XcalTags.textVal)) {
            QName tag = new QName(XcalTags.namespace, val.getName().toLowerCase());
            xml.property(tag, val.getValue());
        } else {
            QName tag = openTag(xml, val.getName());
            xml.property(ptype, val.getValue());
            xml.closeTag(tag);
        }
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : QName(javax.xml.namespace.QName) ParameterInfoIndex(org.bedework.util.calendar.PropertyIndex.ParameterInfoIndex) DataType(org.bedework.util.calendar.PropertyIndex.DataType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 50 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class IcalUtil method parseVpollCandidates.

/**
 * @param poll the poll entity
 * @return Parsed components.
 * @throws Throwable
 */
public static Map<Integer, Component> parseVpollCandidates(final BwEvent poll) throws Throwable {
    final StringBuilder sb = new StringBuilder();
    sb.append("BEGIN:VCALENDAR\n");
    sb.append("PRODID://Bedework.org//BedeWork V3.9//EN\n");
    sb.append("VERSION:2.0\n");
    if (!Util.isEmpty(poll.getPollItems())) {
        for (final String s : poll.getPollItems()) {
            sb.append(s);
        }
    }
    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<Integer, Component> comps = new HashMap<>();
        for (final Object o : ical.getComponents()) {
            final Component comp = (Component) o;
            final PollItemId pid = (PollItemId) comp.getProperty(Property.POLL_ITEM_ID);
            if (pid == null) {
                continue;
            }
            comps.put(pid.getPollitemid(), comp);
        }
        return comps;
    } 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) HashMap(java.util.HashMap) UnfoldingReader(net.fortuna.ical4j.data.UnfoldingReader) Calendar(net.fortuna.ical4j.model.Calendar) PollItemId(net.fortuna.ical4j.model.property.PollItemId) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) StringReader(java.io.StringReader) CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) StartEndComponent(org.bedework.calfacade.base.StartEndComponent) Component(net.fortuna.ical4j.model.Component)

Aggregations

CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)298 BwCalendar (org.bedework.calfacade.BwCalendar)55 BwEvent (org.bedework.calfacade.BwEvent)55 EventInfo (org.bedework.calfacade.svc.EventInfo)37 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)32 ArrayList (java.util.ArrayList)28 BwString (org.bedework.calfacade.BwString)26 BwDateTime (org.bedework.calfacade.BwDateTime)24 IndexException (org.bedework.util.indexing.IndexException)23 BwPrincipal (org.bedework.calfacade.BwPrincipal)22 TreeSet (java.util.TreeSet)19 BwAttendee (org.bedework.calfacade.BwAttendee)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)16 Calendar (net.fortuna.ical4j.model.Calendar)15 DateTime (net.fortuna.ical4j.model.DateTime)15 Period (net.fortuna.ical4j.model.Period)13 BwCategory (org.bedework.calfacade.BwCategory)13 StringReader (java.io.StringReader)12 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)12 BwEventProxy (org.bedework.calfacade.BwEventProxy)12