Java Code Examples for net.fortuna.ical4j.model.PropertyList#add()

The following examples show how to use net.fortuna.ical4j.model.PropertyList#add() . 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: ICalRecurConverter.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
public static void convert(TemporalExpression expr, PropertyList<Property> eventProps) {
    ICalRecurConverter converter = new ICalRecurConverter();
    expr.accept(converter);
    DtStart dateStart = (DtStart) eventProps.getProperty(Property.DTSTART);
    if (converter.dateStart != null) {
        if (dateStart != null) {
            eventProps.remove(dateStart);
        }
        dateStart = converter.dateStart;
        eventProps.add(dateStart);
    }
    if (dateStart != null && converter.exRuleList.size() > 0) {
        // iCalendar quirk - if exclusions exist, then the start date must be excluded also
        ExDate exdate = new ExDate();
        exdate.getDates().add(dateStart.getDate());
        converter.exDateList.add(exdate);
    }
    eventProps.addAll(converter.incDateList);
    eventProps.addAll(converter.incRuleList);
    eventProps.addAll(converter.exDateList);
    eventProps.addAll(converter.exRuleList);
}
 
Example 2
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public void setRecurrenceDates(DateList dates) {
    if (dates == null) {
        return;
    }
    
    PropertyList<RDate> rdateList = getEvent().getProperties().getProperties(Property.RDATE);
    for (RDate rdate : rdateList) {
        rdateList.remove(rdate);
    }
    if (dates.isEmpty()) {
        return;
    }
    
    RDate rDate = new RDate(dates);
    setDateListPropertyValue(rDate);
    rdateList.add(rDate);   
}
 
Example 3
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public void setExceptionDates(DateList dates) {
    if (dates == null) {
        return;
    }
    
    PropertyList<Property> properties = getEvent().getProperties();
    for (Property exdate : properties.getProperties(Property.EXDATE)) {
        properties.remove(exdate);
    }
    if (dates.isEmpty()) {
        return;
    }
    
    ExDate exDate = new ExDate(dates);
    setDateListPropertyValue(exDate);
    properties.add(exDate);
}
 
Example 4
Source File: MockBaseEventStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Sets recurrence dates.
 * @param dates The date list.
 */    
public void setRecurrenceDates(DateList dates) { 
    if (dates == null) {
        return;
    }
    
    PropertyList<Property> pl = getEvent().getProperties();
    for (Property rdate : pl.getProperties(Property.RDATE)) {
        pl.remove(rdate);
    }
    if (dates.isEmpty()) {
        return;
    }
    
    RDate rDate = new RDate(dates);
    setDateListPropertyValue(rDate);
    pl.add(rDate);   
}
 
Example 5
Source File: MockBaseEventStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Sets exception dates.
 * @param dates The date list.
 */    
public void setExceptionDates(DateList dates) {
    if (dates == null) {
        return;
    }
    
    PropertyList<Property> properties = getEvent().getProperties();
    for (Property exdate : properties.getProperties(Property.EXDATE)) {
        properties.remove(exdate);
    }
    if (dates.isEmpty()) {
        return;
    }
    
    ExDate exDate = new ExDate(dates);
    setDateListPropertyValue(exDate);
    properties.add(exDate);
}
 
Example 6
Source File: ICalUtils.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
protected static Calendar createTestCalendar(ZonedDateTime start, ZonedDateTime end, String summary, String attendee) {
    // Create a TimeZone
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    String tzId = start.getZone().getId();
    TimeZone timezone = registry.getTimeZone(tzId.equals("Z") ? "UTC" : tzId);
    VTimeZone tz = timezone.getVTimeZone();

    // Create the event
    PropertyList propertyList = new PropertyList();
    DateTime ts = new DateTime(true);
    ts.setTime(0);
    propertyList.add(new DtStamp(ts));
    propertyList.add(new DtStart(toDateTime(start, registry)));
    propertyList.add(new DtEnd(toDateTime(end, registry)));
    propertyList.add(new Summary(summary));
    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:" + attendee));
    dev1.getParameters().add(Role.REQ_PARTICIPANT);
    dev1.getParameters().add(new Cn(attendee));
    meeting.getProperties().add(dev1);

    // 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;
}
 
