use of com.zimbra.cs.mailbox.calendar.Recurrence.CancellationRule in project zm-mailbox by Zimbra.
the class ExpandRecur method parseRecur.
protected static ParsedRecurrence parseRecur(Element request, TimeZoneMap tzmap) throws ServiceException {
CalendarUtils.parseTimeZones(request, tzmap);
IRecurrence recurrence = null;
List<IException> exceptions = new ArrayList<IException>();
for (Iterator<Element> compIter = request.elementIterator(); compIter.hasNext(); ) {
Element elem = compIter.next();
String elemName = elem.getName();
boolean isCancel = false;
if (MailConstants.E_CAL_CANCEL.equals(elemName)) {
isCancel = true;
} else if (!MailConstants.E_INVITE_COMPONENT.equals(elemName) && !MailConstants.E_CAL_EXCEPT.equals(elemName)) {
continue;
}
RecurId recurId = null;
Element recurIdElem = elem.getOptionalElement(MailConstants.E_CAL_EXCEPTION_ID);
if (recurIdElem != null)
recurId = CalendarUtils.parseRecurId(recurIdElem, tzmap);
if (!isCancel) {
ParsedDateTime dtStart = null;
Element dtStartElem = elem.getElement(MailConstants.E_CAL_START_TIME);
dtStart = CalendarUtils.parseDateTime(dtStartElem, tzmap);
ParsedDateTime dtEnd = null;
Element dtEndElem = elem.getOptionalElement(MailConstants.E_CAL_END_TIME);
if (dtEndElem != null)
dtEnd = CalendarUtils.parseDateTime(dtEndElem, tzmap);
ParsedDuration dur = null;
Element durElem = elem.getOptionalElement(MailConstants.E_CAL_DURATION);
if (durElem != null)
dur = ParsedDuration.parse(durElem);
if (dtEnd == null && dur == null)
throw ServiceException.INVALID_REQUEST("Must specify either " + MailConstants.E_CAL_END_TIME + " or " + MailConstants.E_CAL_DURATION + " in " + elemName, null);
Element recurElem = elem.getOptionalElement(MailConstants.E_CAL_RECUR);
if (recurElem != null) {
// series with a rule
recurrence = CalendarUtils.parseRecur(recurElem, tzmap, dtStart, dtEnd, dur, recurId);
} else {
// modified instance, or it has no rule and no recurrence-id
if (dur == null && dtStart != null && dtEnd != null)
dur = dtEnd.difference(dtStart);
if (recurId == null)
recurId = new RecurId(dtStart, RecurId.RANGE_NONE);
exceptions.add(new ExceptionRule(recurId, dtStart, dur, null));
}
} else if (recurId != null) {
// canceled instance
exceptions.add(new CancellationRule(recurId));
}
}
ParsedRecurrence parsed = new ParsedRecurrence();
if (recurrence instanceof RecurrenceRule) {
RecurrenceRule rrule = (RecurrenceRule) recurrence;
for (IException exception : exceptions) {
rrule.addException(exception);
}
parsed.rrule = rrule;
} else {
parsed.exceptions = exceptions;
}
return parsed;
}
Aggregations