1 28 29 package com.caucho.xml; 30 31 import com.caucho.util.CharBuffer; 32 33 import org.w3c.dom.Document ; 34 import org.w3c.dom.DocumentFragment ; 35 import org.w3c.dom.Node ; 36 37 import java.io.IOException ; 38 39 public class QDocumentFragment extends QNode implements DocumentFragment { 40 protected Document _masterDoc; 41 42 QDocumentFragment() 43 { 44 } 45 46 protected QDocumentFragment(QDocument owner) 47 { 48 super(owner); 49 } 50 51 public short getNodeType() { return DOCUMENT_FRAGMENT_NODE; } 52 53 public Document getMasterDoc() 54 { 55 return _masterDoc; 56 } 57 58 public String getNodeName() { return "#document"; } 59 60 68 Node importNode(QDocument owner, boolean deep) 69 { 70 QDocumentFragment frag = new QDocumentFragment(); 71 frag._owner = owner; 72 73 if (! deep) 74 return frag; 75 76 for (Node node = getFirstChild(); 77 node != null; 78 node = node.getNextSibling()) { 79 frag.appendChild(node.cloneNode(true)); 80 } 81 82 return frag; 83 } 84 85 public String getTextValue() 86 { 87 CharBuffer cb = new CharBuffer(); 88 89 for (QAbstractNode node = _firstChild; node != null; node = node._next) { 90 cb.append(node.getTextValue()); 91 } 92 93 return cb.toString(); 94 } 95 96 void print(XmlPrinter out) throws IOException 97 { 98 out.print("<#fragment>"); 99 for (QAbstractNode node = _firstChild; node != null; node = node._next) { 100 node.print(out); 101 } 102 out.print("</#fragment>"); 103 } 104 105 private Object writeReplace() 106 { 107 return new SerializedXml(this); 108 } 109 110 public String toString() 111 { 112 if (_firstChild == null) 113 return "DocumentFragment[]"; 114 else if (_firstChild == _lastChild) 115 return "DocumentFragment[" + _firstChild.getNodeName() + "]"; 116 else 117 return ("DocumentFragment[" + _firstChild.getNodeName() + 118 " " + _lastChild.getNodeName() + "]"); 119 } 120 } 121 | Popular Tags |