Search in sources :

Example 1 with CalendarOutputter

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());
    }
}
Also used : ValidationException(net.fortuna.ical4j.model.ValidationException) FileOutputStream(java.io.FileOutputStream) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter) IOException(java.io.IOException) File(java.io.File)

Example 2 with CalendarOutputter

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;
}
Also used : Header(org.apache.commons.httpclient.Header) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Calendar(net.fortuna.ical4j.model.Calendar) PutMethod(org.osaf.caldav4j.methods.PutMethod) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter) IOException(java.io.IOException) IOException(java.io.IOException) DavException(org.apache.jackrabbit.webdav.DavException)

Example 3 with CalendarOutputter

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter)

Example 4 with CalendarOutputter

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);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter)

Example 5 with CalendarOutputter

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();
}
Also used : PropertyList(net.fortuna.ical4j.model.PropertyList) StringWriter(java.io.StringWriter) VFreeBusy(net.fortuna.ical4j.model.component.VFreeBusy) BwCalendar(org.bedework.calfacade.BwCalendar) Calendar(net.fortuna.ical4j.model.Calendar) Method(net.fortuna.ical4j.model.property.Method) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter) ProdId(net.fortuna.ical4j.model.property.ProdId) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) Writer(java.io.Writer) StringWriter(java.io.StringWriter)

Aggregations

CalendarOutputter (net.fortuna.ical4j.data.CalendarOutputter)16 FileOutputStream (java.io.FileOutputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Calendar (net.fortuna.ical4j.model.Calendar)5 ProdId (net.fortuna.ical4j.model.property.ProdId)5 File (java.io.File)4 VEvent (net.fortuna.ical4j.model.component.VEvent)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 URISyntaxException (java.net.URISyntaxException)3 ParseException (java.text.ParseException)3 Calendar (java.util.Calendar)3 Date (java.util.Date)3 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)3 Test (org.junit.Test)3 BufferedOutputStream (java.io.BufferedOutputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2