URL calUrl = new URL ( CALENDAR_FEED_URL );
// Get Number of calendars
Query calQuery = new Query(calUrl);
calQuery.setMaxResults(1);
CalendarFeed calFeed = calService.query(calQuery, CalendarFeed.class);
if (calFeed.getTotalResults() == 0) {
System.out.println("No Calendars");
} else {
// Set Number of calendars for query
calQuery.setMaxResults(calFeed.getTotalResults());
calFeed = calService.query(calQuery, CalendarFeed.class);
}
// Search calendar
System.out.println("Calendar to use for birthdays");
for (CalendarEntry entry : calFeed.getEntries()) {
if ( entry.getTitle().getPlainText().equals( CALENDAR_NAME ) ) {
calEntry = entry;
}
}
if (calEntry == null) {
// No calendar found - Add a birthday calendar
calEntry = new CalendarEntry();
calEntry.setTitle(new PlainTextConstruct( CALENDAR_NAME ));
calEntry.setSummary(new PlainTextConstruct( CALENDAR_SUMMARY ));
calEntry.setTimeZone(calFeed.getEntries().get(0).getTimeZone());
calEntry.setHidden(HiddenProperty.FALSE);
calEntry.setColor(new ColorProperty( CALENDAR_COLOR ));
calEntry.setSelected(SelectedProperty.TRUE);
//calEntry.addLocation(new Where("", "", "Oakland"));
//calEntry.addLocation(calFeed.getEntries().get(0).getLocations().);
// Insert the calendar
calService.insert(calUrl, calEntry);
System.out.println("\tCreated: " + calEntry.getTitle().getPlainText());
//Thread.sleep(5000);
calQuery.setMaxResults(calFeed.getTotalResults()+1);
calFeed = calService.query(calQuery, CalendarFeed.class);
for (CalendarEntry entry : calFeed.getEntries()) {
if ( entry.getTitle().getPlainText().equals( CALENDAR_NAME ) ) {
calEntry = entry;
}
}
}