Search in sources :

Example 1 with PropertyList

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;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) GregorianCalendar(java.util.GregorianCalendar) Calendar(net.fortuna.ical4j.model.Calendar) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) GregorianCalendar(java.util.GregorianCalendar) Cn(net.fortuna.ical4j.model.parameter.Cn) ProdId(net.fortuna.ical4j.model.property.ProdId) Calendar(net.fortuna.ical4j.model.Calendar) DateTime(net.fortuna.ical4j.model.DateTime) Attendee(net.fortuna.ical4j.model.property.Attendee) Uid(net.fortuna.ical4j.model.property.Uid) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) TimeZone(net.fortuna.ical4j.model.TimeZone) DtStamp(net.fortuna.ical4j.model.property.DtStamp) PropertyList(net.fortuna.ical4j.model.PropertyList) DtStart(net.fortuna.ical4j.model.property.DtStart) Summary(net.fortuna.ical4j.model.property.Summary) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Example 2 with PropertyList

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;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) GregorianCalendar(java.util.GregorianCalendar) Calendar(net.fortuna.ical4j.model.Calendar) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) GregorianCalendar(java.util.GregorianCalendar) Cn(net.fortuna.ical4j.model.parameter.Cn) ProdId(net.fortuna.ical4j.model.property.ProdId) Calendar(net.fortuna.ical4j.model.Calendar) DateTime(net.fortuna.ical4j.model.DateTime) Attendee(net.fortuna.ical4j.model.property.Attendee) Uid(net.fortuna.ical4j.model.property.Uid) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) TimeZone(net.fortuna.ical4j.model.TimeZone) DtStamp(net.fortuna.ical4j.model.property.DtStamp) PropertyList(net.fortuna.ical4j.model.PropertyList) DtStart(net.fortuna.ical4j.model.property.DtStart) Summary(net.fortuna.ical4j.model.property.Summary) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Example 3 with PropertyList

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);
    }
}
Also used : Dur(net.fortuna.ical4j.model.Dur) RDate(net.fortuna.ical4j.model.property.RDate) RRule(net.fortuna.ical4j.model.property.RRule) PeriodList(net.fortuna.ical4j.model.PeriodList) Period(net.fortuna.ical4j.model.Period) RDate(net.fortuna.ical4j.model.property.RDate) Date(net.fortuna.ical4j.model.Date) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) PropertyList(net.fortuna.ical4j.model.PropertyList) Iterator(java.util.Iterator) DateList(net.fortuna.ical4j.model.DateList)

Example 4 with PropertyList

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);
    }
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) XProperty(net.fortuna.ical4j.model.property.XProperty) ComponentList(net.fortuna.ical4j.model.ComponentList) BwAlarm(org.bedework.calfacade.BwAlarm) BwAttendee(org.bedework.calfacade.BwAttendee) Attendee(net.fortuna.ical4j.model.property.Attendee) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Uid(net.fortuna.ical4j.model.property.Uid) PropertyList(net.fortuna.ical4j.model.PropertyList) VPoll(net.fortuna.ical4j.model.component.VPoll) BwXproperty(org.bedework.calfacade.BwXproperty) Iterator(java.util.Iterator) VAlarm(net.fortuna.ical4j.model.component.VAlarm) Property(net.fortuna.ical4j.model.Property) XProperty(net.fortuna.ical4j.model.property.XProperty) TriggerVal(org.bedework.calfacade.BwAlarm.TriggerVal) VToDo(net.fortuna.ical4j.model.component.VToDo)

Example 5 with PropertyList

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);
    }
}
Also used : PropertyList(net.fortuna.ical4j.model.PropertyList) Attach(net.fortuna.ical4j.model.property.Attach) Value(net.fortuna.ical4j.model.parameter.Value) Iterator(java.util.Iterator) ParameterList(net.fortuna.ical4j.model.ParameterList) Parameter(net.fortuna.ical4j.model.Parameter) XParameter(net.fortuna.ical4j.model.parameter.XParameter) BwString(org.bedework.calfacade.BwString) DateListProperty(net.fortuna.ical4j.model.property.DateListProperty) Property(net.fortuna.ical4j.model.Property) XParameter(net.fortuna.ical4j.model.parameter.XParameter)

Aggregations

PropertyList (net.fortuna.ical4j.model.PropertyList)41 VEvent (net.fortuna.ical4j.model.component.VEvent)17 Property (net.fortuna.ical4j.model.Property)13 XProperty (net.fortuna.ical4j.model.property.XProperty)12 DateTime (net.fortuna.ical4j.model.DateTime)11 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)11 DtStart (net.fortuna.ical4j.model.property.DtStart)9 Uid (net.fortuna.ical4j.model.property.Uid)9 URISyntaxException (java.net.URISyntaxException)8 Calendar (net.fortuna.ical4j.model.Calendar)8 Description (net.fortuna.ical4j.model.property.Description)8 Date (java.util.Date)7 Period (net.fortuna.ical4j.model.Period)7 DtEnd (net.fortuna.ical4j.model.property.DtEnd)7 Duration (net.fortuna.ical4j.model.property.Duration)7 RecurrenceId (net.fortuna.ical4j.model.property.RecurrenceId)7 Parameter (net.fortuna.ical4j.model.Parameter)6 PeriodList (net.fortuna.ical4j.model.PeriodList)6 VFreeBusy (net.fortuna.ical4j.model.component.VFreeBusy)6 VTimeZone (net.fortuna.ical4j.model.component.VTimeZone)6