if (DefaultResultSequence.isAtomicValue(node)) {
return (Element) node.copy(); // atomic values are already properly wrapped
}
// make a copy of the template associated with the given node type:
Element item = (Element) TEMPLATES.get(node.getClass().getName());
if (item == null) // FIXME: also allow Node subclasses
throw new IllegalArgumentException("Unrecognized node type: " + node.getClass());
item = new Element(item);
// add copy of content to wrapper:
if (node instanceof Attribute) {
Attribute attr = (Attribute) node;
item.addAttribute((Attribute) attr.copy());
} else if (node instanceof Document) {
Document doc = (Document) node;
for (int j=0; j < doc.getChildCount(); j++) {
item.appendChild(doc.getChild(j).copy());
}
// } else if (node instanceof Namespace) { // xom >= 1.1 only
// Namespace ns = (Namespace) node;
//// item.addNamespaceDeclaration(ns.getPrefix(), ns.getValue());
// if (ns.getPrefix().length() > 0) {
// item.addAttribute(new Attribute("prefix", ns.getPrefix()));
// }
// item.addAttribute(new Attribute("uri", ns.getValue()));
} else if (node instanceof DocType) {
DocType docType = (DocType) node;
Element e;
e = new Element("rootName");
e.appendChild(docType.getRootElementName());
item.appendChild(e);
if (docType.getPublicID() != null) {
e = new Element("publicID");
e.appendChild(docType.getPublicID());
item.appendChild(e);
}
if (docType.getSystemID() != null) {
e = new Element("systemID");
e.appendChild(docType.getSystemID());
item.appendChild(e);
}
if (docType.getInternalDTDSubset().length() > 0) {
e = new Element("internalDTDSubset");
e.appendChild(docType.getInternalDTDSubset());
item.appendChild(e);
}
} else { // Element, Text, Comment, ProcessingInstruction
item.appendChild(node.copy());
}