Feed feed = new Feed();
feed.setId(atomURL
+"/"+website.getHandle() + "/resources/" + path + start);
feed.setTitle(website.getName());
Link link = new Link();
link.setHref(absUrl + "/" + website.getHandle());
link.setRel("alternate");
link.setType("text/html");
feed.setAlternateLinks(Collections.singletonList(link));
FileManager fmgr = roller.getFileManager();
ThemeResource[] files = fmgr.getFiles(website, path);
SortedSet sortedSet = new TreeSet(new Comparator() {
public int compare(Object o1, Object o2) {
ThemeResource f1 = (ThemeResource)o1;
ThemeResource f2 = (ThemeResource)o2;
if (f1.getLastModified() < f2.getLastModified()) return 1;
else if (f1.getLastModified() == f2.getLastModified()) return 0;
else return -1;
}
});
if (files != null && start < files.length) {
for (int j=0; j<files.length; j++) {
sortedSet.add(files[j]);
}
int count = 0;
ThemeResource[] sortedResources =
(ThemeResource[])sortedSet.toArray(new ThemeResource[sortedSet.size()]);
List atomEntries = new ArrayList();
for (int i=start; i<(start + max) && i<(sortedResources.length); i++) {
Entry entry = createAtomResourceEntry(website, sortedResources[i]);
atomEntries.add(entry);
if (count == 0) {
// first entry is most recent
feed.setUpdated(entry.getUpdated());
}
count++;
}
List otherLinks = new ArrayList();
if (start + count < files.length) { // add next link
int nextOffset = start + max;
String url = atomURL
+"/"+ website.getHandle() + "/resources/" + path + nextOffset;
Link nextLink = new Link();
nextLink.setRel("next");
nextLink.setHref(url);
otherLinks.add(nextLink);
}
if (start > 0) { // add previous link
int prevOffset = start > max ? start - max : 0;
String url = atomURL
+"/"+website.getHandle() + "/resources/" + path + prevOffset;
Link prevLink = new Link();
prevLink.setRel("previous");
prevLink.setHref(url);
otherLinks.add(prevLink);
}
feed.setOtherLinks(otherLinks);
feed.setEntries(atomEntries);
}