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
REPORT
request containing acalendar-query
. You can find a sample in RFC 4719 Section 7.8.1. I don't know Sardine, but yes,report
sounds 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-query
REPORT
is just a regular WebDAV207
multi-status
response. Nothing extra required. (theResult
object would be the same like in theirSyncCollectionReport
but w/o the extra syncToken).