Example 7
Source File: ICalConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
protected static void loadRelatedParties(List<GenericValue> relatedParties, PropertyList<Property> componentProps, Map<String, Object> context) {
    PropertyList<Property> attendees = componentProps.getProperties("ATTENDEE");
    for (GenericValue partyValue : relatedParties) {
        if ("CAL_ORGANIZER~CAL_OWNER".contains(partyValue.getString("roleTypeId"))) {
            // RFC 2445 4.6.1, 4.6.2, and 4.6.3 ORGANIZER can appear only once
            replaceProperty(componentProps, createOrganizer(partyValue, context));
        } else {
            String partyId = partyValue.getString("partyId");
            boolean newAttendee = true;
            // SCIPIO: cast not necessary
            //Attendee attendee = null;
            //Iterator<Attendee> i = UtilGenerics.cast(attendees.iterator());
            Property attendee = null;
            Iterator<Property> i = attendees.iterator();
            while (i.hasNext()) {
                attendee = i.next();
                Parameter xParameter = attendee.getParameter(partyIdXParamName);
                if (xParameter != null && partyId.equals(xParameter.getValue())) {
                    loadPartyAssignment(attendee, partyValue, context);
                    newAttendee = false;
                    break;
                }
            }
            if (newAttendee) {
                attendee = createAttendee(partyValue, context);
                componentProps.add(attendee);
            }
        }
    }
}
 
Example 8
Source File: ICalConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
protected static void replaceProperty(PropertyList<Property> propertyList, Property property) {
    if (property == null) {
        return;
    }
    Property existingProp = propertyList.getProperty(property.getName());
    if (existingProp != null) {
        propertyList.remove(existingProp);
    }
    propertyList.add(property);
}
 
Example 9
Source File: CalendarFilterEvaluater.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluates.
 * @param props The property list.
 * @param filter The text match filter.
 * @return The property list.
 */
private PropertyList<Property> evaluate(PropertyList<Property> props, TextMatchFilter filter) {
    PropertyList<Property> results = new PropertyList<>();
    for(Property prop : props) {
        if(evaluate(prop,filter)==true) {
            results.add(prop);
        }
    }
    return results;
}
 
Example 10
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public void setRecurrenceRules(List<Recur> recurs) {
    if (recurs == null) {
        return;
    }
    PropertyList<Property> properties = getEvent().getProperties();
    for (Property rrule : properties.getProperties(Property.RRULE)) {
        properties.remove(rrule);
    }
    for (Recur recur : recurs) {
        properties.add(new RRule(recur));
    }      
}
 
Example 11
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public void setExceptionRules(List<Recur> recurs) {
    if (recurs == null) {
        return;
    }
    PropertyList<Property> properties = getEvent().getProperties();
    for (Property exrule : properties.getProperties(Property.EXRULE)) {
        properties.remove(exrule);
    }
    for (Recur recur : recurs) {
        properties.add(new ExRule(recur));
    }
}
 
Example 12
Source File: MockBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Sets recurrence rules.
 * @param recurs List with recurrence rules.
 */
public void setRecurrenceRules(List<Recur> recurs) {
    if (recurs == null) {
        return;
    }
    PropertyList<Property> pl = getEvent().getProperties();
    for (Property rrule : pl.getProperties(Property.RRULE)) {
        pl.remove(rrule);
    }
    for (Recur recur : recurs) {
        pl.add(new RRule(recur));
    }
  
}
 
Example 13
Source File: MockBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Sets exception rules.
 * @param recurs The list.
 */
public void setExceptionRules(List<Recur> recurs) {
    if (recurs == null) {
        return;
    }
    PropertyList<Property> pl = getEvent().getProperties();
    for (Property exrule : pl.getProperties(Property.EXRULE)) {
        pl.remove(exrule);
    }
    for (Recur recur : recurs) {
        pl.add(new ExRule(recur));
    }
}
 
Example 14
Source File: ICalFormatTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
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:[email protected]"));
    dev1.getParameters().add(Role.REQ_PARTICIPANT);
    dev1.getParameters().add(new Cn("Developer 1"));
    meeting.getProperties().add(dev1);

    Attendee dev2 = new Attendee(URI.create("mailto:[email protected]"));
    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;
}