Search in sources :

Example 41 with CalFacadeException

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

the class Notifications method add.

@Override
public boolean add(final NotificationType val) throws CalFacadeException {
    if ((val == null) || (val.getNotification() == null) || (val.getNotification().getElementName() == null)) {
        return false;
    }
    final BwCalendar ncol = getCols().getSpecial(BwCalendar.calTypeNotifications, true);
    if (ncol == null) {
        return false;
    }
    final BwResource noteRsrc = new BwResource();
    noteRsrc.setName(val.getName());
    noteRsrc.setEncoding(val.getNotification().getEncoding());
    final BwResourceContent rc = new BwResourceContent();
    noteRsrc.setContent(rc);
    try {
        final String xml = val.toXml(true);
        if (xml == null) {
            return false;
        }
        final byte[] xmlData = xml.getBytes();
        rc.setValue(getSvc().getBlob(xmlData));
        noteRsrc.setContentLength(xmlData.length);
        noteRsrc.setContentType(val.getContentType());
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    for (int i = 0; i <= 100; i++) {
        if (getRess().saveNotification(ncol.getPath(), noteRsrc)) {
            getNoteClient().informNotifier(getPrincipalHref(), noteRsrc.getName());
            return true;
        }
        noteRsrc.setName(val.getName() + "-" + i);
    }
    throw new CalFacadeException(CalFacadeException.duplicateResource, val.getName());
}
Also used : BwResource(org.bedework.calfacade.BwResource) BwResourceContent(org.bedework.calfacade.BwResourceContent) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 42 with CalFacadeException

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

the class IcalTranslator method xmlProperty.

private void xmlProperty(final XmlEmit xml, final Property val) throws CalFacadeException {
    try {
        QName tag = openTag(xml, val.getName());
        ParameterList pl = val.getParameters();
        if (pl.size() > 0) {
            xml.openTag(XcalTags.parameters);
            Iterator pli = pl.iterator();
            while (pli.hasNext()) {
                xmlParameter(xml, (Parameter) pli.next());
            }
            xml.closeTag(XcalTags.parameters);
        }
        PropertyInfoIndex pii = PropertyInfoIndex.fromName(val.getName());
        QName ptype = XcalTags.textVal;
        if (pii != null) {
            DataType dtype = pii.getPtype();
            if (dtype != null) {
                ptype = dtype.getXcalType();
            }
        }
        if (ptype == null) {
            // Special processing I haven't done
            warn("Unimplemented value type for " + val.getName());
            ptype = XcalTags.textVal;
        }
        if (ptype.equals(XcalTags.recurVal)) {
            // Emit individual parts of recur rule
            xml.openTag(ptype);
            Recur r;
            if (val instanceof ExRule) {
                r = ((ExRule) val).getRecur();
            } else {
                r = ((RRule) val).getRecur();
            }
            xml.property(XcalTags.freq, r.getFrequency());
            xmlProp(xml, XcalTags.wkst, r.getWeekStartDay().name());
            if (r.getUntil() != null) {
                xmlProp(xml, XcalTags.until, r.getUntil().toString());
            }
            xmlProp(xml, XcalTags.count, String.valueOf(r.getCount()));
            xmlProp(xml, XcalTags.interval, String.valueOf(r.getInterval()));
            xmlProp(xml, XcalTags.bymonth, r.getMonthList());
            xmlProp(xml, XcalTags.byweekno, r.getWeekNoList());
            xmlProp(xml, XcalTags.byyearday, r.getYearDayList());
            xmlProp(xml, XcalTags.bymonthday, r.getMonthDayList());
            xmlProp(xml, XcalTags.byday, r.getDayList());
            xmlProp(xml, XcalTags.byhour, r.getHourList());
            xmlProp(xml, XcalTags.byminute, r.getMinuteList());
            xmlProp(xml, XcalTags.bysecond, r.getSecondList());
            xmlProp(xml, XcalTags.bysetpos, r.getSetPosList());
            xml.closeTag(ptype);
        } else {
            xml.property(ptype, val.getValue());
        }
        xml.closeTag(tag);
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : PropertyInfoIndex(org.bedework.util.calendar.PropertyIndex.PropertyInfoIndex) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) ParameterList(net.fortuna.ical4j.model.ParameterList) DataType(org.bedework.util.calendar.PropertyIndex.DataType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Recur(net.fortuna.ical4j.model.Recur) ExRule(net.fortuna.ical4j.model.property.ExRule)

Example 43 with CalFacadeException

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

the class IcalTranslator method toIcalString.

/**
 * Make a new Calendar with the freebusy object
 *
 * @param methodType
 * @param ent
 * @return String representation
 * @throws CalFacadeException
 */
public static String toIcalString(final int methodType, final BwEvent ent) throws CalFacadeException {
    Calendar cal = new Calendar();
    PropertyList pl = cal.getProperties();
    pl.add(new ProdId(prodId));
    pl.add(Version.VERSION_2_0);
    if ((methodType > ScheduleMethods.methodTypeNone) && (methodType < ScheduleMethods.methodTypeUnknown)) {
        pl.add(new Method(ScheduleMethods.methods[methodType]));
    }
    if (ent.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
        VFreeBusy vfreeBusy = VFreeUtil.toVFreeBusy(ent);
        cal.getComponents().add(vfreeBusy);
    } else {
        throw new CalFacadeException("Unexpected entity type");
    }
    CalendarOutputter co = new CalendarOutputter(false, 74);
    Writer wtr = new StringWriter();
    try {
        co.output(cal, wtr);
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
    return wtr.toString();
}
Also used : PropertyList(net.fortuna.ical4j.model.PropertyList) StringWriter(java.io.StringWriter) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) BwCalendar(org.bedework.calfacade.BwCalendar) Calendar(net.fortuna.ical4j.model.Calendar) Method(net.fortuna.ical4j.model.property.Method) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter) ProdId(net.fortuna.ical4j.model.property.ProdId) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Writer(java.io.Writer) StringWriter(java.io.StringWriter)

Example 44 with CalFacadeException

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

the class IcalTranslator method fromIcal.

/**
 * Convert the Icalendar object to a Collection of Calendar objects
 *
 * @param col      collection the entities will live in - possibly null
 * @param ical
 * @param diff     True if we should assume we are updating existing events.
 * @return Icalendar
 * @throws CalFacadeException
 */
public Icalendar fromIcal(final BwCalendar col, final IcalendarType ical, final boolean diff) throws CalFacadeException {
    Icalendar ic = new Icalendar();
    setSystemProperties();
    WsXMLTranslator bldr = new WsXMLTranslator(ic);
    try {
        Calendar cal = bldr.fromXcal(ical);
        return makeIc(col, ic, cal, diff, false);
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) Calendar(net.fortuna.ical4j.model.Calendar) WsXMLTranslator(org.bedework.util.calendar.WsXMLTranslator) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 45 with CalFacadeException

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

the class IcalTranslator method tzFromTzdef.

/**
 * Get a TimeZone object from a VCALENDAR string definition
 *
 * @param val
 * @return TimeZone
 * @throws CalFacadeException
 */
public TimeZone tzFromTzdef(final String val) throws CalFacadeException {
    StringReader sr = new StringReader(val);
    Icalendar ic = fromIcal(null, sr);
    if ((ic == null) || // No components other than timezones
    (ic.size() != 0) || (ic.getTimeZones().size() != 1)) {
        if (debug) {
            debug("Not icalendar");
        }
        throw new CalFacadeException("Not icalendar");
    }
    /* This should be the only timezone ion the Calendar object
     */
    return ic.getTimeZones().iterator().next().tz;
}
Also used : StringReader(java.io.StringReader) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

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