use of net.fortuna.ical4j.model.PropertyList in project camel by apache.
the class ICalDataFormatTest method createTestCalendar.
/**
* Creates test calendar instance.
*
* @return ICal calendar object.
*/
protected Calendar createTestCalendar() throws ParseException {
// Create a TimeZone
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone("America/New_York");
VTimeZone tz = timezone.getVTimeZone();
// Start Date is on: April 1, 2013, 9:00 am
java.util.Calendar startDate = new GregorianCalendar();
startDate.setTimeZone(timezone);
startDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
startDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
startDate.set(java.util.Calendar.YEAR, 2013);
startDate.set(java.util.Calendar.HOUR_OF_DAY, 17);
startDate.set(java.util.Calendar.MINUTE, 0);
startDate.set(java.util.Calendar.SECOND, 0);
// End Date is on: April 1, 2013, 13:00
java.util.Calendar endDate = new GregorianCalendar();
endDate.setTimeZone(timezone);
endDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
endDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
endDate.set(java.util.Calendar.YEAR, 2013);
endDate.set(java.util.Calendar.HOUR_OF_DAY, 21);
endDate.set(java.util.Calendar.MINUTE, 0);
endDate.set(java.util.Calendar.SECOND, 0);
// Create the event
PropertyList propertyList = new PropertyList();
propertyList.add(new DtStamp("20130324T180000Z"));
propertyList.add(new DtStart(new DateTime(startDate.getTime())));
propertyList.add(new DtEnd(new DateTime(endDate.getTime())));
propertyList.add(new Summary("Progress Meeting"));
VEvent meeting = new VEvent(propertyList);
// add timezone info..
meeting.getProperties().add(tz.getTimeZoneId());
// generate unique identifier..
meeting.getProperties().add(new Uid("00000000"));
// add attendees..
Attendee dev1 = new Attendee(URI.create("mailto:dev1@mycompany.com"));
dev1.getParameters().add(Role.REQ_PARTICIPANT);
dev1.getParameters().add(new Cn("Developer 1"));
meeting.getProperties().add(dev1);
Attendee dev2 = new Attendee(URI.create("mailto:dev2@mycompany.com"));
dev2.getParameters().add(Role.OPT_PARTICIPANT);
dev2.getParameters().add(new Cn("Developer 2"));
meeting.getProperties().add(dev2);
// Create a calendar
net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
icsCalendar.getProperties().add(Version.VERSION_2_0);
icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
icsCalendar.getProperties().add(CalScale.GREGORIAN);
// Add the event and print
icsCalendar.getComponents().add(meeting);
return icsCalendar;
}
use of net.fortuna.ical4j.model.PropertyList in project wildfly-camel by wildfly-extras.
the class ICalFormatTest method createTestCalendar.
private Calendar createTestCalendar() throws ParseException {
// Create a TimeZone
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone("America/New_York");
VTimeZone tz = timezone.getVTimeZone();
// Start Date is on: April 1, 2013, 9:00 am
java.util.Calendar startDate = new GregorianCalendar();
startDate.setTimeZone(timezone);
startDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
startDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
startDate.set(java.util.Calendar.YEAR, 2013);
startDate.set(java.util.Calendar.HOUR_OF_DAY, 17);
startDate.set(java.util.Calendar.MINUTE, 0);
startDate.set(java.util.Calendar.SECOND, 0);
// End Date is on: April 1, 2013, 13:00
java.util.Calendar endDate = new GregorianCalendar();
endDate.setTimeZone(timezone);
endDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
endDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
endDate.set(java.util.Calendar.YEAR, 2013);
endDate.set(java.util.Calendar.HOUR_OF_DAY, 21);
endDate.set(java.util.Calendar.MINUTE, 0);
endDate.set(java.util.Calendar.SECOND, 0);
// Create the event
PropertyList propertyList = new PropertyList();
propertyList.add(new DtStamp("20130324T180000Z"));
propertyList.add(new DtStart(new DateTime(startDate.getTime())));
propertyList.add(new DtEnd(new DateTime(endDate.getTime())));
propertyList.add(new Summary("Progress Meeting"));
VEvent meeting = new VEvent(propertyList);
// add timezone info..
meeting.getProperties().add(tz.getTimeZoneId());
// generate unique identifier..
meeting.getProperties().add(new Uid("00000000"));
// add attendees..
Attendee dev1 = new Attendee(URI.create("mailto:dev1@mycompany.com"));
dev1.getParameters().add(Role.REQ_PARTICIPANT);
dev1.getParameters().add(new Cn("Developer 1"));
meeting.getProperties().add(dev1);
Attendee dev2 = new Attendee(URI.create("mailto:dev2@mycompany.com"));
dev2.getParameters().add(Role.OPT_PARTICIPANT);
dev2.getParameters().add(new Cn("Developer 2"));
meeting.getProperties().add(dev2);
// Create a calendar
net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
icsCalendar.getProperties().add(Version.VERSION_2_0);
icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
icsCalendar.getProperties().add(CalScale.GREGORIAN);
// Add the event and print
icsCalendar.getComponents().add(meeting);
return icsCalendar;
}
use of net.fortuna.ical4j.model.PropertyList in project bw-calendar-engine by Bedework.
the class RecurUtil method getLatestRecurrenceDate.
/**
* Return the absolute latest end date for this event. Note that
* exclusions may mean the actual latest date is earlier.
*
* @param evprops
* @param vstart
* @param enddt
* @param d
* @param maxRangeEnd
* @return date
* @throws CalFacadeException
*/
private static Date getLatestRecurrenceDate(final PropertyList evprops, final DtStart vstart, final DtEnd enddt, final Duration d, final Date maxRangeEnd) throws CalFacadeException {
boolean debug = getLog().isDebugEnabled();
try {
Date start = vstart.getDate();
Date until = null;
/* Get the duration of the event to get us past the end
*/
Dur dur;
if (d != null) {
dur = d.getDuration();
} else {
Date evend;
if (enddt == null) {
evend = start;
} else {
evend = enddt.getDate();
}
dur = new Dur(start, evend);
}
/* Make a new duration incremented a little to avoid any boundary
conditions */
if (dur.getWeeks() != 0) {
dur = new Dur(dur.getWeeks() + 1);
} else {
dur = new Dur(dur.getDays() + 1, dur.getHours(), dur.getMinutes(), dur.getSeconds());
}
PropertyList rrules = evprops.getProperties(Property.RRULE);
PropertyList rdts = evprops.getProperties(Property.RDATE);
if ((rrules == null) && (rdts == null)) {
// Not a recurring event
return null;
}
if (rrules != null) {
Iterator rit = rrules.iterator();
while (rit.hasNext()) {
RRule r = (RRule) rit.next();
Date nextUntil = getLastDate(r.getRecur(), start, maxRangeEnd);
if (nextUntil == null) {
/* We have a rule without an end date so it's infinite.
*/
return null;
}
if (debug) {
debugMsg("Last date for recur=" + nextUntil);
}
if ((until == null) || (nextUntil.after(until))) {
until = nextUntil;
}
}
/* We have some rules - none have an end date so it's infinite.
*/
if (until == null) {
// infinite
return null;
}
}
if (rdts != null) {
// Get the latest date from each
// XXX are these sorted?
Iterator rit = rdts.iterator();
while (rit.hasNext()) {
RDate r = (RDate) rit.next();
if (Value.PERIOD.equals(r.getParameter(Parameter.VALUE))) {
PeriodList pl = r.getPeriods();
Iterator it = pl.iterator();
while (it.hasNext()) {
Period p = (Period) it.next();
// Not sure if a single date gives a null end
Date nextUntil = p.getEnd();
if (nextUntil == null) {
nextUntil = p.getStart();
}
if ((until == null) || (nextUntil.after(until))) {
until = nextUntil;
}
}
} else {
// date or datetime
DateList startDates = r.getDates();
for (int j = 0; j < startDates.size(); j++) {
Date startDate = (Date) startDates.get(j);
Date endDate = new Date(dur.getTime(startDate));
if ((until == null) || (endDate.after(until))) {
until = endDate;
}
}
}
}
}
if (debug) {
debugMsg("Last date before fix=" + until);
}
/* Now add the duration of the event to get us past the end
*/
if (until instanceof DateTime) {
until = new DateTime(dur.getTime(until));
((DateTime) until).setUtc(true);
} else {
until = new Date(dur.getTime(until));
}
if (debug) {
debugMsg("Last date after fix=" + until);
}
return until;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of net.fortuna.ical4j.model.PropertyList in project bw-calendar-engine by Bedework.
the class VAlarmUtil method processComponentAlarms.
/**
* If there are any alarms for this component add them to the events alarm
* collection
*
* @param cb IcalCallback object
* @param val
* @param ev
* @param currentPrincipal - href for current authenticated user
* @param chg
* @throws CalFacadeException
*/
public static void processComponentAlarms(final IcalCallback cb, final Component val, final BwEvent ev, final String currentPrincipal, final ChangeTable chg) throws CalFacadeException {
try {
ComponentList als = null;
if (val instanceof VEvent) {
als = ((VEvent) val).getAlarms();
} else if (val instanceof VToDo) {
als = ((VToDo) val).getAlarms();
} else if (val instanceof VPoll) {
als = ((VPoll) val).getAlarms();
} else {
return;
}
if ((als == null) || als.isEmpty()) {
return;
}
for (Object o : als) {
if (!(o instanceof VAlarm)) {
throw new IcalMalformedException("Invalid alarm list");
}
VAlarm va = (VAlarm) o;
PropertyList pl = va.getProperties();
if (pl == null) {
// Empty VAlarm
throw new IcalMalformedException("Invalid alarm list");
}
Property prop;
BwAlarm al;
/* XXX Handle mozilla alarm stuff in a way that might work better with other clients.
*
*/
prop = pl.getProperty("X-MOZ-LASTACK");
boolean mozlastAck = prop != null;
String mozSnoozeTime = null;
if (mozlastAck) {
prop = pl.getProperty("X-MOZ-SNOOZE-TIME");
if (prop == null) {
// lastack and no snooze - presume dismiss so delete alarm
continue;
}
// UTC time
mozSnoozeTime = prop.getValue();
}
// All alarm types require action and trigger
prop = pl.getProperty(Property.ACTION);
if (prop == null) {
throw new IcalMalformedException("Invalid alarm");
}
String actionStr = prop.getValue();
TriggerVal tr = getTrigger(pl, "NONE".equals(actionStr));
if (mozSnoozeTime != null) {
tr.trigger = mozSnoozeTime;
tr.triggerDateTime = true;
tr.triggerStart = false;
}
DurationRepeat dr = getDurationRepeat(pl);
if ("EMAIL".equals(actionStr)) {
al = BwAlarm.emailAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "ATTACH"), getReqStr(pl, "DESCRIPTION"), getReqStr(pl, "SUMMARY"), null);
Iterator<?> atts = getReqStrs(pl, "ATTENDEE");
while (atts.hasNext()) {
al.addAttendee(getAttendee(cb, (Attendee) atts.next()));
}
} else if ("AUDIO".equals(actionStr)) {
al = BwAlarm.audioAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "ATTACH"));
} else if ("DISPLAY".equals(actionStr)) {
al = BwAlarm.displayAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getReqStr(pl, "DESCRIPTION"));
} else if ("PROCEDURE".equals(actionStr)) {
al = BwAlarm.procedureAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getReqStr(pl, "ATTACH"), getOptStr(pl, "DESCRIPTION"));
} else if ("NONE".equals(actionStr)) {
al = BwAlarm.noneAlarm(ev, ev.getCreatorHref(), tr, dr.duration, dr.repeat, getOptStr(pl, "DESCRIPTION"));
} else {
al = BwAlarm.otherAlarm(ev, ev.getCreatorHref(), actionStr, tr, dr.duration, dr.repeat, getOptStr(pl, "DESCRIPTION"));
}
/* Mozilla is add xprops to the containing event to set the snooze time.
* Seems wrong - there could be multiple alarms.
*
* We possibly want to try this sort of trick..
prop = pl.getProperty("X-MOZ-LASTACK");
boolean mozlastAck = prop != null;
String mozSnoozeTime = null;
if (mozlastAck) {
prop = pl.getProperty("X-MOZ-SNOOZE-TIME");
if (prop == null) {
// lastack and no snooze - presume dismiss so delete alarm
continue;
}
mozSnoozeTime = prop.getValue(); // UTC time
}
...
TriggerVal tr = getTrigger(pl);
if (mozSnoozeTime != null) {
tr.trigger = mozSnoozeTime;
tr.triggerDateTime = true;
tr.triggerStart = false;
}
*/
Iterator it = pl.iterator();
while (it.hasNext()) {
prop = (Property) it.next();
if (prop instanceof XProperty) {
/* ------------------------- x-property --------------------------- */
XProperty xp = (XProperty) prop;
al.addXproperty(new BwXproperty(xp.getName(), xp.getParameters().toString(), xp.getValue()));
continue;
}
if (prop instanceof Uid) {
Uid p = (Uid) prop;
al.addXproperty(BwXproperty.makeIcalProperty(p.getName(), p.getParameters().toString(), p.getValue()));
continue;
}
}
al.setEvent(ev);
al.setOwnerHref(currentPrincipal);
chg.addValue(PropertyInfoIndex.VALARM, al);
}
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of net.fortuna.ical4j.model.PropertyList in project bw-calendar-engine by Bedework.
the class VEventUtil method mergeXparams.
/* ====================================================================
Private methods
==================================================================== */
private static void mergeXparams(final Property p, final Component c) {
if (c == null) {
return;
}
PropertyList pl = c.getProperties(p.getName());
if (Util.isEmpty(pl)) {
return;
}
String pval = p.getValue();
if (p instanceof Attach) {
// We just saved the hash for binary content
Value v = (Value) p.getParameter(Parameter.VALUE);
if (v != null) {
pval = String.valueOf(pval.hashCode());
}
}
Property from = null;
if (pl.size() == 1) {
from = (Property) pl.get(0);
} else {
// Look for value?
Iterator pit = pl.iterator();
while (pit.hasNext()) {
from = (Property) pit.next();
if (from.getValue().equals(pval)) {
break;
}
}
}
if (from == null) {
return;
}
ParameterList params = from.getParameters();
Iterator parit = params.iterator();
while (parit.hasNext()) {
Parameter param = (Parameter) parit.next();
if (!(param instanceof XParameter)) {
continue;
}
XParameter xpar = (XParameter) param;
if (xpar.getName().toUpperCase().equals(BwXproperty.xparUid)) {
continue;
}
p.getParameters().add(xpar);
}
}
Aggregations