net.fortuna.ical4j.model.ComponentList Java Examples

The following examples show how to use net.fortuna.ical4j.model.ComponentList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InstanceListTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
    * Adds to instance list.
    *
    * @param calendar  The calendar.
    * @param instances The instances.
    * @param start     The start.
    * @param end       The end.
    */
   private static void addToInstanceList(Calendar calendar,
                                         InstanceList instances, Date start, Date end) {
       ComponentList<VEvent> vevents = calendar.getComponents().getComponents(VEvent.VEVENT);
Iterator<VEvent> it = vevents.iterator();
       boolean addedMaster = false;
       while (it.hasNext()) {
           VEvent event = (VEvent)it.next();
           if (event.getRecurrenceId() == null) {
               addedMaster = true;
               instances.addComponent(event, start, end);
           } else {
               Assert.assertTrue(addedMaster);
               instances.addOverride(event, start, end);
           }
       }
   }
 
Example #2
Source File: FreeBusyUtil.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Obfuscates the specified calendar by removing unnecessary properties and replacing text fields with specified
 * text.
 * 
 * @param original
 *            calendar to be obfuscated
 * @param productId
 *            productId to be set for the copy calendar.
 * @param freeBusyText
 * @return obfuscated calendar.
 */
public static Calendar getFreeBusyCalendar(Calendar original, String productId, String freeBusyText) {
    // Make a copy of the original calendar
    Calendar copy = new Calendar();
    copy.getProperties().add(new ProdId(productId));
    copy.getProperties().add(Version.VERSION_2_0);
    copy.getProperties().add(CalScale.GREGORIAN);
    copy.getProperties().add(new XProperty(FREE_BUSY_X_PROPERTY, Boolean.TRUE.toString()));

    ComponentList<CalendarComponent> events = original.getComponents(Component.VEVENT);
    for (Component event : events) {
        copy.getComponents().add(getFreeBusyEvent((VEvent) event, freeBusyText));
    }
    return copy;
}
 
Example #3
Source File: ICal3ClientFilter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public void filterCalendar(Calendar calendar) {
   
    try {
        ComponentList<VEvent> events = calendar.getComponents(Component.VEVENT);
        for(VEvent event : events) {                 
            // fix VALUE=DATE-TIME instances
            fixDateTimeProperties(event);
            // fix EXDATEs
            if(event.getRecurrenceId()==null) {
                fixExDates(event);
            }
        }
    } catch (Exception e) {
        throw new CosmoException(e);
    } 
}
 
Example #4
Source File: EntityConverter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Updates note modification.
 * @param noteMod The note item modified.
 * @param event The event.
 */
private void updateNoteModification(NoteItem noteMod,
                                    VEvent event) {
    EventExceptionStamp exceptionStamp =
        StampUtils.getEventExceptionStamp(noteMod);
    exceptionStamp.setExceptionEvent(event);
    
    // copy VTIMEZONEs to front if present
    ComponentList<VTimeZone> vtimezones = exceptionStamp.getMasterStamp()
            .getEventCalendar().getComponents(Component.VTIMEZONE);
    for(VTimeZone vtimezone : vtimezones) {
        exceptionStamp.getEventCalendar().getComponents().add(0, vtimezone);
    }
    
    noteMod.setClientModifiedDate(new Date());
    noteMod.setLastModifiedBy(noteMod.getModifies().getLastModifiedBy());
    noteMod.setLastModification(ContentItem.Action.EDITED);
    
    setCalendarAttributes(noteMod, event);
}
 
Example #5
Source File: EntityConverter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Compact timezones.
 * @param calendar The calendar.
 */
private void compactTimezones(Calendar calendar) {
    
    if (calendar==null) {
        return;
    }

    // Get list of timezones in master calendar and remove all timezone
    // definitions that are in the registry.  The idea is to not store
    // extra data.  Instead, the timezones will be added to the calendar
    // by the getCalendar() api.
    ComponentList<VTimeZone> timezones = calendar.getComponents(Component.VTIMEZONE);
    List<VTimeZone> toRemove = new ArrayList<>();
    for(VTimeZone vtz : timezones) {
        String tzid = vtz.getTimeZoneId().getValue();
        TimeZone tz = TIMEZONE_REGISTRY.getTimeZone(tzid);
        //  Remove timezone iff it matches the one in the registry
        if(tz!=null && vtz.equals(tz.getVTimeZone())) {
            toRemove.add(vtz);
        }
    }

    // remove known timezones from master calendar
    calendar.getComponents().removeAll(toRemove);
}
 
