res.setContentType("text/html");
PrintWriter out = res.getWriter();
// Create the DOM tree for the full document
Template template = new Template();
// Create the DOM Tree that contains the internal content
ToolView toolview = new ToolView();
// Get the prototype tool view record
HTMLDivElement record = toolview.getElementRecord();
// Get a reference to the insertion point for the tool list
HTMLDivElement insertionPoint = template.getElementContent();
Node insertionParent = insertionPoint.getParentNode();
// Set the template title, deck, and desc
// Pull the data from the toolview.html file
String title = ((Text)toolview.getElementTitle().getFirstChild()).getData();
String deck = ((Text)toolview.getElementDeck().getFirstChild()).getData();
String desc = ((Text)toolview.getElementDesc().getFirstChild()).getData();
template.setTitle(title); // the page title
template.setTextTitle(title); // the element marked "title"
template.setTextDeck(deck); // the element marked "deck"
template.setTextDesc(desc); // the element marked "desc"
// Loop over the tools adding a record for each
for (int i = 0; i < tools.length; i++) {
Tool tool = tools[i];
toolview.setTextToolName(tool.name);
toolview.setTextToolComments(tool.comments);
if (tool.isNewWithin(45)) {
toolview.setTextToolStatus(" (New!) ");
}
else if (tool.isUpdatedWithin(45)) {
toolview.setTextToolStatus(" (Updated!) ");
}
else {
toolview.setTextToolStatus("");
}
HTMLAnchorElement link = toolview.getElementToolLink();
link.setHref(tool.homeURL);
Text linkText = toolview.createTextNode(tool.homeURL);
link.replaceChild(linkText, link.getLastChild());
// importNode() is DOM Level 2
insertionParent.insertBefore(template.importNode(record, true), null);
}
// Remove insertion placeholder
insertionParent.removeChild(insertionPoint);
// Output the document
DOMFormatter formatter = new DOMFormatter(); // can be heavily tweaked
formatter.write(template, out);