public void generate(ItemDestination dest,Iterator<Entry> entries,String prevRef,String nextRef)
throws XMLException
{
//getContext().getLogger().info("Generating feed for term "+term);
ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
dest.send(constructor.createDocument());
dest.send(constructor.createElement(AtomResource.FEED_NAME));
dest.send(constructor.createCharacters("\n"));
link(constructor,dest,"self",getRequest().getResourceRef().toString());
if (prevRef!=null) {
link(constructor,dest,"previous",prevRef);
}
link(constructor,dest,"next",nextRef);
dest.send(constructor.createCharacters("\n"));
text(constructor,dest,AtomResource.TITLE_NAME,"Updated");
dest.send(constructor.createCharacters("\n"));
text(constructor,dest,AtomResource.ID_NAME,getRequest().getResourceRef().toString());
dest.send(constructor.createCharacters("\n"));
text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(new Date()));
Reference resourceBase = (Reference)getContext().getAttributes().get(AtomApplication.RESOURCE_BASE_ATTR);
App app = (App)getContext().getAttributes().get(AtomApplication.APP_ATTR);
try {
while (entries.hasNext()) {
Entry entry = entries.next();
Feed feed = entry.getFeed();
String feedPath = feed.getPath();
String feedBaseURI = resourceBase.toString()+feedPath;
dest.send(constructor.createCharacters("\n"));
// get the entry representation
Representation rep = app.getStorage().getEntry(feedBaseURI,feedPath,feed.getUUID(),entry.getUUID());
// avoid thread creation because reading an output representation requires a thread
StringWriter sw = new StringWriter();
rep.write(sw);
rep.release();
DocumentLoader loader = new SAXDocumentLoader();
loader.generate(new StringReader(sw.toString()), new RemoveDocumentFilter(dest));
}
} catch (Exception ex) {
throw new XMLException("Exception while getting ancestors.",ex);
}
dest.send(constructor.createCharacters("\n"));
dest.send(constructor.createElementEnd(AtomResource.FEED_NAME));
dest.send(constructor.createDocumentEnd());
}