}
if (replaceNode != null) {
if (overwrite) {
if (parent.getNodeType() == Node.DOCUMENT_NODE) {
// replacing of the document element is not allowed
DOMParser parser = (DOMParser)this.manager.lookup(DOMParser.ROLE);
try {
resource = parser.createDocument();
} finally {
this.manager.release( parser );
}
resource.appendChild(resource.importNode(importNode, true));
parent = resource;
replaceNode = resource.importNode(replaceNode, true);
} else {
parent.replaceChild(importNode, replaceNode);
}
message += ", replacing: " + replacePath;
if (reinsertPath != null) {
Node insertAt = DOMUtil.getSingleNode(parent, reinsertPath, this.xpathProcessor);
if (insertAt != null) {
while (replaceNode.hasChildNodes()) {
insertAt.appendChild(replaceNode.getFirstChild());
}
} else { // reinsert point null
message = "replace failed, could not find your reinsert path: " + reinsertPath;
resource = null;
}
}
} else { // overwrite was false
message = "replace failed, no overwrite allowed.";
resource = null;
}
} else { // specified replaceNode was not found
parent.appendChild(importNode);
}
} catch (javax.xml.transform.TransformerException sax) {
throw new ProcessingException("TransformerException: " + sax, sax);
}
} else { // no replace path, just do an insert at end
parent.appendChild(importNode);
}
} else if (create) {
DOMParser parser = (DOMParser)this.manager.lookup(DOMParser.ROLE);
try {
resource = parser.createDocument();
} finally {
this.manager.release( parser );
}
// import the fragment
Node importNode = resource.importNode(fragment, true);