Search in sources :

Example 11 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 12 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 13 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)

Example 14 with ParsedDateTime

use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.

the class Alarm method parse.

/**
     * Create an Alarm from ZComponent.  Return value may be null.
     * @param comp
     * @return
     * @throws ServiceException
     */
public static Alarm parse(ZComponent comp) 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;
    List<ZProperty> xprops = new ArrayList<ZProperty>();
    Iterator<ZProperty> propIter = comp.getPropertyIterator();
    while (propIter.hasNext()) {
        ZProperty prop = propIter.next();
        ICalTok tok = prop.getToken();
        String val = prop.getValue();
        if (tok == null) {
            String name = prop.getName();
            if (name.startsWith("X-") || name.startsWith("x-")) {
                xprops.add(prop);
            }
            continue;
        }
        switch(tok) {
            case ACTION:
                if (val != null) {
                    action = Action.lookup(val);
                    if (action == null)
                        throw ServiceException.INVALID_REQUEST("Invalid ACTION value " + val, null);
                    if (!actionAllowed(action))
                        return null;
                }
                break;
            case TRIGGER:
                ZParameter valueType = prop.getParameter(ICalTok.VALUE);
                if (valueType != null) {
                    String vt = valueType.getValue();
                    if (ICalTok.DATE_TIME.toString().equals(vt))
                        triggerType = TriggerType.ABSOLUTE;
                }
                if (TriggerType.RELATIVE.equals(triggerType)) {
                    ZParameter related = prop.getParameter(ICalTok.RELATED);
                    if (related != null) {
                        String rel = related.getValue();
                        if (rel != null) {
                            triggerRelated = TriggerRelated.lookup(rel);
                            if (triggerRelated == null)
                                throw ServiceException.INVALID_REQUEST("Invalid RELATED value " + rel, null);
                        }
                    }
                    triggerRelative = ParsedDuration.parse(val);
                } else {
                    try {
                        if (val != null)
                            triggerAbsolute = ParsedDateTime.parseUtcOnly(val);
                    } catch (ParseException e) {
                        throw ServiceException.INVALID_REQUEST("Invalid TRIGGER value " + val, e);
                    }
                }
                break;
            case DURATION:
                if (val != null)
                    repeatDuration = ParsedDuration.parse(val);
                break;
            case REPEAT:
                if (val != null) {
                    try {
                        repeatCount = Integer.parseInt(val);
                    } catch (NumberFormatException e) {
                        throw ServiceException.INVALID_REQUEST("Invalid REPEAT value " + val, e);
                    }
                }
                break;
            case DESCRIPTION:
                description = val;
                break;
            case SUMMARY:
                summary = val;
                break;
            case ATTACH:
                attach = Attach.parse(prop);
                break;
            case ATTENDEE:
                ZAttendee attendee = new ZAttendee(prop);
                if (attendees == null)
                    attendees = new ArrayList<ZAttendee>();
                attendees.add(attendee);
                break;
        }
    }
    Alarm alarm = new Alarm(action, triggerType, triggerRelated, triggerRelative, triggerAbsolute, repeatDuration, repeatCount, description, summary, attach, attendees, xprops);
    return alarm;
}
Also used : ParsedDuration(com.zimbra.common.calendar.ParsedDuration) Attach(com.zimbra.common.calendar.Attach) CalendarAttach(com.zimbra.soap.mail.type.CalendarAttach) ArrayList(java.util.ArrayList) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) ICalTok(com.zimbra.common.calendar.ZCalendar.ICalTok) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException)

Example 15 with ParsedDateTime

use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.

the class ToXML method encodeCalendarItemRecur.

public static void encodeCalendarItemRecur(Element parent, CalendarItem calItem) {
    TimeZoneMap tzmap = calItem.getTimeZoneMap();
    encodeTimeZoneMap(parent, tzmap);
    Invite[] invites = calItem.getInvites();
    for (Invite inv : invites) {
        String elemName;
        if (inv.isCancel()) {
            elemName = MailConstants.E_CAL_CANCEL;
        } else if (inv.hasRecurId()) {
            elemName = MailConstants.E_CAL_EXCEPT;
        } else {
            elemName = MailConstants.E_INVITE_COMPONENT;
        }
        Element compElem = parent.addElement(elemName);
        boolean allDay = inv.isAllDayEvent();
        // RECURRENCE-ID
        if (inv.hasRecurId())
            encodeRecurId(compElem, inv.getRecurId(), allDay);
        if (!inv.isCancel()) {
            // DTSTART
            ParsedDateTime dtStart = inv.getStartTime();
            if (dtStart != null)
                encodeDtStart(compElem, dtStart, allDay, false);
            // DTEND or DURATION
            ParsedDateTime dtEnd = inv.getEndTime();
            if (dtEnd != null) {
                encodeDtEnd(compElem, dtEnd, allDay, inv.isTodo(), false);
            } else {
                ParsedDuration dur = inv.getDuration();
                if (dur != null)
                    dur.toXml(compElem);
            }
            // recurrence definition
            IRecurrence recurrence = inv.getRecurrence();
            if (recurrence != null) {
                Element recurElem = compElem.addElement(MailConstants.E_CAL_RECUR);
                recurrence.toXml(recurElem);
            }
        }
    }
}
Also used : IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) ParsedDuration(com.zimbra.common.calendar.ParsedDuration) Element(com.zimbra.common.soap.Element) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) Invite(com.zimbra.cs.mailbox.calendar.Invite)

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