URL feedUrl = null;
try {
feedUrl = new URL(urlString);
} catch (MalformedURLException murle) {
LOGGER.severe(murle.toString());
throw new RepositoryException(murle);
}
DateTime ifModifiedSince = null;
if (checkpoint != null) {
String dateString = checkpoint.substring(0, checkpoint.indexOf("!"));
try {
ifModifiedSince = DateTime.parseDateTime(dateString);
} catch (NumberFormatException nfe) {
LOGGER.info("Got " + nfe.toString() + " while parsing date part of"
+ "checkpoint. Continuing as if no date was specified.");
}
}
// If ifModifiedSince is null at this point service.query() will treat it
// as if no threshold was specified (equivalent to the 2-arg form).
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);
}
Feed feed = null;
try {
feed = (Feed) service.query(query, Feed.class, ifModifiedSince);
} catch (NotModifiedException nme) {
// excellent! no work to do
return new LinkedList();
} catch (ServiceException se) {
LOGGER.severe(se.toString());
throw new RepositoryException(se);
} catch (IOException ioe) {
LOGGER.severe(ioe.toString());
throw new RepositoryException(ioe);
}
List entries = feed.getEntries();
Collections.sort(entries, comparator);
Entry lastEntry = (Entry) entries.get(entries.size() - 1);
lastEntryId = lastEntry.getId();