* @return a DocumentList of entries from the feed
*/
private DocumentList fetchResults (DateTime ifModifiedSince)
throws RepositoryException {
List documents = new LinkedList();
DateTime fetchTime = DateTime.now();
Query query = new Query(feedUrl);
query.setMaxResults(MAX_RESULTS);
if (ifModifiedSince != null) {
// The use of ifModifiedSince here filters out entries that were
// modified before the given date. Logically, we only care about those
// entries that were modified recently.
query.setUpdatedMin(ifModifiedSince);
}
try {
// The use of ifModifiedSince here tells the server this can avoid
// returning a result feed if the feed contained only entries that
// have been modified after the given date. Without this, when there
// are no changes, we would still have all of the overhead of fetching
// the feed's meta data but get zero entries. In terms of efficiency,
// we don't care about the feed unless it is going to tell us something
// new.
Feed feed = (Feed) service.query(query, Feed.class, ifModifiedSince);
List entries = feed.getEntries();
LOGGER.info("Fetched " + entries.size() + " of " +
feed.getTotalResults() + " total updated entries.");
Collections.sort(entries, new EntryUpdatedAscendingComparator());
for (ListIterator ei = entries.listIterator(); ei.hasNext();) {
Entry entry = (Entry) ei.next();
documents.add(makeDocument(entry));
}
} catch (NotModifiedException nme) {
// silently return empty result set
if (LOGGER.isLoggable(Level.INFO))
LOGGER.info(nme.toString());
} catch (IOException ioe) {
throw new RepositoryException(ioe);
} catch (ServiceException se) {
throw new RepositoryException(se);
}
return new GdDocumentList(documents, fetchTime.toString());
}