Ejemplo n.º 1
0
 private Node resolve(XmlUtils xml, String xpath) throws Exception {
   Node parent = xml.getSingleNode(xpath);
   if (parent == null) {
     log.trace("Failed to resolve " + xpath + ", creating node");
     try {
       // This can be quite an obscure stack trace.
       parent = xml.createNode(xpath);
     } catch (Exception e) {
       throw new Exception("Failed to create node [" + xpath + "]", e);
     }
   }
   return parent;
 }
Ejemplo n.º 2
0
 @Override
 public Document merge(Document original, Document newDoc) throws Exception {
   if (getXpathToParentNode() == null) {
     throw new Exception("No parent node configured");
   }
   Document resultDoc = original;
   XmlUtils xml = create(resultDoc);
   Node parent = resolve(xml, getXpathToParentNode());
   if (parent.getOwnerDocument() == null) {
     throw new Exception("Invalid xpath-to-parent-node [" + getXpathToParentNode() + "]");
   }
   xml.appendNode(newDoc.getDocumentElement(), parent);
   return resultDoc;
 }