Example #6
Source File: ExpandRecurringEventsTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Verify expand calendar.
 * @param calendar The calendar.
 */
private void verifyExpandedCalendar(Calendar calendar) {
    // timezone should be stripped
    Assert.assertNull(calendar.getComponents().getComponent("VTIMEZONE"));
    
    ComponentList<VEvent> comps = calendar.getComponents().getComponents("VEVENT");
    
    for(VEvent event : comps) {
        DateTime dt = (DateTime) event.getStartDate().getDate();
        
        // verify start dates are UTC
        Assert.assertNull(event.getStartDate().getParameters().getParameter(Parameter.TZID));
        Assert.assertTrue(dt.isUtc());
        
        // verify no recurrence rules
        Assert.assertNull(event.getProperties().getProperty(Property.RRULE));
    }
}
 
Example #7
Source File: CalendarFilterEvaluater.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluates.
 * @param comps The component list.
 * @param filter The time range filter.
 * @return the result.
 */
private boolean evaluate(ComponentList<? extends Component> comps, TimeRangeFilter filter) {
    
    Component comp = (Component) comps.get(0);
    
    if(comp instanceof VEvent) {
        return evaluateVEventTimeRange(comps, filter);
    }
    else if(comp instanceof VFreeBusy) {
        return evaulateVFreeBusyTimeRange((VFreeBusy) comp, filter);
    }
    else if(comp instanceof VToDo) {
        return evaulateVToDoTimeRange(comps, filter);
    }
    else if(comp instanceof VJournal) {
        return evaluateVJournalTimeRange((VJournal) comp, filter);
    }
    else if(comp instanceof VAlarm) {
        return evaluateVAlarmTimeRange(comps, filter);
    }
    else {
        return false;
    }
}
 
Example #8
Source File: ICalendarUtils.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Find and return the first DISPLAY VALARM in a comoponent
 * @param component VEVENT or VTODO
 * @return first DISPLAY VALARM, null if there is none
 */
public static VAlarm getDisplayAlarm(Component component) {
    ComponentList<VAlarm> alarms = null;
    
    if(component instanceof VEvent) {
        alarms = ((VEvent) component).getAlarms();
    }
    else if(component instanceof VToDo) {
        alarms = ((VToDo) component).getAlarms();
    }
    
    if(alarms==null || alarms.size()==0) {
        return null;
    }
    
    for(Iterator<VAlarm> it = alarms.iterator();it.hasNext();) {
        VAlarm alarm = it.next();
        if(Action.DISPLAY.equals(alarm.getAction())) {
            return alarm;
        }
    }
    
    return null;   
}
 
Example #9
Source File: RecurrenceExpander.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Expand recurring event for given time-range.
 * @param calendar calendar containing recurring event and modifications
 * @param rangeStart expand start
 * @param rangeEnd expand end
 * @param timezone Optional timezone to use for floating dates.  If null, the
 *        system default is used.
 * @return InstanceList containing all occurences of recurring event during
 *         time range
 */
public InstanceList getOcurrences(Calendar calendar, Date rangeStart, Date rangeEnd, TimeZone timezone) {
    ComponentList<VEvent> vevents = calendar.getComponents().getComponents(Component.VEVENT);
    
    List<Component> exceptions = new ArrayList<Component>();
    Component masterComp = null;
    
    // get list of exceptions (VEVENT with RECURRENCEID)
    for (Iterator<VEvent> i = vevents.iterator(); i.hasNext();) {
        VEvent event = i.next();
        if (event.getRecurrenceId() != null) {
            exceptions.add(event);
        }
        else {
            masterComp = event; 
        }
        
    }
    
    return getOcurrences(masterComp, exceptions, rangeStart, rangeEnd, timezone);
}
 
