private List<ICalResource> findCalendarResources(CalendarResource calendar, Document doc) {
// build a list of all calendar resources
List<ICalResource> list = new ArrayList<ICalResource>();
for(Resource r : calendar.getChildren()) {
if( r instanceof ICalResource) {
ICalResource cr = (ICalResource) r;
list.add(cr);
}
}
// filter out those that don't match
Element elFilterRoot = doc.getRootElement().getChild("filter", NS_CAL);
if (elFilterRoot == null) {
// no filter so return all
return list;
}
Element elSecondFilter = elFilterRoot.getChild("comp-filter", NS_CAL);
if (elSecondFilter == null) {
// no second filter so return all
return list;
}
Element elTimeRange = elSecondFilter.getChild("time-range", NS_CAL);
if (elTimeRange == null) {
// no time range filter so return all
return list;
}
String sStart = elTimeRange.getAttributeValue("start");
String sFinish = elTimeRange.getAttributeValue("end");
Date start = null;
Date end = null;
if( sStart != null && sStart.length() > 0) {
try {
start = DateUtils.parseDate(sStart);
} catch (DateParseException ex) {
log.error("Couldnt parse start date in calendar-query: " + sStart);
}
}
if( sFinish != null && sFinish.length() > 0) {
try {
end = DateUtils.parseDate(sFinish);
} catch (DateParseException ex) {
log.error("Couldnt parse end date in calendar-query: " + sFinish);
}
}
// So now we have (or might have) start and end dates, so filter list
Iterator<ICalResource> it = list.iterator();
while(it.hasNext()) {
ICalResource r = it.next();
if( outsideDates(r, start, end)) {
it.remove();
}
}
return list;