Java Examples for net.fortuna.ical4j.model.property.ExRule

The following java examples will help you to understand the usage of net.fortuna.ical4j.model.property.ExRule. These source code samples are taken from different open source projects.

Example 1
Project: CalendarPortlet-master  File: ICalendarContentProcessorImpl.java View source code
/**
   * @param calendar
   * @param interval
   * @return
   * @throws CalendarException
   */
@SuppressWarnings("unchecked")
protected final Set<VEvent> convertCalendarToEvents(net.fortuna.ical4j.model.Calendar calendar, Interval interval) throws CalendarException {
    Period period = new Period(new net.fortuna.ical4j.model.DateTime(interval.getStartMillis()), new net.fortuna.ical4j.model.DateTime(interval.getEndMillis()));
    Set<VEvent> events = new HashSet<VEvent>();
    // if the calendar is null, return empty set
    if (calendar == null) {
        log.warn("calendar was empty, returning empty set");
        return Collections.emptySet();
    }
    // specified time period
    for (Iterator<Component> it = calendar.getComponents().iterator(); it.hasNext(); ) {
        /*
       * CAP-143:  Log a warning and ignore events that cannot be
       * processed at this stage
       */
        Component component = it.next();
        try {
            if (component.getName().equals("VEVENT")) {
                VEvent event = (VEvent) component;
                if (log.isTraceEnabled()) {
                    log.trace("processing event " + event.getSummary());
                }
                // calculate the recurrence set for this event
                // for the specified time period
                PeriodList periods = event.calculateRecurrenceSet(period);
                // add each recurrence instance to the event list
                for (Iterator<Period> iter = periods.iterator(); iter.hasNext(); ) {
                    Period eventper = iter.next();
                    if (log.isDebugEnabled()) {
                        log.debug("Found time period staring at " + eventper.getStart().isUtc() + ", " + eventper.getStart().getTimeZone() + ", " + event.getStartDate().getTimeZone() + ", " + event.getStartDate().isUtc());
                    }
                    PropertyList props = event.getProperties();
                    // create a new property list, setting the date
                    // information to this event period
                    PropertyList newprops = new PropertyList();
                    DtStart start;
                    if (event.getStartDate().getDate() instanceof net.fortuna.ical4j.model.DateTime) {
                        start = new DtStart(new net.fortuna.ical4j.model.DateTime(eventper.getStart()));
                    } else {
                        start = new DtStart(new net.fortuna.ical4j.model.Date(eventper.getStart()));
                    }
                    newprops.add(start);
                    if (event.getEndDate() != null) {
                        DtEnd end;
                        if (event.getEndDate().getDate() instanceof net.fortuna.ical4j.model.DateTime) {
                            end = new DtEnd(new net.fortuna.ical4j.model.DateTime(eventper.getEnd()));
                        } else {
                            end = new DtEnd(new net.fortuna.ical4j.model.Date(eventper.getEnd()));
                        }
                        newprops.add(end);
                    }
                    for (Iterator<Property> iter2 = props.iterator(); iter2.hasNext(); ) {
                        Property prop = iter2.next();
                        // only add non-date-related properties
                        if (!(prop instanceof DtStart) && !(prop instanceof DtEnd) && !(prop instanceof Duration) && !(prop instanceof RRule) && !(prop instanceof RDate) && !(prop instanceof ExRule) && !(prop instanceof ExDate)) {
                            newprops.add(prop);
                        }
                    }
                    // create the new event from our property list
                    VEvent newevent = new VEvent(newprops);
                    events.add(newevent);
                    log.trace("added event " + newevent);
                }
            }
        } catch (Exception e) {
            final String msg = "Failed to process the following ical4j component:  " + component;
            log.warn(msg, e);
        }
    }
    return events;
}
Example 2
Project: AndroidCaldavSyncAdapater-master  File: AndroidEvent.java View source code
/**
	 * generates a new ics-file.
	 * uses {@link AndroidEvent#ContentValues} as source.
	 * this should only be used when a new event has been generated within android.
	 * @param strUid the UID for this event. example: UID:e6be67c6-eff0-44f8-a1a0-6c2cb1029944-caldavsyncadapter
	 * @return success of the function
	 * @see CalendarEvent#fetchBody()
	 */