Example #10
Source File: RecurrenceExpander.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Return start and end Date that represent the start of the first 
 * occurrence of a recurring component and the end of the last
 * occurence.  If the recurring component has no end(infinite recurring event),
 * then no end date will be returned.
 * @param calendar Calendar containing master and modification components
 * @return array containing start (located at index 0) and end (index 1) of
 *         recurring component.
 */
public Date[] calculateRecurrenceRange(Calendar calendar) {
    try{
        ComponentList<VEvent> vevents = calendar.getComponents().getComponents(Component.VEVENT);
        
        List<Component> exceptions = new ArrayList<Component>();
        Component masterComp = null;
        
        // get list of exceptions (VEVENT with RECURRENCEID)
        for (Iterator<VEvent> i = vevents.iterator(); i.hasNext();) {
            VEvent event = i.next();
            if (event.getRecurrenceId() != null) {
                exceptions.add(event);
            }
            else {
                masterComp = event;
            }
            
        }
        
        return calculateRecurrenceRange(masterComp, exceptions);
    } catch (Exception e){
        LOG.error("ERROR in calendar: " + calendar, e);
        throw e;
    }
}
 
Example #11
Source File: IcalUtils.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a Calendar with multiple VEvents into Appointments
 *
 * @param calendar Calendar to Parse
 * @param ownerId  Owner of the Appointments
 * @return <code>List</code> of Appointments
 */
public List<Appointment> parseCalendartoAppointments(Calendar calendar, Long ownerId) {
	List<Appointment> appointments = new ArrayList<>();
	ComponentList<CalendarComponent> events = calendar.getComponents(Component.VEVENT);
	User owner = userDao.get(ownerId);

	for (CalendarComponent event : events) {
		Appointment a = new Appointment();
		a.setOwner(owner);
		a.setDeleted(false);
		a.setRoom(createDefaultRoom());
		a.setReminder(Appointment.Reminder.NONE);
		a = addVEventPropertiestoAppointment(a, event);
		appointments.add(a);
	}
	return appointments;
}
 
Example #12
Source File: EntityConverterTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
   * Tests convert task.
   * @throws Exception - if something is wrong this exception is thrown.
   */
  @Test
  public void testConvertTask() throws Exception {
      @SuppressWarnings("unused")
TimeZoneRegistry registry =
          TimeZoneRegistryFactory.getInstance().createRegistry();
      NoteItem master = new MockNoteItem();
      master.setDisplayName("displayName");
      master.setBody("body");
      master.setIcalUid("icaluid");
      master.setClientModifiedDate(new DateTime("20070101T100000Z"));
      master.setTriageStatus(TriageStatusUtil.initialize(new MockTriageStatus()));
      
      Calendar cal = converter.convertNote(master);
      cal.validate();
      
      Assert.assertEquals(1, cal.getComponents().size());
      
      ComponentList<VToDo> comps = cal.getComponents(Component.VTODO);
      Assert.assertEquals(1, comps.size());
      VToDo task = comps.get(0);
      
      Assert.assertNull(task.getDateCompleted());
      Assert.assertNull(ICalendarUtils.getXProperty("X-OSAF-STARRED", task));
      
      DateTime completeDate = new DateTime("20080122T100000Z");
      
      master.getTriageStatus().setCode(TriageStatus.CODE_DONE);
      master.getTriageStatus().setRank(TriageStatusUtil.getRank(completeDate.getTime()));
      master.addStamp(new MockTaskStamp());
      
      cal = converter.convertNote(master);
      task = (VToDo) cal.getComponents().get(0);
      
      Completed completed = task.getDateCompleted();
      Assert.assertNotNull(completed);
      Assert.assertEquals(completeDate.getTime(), completed.getDate().getTime());
      Assert.assertEquals("TRUE", ICalendarUtils.getXProperty("X-OSAF-STARRED", task));
      
  }
 
Example #13
Source File: ThisAndFutureHelperTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Creates event.
 * @param uid The uid.
 * @param calendar The calendar.
 * @return The note item.
 */
