public static void generate(Storage storage,Feed feed,Reference metaRef,Reference feedRef,String resourceBase,ItemDestination dest)
throws XMLException
{
XMLRepresentationParser xmlParser = new XMLRepresentationParser();
ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
dest.send(constructor.createDocument());
dest.send(constructor.createElement(AtomResource.FEED_NAME));
link(constructor,dest,"self",metaRef.toString());
link(constructor,dest,"related",feedRef.toString());
try {
org.atomojo.app.client.Feed feedRep = new org.atomojo.app.client.Feed(xmlParser.load(storage.getFeedHead(feed.getPath(), feed.getUUID())));
text(constructor,dest,AtomResource.TITLE_NAME,feedRep.getTitle());
String summary = feedRep.getSummary();
if (summary!=null) {
text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
}
} catch (Exception ex) {
throw new XMLException("Exception while getting feed title.",ex);
}
text(constructor,dest,AtomResource.ID_NAME,feed.getUUID().toString());
text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(feed.getEdited()));
try {
Iterator<TermInstance<Feed>> categorization = feed.getTerms();
while (categorization.hasNext()) {
TermInstance<Feed> category = categorization.next();
term(constructor,dest,category.getTerm().getURI(),category.getValue());
}
} catch (Exception ex) {
throw new XMLException("Exception while getting categorization.",ex);
}
try {
List<Feed> ancestors = new ArrayList<Feed>();
Feed parent = feed;
do {
parent = parent.getParent();
if (parent!=null) {
ancestors.add(parent);
}
} while (parent!=null);
Collections.reverse(ancestors);
for (Feed ancestor : ancestors) {
org.atomojo.app.client.Feed feedRep = new org.atomojo.app.client.Feed(xmlParser.load(storage.getFeedHead(ancestor.getPath(), ancestor.getUUID())));
dest.send(constructor.createElement(AtomResource.ENTRY_NAME));
text(constructor,dest,AtomResource.ID_NAME,ancestor.getUUID().toString());
text(constructor,dest,AtomResource.PUBLISHED_NAME,AtomResource.toXSDDate(ancestor.getCreated()));
text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(ancestor.getEdited()));
text(constructor,dest,AtomResource.TITLE_NAME,feedRep.getTitle());
String summary = feedRep.getSummary();
if (summary!=null) {
text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
}
term(constructor,dest,Categorization.ANCESTOR_TERM,null);
Iterator<TermInstance<Feed>> categorization = ancestor.getTerms();
while (categorization.hasNext()) {
TermInstance<Feed> category = categorization.next();
term(constructor,dest,category.getTerm().getURI(),category.getValue());
}
link(constructor,dest,"related",resourceBase+ancestor.getPath());
dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
}
} catch (Exception ex) {
throw new XMLException("Exception while getting ancestors.",ex);
}
try {
Term hidden = feed.getDB().findTerm(Categorization.HIDDEN_TYPE_TERM);
if (hidden==null) {
hidden = feed.getDB().createTerm(Categorization.HIDDEN_TYPE_TERM);
}
Iterator<Feed> children = feed.getChildren();
while (children.hasNext()) {
Feed child = children.next();
if (child.getTerm(hidden)!=null) {
continue;
}
org.atomojo.app.client.Feed feedRep = new org.atomojo.app.client.Feed(xmlParser.load(storage.getFeedHead(child.getPath(), child.getUUID())));
dest.send(constructor.createElement(AtomResource.ENTRY_NAME));
text(constructor,dest,AtomResource.ID_NAME,child.getUUID().toString());
text(constructor,dest,AtomResource.PUBLISHED_NAME,AtomResource.toXSDDate(child.getCreated()));
text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(child.getEdited()));
text(constructor,dest,AtomResource.TITLE_NAME,feedRep.getTitle());
String summary = feedRep.getSummary();
if (summary!=null) {
text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
}
term(constructor,dest,Categorization.CHILD_TERM,null);
Iterator<TermInstance<Feed>> categorization = child.getTerms();
while (categorization.hasNext()) {
TermInstance<Feed> category = categorization.next();
term(constructor,dest,category.getTerm().getURI(),category.getValue());
}
link(constructor,dest,"related",feedRef.toString()+child.getName()+"/");
dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
}
} catch (Exception ex) {
throw new XMLException("Exception while getting feed children.",ex);
}
dest.send(constructor.createElementEnd(AtomResource.FEED_NAME));
dest.send(constructor.createDocumentEnd());
}