private void applyTagsHelper(FormEntrySession session, PrintWriter out, Node parent, Node node,
Map<String, TagHandler> tagHandlerCache) {
if (tagHandlerCache == null)
tagHandlerCache = new HashMap<String, TagHandler>();
TagHandler handler = null;
// Find the handler for this node
{
String name = node.getNodeName();
if (name != null) {
if (tagHandlerCache.containsKey(name)) {
// we've looked this up before (though it could be null)
handler = tagHandlerCache.get(name);
} else {
handler = HtmlFormEntryUtil.getService().getHandlerByTagName(name);
tagHandlerCache.put(name, handler);
}
}
}
if (handler == null)
handler = this; // do default actions
try {
boolean handleContents = handler.doStartTag(session, out, parent, node);
// Unless the handler told us to skip them, then iterate over any children
if (handleContents) {
if (handler != null && handler instanceof IteratingTagHandler) {
// recurse as many times as the tag wants
IteratingTagHandler iteratingHandler = (IteratingTagHandler) handler;
while (iteratingHandler.shouldRunAgain(session, out, parent, node)) {
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); ++i) {
applyTagsHelper(session, out, node, list.item(i), tagHandlerCache);
}
}
} else { // recurse to contents once
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); ++i) {
applyTagsHelper(session, out, node, list.item(i), tagHandlerCache);
}
}
}
handler.doEndTag(session, out, parent, node);
} catch (BadFormDesignException e) {
out.print("<div class=\"error\">" + handler + " reported an error in the design of the form. Consult your administrator.<br/><pre>");
e.printStackTrace(out);
out.print("</pre></div>");
}