Wednesday, May 09, 2007
Integrate your Java agenda and ICalendar clients (Outlook) with iCal4j
This post concerns integrating a calendar/agenda you created in your Java application with external clients. It is a relevant feature, because applications are not released in a void, but in a world where people already use several applications, among which often there is a calendar client, typically Microsoft Outlook, sometimes also integrated with Exchange Server. Then there are all the non-Microsoft people, with several different clients and tools (see here for a list). So if you build a group calendar management, by making it interact with the agenda clients you will be lowering considerably the adoption barrier.
What's nice of the presented solution is that
- it works with most clients, through the ICalendar standard,
- is compatible with the presence of a calendar group server,
- its very light: we just use mail headers and a simple textual standard (ICalendar).
Your Java application
We use Teamwork as example application which has to be integrated. We assume that you have built a solution to keep track in Java of your team's calendar, managing also recurrent events of the different kinds, which is the hardest part: you have to manage daily, weekly, monthly and yearly recurrences, answering fast to questions like "when will the two appointments 'all 4th of month' and 'every Tuesday every two weeks' next intersect? Outlook does all of this, so you need to provide a formalization in your app to synch with it. People (or "resources") involved will be identified by their e-mail in he synch process, and actually this is what Outlook does when you "invite" resources to join meetings.
iCal4j
A basic free tool which you should use is the iCal4j API, through which you will get Java objects modeling ICalendar messages. In our implementation, we had to add a "fake" property to the set provided by iCal4j because of problems with the "CN=..." format, but this is a side detail.
Action
The flow of group meetings creation, editing and approval can go in several directions, and you have to handle all of them.
Create event in Teamwork and send copy to clients
and Outlook will recognize it, presenting the mail received as in the picture.
The appointment will be put in Outlook's calendar when received, and it will be possible to accept them or not.
We did this simply by making our application capable of downloading e-mail. Then when you create your appointment in Outlook, you just "send" it to your app, by having among the attendees the e-mail of your app. You need a scheduled mail download (and hence a job handler), and to parse the received relevant string body part in a V-event, which too is provided by the Ical4j API: in particular, you have to consider the cases
and by working on the V-event UID you can decide whether to create or update an event in your web-app, which will be the final step. To recognize the e-mail received as one relative to calendar, look at the content type which will be "text/calendar". Notice that you will also receive "DECLINED" events, in which case you must remove that attendee from your event.
Conclusion
The outline above can proceed further by handling people who want to remove themselves from event. Then it is natural to proceed in the integration by exporting contacts from the mail client to your application; this is exactly how we proceeded in Teamwork's case, but this is another matter.
More can be found at http://www.twproject.com/icalendar.page
Microsoft Outlook and Exchange Server are (c) Microsoft Corporation. Mozilla Thunderbird is (c) the Mozilla Corporation. iCal4J is Copyright (c) 2006, Ben Fortuna. See http://ical4j.sourceforge.net.
Labels: Java Outlook