protected NoteItem createEvent(String uid, Calendar calendar) {
    NoteItem master = new MockNoteItem();
    master.setUid(uid);
    EventStamp es = new MockEventStamp(master);
    master.addStamp(es);
    
    ComponentList<VEvent> vevents = calendar.getComponents().getComponents(Component.VEVENT);
    List<VEvent> exceptions = new ArrayList<VEvent>();        
    // get list of exceptions (VEVENT with RECURRENCEID)        
    for (VEvent event : vevents) {            
        if (event.getRecurrenceId() != null) {
            exceptions.add(event);
            NoteItem mod = new MockNoteItem();
            mod.setUid(new ModificationUidImpl(master,event.getRecurrenceId().getDate()).toString());
            mod.setModifies(master);
            master.addModification(mod);
            EventExceptionStamp ees = new MockEventExceptionStamp(mod);
            mod.addStamp(ees);
            ees.createCalendar();
            ees.setRecurrenceId(event.getRecurrenceId().getDate());
            ees.setStartDate(event.getStartDate().getDate());
            ees.setAnyTime(null);
        } 
    }
    
    
    for (VEvent ex: exceptions) {
        calendar.getComponents().remove(ex);
    }
    
    es.setEventCalendar(calendar);
    
    return master;
}
 
Example #14
Source File: MockEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Gets master event.
 * @return The event.
 */
public VEvent getMasterEvent() {
    if (getEventCalendar() == null) {
        return null;
    }
    
    ComponentList<VEvent> events = getEventCalendar().getComponents().getComponents(
            Component.VEVENT);
    
    if (events.size() == 0) {
        return null;
    }
    
    return (VEvent) events.get(0);
}
 
Example #15
Source File: StandardContentServiceTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Gets event.
 * @param recurrenceId The recurrence id.
 * @param calendar The calendar.
 * @return The event.
 */
private VEvent getEvent(String recurrenceId, Calendar calendar) {
    ComponentList<VEvent> events = calendar.getComponents().getComponents(Component.VEVENT);
    for(VEvent event : events) {            
        if(event.getRecurrenceId()!=null && event.getRecurrenceId().getDate().toString().equals(recurrenceId))
            return event;
    }
    return null;
}
 
Example #16
Source File: LimitRecurrenceSetTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the set of limit recurrence.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testLimitRecurrenceSetThisAndFuture() throws Exception {
    CalendarBuilder cb = new CalendarBuilder();
    FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_taf_test.ics");
    Calendar calendar = cb.build(fis);
    
    Assert.assertEquals(4, calendar.getComponents().getComponents("VEVENT").size());
    
    VTimeZone vtz = (VTimeZone) calendar.getComponents().getComponent("VTIMEZONE");
    TimeZone tz = new TimeZone(vtz);
    OutputFilter filter = new OutputFilter("test");
    DateTime start = new DateTime("20060108T170000", tz);
    DateTime end = new DateTime("20060109T170000", tz);
    start.setUtc(true);
    end.setUtc(true);
    
    Period period = new Period(start, end);
    filter.setLimit(period);
    filter.setAllSubComponents();
    filter.setAllProperties();
    
    StringBuilder buffer = new StringBuilder();
    filter.filter(calendar, buffer);
    StringReader sr = new StringReader(buffer.toString());
    
    Calendar filterCal = cb.build(sr);
    
    Assert.assertEquals(2, filterCal.getComponents().getComponents("VEVENT").size());
    // Make sure 2nd and 3rd override are dropped
    ComponentList<VEvent> vevents = filterCal.getComponents().getComponents(VEvent.VEVENT);
    
    for(VEvent c : vevents) {            
        Assert.assertNotSame("event 6 changed",c.getProperties().getProperty("SUMMARY").getValue());
        Assert.assertNotSame("event 6 changed 2",c.getProperties().getProperty("SUMMARY").getValue());
    }   
}
 
