}
public DocumentFragment loadTemplateRecurse(
Element template,
Set<String> templatesLoaded) {
DocumentTraversal dt = (DocumentTraversal) templateLibrary;
Set<String> modes = new HashSet<String>();
DocumentFragment fragment = templateLibrary.createDocumentFragment();
String nm = template.getAttribute("name");
String md = template.getAttribute("mode");
String k = nm + "-" + (md == null ? "dexter-nomode" : md);
if(! templatesLoaded.contains(k)) {
templatesLoaded.add(k);
fragment.appendChild(fragment.getOwnerDocument().createTextNode("\n"));
fragment.appendChild(template.cloneNode(true));
fragment.appendChild(fragment.getOwnerDocument().createTextNode("\n"));
// fetch list of referenced modes
NodeIterator ii = dt.createNodeIterator(template,
NodeFilter.FILTER_ACCEPT,
new ModeFilter(), false);
Node oo;
while((oo = ii.nextNode()) != null) {
Element ee = (Element) oo;
modes.add(ee.getAttribute("mode"));
}
for(String mm : modes) {
// get a list of all modes referred to
NodeIterator jj = dt.createNodeIterator(templateLibrary,
NodeFilter.FILTER_ACCEPT,
new ModeTemplateFilter(mm), false);
Node pp;
while((pp = jj.nextNode()) != null) {
fragment.appendChild(
loadTemplateRecurse((Element) pp, templatesLoaded));
}
}
ii = dt.createNodeIterator(template,
NodeFilter.FILTER_ACCEPT,
new CallTemplateFilter(), false);
while((oo = ii.nextNode()) != null) {
Element el = (Element) oo;
String n = el.getAttribute("name");
NodeIterator it = dt.createNodeIterator(templateLibrary,
NodeFilter.FILTER_ACCEPT,
new TemplateFilter(n), false);
Element ee;
while((ee = (Element) it.nextNode()) != null) {
fragment.appendChild(