Element orgElt = element .getOptionalElement(MailService.E_APPT_ORGANIZER); if (orgElt == null) { throw ServiceException.INVALID_REQUEST( "Event must have an Organizer", null); } else { String address = orgElt.getAttribute(MailService.A_ADDRESS); String cn = orgElt.getAttribute(MailService.A_DISPLAY, null); String sentBy = orgElt.getAttribute(MailService.A_APPT_SENTBY, null); String dir = orgElt.getAttribute(MailService.A_APPT_DIR, null); String lang = orgElt.getAttribute(MailService.A_APPT_LANGUAGE, null);  ZOrganizer org = new ZOrganizer(address, cn, sentBy, dir, lang); newInv.setOrganizer(org); }
    private static void parseInviteElementCommon(            Account account, Element element, Invite newInv,            boolean recurrenceIdAllowed, boolean recurAllowed)    throws ServiceException {    	Element compElem = element.getOptionalElement(MailService.E_INVITE_COMPONENT);    	if (compElem != null)    		element = compElem;    	TimeZoneMap tzMap = newInv.getTimeZoneMap();        parseTimeZones(element.getParent(), tzMap);        // component type (event, todo, or journal)        String compType = element.getAttribute(MailService.A_APPT_TYPE,                                               IcalXmlStrMap.COMPTYPE_EVENT);        newInv.setCompType(compType);        // UID        String uid = element.getAttribute(MailService.A_UID, null);        if (uid == null || uid.length() == 0)            uid = LdapUtil.generateUUID();        newInv.setUid(uid);        // RECURRENCE-ID        if (recurrenceIdAllowed) {            Element e = element.getElement(MailService.E_APPT_EXCEPTION_ID);            ParsedDateTime dt = parseDateTime(e, tzMap, newInv);            RecurId recurId = new RecurId(dt, RecurId.RANGE_NONE);            newInv.setRecurId(recurId);        } else {            if (element.getOptionalElement(MailService.E_APPT_EXCEPTION_ID) != null) {                throw ServiceException.INVALID_REQUEST(                        "May not specify an <exceptId> in this request",                        null);            }        }        boolean allDay = element.getAttributeBool(MailService.A_APPT_ALLDAY,                false);        newInv.setIsAllDayEvent(allDay);        String name = element.getAttribute(MailService.A_NAME, "");        String location = element.getAttribute(MailService.A_APPT_LOCATION, "");        // SEQUENCE        int seq = (int) element.getAttributeLong(MailService.A_APPT_SEQUENCE, 0);        newInv.setSeqNo(seq);        // ORGANIZER        Element orgElt = element                .getOptionalElement(MailService.E_APPT_ORGANIZER);        if (orgElt == null) {            throw ServiceException.INVALID_REQUEST(                    "Event must have an Organizer", null);        } else {            String address = orgElt.getAttribute(MailService.A_ADDRESS);            String cn = orgElt.getAttribute(MailService.A_DISPLAY, null);            String sentBy = orgElt.getAttribute(MailService.A_APPT_SENTBY, null);            String dir = orgElt.getAttribute(MailService.A_APPT_DIR, null);            String lang = orgElt.getAttribute(MailService.A_APPT_LANGUAGE, null);            ZOrganizer org = new ZOrganizer(address, cn, sentBy, dir, lang);            newInv.setOrganizer(org);        }        // SUMMARY (aka Name or Subject)        newInv.setName(name);        // DTSTART        {            Element s;            if (newInv.isTodo())                s = element.getOptionalElement(MailService.E_APPT_START_TIME);            else                s = element.getElement(MailService.E_APPT_START_TIME);            if (s != null) {                ParsedDateTime dt = parseDtElement(s, tzMap, newInv);                if (dt.hasTime()) {                    if (allDay) {                        throw ServiceException.INVALID_REQUEST(                                        "AllDay event must have DATE, not DATETIME for start time",                                        null);                    }                } else {                    if (!allDay) {                        throw ServiceException.INVALID_REQUEST(                                        "Request must have allDay=\"1\" if using a DATE start time instead of DATETIME",                                        null);                    }                }                newInv.setDtStart(dt);            }        }        // DTEND (for VEVENT) or DUE (for VTODO)        {            Element e = element.getOptionalElement(MailService.E_APPT_END_TIME);            if (e != null) {                if (element.getOptionalElement(MailService.E_APPT_DURATION) != null) {                    throw ServiceException.INVALID_REQUEST(                                    "<comp> may have <e> end or <d> duration but not both",                                    null);                }                ParsedDateTime dt = parseDtElement(e, tzMap, newInv);                if (allDay) {                    // HACK ALERT: okay, campers, here's the deal.                    // By definition, our end dates are EXCLUSIVE: DTEND is not                    // included.. eg a meeting 7-8pm actually stops at 7:59                    //                    // This makes sense for normal appointments, but apparently                    // this rule is confusing to people when making                    // all-day-events                    //                    // For all-day-events, people want to say that a 1-day-long                    // appointment starts on 11/1 and ends on 11/1, for example                    // this is inconsistent (and incompatible with RFC2445) but                    // it is what people want. Sooo, we to a bit of a hacky                    // translation when sending/receiving all-day-events.                    //                         dt = dt.add(ParsedDuration.ONE_DAY);                }                if (dt.hasTime()) {                    if (allDay) {                        throw ServiceException.INVALID_REQUEST(                                        "AllDay event must have DATE, not DATETIME for start time",                                        null);                    }                } else {                    if (!allDay) {                        throw ServiceException.INVALID_REQUEST(                                        "Request must have allDay=\"1\" if using a DATE start time instead of DATETIME",                                        null);                    }                }                newInv.setDtEnd(dt);            }        }        // DURATION        {            Element d = element.getOptionalElement(MailService.E_APPT_DURATION);            if (d != null) {                ParsedDuration pd = ParsedDuration.parse(d);                newInv.setDuration(pd);            }        }        // LOCATION        newInv.setLocation(location);        // STATUS        String status = element.getAttribute(MailService.A_APPT_STATUS,                IcalXmlStrMap.STATUS_CONFIRMED);        validateAttr(IcalXmlStrMap.sStatusMap, MailService.A_APPT_STATUS,                status);        newInv.setStatus(status);        // PRIORITY        String priority = element.getAttribute(MailService.A_APPT_PRIORITY, null);        newInv.setPriority(priority);        if (newInv.isEvent()) {            // FreeBusy            String fb = element.getAttribute(MailService.A_APPT_FREEBUSY,                    IcalXmlStrMap.FBTYPE_BUSY);            newInv.setFreeBusy(fb);                // TRANSPARENCY            String transp = element.getAttribute(MailService.A_APPT_TRANSPARENCY,                    IcalXmlStrMap.TRANSP_OPAQUE);            validateAttr(IcalXmlStrMap.sTranspMap, MailService.A_APPT_TRANSPARENCY,                    transp);            newInv.setTransparency(transp);        }        if (newInv.isTodo()) {            // PERCENT-COMPLETE            String pctComplete = element.getAttribute(MailService.A_APPT_PERCENT_COMPLETE, null);            newInv.setPercentComplete(pctComplete);            // COMPLETED            String completed = element.getAttribute(MailService.A_APPT_COMPLETED, null);            if (completed != null) {                try {                    ParsedDateTime c = ParsedDateTime.parseUtcOnly(completed);                    newInv.setCompleted(c.getUtcTime());                } catch (ParseException e) {                    throw ServiceException.INVALID_REQUEST("Invalid COMPLETED value: " + completed, e);                }            }        }        // ATTENDEEs        boolean hasAttendees = false;        for (Iterator iter = element                .elementIterator(MailService.E_APPT_ATTENDEE); iter.hasNext();) {            Element cur = (Element) (iter.next());            String address = cur.getAttribute(MailService.A_ADDRESS);            String cn = cur.getAttribute(MailService.A_DISPLAY, null);            String sentBy = cur.getAttribute(MailService.A_APPT_SENTBY, null);            String dir = cur.getAttribute(MailService.A_APPT_DIR, null);            String lang = cur.getAttribute(MailService.A_APPT_LANGUAGE, null);            String cutype = cur.getAttribute(MailService.A_APPT_CUTYPE, null);            if (cutype != null)            	validateAttr(IcalXmlStrMap.sCUTypeMap, MailService.A_APPT_CUTYPE, cutype);            String role = cur.getAttribute(MailService.A_APPT_ROLE);            validateAttr(IcalXmlStrMap.sRoleMap, MailService.A_APPT_ROLE, role);            String partStat = cur.getAttribute(MailService.A_APPT_PARTSTAT);            validateAttr(IcalXmlStrMap.sPartStatMap,                    MailService.A_APPT_PARTSTAT, partStat);            String member = cur.getAttribute(MailService.A_APPT_MEMBER, null);            String delTo = cur.getAttribute(MailService.A_APPT_DELEGATED_TO, null);            String delFrom = cur.getAttribute(MailService.A_APPT_DELEGATED_FROM, null);            boolean rsvp = cur.getAttributeBool(MailService.A_APPT_RSVP, false);//            if (partStat.equals(IcalXmlStrMap.PARTSTAT_NEEDS_ACTION))//                rsvp = true;            ZAttendee at =                new ZAttendee(address, cn, sentBy, dir, lang,                              cutype, role, partStat,                              rsvp ? Boolean.TRUE : Boolean.FALSE,                              member, delTo, delFrom);            newInv.addAttendee(at);            hasAttendees = true;        }        if (hasAttendees &&            newInv.getMethod().equals(ICalTok.PUBLISH.toString())) {            newInv.setMethod(ICalTok.REQUEST.toString());        }        // RECUR        Element recur = element.getOptionalElement(MailService.A_APPT_RECUR);        if (recur != null) {            if (!recurAllowed) {                throw ServiceException.INVALID_REQUEST(                        "No <recur> allowed in an exception", null);            }            Recurrence.IRecurrence recurrence = parseRecur(recur, tzMap,                    newInv);            newInv.setRecurrence(recurrence);        }        List<ZProperty> xprops = parseXProps(element);        for (ZProperty prop : xprops)            newInv.addXProp(prop);    }