Example #17
Source File: LimitRecurrenceSetTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests limit floating recurrence set.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testLimitFloatingRecurrenceSet() throws Exception {
    CalendarBuilder cb = new CalendarBuilder();
    FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_float_test.ics");
    Calendar calendar = cb.build(fis);
    
    Assert.assertEquals(3, calendar.getComponents().getComponents("VEVENT").size());
    
    OutputFilter filter = new OutputFilter("test");
    DateTime start = new DateTime("20060102T170000");
    DateTime end = new DateTime("20060104T170000");
    
    start.setUtc(true);
    end.setUtc(true);
    
    Period period = new Period(start, end);
    filter.setLimit(period);
    filter.setAllSubComponents();
    filter.setAllProperties();
    
    StringBuilder buffer = new StringBuilder();
    filter.filter(calendar, buffer);
    StringReader sr = new StringReader(buffer.toString());
    
    Calendar filterCal = cb.build(sr);
    
    Assert.assertEquals(2, filterCal.getComponents().getComponents("VEVENT").size());
    // Make sure 2nd override is dropped
    ComponentList<VEvent> vevents = filterCal.getComponents().getComponents(VEvent.VEVENT);        
    for(VEvent c : vevents) {            
        Assert.assertNotSame("event 6 changed 2",c.getProperties().getProperty("SUMMARY").getValue());
    }   
}
 
Example #18
Source File: LimitRecurrenceSetTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests limit recurrence set.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testLimitRecurrenceSet() throws Exception {
    CalendarBuilder cb = new CalendarBuilder();
    FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_test.ics");
    Calendar calendar = cb.build(fis);
    
    Assert.assertEquals(5, calendar.getComponents().getComponents("VEVENT").size());
    
    VTimeZone vtz = (VTimeZone) calendar.getComponents().getComponent("VTIMEZONE");
    TimeZone tz = new TimeZone(vtz);
    OutputFilter filter = new OutputFilter("test");
    DateTime start = new DateTime("20060104T010000", tz);
    DateTime end = new DateTime("20060106T010000", tz);
    start.setUtc(true);
    end.setUtc(true);
    
    Period period = new Period(start, end);
    filter.setLimit(period);
    filter.setAllSubComponents();
    filter.setAllProperties();
    
    StringBuilder buffer = new StringBuilder();
    filter.filter(calendar, buffer);
    StringReader sr = new StringReader(buffer.toString());
    
    Calendar filterCal = cb.build(sr);
    
    ComponentList<CalendarComponent> comps = filterCal.getComponents();
    Assert.assertEquals(3, comps.getComponents("VEVENT").size());
    Assert.assertEquals(1, comps.getComponents("VTIMEZONE").size());
    
    // Make sure 3rd and 4th override are dropped

    ComponentList<CalendarComponent> events = comps.getComponents("VEVENT");
    for(CalendarComponent c : events) {            
        Assert.assertNotSame("event 6 changed 3",c.getProperties().getProperty("SUMMARY").getValue());
        Assert.assertNotSame("event 6 changed 4",c.getProperties().getProperty("SUMMARY").getValue());
    }
}
 
Example #19
Source File: DavJournal.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * @param cal Imports a calendar object containing a VJOURNAL. Sets the
 * following properties:
 * </p>
 * <ul>
 * <li>display name: the VJOURNAL's SUMMARY (or the item's name, if the
 * SUMMARY is blank)</li>
 * <li>icalUid: the VJOURNAL's UID</li>
 * <li>body: the VJOURNAL's DESCRIPTION</li>
 * </ul>
 */
public void setCalendar(Calendar cal)
    throws CosmoDavException {
    NoteItem note = (NoteItem) getItem();
  
    ComponentList<VJournal> vjournals = cal.getComponents(Component.VJOURNAL);
    if (vjournals.isEmpty()) {
        throw new UnprocessableEntityException("VCALENDAR does not contain any VJOURNALS");
    }

    EntityConverter converter = new EntityConverter(getEntityFactory());
    converter.convertJournalCalendar(note, cal);
}
 
Example #20
Source File: DavEvent.java    From cosmo with Apache License 2.0 5 votes vote down vote up
protected void setCalendar(Calendar calendar) throws CosmoDavException {

        ComponentList<VEvent> vevents = calendar.getComponents(Component.VEVENT);
        if (vevents.isEmpty()) {
            throw new UnprocessableEntityException("VCALENDAR does not contain any VEVENTs");
        }

        getEventStamp().setEventCalendar(calendar);
    }
 
