1 19 20 package org.netbeans.modules.xml.xdm.diff; 21 22 import java.util.List ; 23 import org.netbeans.modules.xml.xam.dom.ElementIdentity; 24 import org.netbeans.modules.xml.xdm.XDMModel; 25 import org.netbeans.modules.xml.xdm.nodes.Document; 26 import org.netbeans.modules.xml.xdm.nodes.Element; 27 import org.netbeans.modules.xml.xdm.nodes.Node; 28 import org.w3c.dom.NodeList ; 29 30 36 public class XDMTreeDiff { 37 38 private ElementIdentity eID; 39 40 41 public XDMTreeDiff(ElementIdentity eID) { 42 this.eID = eID; 43 } 44 45 public List <Difference> performDiff(Document doc1, Document doc2) { 46 List <Difference> deList = new DiffFinder(eID).findDiff(doc1, doc2); 51 return deList; 52 } 53 54 public List <Difference> performDiff(XDMModel model, Document doc2) { 55 return performDiff(model.getDocument(), doc2); 56 } 57 58 public List <Difference> performDiffAndMutate(XDMModel model, Document doc2) { 59 List <Difference> deList = performDiff(model.getDocument(), doc2); 60 model.mergeDiff(deList); 61 return deList; 62 } 63 64 public static void printDocument(Node node) { 65 String name = node.getNodeName(); 66 if(node instanceof Element && node.getAttributes().getLength() > 0) 67 name+=node.getAttributes().item(0).getNodeValue(); 68 System.out.println("node: "+name+" id:"+node.getId()); 69 NodeList childs = node.getChildNodes(); 70 for(int i=0;i<childs.getLength();i++) 71 printDocument((Node) childs.item(i)); 72 } 73 } 74 | Popular Tags |