Question

I want to parse ics files received from an Exchange using iCal4j to create a VEvent for local processing, and modify them to create a new time proposal (COUNTER method) for sending them back to the Exchange. The problem is that I was only able to build Calendar objects (see the code below), no VEvent.

File file = new File(PATH);
CalendarBuilder builder = new CalendarBuilder();
net.fortuna.ical4j.model.Calendar cal = null;
try {
    FileInputStream fis = new FileInputStream(file);
    cal = builder.build(fis);
} catch (Exception e) {
    e.printStackTrace();
}

Most probably, I would be able to create the replies from scratch, but if I could create them from the invite directly, I guess the result would be more likely to work. Also, I really would like to avoid parsing the files manually and hack around with string matching and things like that.

Was it helpful?

Solution

It seems that the solution is rather simple, it is just not detailed in the examples of iCal4j, where I was looking for help. (Sorry, I am a novice programmer). But after looking into the API reference of iCal4j, I found the following:

If you parse an ics file to a Calendar object, it will have only a few Properties, like METHOD, PRODID and VERSION in our case. But it might (and most probably will) have some Components too, like VEvent, VTodo, etc, which is the actual content of the ics file. You can get the Components' list with

ComponentList cl = cal.getComponents();

For us, parsing, modifying and sending them will be much easier than creating them from scratch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top