Example #21
Source File: ICalConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/** Returns a calendar derived from a Work Effort calendar publish point.
 * @param workEffortId ID of a work effort with <code>workEffortTypeId</code> equal to
 * <code>PUBLISH_PROPS</code>.
 * @param context The conversion context
 * @return An iCalendar as a <code>String</code>, or <code>null</code>
 * if <code>workEffortId</code> is invalid.
 * @throws GenericEntityException
 */
public static ResponseProperties getICalendar(String workEffortId, Map<String, Object> context) throws GenericEntityException {
    Delegator delegator = (Delegator) context.get("delegator");
    GenericValue publishProperties = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortId).queryOne();
    if (!isCalendarPublished(publishProperties)) {
        Debug.logInfo("WorkEffort calendar is not published: " + workEffortId, module);
        return ICalWorker.createNotFoundResponse(null);
    }
    if (!"WES_PUBLIC".equals(publishProperties.get("scopeEnumId"))) {
        if (context.get("userLogin") == null) {
            return ICalWorker.createNotAuthorizedResponse(null);
        }
        if (!hasPermission(workEffortId, "VIEW", context)) {
            return ICalWorker.createForbiddenResponse(null);
        }
    }
    Calendar calendar = makeCalendar(publishProperties, context);
    ComponentList<CalendarComponent> components = calendar.getComponents();
    List<GenericValue> workEfforts = getRelatedWorkEfforts(publishProperties, context);
    if (workEfforts != null) {
        for (GenericValue workEffort : workEfforts) {
            ResponseProperties responseProps = toCalendarComponent(components, workEffort, context);
            if (responseProps != null) {
                return responseProps;
            }
        }
    }
    if (Debug.verboseOn()) {
        try {
            calendar.validate(true);
            Debug.logVerbose("iCalendar passes validation", module);
        } catch (ValidationException e) {
            if (Debug.verboseOn()) Debug.logVerbose("iCalendar fails validation: " + e, module);
        }
    }
    return ICalWorker.createOkResponse(calendar.toString());
}
 
Example #22
Source File: ICalendarUtils.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Return list of subcomponents for a component.  Ica4j doesn't have
 * a generic way to do this.
 * @param component The component.
 * @return list of subcomponents
 */
public static ComponentList<?> getSubComponents(Component component) {
    if(component instanceof VEvent) {
        return ((VEvent) component).getAlarms();
    }
    else if(component instanceof VTimeZone) {
        return ((VTimeZone) component).getObservances();
    }
    else if(component instanceof VToDo) {
        return ((VToDo) component).getAlarms();
    }
    
    return new ComponentList<>();
}
 
Example #23
Source File: EntityConverter.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * gets master component.
 * @param components The component list.
 * @return The component.
 */
private Component getMasterComponent(ComponentList<? extends Component> components) {
    Iterator<? extends Component> it = components.iterator();
    while(it.hasNext()) {
        Component c = it.next();
        if(c.getProperty(Property.RECURRENCE_ID)==null) {
            return c;
        }
    }
    
    throw new IllegalArgumentException("no master found");
}
 
Example #24
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public void removeDisplayAlarm() {
    VEvent event = getEvent();
    
    if(event==null) {
        return;
    }
     
    ComponentList<VAlarm> alarmsList = event.getAlarms();
    for(VAlarm alarm: alarmsList) {
        if (alarm.getProperties().getProperty(Property.ACTION).equals(
                Action.DISPLAY)) {
            alarmsList.remove(alarm);
        }
    }
}
 
Example #25
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
protected VAlarm getDisplayAlarm(VEvent event) {
    ComponentList<VAlarm> alarmsList = event.getAlarms();
    for(VAlarm alarm: alarmsList) {
        if (alarm.getProperties().getProperty(Property.ACTION).equals(
                Action.DISPLAY)) {
            return alarm;
        }
    }
    
    return null;
}
 
