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());
}
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);
}
}
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();
}
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);
}
}
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;
}
Aggregations