|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| package org.dom4j.dom; |
|
11 |
| |
|
12 |
| import java.util.ArrayList; |
|
13 |
| |
|
14 |
| import org.dom4j.DocumentFactory; |
|
15 |
| import org.dom4j.QName; |
|
16 |
| import org.dom4j.tree.DefaultDocument; |
|
17 |
| import org.w3c.dom.DOMException; |
|
18 |
| import org.w3c.dom.NamedNodeMap; |
|
19 |
| import org.w3c.dom.NodeList; |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| public class DOMDocument extends DefaultDocument implements org.w3c.dom.Document { |
|
28 |
| |
|
29 |
| |
|
30 |
| private static final DOMDocumentFactory DOCUMENT_FACTORY = (DOMDocumentFactory) DOMDocumentFactory.getInstance(); |
|
31 |
| |
|
32 |
| |
|
33 |
10
| public DOMDocument() {
|
|
34 |
10
| init();
|
|
35 |
| } |
|
36 |
| |
|
37 |
4
| public DOMDocument(String name) {
|
|
38 |
4
| super(name);
|
|
39 |
4
| init();
|
|
40 |
| } |
|
41 |
| |
|
42 |
0
| public DOMDocument(DOMElement rootElement) {
|
|
43 |
0
| super(rootElement);
|
|
44 |
0
| init();
|
|
45 |
| } |
|
46 |
| |
|
47 |
0
| public DOMDocument(DOMDocumentType docType) {
|
|
48 |
0
| super(docType);
|
|
49 |
0
| init();
|
|
50 |
| } |
|
51 |
| |
|
52 |
0
| public DOMDocument(DOMElement rootElement, DOMDocumentType docType) {
|
|
53 |
0
| super(rootElement, docType);
|
|
54 |
0
| init();
|
|
55 |
| } |
|
56 |
| |
|
57 |
0
| public DOMDocument(String name, DOMElement rootElement, DOMDocumentType docType) {
|
|
58 |
0
| super(name, rootElement, docType);
|
|
59 |
0
| init();
|
|
60 |
| } |
|
61 |
| |
|
62 |
14
| private void init() {
|
|
63 |
14
| setDocumentFactory(DOCUMENT_FACTORY);
|
|
64 |
| } |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
0
| public boolean supports(String feature, String version) {
|
|
69 |
0
| return DOMNodeHelper.supports(this, feature, version);
|
|
70 |
| } |
|
71 |
| |
|
72 |
0
| public String getNamespaceURI() {
|
|
73 |
0
| return DOMNodeHelper.getNamespaceURI(this);
|
|
74 |
| } |
|
75 |
| |
|
76 |
0
| public String getPrefix() {
|
|
77 |
0
| return DOMNodeHelper.getPrefix(this);
|
|
78 |
| } |
|
79 |
| |
|
80 |
0
| public void setPrefix(String prefix) throws DOMException {
|
|
81 |
0
| DOMNodeHelper.setPrefix(this, prefix);
|
|
82 |
| } |
|
83 |
| |
|
84 |
0
| public String getLocalName() {
|
|
85 |
0
| return DOMNodeHelper.getLocalName(this);
|
|
86 |
| } |
|
87 |
| |
|
88 |
0
| public String getNodeName() {
|
|
89 |
0
| return "#document";
|
|
90 |
| } |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
0
| public String getNodeValue() throws DOMException {
|
|
99 |
0
| return null;
|
|
100 |
| } |
|
101 |
| |
|
102 |
0
| public void setNodeValue(String nodeValue) throws DOMException {
|
|
103 |
| } |
|
104 |
| |
|
105 |
| |
|
106 |
0
| public org.w3c.dom.Node getParentNode() {
|
|
107 |
0
| return DOMNodeHelper.getParentNode(this);
|
|
108 |
| } |
|
109 |
| |
|
110 |
0
| public NodeList getChildNodes() {
|
|
111 |
0
| return DOMNodeHelper.createNodeList( content() );
|
|
112 |
| } |
|
113 |
| |
|
114 |
0
| public org.w3c.dom.Node getFirstChild() {
|
|
115 |
0
| return DOMNodeHelper.asDOMNode( node(0) );
|
|
116 |
| } |
|
117 |
| |
|
118 |
0
| public org.w3c.dom.Node getLastChild() {
|
|
119 |
0
| return DOMNodeHelper.asDOMNode( node( nodeCount() - 1 ) );
|
|
120 |
| } |
|
121 |
| |
|
122 |
0
| public org.w3c.dom.Node getPreviousSibling() {
|
|
123 |
0
| return DOMNodeHelper.getPreviousSibling(this);
|
|
124 |
| } |
|
125 |
| |
|
126 |
0
| public org.w3c.dom.Node getNextSibling() {
|
|
127 |
0
| return DOMNodeHelper.getNextSibling(this);
|
|
128 |
| } |
|
129 |
| |
|
130 |
0
| public NamedNodeMap getAttributes() {
|
|
131 |
0
| return null;
|
|
132 |
| } |
|
133 |
| |
|
134 |
0
| public org.w3c.dom.Document getOwnerDocument() {
|
|
135 |
0
| return null;
|
|
136 |
| } |
|
137 |
| |
|
138 |
0
| public org.w3c.dom.Node insertBefore(
|
|
139 |
| org.w3c.dom.Node newChild, |
|
140 |
| org.w3c.dom.Node refChild |
|
141 |
| ) throws DOMException { |
|
142 |
0
| checkNewChildNode(newChild);
|
|
143 |
0
| return DOMNodeHelper.insertBefore(this, newChild, refChild);
|
|
144 |
| } |
|
145 |
| |
|
146 |
0
| public org.w3c.dom.Node replaceChild(
|
|
147 |
| org.w3c.dom.Node newChild, |
|
148 |
| org.w3c.dom.Node oldChild |
|
149 |
| ) throws DOMException { |
|
150 |
0
| checkNewChildNode(newChild);
|
|
151 |
0
| return DOMNodeHelper.replaceChild(this, newChild, oldChild);
|
|
152 |
| } |
|
153 |
| |
|
154 |
0
| public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) throws DOMException {
|
|
155 |
0
| return DOMNodeHelper.removeChild(this, oldChild);
|
|
156 |
| } |
|
157 |
| |
|
158 |
8
| public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild) throws DOMException {
|
|
159 |
8
| checkNewChildNode(newChild);
|
|
160 |
8
| return DOMNodeHelper.appendChild(this, newChild);
|
|
161 |
| } |
|
162 |
| |
|
163 |
8
| private void checkNewChildNode(org.w3c.dom.Node newChild) throws DOMException {
|
|
164 |
8
| final int nodeType = newChild.getNodeType();
|
|
165 |
8
| if (!(nodeType == org.w3c.dom.Node.ELEMENT_NODE ||
|
|
166 |
| nodeType == org.w3c.dom.Node.COMMENT_NODE || |
|
167 |
| nodeType == org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE || |
|
168 |
| nodeType == org.w3c.dom.Node.DOCUMENT_TYPE_NODE)) { |
|
169 |
0
| throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
|
|
170 |
| "Specified node cannot be a child of document"); |
|
171 |
| } |
|
172 |
| } |
|
173 |
| |
|
174 |
| |
|
175 |
0
| public boolean hasChildNodes() {
|
|
176 |
0
| return nodeCount() > 0;
|
|
177 |
| } |
|
178 |
| |
|
179 |
0
| public org.w3c.dom.Node cloneNode(boolean deep) {
|
|
180 |
0
| return DOMNodeHelper.cloneNode(this, deep);
|
|
181 |
| } |
|
182 |
| |
|
183 |
0
| public boolean isSupported(String feature, String version) {
|
|
184 |
0
| return DOMNodeHelper.isSupported(this, feature, version);
|
|
185 |
| } |
|
186 |
| |
|
187 |
0
| public boolean hasAttributes() {
|
|
188 |
0
| return DOMNodeHelper.hasAttributes(this);
|
|
189 |
| } |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
0
| public NodeList getElementsByTagName(String name) {
|
|
195 |
0
| ArrayList list = new ArrayList();
|
|
196 |
0
| DOMNodeHelper.appendElementsByTagName( list, this, name );
|
|
197 |
0
| return DOMNodeHelper.createNodeList( list );
|
|
198 |
| } |
|
199 |
| |
|
200 |
0
| public NodeList getElementsByTagNameNS(
|
|
201 |
| String namespaceURI, String localName |
|
202 |
| ) { |
|
203 |
0
| ArrayList list = new ArrayList();
|
|
204 |
0
| DOMNodeHelper.appendElementsByTagNameNS(list, this, namespaceURI, localName );
|
|
205 |
0
| return DOMNodeHelper.createNodeList( list );
|
|
206 |
| } |
|
207 |
| |
|
208 |
| |
|
209 |
0
| public org.w3c.dom.DocumentType getDoctype() {
|
|
210 |
0
| return DOMNodeHelper.asDOMDocumentType( getDocType() );
|
|
211 |
| } |
|
212 |
| |
|
213 |
0
| public org.w3c.dom.DOMImplementation getImplementation() {
|
|
214 |
0
| if (getDocumentFactory() instanceof org.w3c.dom.DOMImplementation) {
|
|
215 |
0
| return (org.w3c.dom.DOMImplementation) getDocumentFactory();
|
|
216 |
| } |
|
217 |
| else { |
|
218 |
0
| return DOCUMENT_FACTORY;
|
|
219 |
| } |
|
220 |
| |
|
221 |
| } |
|
222 |
| |
|
223 |
6
| public org.w3c.dom.Element getDocumentElement() {
|
|
224 |
6
| return DOMNodeHelper.asDOMElement( getRootElement() );
|
|
225 |
| } |
|
226 |
| |
|
227 |
14
| public org.w3c.dom.Element createElement(String tagName) throws DOMException {
|
|
228 |
14
| return (org.w3c.dom.Element) getDocumentFactory().createElement(tagName);
|
|
229 |
| } |
|
230 |
| |
|
231 |
0
| public org.w3c.dom.DocumentFragment createDocumentFragment() {
|
|
232 |
0
| DOMNodeHelper.notSupported();
|
|
233 |
0
| return null;
|
|
234 |
| } |
|
235 |
| |
|
236 |
28
| public org.w3c.dom.Text createTextNode(String data) {
|
|
237 |
28
| return (org.w3c.dom.Text) getDocumentFactory().createText(data);
|
|
238 |
| } |
|
239 |
| |
|
240 |
0
| public org.w3c.dom.Comment createComment(String data) {
|
|
241 |
0
| return (org.w3c.dom.Comment) getDocumentFactory().createComment(data);
|
|
242 |
| } |
|
243 |
| |
|
244 |
0
| public org.w3c.dom.CDATASection createCDATASection(String data) throws DOMException {
|
|
245 |
0
| return (org.w3c.dom.CDATASection) getDocumentFactory().createCDATA(data);
|
|
246 |
| } |
|
247 |
| |
|
248 |
0
| public org.w3c.dom.ProcessingInstruction createProcessingInstruction(
|
|
249 |
| String target, String data |
|
250 |
| ) throws DOMException { |
|
251 |
0
| return (org.w3c.dom.ProcessingInstruction) getDocumentFactory().createProcessingInstruction(target, data);
|
|
252 |
| } |
|
253 |
| |
|
254 |
0
| public org.w3c.dom.Attr createAttribute(String name) throws DOMException {
|
|
255 |
0
| QName qname = getDocumentFactory().createQName(name);
|
|
256 |
0
| return (org.w3c.dom.Attr) getDocumentFactory().createAttribute(null, qname, "");
|
|
257 |
| } |
|
258 |
| |
|
259 |
0
| public org.w3c.dom.EntityReference createEntityReference(String name) throws DOMException {
|
|
260 |
0
| return (org.w3c.dom.EntityReference) ((DOMDocumentFactory) getDocumentFactory()).createEntity(name);
|
|
261 |
| } |
|
262 |
| |
|
263 |
0
| public org.w3c.dom.Node importNode(
|
|
264 |
| org.w3c.dom.Node importedNode, boolean deep |
|
265 |
| ) throws DOMException { |
|
266 |
0
| DOMNodeHelper.notSupported();
|
|
267 |
0
| return null;
|
|
268 |
| } |
|
269 |
| |
|
270 |
20
| public org.w3c.dom.Element createElementNS(
|
|
271 |
| String namespaceURI, String qualifiedName |
|
272 |
| ) throws DOMException { |
|
273 |
20
| QName qname = getDocumentFactory().createQName( qualifiedName, namespaceURI );
|
|
274 |
20
| return (org.w3c.dom.Element) getDocumentFactory().createElement(qname);
|
|
275 |
| } |
|
276 |
| |
|
277 |
0
| public org.w3c.dom.Attr createAttributeNS(
|
|
278 |
| String namespaceURI, String qualifiedName |
|
279 |
| ) throws DOMException { |
|
280 |
0
| QName qname = getDocumentFactory().createQName( qualifiedName, namespaceURI );
|
|
281 |
0
| return (org.w3c.dom.Attr) getDocumentFactory().createAttribute(null, qname, null);
|
|
282 |
| } |
|
283 |
| |
|
284 |
| |
|
285 |
0
| public org.w3c.dom.Element getElementById(String elementId) {
|
|
286 |
0
| return DOMNodeHelper.asDOMElement( elementByID( elementId ) );
|
|
287 |
| } |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
112
| protected DocumentFactory getDocumentFactory() {
|
|
294 |
112
| if (super.getDocumentFactory() == null) {
|
|
295 |
0
| return DOCUMENT_FACTORY;
|
|
296 |
| } |
|
297 |
| else { |
|
298 |
112
| return super.getDocumentFactory();
|
|
299 |
| } |
|
300 |
| } |
|
301 |
| } |
|
302 |
| |
|
303 |
| |
|
304 |
| |
|
305 |
| |
|
306 |
| |
|
307 |
| |
|
308 |
| |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
| |
|
313 |
| |
|
314 |
| |
|
315 |
| |
|
316 |
| |
|
317 |
| |
|
318 |
| |
|
319 |
| |
|
320 |
| |
|
321 |
| |
|
322 |
| |
|
323 |
| |
|
324 |
| |
|
325 |
| |
|
326 |
| |
|
327 |
| |
|
328 |
| |
|
329 |
| |
|
330 |
| |
|
331 |
| |
|
332 |
| |
|
333 |
| |
|
334 |
| |
|
335 |
| |
|
336 |
| |
|
337 |
| |
|
338 |
| |
|
339 |
| |
|
340 |
| |
|
341 |
| |
|
342 |
| |
|
343 |
| |
|
344 |
| |
|
345 |
| |
|
346 |
| |
|
347 |
| |
|
348 |
| |
|
349 |
| |