1 7 8 package org.dom4j.dom; 9 10 import org.dom4j.CDATA; 11 import org.dom4j.Element; 12 import org.dom4j.tree.DefaultCDATA; 13 14 import org.w3c.dom.DOMException ; 15 import org.w3c.dom.Document ; 16 import org.w3c.dom.NamedNodeMap ; 17 import org.w3c.dom.NodeList ; 18 19 28 public class DOMCDATA extends DefaultCDATA implements org.w3c.dom.CDATASection { 29 public DOMCDATA(String text) { 30 super(text); 31 } 32 33 public DOMCDATA(Element parent, String text) { 34 super(parent, text); 35 } 36 37 public boolean supports(String feature, String version) { 40 return DOMNodeHelper.supports(this, feature, version); 41 } 42 43 public String getNamespaceURI() { 44 return DOMNodeHelper.getNamespaceURI(this); 45 } 46 47 public String getPrefix() { 48 return DOMNodeHelper.getPrefix(this); 49 } 50 51 public void setPrefix(String prefix) throws DOMException { 52 DOMNodeHelper.setPrefix(this, prefix); 53 } 54 55 public String getLocalName() { 56 return DOMNodeHelper.getLocalName(this); 57 } 58 59 public String getNodeName() { 60 return "#cdata-section"; 61 } 62 63 public String getNodeValue() throws DOMException { 67 return DOMNodeHelper.getNodeValue(this); 68 } 69 70 public void setNodeValue(String nodeValue) throws DOMException { 71 DOMNodeHelper.setNodeValue(this, nodeValue); 72 } 73 74 public org.w3c.dom.Node getParentNode() { 75 return DOMNodeHelper.getParentNode(this); 76 } 77 78 public NodeList getChildNodes() { 79 return DOMNodeHelper.getChildNodes(this); 80 } 81 82 public org.w3c.dom.Node getFirstChild() { 83 return DOMNodeHelper.getFirstChild(this); 84 } 85 86 public org.w3c.dom.Node getLastChild() { 87 return DOMNodeHelper.getLastChild(this); 88 } 89 90 public org.w3c.dom.Node getPreviousSibling() { 91 return DOMNodeHelper.getPreviousSibling(this); 92 } 93 94 public org.w3c.dom.Node getNextSibling() { 95 return DOMNodeHelper.getNextSibling(this); 96 } 97 98 public NamedNodeMap getAttributes() { 99 return null; 100 } 101 102 public Document getOwnerDocument() { 103 return DOMNodeHelper.getOwnerDocument(this); 104 } 105 106 public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, 107 org.w3c.dom.Node refChild) throws DOMException { 108 checkNewChildNode(newChild); 109 110 return DOMNodeHelper.insertBefore(this, newChild, refChild); 111 } 112 113 public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, 114 org.w3c.dom.Node oldChild) throws DOMException { 115 checkNewChildNode(newChild); 116 117 return DOMNodeHelper.replaceChild(this, newChild, oldChild); 118 } 119 120 public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) 121 throws DOMException { 122 return DOMNodeHelper.removeChild(this, oldChild); 123 } 124 125 public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) 126 throws DOMException { 127 checkNewChildNode(newChild); 128 129 return DOMNodeHelper.appendChild(this, newChild); 130 } 131 132 private void checkNewChildNode(org.w3c.dom.Node newChild) 133 throws DOMException { 134 throw new DOMException (DOMException.HIERARCHY_REQUEST_ERR, 135 "CDATASection nodes cannot have children"); 136 } 137 138 public boolean hasChildNodes() { 139 return DOMNodeHelper.hasChildNodes(this); 140 } 141 142 public org.w3c.dom.Node cloneNode(boolean deep) { 143 return DOMNodeHelper.cloneNode(this, deep); 144 } 145 146 public void normalize() { 147 DOMNodeHelper.normalize(this); 148 } 149 150 public boolean isSupported(String feature, String version) { 151 return DOMNodeHelper.isSupported(this, feature, version); 152 } 153 154 public boolean hasAttributes() { 155 return DOMNodeHelper.hasAttributes(this); 156 } 157 158 public String getData() throws DOMException { 161 return DOMNodeHelper.getData(this); 162 } 163 164 public void setData(String data) throws DOMException { 165 DOMNodeHelper.setData(this, data); 166 } 167 168 public int getLength() { 169 return DOMNodeHelper.getLength(this); 170 } 171 172 public String substringData(int offset, int count) throws DOMException { 173 return DOMNodeHelper.substringData(this, offset, count); 174 } 175 176 public void appendData(String arg) throws DOMException { 177 DOMNodeHelper.appendData(this, arg); 178 } 179 180 public void insertData(int offset, String arg) throws DOMException { 181 DOMNodeHelper.insertData(this, offset, arg); 182 } 183 184 public void deleteData(int offset, int count) throws DOMException { 185 DOMNodeHelper.deleteData(this, offset, count); 186 } 187 188 public void replaceData(int offset, int count, String arg) 189 throws DOMException { 190 DOMNodeHelper.replaceData(this, offset, count, arg); 191 } 192 193 public org.w3c.dom.Text splitText(int offset) throws DOMException { 196 if (isReadOnly()) { 197 throw new DOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, 198 "CharacterData node is read only: " + this); 199 } else { 200 String text = getText(); 201 int length = (text != null) ? text.length() : 0; 202 203 if ((offset < 0) || (offset >= length)) { 204 throw new DOMException (DOMException.INDEX_SIZE_ERR, 205 "No text at offset: " + offset); 206 } else { 207 String start = text.substring(0, offset); 208 String rest = text.substring(offset); 209 setText(start); 210 211 Element parent = getParent(); 212 CDATA newText = createCDATA(rest); 213 214 if (parent != null) { 215 parent.add(newText); 216 } 217 218 return DOMNodeHelper.asDOMText(newText); 219 } 220 } 221 } 222 223 protected CDATA createCDATA(String text) { 226 return new DOMCDATA(text); 227 } 228 } 229 230 266 | Popular Tags |