Example #26
Source File: CalendarFilterEvaluater.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluates.
 * @param comps The component list.
 * @param filter The component filter.
 * @return The result.
 */
private boolean evaluate(ComponentList<? extends Component> comps, ComponentFilter filter) {
    // Evaluate component filter against a set of components.
    // If any component matches, then evaluation succeeds.
    // This is basically a big OR
    for(Component parent : comps) {
        stack.push(parent);
        if(evaluateComps(getSubComponents(parent),filter)==true) {
            stack.pop();
            return true;
        }
        stack.pop();
    }
    return false;
}
 
Example #27
Source File: OutputFilter.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Filter sub component.
 * @param subComponents The component list.
 * @param buffer The string buffer.
 */ 
private void filterSubComponents(ComponentList<?> subComponents,
                                 StringBuilder buffer) {
    if (isAllSubComponents() && getLimit() != null) {
        buffer.append(subComponents.toString());
        return;
    }

    if (! (hasSubComponentFilters() || isAllSubComponents())) {
        return;
    }

    for (Component component : subComponents) {
        if (getLimit() != null && component instanceof VEvent &&
                ! includeOverride((VEvent) component)) {
            continue;
        }

        if (isAllSubComponents()) {
            buffer.append(component.toString());
        }
        else {
            OutputFilter subfilter = getSubComponentFilter(component);
            if (subfilter != null) {
                subfilter.filterSubComponent(component, buffer);
            }
        }
    }
}
 
Example #28
Source File: OutputFilter.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * @param comp The component.
 */
private void componentToUTC(Component comp) {
    // Do to each top-level property
    for (Property prop : (List<Property>) comp.getProperties()) {
        if (prop instanceof DateProperty) {
            DateProperty dprop = (DateProperty) prop;
            Date date = dprop.getDate();
            if (date instanceof DateTime &&
                (((DateTime) date).getTimeZone() != null)) {
                dprop.setUtc(true);
            }
        }
    }

    // Do to each embedded component
    ComponentList<? extends CalendarComponent> subcomps = null;
    if (comp instanceof VEvent) {
        subcomps = ((VEvent) comp).getAlarms() ;
    }
    else if (comp instanceof VToDo) {
        subcomps = ((VToDo)comp).getAlarms();
    }

    if (subcomps != null) {
        for (CalendarComponent subcomp :  subcomps) {
            componentToUTC(subcomp);
        }
    }
}
 
Example #29
Source File: CalendarFilterEvaluater.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * A VALARM component is said to overlap a given time range if the
    following condition holds:

       (start <= trigger-time) AND (end > trigger-time)

   A VALARM component can be defined such that it triggers repeatedly.
   Such a VALARM component is said to overlap a given time range if at
   least one of its triggers overlaps the time range.
   @param comps The component list.
   @param filter The time range filter.
   @return The result.
 */
        
private boolean evaluateVAlarmTimeRange(ComponentList<? extends Component> comps, TimeRangeFilter filter) {
    
    // VALARAM must have parent VEVENT or VTODO
    Component parent = stack.peek();
    if(parent==null) {
        return false;
    }
   
    // See if trigger-time overlaps the time range for each VALARM
    for(Component component : comps) {
        if (!(component instanceof VAlarm)) {
            continue;
        }
        VAlarm alarm = (VAlarm) component;
        Trigger trigger = alarm.getTrigger();
        if(trigger==null) {
            continue;
        }
        
        List<Date> triggerDates = ICalendarUtils.getTriggerDates(alarm, parent);
        
        for(Date triggerDate: triggerDates) {
            if(filter.getPeriod().getStart().compareTo(triggerDate)<=0 &&
               filter.getPeriod().getEnd().after(triggerDate)) {
               return true;
            }
        }
    }
    
    return false;
}
 
Example #30
Source File: HibEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public VEvent getMasterEvent() {
    if(getEventCalendar()==null) {
        return null;
    }
    
    ComponentList<VEvent> events = getEventCalendar().getComponents().getComponents(
            Component.VEVENT);
    
    if(events.size()==0) {
        return null;
    }
    
    return (VEvent) events.get(0);
}