1 23 24 package org.enhydra.xml.xmlc.perf; 25 26 import org.w3c.dom.Document ; 27 import org.w3c.dom.Element ; 28 import org.w3c.dom.Node ; 29 import org.w3c.dom.NodeList ; 30 ; 31 32 36 public class TextNodeEditor implements DOMEditor { 37 38 private boolean fHasRun = false; 39 40 public int edit(Document doc) throws Exception { 41 Element e = doc.getDocumentElement(); 42 return edit(e); 43 } 44 45 public int edit(Node node) throws Exception { 46 int cnt = 0; 47 if (node.getNodeType() == Node.TEXT_NODE) { 48 node.setNodeValue("hello"); 49 cnt++; 50 } else { 51 NodeList children = node.getChildNodes(); 52 for (int i=0; i<children.getLength(); i++) { 53 cnt += edit(children.item(i)); 54 } 55 } 56 return cnt; 57 } 58 59 60 public boolean next() { 61 if (fHasRun) { 62 return false; 63 } else { 64 fHasRun = true; 65 return true; 66 } 67 } 68 69 70 71 public void reset() { 72 fHasRun = false; 73 } 74 75 76 public String toString() { 77 return "TextNodeEditor: edits all text nodes in the DOM tree."; 78 } 79 80 } 81 82 83 84 85 86 87 | Popular Tags |