I'm trying to fetch events from a CalDAV server using Sardine (and biweekly). Fetching an entire calendar is working for me:
Sardine sardine = SardineFactory.begin();
InputStream is = sardine.get(CALDAV_URL_STRING);
ICalendar iCalendar = Biweekly.parse(is).first();
Now I would like to fetch events for specific time range. Based on this "Building a CalDAV client" article, I assume you should use Sardines report method to do so, right?
If so, how should you use that method? It's not documented in the wiki, and the Javadoc is also not very clear.
Should I write my own SardineReport? I looks like I should end up with something like:
Sardine sardine = SardineFactory.begin();
SardineReport<List<VEvent>> report = new MyRangeReport(FROM_DATE, END_DATE);
List<VEvent> result = sardine.report(CALDAV_URL_STRING, 1, report);
Am I on the right track? Does anyone have any pointers to how to write your own Sardine report?
You are correct, to run a time range query you need to issue an HTTP
REPORTrequest containing acalendar-query. You can find a sample in RFC 4719 Section 7.8.1. I don't know Sardine, but yes,reportsounds right ;-)Simplified even further:
Looks like, scanning over the GitHub of Sardine it doesn't seem to include CalDAV queries. You can probably base yours on their SyncCollectionReport.java.
Note that the response to the
calendar-queryREPORTis just a regular WebDAV207multi-statusresponse. Nothing extra required. (theResultobject would be the same like in theirSyncCollectionReportbut w/o the extra syncToken).