javaicalendarical4j

How should I use iCal4j to add a meeting organizer to an iCal event


This is how I successfully create the event, but I couldn't successfully code the organizer addtion:

    //Creating a new calendar
    net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
    calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
    calendar.getProperties().add(Version.VERSION_2_0);
    calendar.getProperties().add(CalScale.GREGORIAN);

    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timezone = registry.getTimeZone("Etc/GMT");

    //Creating an event
    java.util.Calendar startCal = java.util.Calendar.getInstance(timezone);
    startCal.set(java.util.Calendar.YEAR, 2005);
    startCal.set(java.util.Calendar.MONTH, java.util.Calendar.NOVEMBER);
    startCal.set(java.util.Calendar.DAY_OF_MONTH, 1);
    startCal.set(java.util.Calendar.HOUR_OF_DAY, 15);
    startCal.clear(java.util.Calendar.MINUTE);
    startCal.clear(java.util.Calendar.SECOND);

    java.util.Calendar endCal = java.util.Calendar.getInstance(timezone);
    endCal.set(java.util.Calendar.YEAR, 2005);
    endCal.set(java.util.Calendar.MONTH, java.util.Calendar.NOVEMBER);
    endCal.set(java.util.Calendar.DAY_OF_MONTH, 1);
    endCal.set(java.util.Calendar.HOUR_OF_DAY, 19);
    endCal.clear(java.util.Calendar.MINUTE);
    endCal.clear(java.util.Calendar.SECOND);

    net.fortuna.ical4j.model.DateTime dtStart = new DateTime (startCal.getTime());
    dtStart.setUtc(true);

    net.fortuna.ical4j.model.DateTime dtEnd = new DateTime (endCal.getTime());
    dtEnd.setUtc(true);

    VEvent event = new VEvent(dtStart,dtEnd, "Test Event");

Solution

  • You would use the following line of code

      event.getProperties().add(new Organizer("mailto:bob@example.com"));