/** * @param ical * @return Calendar object or null for no data * @throws Throwable */ public Calendar fromXcal(final IcalendarType ical) throws Throwable { BuildState bs = new BuildState(tzRegistry); bs.setContentHandler(new ContentHandlerImpl(bs)); List<VcalendarType> vcts = ical.getVcalendar(); if (vcts.size() == 0) { return null; } if (vcts.size() > 1) { throw new Exception("More than one vcalendar"); } processVcalendar(vcts.get(0), bs); return bs.getCalendar(); }
/** * Build an iCalendar model by parsing data from the specified reader. * * @param in an unfolding reader to read data from * @return a calendar parsed from the specified reader * @throws IOException where an error occurs reading data from the specified reader * @throws ParserException where an error occurs parsing data from the reader */ public Calendar build(final Reader in) throws IOException, ParserException { BuildState bs = new BuildState(tzRegistry); bs.setContentHandler(new ContentHandlerImpl(bs)); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(in)); process(doc, bs); } catch (SAXException e) { throw new ParserException(e.getMessage(), 0, e); } catch (Throwable t) { throw new ParserException(t.getMessage(), 0, t); } if ((bs.getDatesMissingTimezones().size() > 0) && (tzRegistry != null)) { resolveTimezones(bs); } return bs.getCalendars().iterator().next(); }
/** * Build an iCalendar model by parsing data from the specified reader. * * @param in an unfolding reader to read data from * @return a calendar parsed from the specified reader * @throws java.io.IOException where an error occurs reading data from the specified reader * @throws net.fortuna.ical4j.data.ParserException where an error occurs parsing data from the reader */ public Calendar build(final Reader in) throws IOException, ParserException { BuildState bs = new BuildState(tzRegistry); bs.setContentHandler(new ContentHandlerImpl(bs)); try { final JsonParser parser = jsonFactory.createParser(in); process(parser, bs); } catch (Throwable t) { throw new ParserException(t.getMessage(), 0, t); } if ((bs.getDatesMissingTimezones().size() > 0) && (tzRegistry != null)) { resolveTimezones(bs); } return bs.getCalendars().iterator().next(); }