/** * Return the CalendarOuputter instance. * @return CalendarOutputter */ protected synchronized CalendarOutputter getCalendarOutputterInstance(){ if (calendarOutputter == null){ calendarOutputter = new CalendarOutputter(validatingOutputter); } return calendarOutputter; }
/** * Get IcalBody as ByteArray * * @return - calendar in ICS format as byte[] * @throws Exception * - in case of error during writing to byte array */ public byte[] getIcalAsByteArray() throws Exception { ByteArrayOutputStream bout = new ByteArrayOutputStream(); CalendarOutputter outputter = new CalendarOutputter(); outputter.output(icsCalendar, bout); return bout.toByteArray(); }
public void writeCalendarToOutputStream(final OutputStream stream) { try { CalendarOutputter outputter = new CalendarOutputter(); outputter.output(this.calendar, stream); } catch (IOException e) { log.error("Error while exporting calendar " + e.getMessage()); } }
public ByteArrayOutputStream getCalendarAsByteStream() { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); CalendarOutputter outputter = new CalendarOutputter(); outputter.output(this.calendar, stream); return stream; } catch (IOException e) { log.error("Error while exporting calendar " + e.getMessage()); return null; } }
/** * Write iCal to File * * @param _filerPath * - path to '*.ics' file * @throws Exception * - in case of error during writing to the file */ public void writeDataToFile(String _filerPath) throws Exception { String filerPath = _filerPath.endsWith(".ics") ? _filerPath : String.format("%s.ics", _filerPath); try (FileOutputStream fout = new FileOutputStream(filerPath)) { CalendarOutputter outputter = new CalendarOutputter(); outputter.output(icsCalendar, fout); } }
/** * Convert Calendar object to String * @param calendar * @return string representation of calendar * @throws ValidationException - if something is wrong this exception is thrown. * @throws IOException - if something is wrong this exception is thrown. */ public static String outputCalendar(Calendar calendar) throws ValidationException, IOException { if (calendar == null) { return null; } CalendarOutputter outputter = new CalendarOutputter(); StringWriter sw = new StringWriter(); outputter.output(calendar, sw); return sw.toString(); }
/** * Convert Calendar object to String * @param calendar * @return string representation of calendar * @throws ValidationException - if something is wrong this exception is thrown. * @throws IOException - if something is wrong this exception is thrown. */ public static String outputCalendar(Calendar calendar) throws ValidationException, IOException { if (calendar == null) { return null; } CalendarOutputter outputter = new CalendarOutputter(); StringWriter sw = new StringWriter(); outputter.output(calendar, sw); return sw.toString(); }
private static String writeCalendar(Calendar calendar) throws CosmoDavException { try { StringWriter out = new StringWriter(); CalendarOutputter outputter = new CalendarOutputter(); outputter.output(calendar, out); String output = out.toString(); out.close(); // NB ical4j's outputter generates \r\n line ends but we // need only \n, so remove all \r's from the string output = output.replaceAll("\r", ""); return output; } catch (IOException | ValidationException e) { throw new CosmoDavException(e); } }
private byte[] calendarAsByteArray(net.fortuna.ical4j.model.Calendar calendar) throws FileNotFoundException { byte[] bytes; try { ByteArrayOutputStream output = new ByteArrayOutputStream(); CalendarOutputter outputter = new CalendarOutputter(); outputter.setValidating(false); outputter.output(calendar, output); bytes = output.toByteArray(); FileOutputStream fos = new FileOutputStream("test.ics"); fos.write(bytes); fos.close() } catch (Exception e) { throw new IllegalStateException("can't convert calendar to bytes: "+e); } return bytes; }
private static String writeCalendar(Calendar calendar) throws CosmoDavException { try { StringWriter out = new StringWriter(); CalendarOutputter outputter = new CalendarOutputter(); outputter.output(calendar, out); String output = out.toString(); out.close(); // NB ical4j's outputter generates \r\n line ends but we // need only \n, so remove all \r's from the string output = output.replaceAll("\r", ""); return output; } catch (IOException | ValidationException e) { throw new CosmoDavException(e); } }
/** Write a Calendar * * @param cal Calendar to convert * @param wtr Writer for output * @throws CalFacadeException */ public static void writeCalendar(final Calendar cal, final Writer wtr) throws CalFacadeException { CalendarOutputter co = new CalendarOutputter(false, 74); try { co.output(cal, wtr); } catch (Throwable t) { throw new CalFacadeException(t); } }
/** Create a Calendar object from the named timezone and convert to * a String representation * * @param tzid String timezone id * @return String * @throws CalFacadeException */ public String toStringTzCalendar(final String tzid) throws CalFacadeException { Calendar ical = getTzCalendar(tzid); CalendarOutputter calOut = new CalendarOutputter(true); StringWriter sw = new StringWriter(); try { calOut.output(ical, sw); return sw.toString(); } catch (Throwable t) { throw new CalFacadeException(t); } }
/** * Writes an iCalendar string representing the calendar items * contained within the given calendar collection to the given * output stream. * * Since the calendar content stored with each calendar items * is parsed and validated when the item is created, these * errors should not reoccur when the calendar is being * outputted. * * @param collection the <code>CollectionItem</code> to format * * @throws IllegalArgumentException if the collection is not * stamped as a calendar collection * @throws IOException */ public static void output(Calendar calendar, OutputStream out) throws IOException { CalendarOutputter outputter = new CalendarOutputter(); outputter.setValidating(false); try { outputter.output(calendar, out); } catch (ValidationException e) { throw new IllegalStateException("unable to validate collection calendar", e); } } }
/** * Writes an iCalendar string representing the calendar items * contained within the given calendar collection to the given * output stream. * * Since the calendar content stored with each calendar items * is parsed and validated when the item is created, these * errors should not reoccur when the calendar is being * outputted. * * @param collection the <code>CollectionItem</code> to format * * @throws IllegalArgumentException if the collection is not * stamped as a calendar collection * @throws IOException */ public static void output(Calendar calendar, OutputStream out) throws IOException { CalendarOutputter outputter = new CalendarOutputter(); outputter.setValidating(false); try { outputter.output(calendar, out); } catch (ValidationException e) { throw new IllegalStateException("unable to validate collection calendar", e); } } }
public String toVCard(Object bean) { net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar(); calendar.getProperties().add(new ProdId("-//spliffy.org//iCal4j 1.0//EN")); calendar.getProperties().add(Version.VERSION_2_0); VEvent vevent = new VEvent(); calendar.getComponents().add(vevent); PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(bean); for (PropertyDescriptor pd : pds) { if (pd.getReadMethod() != null && pd.getWriteMethod() != null) { Method read = pd.getReadMethod(); Annotation[] annotations = read.getAnnotations(); for (Annotation anno : annotations) { Mapper mapper = mapOfMappers.get(anno.annotationType()); if (mapper != null) { mapper.mapToCard(calendar, bean, pd); } } } } CalendarOutputter outputter = new CalendarOutputter(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { outputter.output(calendar, bout); } catch (IOException ex) { throw new RuntimeException(ex); } catch (ValidationException ex) { throw new RuntimeException(ex); } return bout.toString(); }
CalendarOutputter co = new CalendarOutputter(false, 74);
/** * Test escaping of commas in categories. */ public void testCommaEscaping() throws ValidationException, IOException, ParserException { Categories cat1 = new Categories("test1"); Categories cat2 = new Categories("test2"); Categories cat3 = new Categories("test1,test2,test 1\\,2\\,3"); VEvent event = new VEvent(); event.getProperties().add(cat1); event.getProperties().add(cat2); event.getProperties().add(cat3); Calendar calendar = new Calendar(); calendar.getComponents().add(event); StringWriter tempOut = new StringWriter(); CalendarOutputter cout = new CalendarOutputter(false); cout.output(calendar, tempOut); CalendarBuilder builder = new CalendarBuilder(); calendar = builder.build(new StringReader(tempOut.getBuffer() .toString())); List<Categories> categories = calendar.getComponent(Component.VEVENT) .getProperties(Property.CATEGORIES); assertEquals(cat1, categories.get(0)); assertEquals(cat2, categories.get(1)); assertEquals(cat3, categories.get(2)); assertEquals(3, cat3.getCategories().size()); }
public void testAttachParameterListString() throws IOException, URISyntaxException, ValidationException, ParserException { //log.info(attach); // create event start date.. java.util.Calendar cal = java.util.Calendar.getInstance(); cal.set(java.util.Calendar.MONTH, java.util.Calendar.DECEMBER); cal.set(java.util.Calendar.DAY_OF_MONTH, 25); DtStart start = new DtStart(new Date(cal.getTime().getTime())); start.getParameters().replace(Value.DATE); Summary summary = new Summary("Christmas Day; \n this is a, test\\"); VEvent christmas = new VEvent(); christmas.getProperties().add(start); christmas.getProperties().add(summary); christmas.getProperties().add(attach); christmas.getProperties().add(new Uid("000001@modularity.net.au")); Calendar calendar = new Calendar(); calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN")); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(CalScale.GREGORIAN); calendar.getComponents().add(christmas); StringWriter sw = new StringWriter(); CalendarOutputter out = new CalendarOutputter(); out.output(calendar, sw); CalendarBuilder builder = new CalendarBuilder(); Calendar cout = builder.build(new StringReader(sw.toString())); VEvent eout = (VEvent) cout.getComponent(Component.VEVENT); Attach aout = (Attach) eout.getProperty(Property.ATTACH); assertNotNull(aout); assertEquals(attach, aout); log.info(sw.toString()); }
final CalendarOutputter outputter = new CalendarOutputter(); outputter.output(calendar, outputStream);
CalendarOutputter cout = new CalendarOutputter(); cout.output(calendar, tempOut);