public boolean createIcs(String strUid) {
    boolean Result = false;
    TimeZone timezone = null;
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    try {
        mCalendar = new Calendar();
        PropertyList propCalendar = mCalendar.getProperties();
        propCalendar.add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
        propCalendar.add(Version.VERSION_2_0);
        propCalendar.add(CalScale.GREGORIAN);
        VEvent event = new VEvent();
        mCalendar.getComponents().add(event);
        PropertyList propEvent = event.getProperties();
        // DTSTAMP -> is created by new VEvent() automatical
        //na 
        // CREATED
        //na
        // LAST-MODIFIED
        //na
        // SEQUENCE
        //na
        // DTSTART
        long lngStart = this.ContentValues.getAsLong(Events.DTSTART);
        String strTZStart = this.ContentValues.getAsString(Events.EVENT_TIMEZONE);
        boolean allDay = this.ContentValues.getAsBoolean(Events.ALL_DAY);
        if (lngStart > 0) {
            DtStart dtStart = new DtStart();
            if (allDay) {
                Date dateStart = new Date();
                dateStart.setTime(lngStart);
                dtStart.setDate(dateStart);
            } else {
                DateTime datetimeStart = new DateTime();
                datetimeStart.setTime(lngStart);
                dtStart.setDate(datetimeStart);
                timezone = registry.getTimeZone(strTZStart);
                dtStart.setTimeZone(timezone);
                // no timezone information for allDay events
                mCalendar.getComponents().add(timezone.getVTimeZone());
            }
            propEvent.add(dtStart);
        }
        // DTEND
        long lngEnd = this.ContentValues.getAsLong(Events.DTEND);
        String strTZEnd = this.ContentValues.getAsString(Events.EVENT_END_TIMEZONE);
        if (strTZEnd == null)
            strTZEnd = strTZStart;
        if (lngEnd > 0) {
            DtEnd dtEnd = new DtEnd();
            if (allDay) {
                Date dateEnd = new Date();
                dateEnd.setTime(lngEnd);
                dtEnd.setDate(dateEnd);
            } else {
                DateTime datetimeEnd = new DateTime();
                datetimeEnd.setTime(lngEnd);
                dtEnd.setDate(datetimeEnd);
                if (strTZEnd != null)
                    timezone = registry.getTimeZone(strTZEnd);
                dtEnd.setTimeZone(timezone);
            }
            propEvent.add(dtEnd);
        }
        // DURATION
        if (this.ContentValues.containsKey(Events.DURATION)) {
            String strDuration = this.ContentValues.getAsString(Events.DURATION);
            if (strDuration != null) {
                Duration duration = new Duration();
                duration.setValue(strDuration);
                propEvent.add(duration);
            }
        }
        //RRULE
        if (this.ContentValues.containsKey(Events.RRULE)) {
            String strRrule = this.ContentValues.getAsString(Events.RRULE);
            if (strRrule != null) {
                if (!strRrule.equals("")) {
                    RRule rrule = new RRule();
                    rrule.setValue(strRrule);
                    propEvent.add(rrule);
                }
            }
        }
        //RDATE
        if (this.ContentValues.containsKey(Events.RDATE)) {
            String strRdate = this.ContentValues.getAsString(Events.RDATE);
            if (strRdate != null) {
                if (!strRdate.equals("")) {
                    RDate rdate = new RDate();
                    rdate.setValue(strRdate);
                    propEvent.add(rdate);
                }
            }
        }
        //EXRULE
        if (this.ContentValues.containsKey(Events.EXRULE)) {
            String strExrule = this.ContentValues.getAsString(Events.EXRULE);
            if (strExrule != null) {
                if (!strExrule.equals("")) {
                    ExRule exrule = new ExRule();
                    exrule.setValue(strExrule);
                    propEvent.add(exrule);
                }
            }
        }
        //EXDATE
        if (this.ContentValues.containsKey(Events.EXDATE)) {
            String strExdate = this.ContentValues.getAsString(Events.EXDATE);
            if (strExdate != null) {
                if (!strExdate.equals("")) {
                    ExDate exdate = new ExDate();
                    exdate.setValue(strExdate);
                    propEvent.add(exdate);
                }
            }
        }
        //SUMMARY
        if (this.ContentValues.containsKey(Events.TITLE)) {
            String strTitle = this.ContentValues.getAsString(Events.TITLE);
            if (strTitle != null) {
                Summary summary = new Summary(strTitle);
                propEvent.add(summary);
            }
        }
        //DESCIPTION
        if (this.ContentValues.containsKey(Events.DESCRIPTION)) {
            String strDescription = this.ContentValues.getAsString(Events.DESCRIPTION);
            if (strDescription != null) {
                if (!strDescription.equals("")) {
                    Description description = new Description(strDescription);
                    propEvent.add(description);
                }
            }
        }
        //LOCATION
        if (this.ContentValues.containsKey(Events.EVENT_LOCATION)) {
            String strLocation = this.ContentValues.getAsString(Events.EVENT_LOCATION);
            if (strLocation != null) {
                if (!strLocation.equals("")) {
                    Location location = new Location(strLocation);
                    propEvent.add(location);
                }
            }
        }
        //CLASS / ACCESS_LEVEL
        if (this.ContentValues.containsKey(Events.ACCESS_LEVEL)) {
            int accessLevel = this.ContentValues.getAsInteger(Events.ACCESS_LEVEL);
            Clazz clazz = new Clazz();
            if (accessLevel == Events.ACCESS_PUBLIC)
                clazz.setValue(Clazz.PUBLIC.getValue());
            else if (accessLevel == Events.ACCESS_PRIVATE)
                clazz.setValue(Clazz.PRIVATE.getValue());
            else if (accessLevel == Events.ACCESS_CONFIDENTIAL)
                clazz.setValue(Clazz.CONFIDENTIAL.getValue());
            else
                clazz.setValue(Clazz.PUBLIC.getValue());
            propEvent.add(clazz);
        }
        //STATUS
        if (this.ContentValues.containsKey(Events.STATUS)) {
            int intStatus = this.ContentValues.getAsInteger(Events.STATUS);
            if (intStatus > -1) {
                Status status = new Status();
                if (intStatus == Events.STATUS_CANCELED)
                    status.setValue(Status.VEVENT_CANCELLED.getValue());
                else if (intStatus == Events.STATUS_CONFIRMED)
                    status.setValue(Status.VEVENT_CONFIRMED.getValue());
                else if (intStatus == Events.STATUS_TENTATIVE)
                    status.setValue(Status.VEVENT_TENTATIVE.getValue());
                propEvent.add(status);
            }
        }
        //UID
        Uid uid = new Uid(strUid);
        propEvent.add(uid);
        // Attendees
        if (mAttendees.size() > 0) {
            for (Object objProp : mAttendees) {
                Property prop = (Property) objProp;
                propEvent.add(prop);
            }
        }
        // Reminders
        if (mReminders.size() > 0) {
            for (Object objComp : mReminders) {
                Component com = (Component) objComp;
                event.getAlarms().add(com);
            }
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return Result;
}
Example 3
Project: bw-calendar-engine-master  File: IcalTranslator.java View source code
private void xmlProperty(final XmlEmit xml, final Property val) throws CalFacadeException {
    try {
        QName tag = openTag(xml, val.getName());
        ParameterList pl = val.getParameters();
        if (pl.size() > 0) {
            xml.openTag(XcalTags.parameters);
            Iterator pli = pl.iterator();
            while (pli.hasNext()) {
                xmlParameter(xml, (Parameter) pli.next());
            }
            xml.closeTag(XcalTags.parameters);
        }
        PropertyInfoIndex pii = PropertyInfoIndex.fromName(val.getName());
        QName ptype = XcalTags.textVal;
        if (pii != null) {
            DataType dtype = pii.getPtype();
            if (dtype != null) {
                ptype = dtype.getXcalType();
            }
        }
        if (ptype == null) {
            // Special processing I haven't done
            warn("Unimplemented value type for " + val.getName());
            ptype = XcalTags.textVal;
        }
        if (ptype.equals(XcalTags.recurVal)) {
            // Emit individual parts of recur rule
            xml.openTag(ptype);
            Recur r;
            if (val instanceof ExRule) {
                r = ((ExRule) val).getRecur();
            } else {
                r = ((RRule) val).getRecur();
            }
            xml.property(XcalTags.freq, r.getFrequency());
            xmlProp(xml, XcalTags.wkst, r.getWeekStartDay().name());
            if (r.getUntil() != null) {
                xmlProp(xml, XcalTags.until, r.getUntil().toString());
            }
            xmlProp(xml, XcalTags.count, String.valueOf(r.getCount()));
            xmlProp(xml, XcalTags.interval, String.valueOf(r.getInterval()));
            xmlProp(xml, XcalTags.bymonth, r.getMonthList());
            xmlProp(xml, XcalTags.byweekno, r.getWeekNoList());
            xmlProp(xml, XcalTags.byyearday, r.getYearDayList());
            xmlProp(xml, XcalTags.bymonthday, r.getMonthDayList());
            xmlProp(xml, XcalTags.byday, r.getDayList());
            xmlProp(xml, XcalTags.byhour, r.getHourList());
            xmlProp(xml, XcalTags.byminute, r.getMinuteList());
            xmlProp(xml, XcalTags.bysecond, r.getSecondList());
            xmlProp(xml, XcalTags.bysetpos, r.getSetPosList());
            xml.closeTag(ptype);
        } else {
            xml.property(ptype, val.getValue());
        }
        xml.closeTag(tag);
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Example 4
Project: cosmo-master  File: InstanceList.java View source code
/**
     * Add a master component if it falls within the specified time range.
     *
     * @param comp       The component.
     * @param rangeStart The start date in range.
     * @param rangeEnd   The end date in range.
     */
public void addMaster(Component comp, Date rangeStart, Date rangeEnd) {
    Date start = getStartDate(comp);
    if (start == null) {
        return;
    }
    Value startValue = start instanceof DateTime ? Value.DATE_TIME : Value.DATE;
    start = convertToUTCIfNecessary(start);
    if (start instanceof DateTime) {
        // adjust floating time if timezone is present
        start = adjustFloatingDateIfNecessary(start);
    }
    Dur duration = null;
    Date end = getEndDate(comp);
    if (end == null) {
        if (startValue.equals(Value.DATE_TIME)) {
            // Its an timed event with no duration
            duration = new Dur(0, 0, 0, 0);
        } else {
            // Its an all day event so duration is one day
            duration = new Dur(1, 0, 0, 0);
        }
        end = org.unitedinternet.cosmo.calendar.util.Dates.getInstance(duration.getTime(start), start);
    } else {
        end = convertToUTCIfNecessary(end);
        if (startValue.equals(Value.DATE_TIME)) {
            // Adjust floating end time if timezone present
            end = adjustFloatingDateIfNecessary(end);
            // will be 0, since it is a timed event
            if (end.before(start)) {
                end = org.unitedinternet.cosmo.calendar.util.Dates.getInstance(new Dur(0, 0, 0, 0).getTime(start), start);
            }
        } else {
            // will be 1 day since its an all-day event
            if (end.before(start)) {
                end = org.unitedinternet.cosmo.calendar.util.Dates.getInstance(new Dur(1, 0, 0, 0).getTime(start), start);
            }
        }
        duration = new Dur(start, end);
    }
    // Always add first instance if included in range..
    if (dateBefore(start, rangeEnd) && (dateAfter(end, rangeStart) || dateEquals(end, rangeStart)) && comp.getProperties(Property.RRULE).isEmpty()) {
        Instance instance = new Instance(comp, start, end);
        put(instance.getRid().toString(), instance);
    }
    // recurrence dates..
    PropertyList<RDate> rDates = comp.getProperties().getProperties(Property.RDATE);
    for (RDate rdate : rDates) {
        // Both PERIOD and DATE/DATE-TIME values allowed
        if (Value.PERIOD.equals(rdate.getParameters().getParameter(Parameter.VALUE))) {
            for (Period period : rdate.getPeriods()) {
                Date periodStart = adjustFloatingDateIfNecessary(period.getStart());
                Date periodEnd = adjustFloatingDateIfNecessary(period.getEnd());
                // Add period if it overlaps rage
                if (periodStart.before(rangeEnd) && periodEnd.after(rangeStart)) {
                    Instance instance = new Instance(comp, periodStart, periodEnd);
                    put(instance.getRid().toString(), instance);
                }
            }
        } else {
            for (Date startDate : rdate.getDates()) {
                startDate = convertToUTCIfNecessary(startDate);
                startDate = adjustFloatingDateIfNecessary(startDate);
                Date endDate = org.unitedinternet.cosmo.calendar.util.Dates.getInstance(duration.getTime(startDate), startDate);
                // Add RDATE if it overlaps range
                if (inRange(startDate, endDate, rangeStart, rangeEnd)) {
                    Instance instance = new Instance(comp, startDate, endDate);
                    put(instance.getRid().toString(), instance);
                }
            }
        }
    }
    // recurrence rules..
    PropertyList<RRule> rRules = comp.getProperties().getProperties(Property.RRULE);
    // Adjust startRange to account for instances that occur before
    // the startRange, and end after it
    Date adjustedRangeStart = null;
    Date ajustedRangeEnd = null;
    if (rRules.size() > 0) {
        adjustedRangeStart = adjustStartRangeIfNecessary(rangeStart, start, duration);
        ajustedRangeEnd = adjustEndRangeIfNecessary(rangeEnd, start);
    }
    for (RRule rrule : rRules) {
        //if start and adjustedRangeStart must be in the same timezone
        DateList startDates = rrule.getRecur().getDates(start, adjustedRangeStart, ajustedRangeEnd, start instanceof DateTime ? Value.DATE_TIME : Value.DATE);
        for (int j = 0; j < startDates.size(); j++) {
            Date sd = (Date) startDates.get(j);
            Date startDate = org.unitedinternet.cosmo.calendar.util.Dates.getInstance(sd, start);
            Date endDate = org.unitedinternet.cosmo.calendar.util.Dates.getInstance(duration.getTime(sd), start);
            Instance instance = new Instance(comp, startDate, endDate);
            put(instance.getRid().toString(), instance);
        }
    }
    // exception dates..
    PropertyList<ExDate> exDates = comp.getProperties().getProperties(Property.EXDATE);
    for (ExDate exDate : exDates) {
        for (Date sd : exDate.getDates()) {
            sd = convertToUTCIfNecessary(sd);
            sd = adjustFloatingDateIfNecessary(sd);
            Instance instance = new Instance(comp, sd, sd);
            remove(instance.getRid().toString());
        }
    }
    // exception rules..
    PropertyList<ExRule> exRules = comp.getProperties().getProperties(Property.EXRULE);
    if (exRules.size() > 0 && adjustedRangeStart == null) {
        adjustedRangeStart = adjustStartRangeIfNecessary(rangeStart, start, duration);
        ajustedRangeEnd = adjustEndRangeIfNecessary(rangeEnd, start);
    }
    for (ExRule exrule : exRules) {
        DateList startDates = exrule.getRecur().getDates(start, adjustedRangeStart, ajustedRangeEnd, start instanceof DateTime ? Value.DATE_TIME : Value.DATE);
        for (Date sd : startDates) {
            Instance instance = new Instance(comp, sd, sd);
            remove(instance.getRid().toString());
        }
    }
}
Example 5
Project: ical4j-0.9.20-master  File: PropertyFactoryImpl.java View source code
/**
     * @return
     */
private PropertyFactory createExRuleFactory() {
    return new PropertyFactory() {

        /* (non-Javadoc)
             * @see net.fortuna.ical4j.model.PropertyFactory#createProperty(java.lang.String, net.fortuna.ical4j.model.ParameterList, java.lang.String)
             */
        public Property createProperty(final String name, final ParameterList parameters, final String value) throws IOException, URISyntaxException, ParseException {
            return new ExRule(parameters, value);
        }

        /* (non-Javadoc)
             * @see net.fortuna.ical4j.model.PropertyFactory#createProperty(java.lang.String)
             */
        public Property createProperty(final String name) {
            return new ExRule();
        }
    };
}
Example 6
Project: Flock-master  File: EventFactory.java View source code
protected static ContentValues getValuesForEvent(LocalEventCollection hack, Long calendarId, ComponentETagPair<Calendar> component) throws InvalidRemoteComponentException, RemoteException {
    VEvent vEvent = (VEvent) component.getComponent().getComponent(VEvent.VEVENT);
    if (vEvent != null) {
        ContentValues values = new ContentValues();
        handleAddValuesForRecurrenceProperties(vEvent, values);
        values.put(CalendarContract.Events.CALENDAR_ID, calendarId);
        if (vEvent.getUid() != null && vEvent.getUid().getValue() != null)
            values.put(COLUMN_NAME_EVENT_UID, vEvent.getUid().getValue());
        else
            values.putNull(COLUMN_NAME_EVENT_UID);
        if (component.getETag().isPresent())
            values.put(COLUMN_NAME_EVENT_ETAG, component.getETag().get());
        DtStart dtStart = vEvent.getStartDate();
        if (dtStart != null && dtStart.getDate() != null) {
            if (dtStart.getTimeZone() != null)
                values.put(CalendarContract.Events.EVENT_TIMEZONE, dtStart.getTimeZone().getID());
            values.put(CalendarContract.Events.DTSTART, dtStart.getDate().getTime());
        } else {
            Log.e(TAG, "no start date found on event");
            throw new InvalidRemoteComponentException("no start date found on event", CalDavConstants.CALDAV_NAMESPACE, hack.getPath(), getUid(vEvent));
        }
        Status status = vEvent.getStatus();
        Property originalInstanceTimeProp = vEvent.getProperty(PROPERTY_NAME_FLOCK_ORIGINAL_INSTANCE_TIME);
        if (status != null && status != Status.VEVENT_CANCELLED && originalInstanceTimeProp != null)
            handleAddValuesForEditExceptionToRecurring(hack, vEvent, values);
        if (status != null && status == Status.VEVENT_CONFIRMED)
            values.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CONFIRMED);
        else if (status != null && status == Status.VEVENT_CANCELLED)
            handleAddValuesForDeletionExceptionToRecurring(hack, vEvent, values);
        else
            values.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_TENTATIVE);
        Summary summary = vEvent.getSummary();
        if (summary != null)
            values.put(CalendarContract.Events.TITLE, summary.getValue());
        Location location = vEvent.getLocation();
        if (location != null)
            values.put(CalendarContract.Events.EVENT_LOCATION, location.getValue());
        Description description = vEvent.getDescription();
        if (description != null)
            values.put(CalendarContract.Events.DESCRIPTION, description.getValue());
        Transp transparency = vEvent.getTransparency();
        if (transparency != null && transparency == Transp.OPAQUE)
            values.put(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY);
        else
            values.put(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_FREE);
        Organizer organizer = vEvent.getOrganizer();
        if (organizer != null && organizer.getCalAddress() != null) {
            URI organizerAddress = organizer.getCalAddress();
            if (organizerAddress.getScheme() != null && organizerAddress.getScheme().equalsIgnoreCase("mailto"))
                values.put(CalendarContract.Events.ORGANIZER, organizerAddress.getSchemeSpecificPart());
        }
        RRule rRule = (RRule) vEvent.getProperty(RRule.RRULE);
        RDate rDate = (RDate) vEvent.getProperty(RDate.RDATE);
        ExRule exRule = (ExRule) vEvent.getProperty(ExRule.EXRULE);
        ExDate exDate = (ExDate) vEvent.getProperty(ExDate.EXDATE);
        if (rRule != null)
            values.put(CalendarContract.Events.RRULE, rRule.getValue());
        if (rDate != null)
            values.put(CalendarContract.Events.RDATE, rDate.getValue());
        if (exRule != null)
            values.put(CalendarContract.Events.EXRULE, exRule.getValue());
        if (exDate != null)
            values.put(CalendarContract.Events.EXDATE, exDate.getValue());
        if (vEvent.getProperty(PROPERTY_NAME_FLOCK_ALL_DAY) != null)
            values.put(CalendarContract.Events.ALL_DAY, 1);
        if (rRule == null && rDate == null) {
            DtEnd dtEnd = vEvent.getEndDate();
            if (dtEnd != null && dtEnd.getDate() != null) {
                if (dtEnd.getTimeZone() != null)
                    values.put(CalendarContract.Events.EVENT_TIMEZONE, dtEnd.getTimeZone().getID());
                values.put(CalendarContract.Events.DTEND, dtEnd.getDate().getTime());
            } else if (vEvent.getDuration() != null) {
                Duration duration = vEvent.getDuration();
                java.util.Date endDate = duration.getDuration().getTime(dtStart.getDate());
                values.put(CalendarContract.Events.DTEND, endDate.getTime());
            } else {
                Log.w(TAG, "event is missing date end and duration, assuming all day event.");
                values.put(CalendarContract.Events.DTEND, dtStart.getDate().getTime() + DateUtils.DAY_IN_MILLIS);
                values.put(CalendarContract.Events.ALL_DAY, 1);
            }
        } else if (vEvent.getDuration() != null)
            values.put(CalendarContract.Events.DURATION, vEvent.getDuration().getValue());
        PropertyList attendees = vEvent.getProperties(Attendee.ATTENDEE);
        if (attendees != null && attendees.size() > 0)
            values.put(CalendarContract.Events.HAS_ATTENDEE_DATA, 1);
        else
            values.put(CalendarContract.Events.HAS_ATTENDEE_DATA, 0);
        PropertyList alarms = vEvent.getProperties(VAlarm.VALARM);
        if (alarms != null && alarms.size() > 0)
            values.put(CalendarContract.Events.HAS_ALARM, 1);
        else
            values.put(CalendarContract.Events.HAS_ALARM, 0);
        return values;
    }
    Log.e(TAG, "no VEVENT found in component");
    throw new InvalidRemoteComponentException("no VEVENT found in component", CalDavConstants.CALDAV_NAMESPACE, hack.getPath(), getUid(component.getComponent()));
}