Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert iCal to HTML or plaintext in Java

Tags:

java

icalendar

I'm looking for a Java API to convert ICS (aka iCal) attachments to nicely formatted HTML or plaintext for display purposes. Ideally, it would be able to handle:

  • Converting dates to a specified timezone.
  • Expanding recurrence patterns into human readable sentences.
  • Multiple VCALENDAR records in a single file.

I'm looking at iCal4j, which has a nice DOM parser, but no way to serialize to anything but iCal.

like image 719
Chase Seibert Avatar asked Jun 17 '09 17:06

Chase Seibert


Video Answer


2 Answers

Sorry mate, if you Googled around and found nothing, then its a sure set of unique requirements you got there, time to innovate.

Take what you have, think up some ideas, and try them out, comes with the job!

like image 70
BakerTheHacker Avatar answered Sep 19 '22 19:09

BakerTheHacker


I didn't find a better alternative to ical4j. I used it fairly successfully. Unfortunately, as you point out, all it does is to bind to XML, with no other way to output it to something else. You could walk the DOM after creation and output the relevant text - although this seems a bit strange since all you want is text/html, I had the same issue and just ended up parsing out the XML.

The iCal4j API is a bit strange and you might want to relax the parsing and enable outlook/notes compatibility to help you along the way. You could write your own Parser and that implements net.fortuna.ical4j.data.CalendarParser and pull out the necessary information into plain text that way. I think the default net.fortuna.ical4j.data.CalendarParserImpl is about 500 lines of code, you could alternatively hack that.

like image 29
Jon Avatar answered Sep 20 '22 19:09

Jon