简体   繁体   中英

Is it possible to create or update events using ical4j

I created a client that is getting calendar data (VEvents) from Yahoo. Now I need to be able to update existing or create new event and 'publish' it, to be visible from Yahoo calendar.

Can this be done with ical4j or I need to find some other way to do it?

Ok, I found a way of doing this. The problem was that for CalDavCollection, you can't actually add event directly, you need to add it as a Calendar. The code that is working:

public void addEvent(VEvent event, VTimeZone timezone){
                    try {
                        Calendar calendar = new Calendar();
                        calendar.getProperties().add(new ProdId(prodId));
                        calendar.getProperties().add(Version.VERSION_2_0);
                        calendar.getProperties().add(CalScale.GREGORIAN);
                        calendar.getComponents().add(event);
                        collection.add(httpClient, calendar);
                    } catch (CalDAV4JException e) {
                        e.printStackTrace();
                    }

    }

The 'prodId' in line

calendar.getProperties().add(new ProdId(prodId));

is the prodId of the Calendar provider (in my case it is PRODID://Yahoo//Calendar//EN)

The collection is the instance of the CalDavCollecion, that is related to specific Calendar, so just adding calendar with new event inside will add it to the server to the correct calendar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM