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;
}
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);
}
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());
}
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;
}
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;
}
Aggregations