Convert iCal to HTML or plaintext in Java
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:
I'm looking at iCal4j, which has a nice DOM parser, but no way to serialize to anything but iCal.
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!
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.
I made an iCalendar API that outputs plain text. All calendar elements (VCALENDAR, VEVENT, etc.) have a toContent() method that will produce plain text. Its real easy to convert multiple VCalendar objects into one long string. For example:
List<VCalendar> calendars = new ArrayList<VCalendar>();
// add VCalendars here
// then concated the text of each into one long string
String allContent = calendars.stream()
.map(v -> v.toContent())
.collect(Collectors.joining(System.lineSeparator()));
To import multiple VCalendars you just need to use the processITIPMethod method to import them with the PUBLISH method. It can handle a list of VCalendar objects.String.
If you want HTML you have to do that yourself.
You can check it out at http://jfxtras.org/
You can download it at https://github.com/JFXtras/jfxtras/tree/8.0/jfxtras-icalendarfx
链接地址: http://www.djcxy.com/p/42750.html