Search in sources :

Example 26 with ParsedDateTime

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;
}
Also used : ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone) ICalTok(com.zimbra.common.calendar.ZCalendar.ICalTok)

Example 27 with ParsedDateTime

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);
    }
}
Also used : ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 28 with ParsedDateTime

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);
    }
}
Also used : ParsedDuration(com.zimbra.common.calendar.ParsedDuration) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException)

Example 29 with ParsedDateTime

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);
    }
}
Also used : ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 30 with ParsedDateTime

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;
}
Also used : ParsedDuration(com.zimbra.common.calendar.ParsedDuration) Attach(com.zimbra.common.calendar.Attach) CalendarAttach(com.zimbra.soap.mail.type.CalendarAttach) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException)

Aggregations

ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)66 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)23 Invite (com.zimbra.cs.mailbox.calendar.Invite)20 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)18 ParseException (java.text.ParseException)16 ArrayList (java.util.ArrayList)16 IRecurrence (com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence)15 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)14 Element (com.zimbra.common.soap.Element)13 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)11 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)10 Account (com.zimbra.cs.account.Account)10 ZOrganizer (com.zimbra.cs.mailbox.calendar.ZOrganizer)10 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)9 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)8 ZAttendee (com.zimbra.cs.mailbox.calendar.ZAttendee)8 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)7 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)7 ServiceException (com.zimbra.common.service.ServiceException)7 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)7