use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.
the class RdateExdate method decodeMetadata.
public static RdateExdate decodeMetadata(Metadata meta, TimeZoneMap tzmap) throws ServiceException {
boolean isRdate = meta.getBool(FN_IS_RDATE, true);
ICalTok propName = isRdate ? ICalTok.RDATE : ICalTok.EXDATE;
ICalTimeZone tz = null;
String tzid = meta.get(FN_TZID, null);
if (tzid != null)
tz = tzmap.lookupAndAdd(tzid);
String vt = meta.get(FN_VALUE_TYPE, VT_DATE_TIME);
ICalTok valueType;
if (vt.equals(VT_DATE_TIME))
valueType = ICalTok.DATE_TIME;
else if (vt.equals(VT_DATE))
valueType = ICalTok.DATE;
else
valueType = ICalTok.PERIOD;
RdateExdate rexdate = new RdateExdate(propName, valueType, tz);
int numValues = (int) meta.getLong(FN_NUM_VALUES, 0);
for (int i = 0; i < numValues; i++) {
String key = FN_VALUE + i;
if (valueType.equals(ICalTok.DATE_TIME) || valueType.equals(ICalTok.DATE)) {
String dtStr = meta.get(key);
ParsedDateTime dt;
try {
dt = ParsedDateTime.parse(dtStr, tzmap, tz, tzmap.getLocalTimeZone());
} catch (ParseException e) {
throw ServiceException.INVALID_REQUEST("Invalid " + propName.toString() + " date/time in metadata: " + meta.toString(), e);
}
rexdate.addValue(dt);
} else if (valueType.equals(ICalTok.PERIOD)) {
Period p = Period.decodeMetadata(meta.getMap(key), tz, tzmap);
rexdate.addValue(p);
}
}
return rexdate;
}
use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.
the class RecurId method fromXml.
public static RecurId fromXml(Element e, TimeZoneMap tzMap) throws ServiceException {
assert (tzMap != null);
String recurrenceId = e.getAttribute(MailConstants.A_CAL_RECURRENCE_ID, null);
if (recurrenceId == null)
return null;
String tzId = e.getAttribute(MailConstants.A_CAL_TIMEZONE, null);
ICalTimeZone tz = tzId != null ? tzMap.lookupAndAdd(tzId) : null;
String rangeType = e.getAttribute(MailConstants.A_CAL_RECURRENCE_RANGE_TYPE, null);
try {
ParsedDateTime dt = ParsedDateTime.parse(recurrenceId, tzMap, tz, tzMap.getLocalTimeZone());
if (rangeType != null)
return new RecurId(dt, rangeType);
else
return new RecurId(dt, RANGE_NONE);
} catch (ParseException x) {
throw ServiceException.FAILURE("recurId=" + recurrenceId + ", tz=" + tzId, x);
}
}
use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.
the class Period method decodeMetadata.
public static Period decodeMetadata(Metadata meta, ICalTimeZone tz, TimeZoneMap tzmap) throws ServiceException {
String start = meta.get(FN_START);
ParsedDateTime startTime;
try {
startTime = ParsedDateTime.parse(start, tzmap, tz, tzmap.getLocalTimeZone());
} catch (ParseException e) {
throw ServiceException.INVALID_REQUEST("Invalid PERIOD start time in metadata: " + meta.toString(), e);
}
String end = meta.get(FN_END, null);
if (end != null) {
ParsedDateTime endTime;
try {
endTime = ParsedDateTime.parse(end, tzmap, tz, tzmap.getLocalTimeZone());
} catch (ParseException e) {
throw ServiceException.INVALID_REQUEST("Invalid PERIOD end time in metadata: " + meta.toString(), e);
}
return new Period(startTime, endTime);
} else {
String durStr = meta.get(FN_DURATION, null);
if (durStr == null)
throw ServiceException.INVALID_REQUEST("PERIOD in metadata missing both end time and duration: " + meta.toString(), null);
ParsedDuration duration = ParsedDuration.parse(durStr);
return new Period(startTime, duration);
}
}
use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.
the class RdateExdate method addAsSeparateProperties.
// bug 59333: Hack for Apple iCal. It doesn't like comma-separate values in a single EXDATE property.
// Output each value as its own EXDATE property.
void addAsSeparateProperties(ZComponent comp) {
if (isRDATE() && !DebugConfig.enableRdate) {
return;
}
ZParameter tzid = mTimeZone != null ? new ZParameter(ICalTok.TZID, mTimeZone.getID()) : null;
ZParameter valType = !ICalTok.DATE_TIME.equals(mValueType) ? new ZParameter(ICalTok.VALUE, mValueType.toString()) : null;
for (Object value : mValues) {
ZProperty prop = new ZProperty(mPropertyName);
if (tzid != null) {
prop.addParameter(tzid);
}
if (valType != null) {
prop.addParameter(valType);
}
if (value instanceof ParsedDateTime) {
ParsedDateTime t = (ParsedDateTime) value;
prop.setValue(t.getDateTimePartString(false));
} else if (value instanceof Period) {
prop.setValue(value.toString());
}
comp.addProperty(prop);
}
}
use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.
the class Alarm method parse.
/**
* Create an Alarm from SOAP. Return value may be null.
* @param alarmElem
* @return
* @throws ServiceException
*/
public static Alarm parse(Element alarmElem) throws ServiceException {
Action action = Action.DISPLAY;
TriggerType triggerType = TriggerType.RELATIVE;
TriggerRelated triggerRelated = null;
ParsedDuration triggerRelative = null;
ParsedDateTime triggerAbsolute = null;
ParsedDuration repeatDuration = null;
int repeatCount = 0;
String description = null;
String summary = null;
Attach attach = null;
List<ZAttendee> attendees = null;
String val;
val = alarmElem.getAttribute(MailConstants.A_CAL_ALARM_ACTION);
action = Action.lookup(val);
if (action == null)
throw ServiceException.INVALID_REQUEST("Invalid " + MailConstants.A_CAL_ALARM_ACTION + " value " + val, null);
if (!actionAllowed(action))
return null;
Element triggerElem = alarmElem.getElement(MailConstants.E_CAL_ALARM_TRIGGER);
Element triggerRelativeElem = triggerElem.getOptionalElement(MailConstants.E_CAL_ALARM_RELATIVE);
if (triggerRelativeElem != null) {
triggerType = TriggerType.RELATIVE;
String related = triggerRelativeElem.getAttribute(MailConstants.A_CAL_ALARM_RELATED, null);
if (related != null) {
triggerRelated = TriggerRelated.lookup(related);
if (triggerRelated == null)
throw ServiceException.INVALID_REQUEST("Invalid " + MailConstants.A_CAL_ALARM_RELATED + " value " + val, null);
}
triggerRelative = ParsedDuration.parse(triggerRelativeElem);
} else {
triggerType = TriggerType.ABSOLUTE;
Element triggerAbsoluteElem = triggerElem.getOptionalElement(MailConstants.E_CAL_ALARM_ABSOLUTE);
if (triggerAbsoluteElem == null)
throw ServiceException.INVALID_REQUEST("<" + MailConstants.E_CAL_ALARM_TRIGGER + "> must have either <" + MailConstants.E_CAL_ALARM_RELATIVE + "> or <" + MailConstants.E_CAL_ALARM_ABSOLUTE + "> child element", null);
String datetime = triggerAbsoluteElem.getAttribute(MailConstants.A_DATE);
try {
triggerAbsolute = ParsedDateTime.parseUtcOnly(datetime);
} catch (ParseException e) {
throw ServiceException.INVALID_REQUEST("Invalid absolute trigger value " + val, e);
}
}
Element repeatElem = alarmElem.getOptionalElement(MailConstants.E_CAL_ALARM_REPEAT);
if (repeatElem != null) {
repeatDuration = ParsedDuration.parse(repeatElem);
repeatCount = (int) repeatElem.getAttributeLong(MailConstants.A_CAL_ALARM_COUNT, 0);
}
Element descElem = alarmElem.getOptionalElement(MailConstants.E_CAL_ALARM_DESCRIPTION);
if (descElem != null) {
description = descElem.getText();
}
Element summaryElem = alarmElem.getOptionalElement(MailConstants.E_CAL_ALARM_SUMMARY);
if (summaryElem != null) {
summary = summaryElem.getText();
}
Element attachElem = alarmElem.getOptionalElement(MailConstants.E_CAL_ATTACH);
if (attachElem != null)
attach = Attach.parse(attachElem);
Iterator<Element> attendeesIter = alarmElem.elementIterator(MailConstants.E_CAL_ATTENDEE);
while (attendeesIter.hasNext()) {
ZAttendee at = ZAttendee.parse(attendeesIter.next());
if (attendees == null)
attendees = new ArrayList<ZAttendee>();
attendees.add(at);
}
Alarm alarm = new Alarm(action, triggerType, triggerRelated, triggerRelative, triggerAbsolute, repeatDuration, repeatCount, description, summary, attach, attendees, CalendarUtils.parseXProps(alarmElem));
return alarm;
}
Aggregations