use of net.fortuna.ical4j.data.CalendarOutputter in project openhab1-addons by openhab.
the class Util method storeToDisk.
public static void storeToDisk(String calendarId, String filename, Calendar calendar) {
File cacheFile = getCacheFile(calendarId, filename);
try {
FileOutputStream fout = new FileOutputStream(cacheFile);
CalendarOutputter outputter = new CalendarOutputter();
outputter.setValidating(false);
outputter.output(calendar, fout);
fout.flush();
fout.close();
} catch (IOException e) {
log.error("cannot store event '{}' to disk (path={}): {}", filename, cacheFile.getAbsoluteFile(), e.getMessage());
} catch (ValidationException e) {
log.error("cannot store event '{}' to disk (path={}): {}", filename, cacheFile.getAbsoluteFile(), e.getMessage());
}
}
use of net.fortuna.ical4j.data.CalendarOutputter in project openmeetings by apache.
the class EtagsHandler method updateItem.
@Override
public boolean updateItem(Appointment appointment) {
OmCalendar calendar = appointment.getCalendar();
String href;
if (calendar != null && calendar.getSyncType() != SyncType.NONE) {
// Store new Appointment on the server
PutMethod putMethod = null;
try {
List<String> hrefs = null;
CalendarOutputter calendarOutputter = new CalendarOutputter();
Calendar ical = utils.parseAppointmenttoCalendar(appointment);
putMethod = new PutMethod();
putMethod.setRequestBody(ical);
putMethod.setCalendarOutputter(calendarOutputter);
if (Strings.isEmpty(appointment.getHref())) {
String temp = path + appointment.getIcalId() + ".ics";
temp = UrlUtils.removeDoubleSlashes(temp);
putMethod.setPath(temp);
putMethod.setIfNoneMatch(true);
putMethod.setAllEtags(true);
} else {
putMethod.setPath(appointment.getHref());
putMethod.setIfMatch(true);
putMethod.addEtag(appointment.getEtag());
}
client.executeMethod(putMethod);
if (putMethod.getStatusCode() == SC_CREATED || putMethod.getStatusCode() == SC_NO_CONTENT) {
href = putMethod.getPath();
appointment.setHref(href);
// Check if the ETag header was returned.
Header etagh = putMethod.getResponseHeader("ETag");
if (etagh == null)
hrefs = Collections.singletonList(appointment.getHref());
else {
appointment.setEtag(etagh.getValue());
appointmentDao.update(appointment, appointment.getOwner().getId());
}
} else {
// Appointment not created on the server
return false;
}
// Get new etags for the ones which didn't return an ETag header
MultigetHandler multigetHandler = new MultigetHandler(hrefs, true, path, calendar, client, appointmentDao, utils);
multigetHandler.syncItems();
return true;
} catch (IOException e) {
log.error("Error executing OptionsMethod during testConnection.", e);
} catch (Exception e) {
log.error("Severe Error in executing OptionsMethod during testConnection.", e);
} finally {
if (putMethod != null) {
putMethod.releaseConnection();
}
}
}
return false;
}
use of net.fortuna.ical4j.data.CalendarOutputter in project openmeetings by apache.
the class IcalHandler method getIcalAsByteArray.
/**
* 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();
}
use of net.fortuna.ical4j.data.CalendarOutputter in project openmeetings by apache.
the class IcalHandler method writeDataToFile.
/**
* 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);
}
}
use of net.fortuna.ical4j.data.CalendarOutputter in project bw-calendar-engine by Bedework.
the class IcalTranslator method toIcalString.
/**
* Make a new Calendar with the freebusy object
*
* @param methodType
* @param ent
* @return String representation
* @throws CalFacadeException
*/
public static String toIcalString(final int methodType, final BwEvent ent) throws CalFacadeException {
Calendar cal = new Calendar();
PropertyList pl = cal.getProperties();
pl.add(new ProdId(prodId));
pl.add(Version.VERSION_2_0);
if ((methodType > ScheduleMethods.methodTypeNone) && (methodType < ScheduleMethods.methodTypeUnknown)) {
pl.add(new Method(ScheduleMethods.methods[methodType]));
}
if (ent.getEntityType() == IcalDefs.entityTypeFreeAndBusy) {
VFreeBusy vfreeBusy = VFreeUtil.toVFreeBusy(ent);
cal.getComponents().add(vfreeBusy);
} else {
throw new CalFacadeException("Unexpected entity type");
}
CalendarOutputter co = new CalendarOutputter(false, 74);
Writer wtr = new StringWriter();
try {
co.output(cal, wtr);
} catch (Throwable t) {
throw new CalFacadeException(t);
}
return wtr.toString();
}
Aggregations