문제

I'm using the iCal4j library to generate an iCalendar feed.

If no events are added to the calendar (simply because there doesn't happen to be any upcoming events to add), iCal4j throws a validation exception when it's time to write the iCalendar data into an outputstream:

net.fortuna.ical4j.model.ValidationException: Calendar must contain at least one component
    at net.fortuna.ical4j.model.Calendar.validate(Calendar.java:287)
    at net.fortuna.ical4j.model.Calendar.validate(Calendar.java:257)
    at net.fortuna.ical4j.data.CalendarOutputter.output(CalendarOutputter.java:96)
    at net.fortuna.ical4j.data.CalendarOutputter.output(CalendarOutputter.java:83)

So is a calendar without events actually invalid according to the iCalendar standard, or is this just iCal4j's validation being unecessarily strict? (And if the latter applies, is there any way to relax the validation?)

도움이 되었습니까?

해결책

Technically iCalendar requires at least one component, as specified in section 3.6:

http://tools.ietf.org/html/rfc5545#section-3.6

   icalbody   = calprops component

   [snip..]

   component  = 1*(eventc / todoc / journalc / freebusyc /
                timezonec / iana-comp / x-comp)

You could use a non-validating CalendarOutputter to avoid this exception, but there is currently no way to selectively disable empty calendar validation in iCal4j.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top