Search in sources :

Example 11 with ZParameter

use of com.zimbra.common.calendar.ZCalendar.ZParameter 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 12 with ZParameter

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

the class ToXML method jaxbXParams.

public static List<XParam> jaxbXParams(Iterator<ZParameter> xparamsIterator) {
    List<XParam> xparams = Lists.newArrayList();
    while (xparamsIterator.hasNext()) {
        ZParameter xparam = xparamsIterator.next();
        String paramName = xparam.getName();
        if (paramName == null) {
            continue;
        }
        xparams.add(new XParam(paramName, xparam.getValue()));
    }
    return Collections.unmodifiableList(xparams);
}
Also used : XParam(com.zimbra.soap.mail.type.XParam) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 13 with ZParameter

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

the class FreeBusy method parse.

/**
     * Create a FreeBusy object from VFREEBUSY ZComponent.
     * @param comp
     * @return
     * @throws ServiceException
     */
public static FreeBusy parse(ZComponent comp) throws ServiceException {
    String name = null;
    ParsedDateTime dtStart = null;
    ParsedDateTime dtEnd = null;
    List<Interval> intervals = new ArrayList<Interval>();
    TimeZoneMap tzmap = new TimeZoneMap(ICalTimeZone.getUTC());
    Iterator<ZProperty> propIter = comp.getPropertyIterator();
    while (propIter.hasNext()) {
        ZProperty prop = propIter.next();
        ICalTok tok = prop.getToken();
        if (tok == null)
            continue;
        switch(tok) {
            case DTSTART:
                try {
                    dtStart = ParsedDateTime.parse(prop, tzmap);
                } catch (ParseException e) {
                    throw ServiceException.INVALID_REQUEST("bad DTSTART: " + prop.toString(), e);
                }
                break;
            case DTEND:
                try {
                    dtEnd = ParsedDateTime.parse(prop, tzmap);
                } catch (ParseException e) {
                    throw ServiceException.INVALID_REQUEST("bad DTEND: " + prop.toString(), e);
                }
                break;
            case ORGANIZER:
                ZOrganizer att = new ZOrganizer(prop);
                name = att.getAddress();
                break;
            case FREEBUSY:
                String fbStatus = IcalXmlStrMap.FBTYPE_FREE;
                ZParameter fbType = prop.getParameter(ICalTok.FBTYPE);
                if (fbType != null)
                    fbStatus = IcalXmlStrMap.sFreeBusyMap.toXml(fbType.getValue());
                List<String> vals = prop.getValueList();
                for (String fbVal : vals) {
                    Period period;
                    try {
                        period = Period.parse(fbVal, ICalTimeZone.getUTC(), tzmap);
                    } catch (ParseException e) {
                        throw ServiceException.INVALID_REQUEST("bad period value: " + fbVal, e);
                    }
                    intervals.add(new Interval(period.getStart().getUtcTime(), period.getEnd().getUtcTime(), fbStatus));
                }
                break;
        }
    }
    if (name == null)
        throw ServiceException.INVALID_REQUEST("VFREEBUSY missing ORGANIZER", null);
    if (dtStart == null || dtEnd == null)
        throw ServiceException.INVALID_REQUEST("VFREEBUSY missing DTSTART/DTEND", null);
    IntervalList ivalList = new IntervalList(dtStart.getUtcTime(), dtEnd.getUtcTime());
    for (Interval ival : intervals) {
        ivalList.addInterval(ival);
    }
    return new FreeBusy(name, ivalList, dtStart.getUtcTime(), dtEnd.getUtcTime());
}
Also used : ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) Period(com.zimbra.cs.mailbox.calendar.Period) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) ICalTok(com.zimbra.common.calendar.ZCalendar.ICalTok) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException)

Example 14 with ZParameter

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

the class TestCalDav method attendee.

public static ZProperty attendee(MailTarget mailTarget, ICalTok role, ICalTok cutype, ICalTok partstat) {
    ZProperty att = new ZProperty(ICalTok.ATTENDEE, "mailto:" + mailTarget.getName());
    String displayName = mailTarget.getAttr(Provisioning.A_displayName);
    if (Strings.isNullOrEmpty(displayName)) {
        displayName = mailTarget.getName().substring(0, mailTarget.getName().indexOf("@"));
    }
    att.addParameter(new ZParameter(ICalTok.CN, displayName));
    att.addParameter(new ZParameter(ICalTok.ROLE, role.toString()));
    att.addParameter(new ZParameter(ICalTok.CUTYPE, cutype.toString()));
    att.addParameter(new ZParameter(ICalTok.PARTSTAT, partstat.toString()));
    return att;
}
Also used : ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 15 with ZParameter

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

the class TestCalDav method organizer.

public static ZProperty organizer(Account acct) {
    ZProperty org = new ZProperty(ICalTok.ORGANIZER, "mailto:" + acct.getName());
    String displayName = acct.getDisplayName();
    if (Strings.isNullOrEmpty(displayName)) {
        displayName = acct.getName().substring(0, acct.getName().indexOf("@"));
    }
    org.addParameter(new ZParameter(ICalTok.CN, displayName));
    return org;
}
Also used : ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Aggregations

ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)28 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)20 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)8 ArrayList (java.util.ArrayList)8 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)7 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)7 ParseException (java.text.ParseException)5 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)4 Metadata (com.zimbra.cs.mailbox.Metadata)4 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)3 Element (com.zimbra.common.soap.Element)3 IRecurrence (com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence)3 Attach (com.zimbra.common.calendar.Attach)2 Geo (com.zimbra.common.calendar.Geo)2 ServiceException (com.zimbra.common.service.ServiceException)2 Account (com.zimbra.cs.account.Account)2 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)2 MailItem (com.zimbra.cs.mailbox.MailItem)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 Invite (com.zimbra.cs.mailbox.calendar.Invite)2