use of net.fortuna.ical4j.data.ParserException in project bw-calendar-engine by Bedework.
the class IcalTranslator method fromIcal.
/**
* Convert the Icalendar reader to a Collection of Calendar objects
*
* @param col collection the entities will live in - possibly null
* @param rdr
* @param contentType
* @param diff True if we should assume we are updating existing events.
* @param mergeAttendees True if we should only update our own attendee.
* @return Icalendar
* @throws CalFacadeException
*/
public Icalendar fromIcal(final BwCalendar col, final Reader rdr, final String contentType, final boolean diff, final boolean mergeAttendees) throws CalFacadeException {
try {
Icalendar ic = new Icalendar();
setSystemProperties();
Calendar cal;
if ((contentType != null) && contentType.equals("application/calendar+xml")) {
XmlCalendarBuilder bldr = new XmlCalendarBuilder(ic);
cal = bldr.build(rdr);
} else if ((contentType != null) && contentType.equals("application/calendar+json")) {
JsonCalendarBuilder bldr = new JsonCalendarBuilder(ic);
cal = bldr.build(rdr);
} else {
CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
UnfoldingReader ufrdr = new UnfoldingReader(rdr, true);
cal = bldr.build(ufrdr);
}
return makeIc(col, ic, cal, diff, mergeAttendees);
} catch (CalFacadeException cfe) {
throw cfe;
} catch (ParserException pe) {
if (debug) {
error(pe);
}
throw new IcalMalformedException(pe.getMessage());
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
use of net.fortuna.ical4j.data.ParserException in project bw-calendar-engine by Bedework.
the class IcalUtil method parseVpollVvoters.
/**
* @param poll the poll entity
* @return Parsed VVOTER components map - key is voter cua.
* @throws Throwable
*/
public static Map<String, VVoter> parseVpollVvoters(final BwEvent poll) throws Throwable {
final StringBuilder sb = new StringBuilder();
// Better if ical4j supported sub-component parsing
sb.append("BEGIN:VCALENDAR\n");
sb.append("PRODID://Bedework.org//BedeWork V3.9//EN\n");
sb.append("VERSION:2.0\n");
sb.append("BEGIN:VPOLL\n");
sb.append("UID:0123\n");
if (!Util.isEmpty(poll.getVvoters())) {
for (final String s : poll.getVvoters()) {
sb.append(s);
}
}
sb.append("END:VPOLL\n");
sb.append("END:VCALENDAR\n");
try {
final StringReader sr = new StringReader(sb.toString());
final Icalendar ic = new Icalendar();
final CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
final UnfoldingReader ufrdr = new UnfoldingReader(sr, true);
final Calendar ical = bldr.build(ufrdr);
final Map<String, VVoter> voters = new HashMap<>();
/* Should be one vpoll object */
final VPoll vpoll = (VPoll) ical.getComponent(Component.VPOLL);
for (final Object o : vpoll.getVoters()) {
final VVoter vvoter = (VVoter) o;
final Voter v = (Voter) vvoter.getProperty(Property.VOTER);
if (v == null) {
continue;
}
voters.put(v.getValue(), vvoter);
}
return voters;
} catch (final ParserException pe) {
throw new IcalMalformedException(pe.getMessage());
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of net.fortuna.ical4j.data.ParserException in project openolat by klemens.
the class ICalServlet method getOutlookVTimeZone.
/**
* Load the VTimeZone for Outlook. ical4j use a static map to reuse the TimeZone objects, we need to load
* and save our specialized TimeZone in a separate map.
*/
private VTimeZone getOutlookVTimeZone(final String id) throws IOException, ParserException {
return outlookVTimeZones.computeIfAbsent(id, (timeZoneId) -> {
try {
URL resource = ResourceLoader.getResource("zoneinfo-outlook/" + id + ".ics");
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = builder.build(resource.openStream());
VTimeZone vTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE);
return vTimeZone;
} catch (Exception e) {
log.error("", e);
return null;
}
});
}
Aggregations