1
|
|
/*
|
2
|
|
* JBind
|
3
|
|
*
|
4
|
|
* Copyright (c) by Stefan Wachter. All rights reserved.
|
5
|
|
*
|
6
|
|
* Usage, modification, and redistribution is subject to license terms that are
|
7
|
|
* available at 'http://www.jbind.org'. The JBind license is like the
|
8
|
|
* 'Apache Software License V 1.1'.
|
9
|
|
*/
|
10
|
|
package org.jbind.xml.dom3.core;
|
11
|
|
|
12
|
|
import java.util.Iterator;
|
13
|
|
|
14
|
|
import org.jbind.xml.core.base.ITextContentProvider;
|
15
|
|
import org.jbind.xml.core.data.IAnyTypeData;
|
16
|
|
import org.jbind.xml.dom3.types.IDomDocument;
|
17
|
|
import org.jbind.xml.dom3.types.IDomDocumentType;
|
18
|
|
import org.jbind.xml.dom3.types.IDomElement;
|
19
|
|
import org.jbind.xml.dom3.types.IDomImplementation;
|
20
|
|
import org.jbind.xml.dom3.types.IDomNode;
|
21
|
|
import org.jbind.xml.dom3.types.IDomNodeList;
|
22
|
|
import org.jbind.xml.dom3.types.IDomVisitor;
|
23
|
|
import org.w3c.dom.Attr;
|
24
|
|
import org.w3c.dom.CDATASection;
|
25
|
|
import org.w3c.dom.Comment;
|
26
|
|
import org.w3c.dom.DOMImplementation;
|
27
|
|
import org.w3c.dom.DocumentFragment;
|
28
|
|
import org.w3c.dom.DocumentType;
|
29
|
|
import org.w3c.dom.Element;
|
30
|
|
import org.w3c.dom.Entity;
|
31
|
|
import org.w3c.dom.EntityReference;
|
32
|
|
import org.w3c.dom.NamedNodeMap;
|
33
|
|
import org.w3c.dom.Node;
|
34
|
|
import org.w3c.dom.NodeList;
|
35
|
|
import org.w3c.dom.ProcessingInstruction;
|
36
|
|
import org.w3c.dom.Text;
|
37
|
|
|
38
|
|
//import org.w3c.dom.DOMErrorHandler;
|
39
|
|
|
40
|
|
public class DomDocument extends DomNonAttrOrElm implements IDomDocument {
|
41
|
|
|
42
|
|
/**
|
43
|
|
* <p>EXPERIMENTAL! Based on the <a
|
44
|
|
* href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
|
45
|
|
* Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
|
46
|
|
* <p>
|
47
|
|
* An attribute specifying, as part of the XML declaration, the encoding
|
48
|
|
* of this document. This is <code>null</code> when unspecified.
|
49
|
|
* @since DOM Level 3
|
50
|
|
*/
|
51
|
|
private String myEncoding = null;
|
52
|
|
|
53
|
|
/**
|
54
|
|
* An attribute specifying the actual encoding of this document. This is
|
55
|
|
* <code>null</code> otherwise.
|
56
|
|
* <br> This attribute represents the property [character encoding scheme]
|
57
|
|
* defined in .
|
58
|
|
* @since DOM Level 3
|
59
|
|
*/
|
60
|
|
private String myActualEncoding = null;
|
61
|
|
|
62
|
|
/**
|
63
|
|
* <p>EXPERIMENTAL! Based on the <a
|
64
|
|
* href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
|
65
|
|
* Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
|
66
|
|
* <p>
|
67
|
|
* An attribute specifying whether errors checking is enforced or not.
|
68
|
|
* When set to <code>false</code>, the implementation is free to not
|
69
|
|
* test every possible error case normally defined on DOM operations,
|
70
|
|
* and not raise any <code>DOMException</code>. In case of error, the
|
71
|
|
* behavior is undefined. This attribute is <code>true</code> by
|
72
|
|
* defaults.
|
73
|
|
* @since DOM Level 3
|
74
|
|
*/
|
75
|
|
private boolean myStrictErrorChecking = true;
|
76
|
|
|
77
|
|
/**
|
78
|
|
* <p>EXPERIMENTAL! Based on the <a
|
79
|
|
* href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
|
80
|
|
* Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
|
81
|
|
* <p>
|
82
|
|
* An attribute specifying, as part of the XML declaration, whether this
|
83
|
|
* document is standalone.
|
84
|
|
* @since DOM Level 3
|
85
|
|
*/
|
86
|
|
private boolean myStandalone = false;
|
87
|
|
|
88
|
|
/**
|
89
|
|
* <p>EXPERIMENTAL! Based on the <a
|
90
|
|
* href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010605'>Document
|
91
|
|
* Object Model (DOM) Level 3 Core Working Draft of 5 June 2001.</a>.
|
92
|
|
* <p>
|
93
|
|
* An attribute specifying, as part of the XML declaration, the version
|
94
|
|
* number of this document. This is <code>null</code> when unspecified.
|
95
|
|
* @since DOM Level 3
|
96
|
|
*/
|
97
|
|
private String myVersion = null;
|
98
|
|
|
99
|
|
private IDomImplementation myDomImplementation = null;
|
100
|
|
|
101
|
0
|
public DomDocument(IDomImplementation aDomImplementation, String aNamespaceUri, String aQName, DocumentType aDocumentType) {
|
102
|
0
|
super(null);
|
103
|
0
|
myOwnerDocument = this;
|
104
|
0
|
myDomImplementation = aDomImplementation;
|
105
|
0
|
if (null != aDocumentType) {
|
106
|
0
|
if (null == aDocumentType.getOwnerDocument()) {
|
107
|
0
|
((IDomDocumentType)aDocumentType).setOwnerDocument(this);
|
108
|
|
}
|
109
|
0
|
appendChild(aDocumentType);
|
110
|
|
}
|
111
|
0
|
if (null != aQName) {
|
112
|
0
|
Element documentElement = createElementNS(aNamespaceUri, aQName);
|
113
|
0
|
appendChild(documentElement);
|
114
|
|
}
|
115
|
|
}
|
116
|
|
|
117
|
0
|
protected DomDocument(IDomDocument aDomDocument, boolean aDeep) {
|
118
|
0
|
super(aDomDocument, aDeep);
|
119
|
0
|
myDomImplementation = (IDomImplementation)aDomDocument.getImplementation();
|
120
|
|
}
|
121
|
|
|
122
|
0
|
public String getNodeName() {
|
123
|
0
|
return "#document";
|
124
|
|
}
|
125
|
|
|
126
|
0
|
public short getNodeType() {
|
127
|
0
|
return DOCUMENT_NODE;
|
128
|
|
}
|
129
|
|
|
130
|
0
|
public String getNodeValue() {
|
131
|
0
|
return null;
|
132
|
|
}
|
133
|
|
|
134
|
0
|
public void setNodeValue(String aString) {
|
135
|
|
// The specification says that setting the node value of a document has no effect
|
136
|
|
}
|
137
|
|
|
138
|
0
|
public Node cloneNode(boolean aDeep) {
|
139
|
0
|
return new DomDocument(this, aDeep);
|
140
|
|
}
|
141
|
|
|
142
|
0
|
protected IDomNodeList doCloneChildNodes(IDomNodeList aDomNodeList, boolean aDeep) {
|
143
|
0
|
return new DomNodeList(aDomNodeList, aDeep);
|
144
|
|
}
|
145
|
|
|
146
|
0
|
public DocumentType getDoctype() {
|
147
|
0
|
return (DocumentType)getChildByClass(DocumentType.class);
|
148
|
|
}
|
149
|
|
|
150
|
0
|
public Node adoptNode(Node source) throws DomException {
|
151
|
|
// TODO
|
152
|
|
assert false : "nyi";
|
153
|
0
|
return null;
|
154
|
|
}
|
155
|
|
|
156
|
0
|
public Attr createAttribute(String aName) throws DomException {
|
157
|
0
|
return new DomAttr(this, aName);
|
158
|
|
}
|
159
|
|
|
160
|
0
|
public Attr createAttributeNS(String aNamespaceUri, String aQualifiedName) throws DomException {
|
161
|
0
|
return new DomAttr(this, aNamespaceUri, aQualifiedName);
|
162
|
|
}
|
163
|
|
|
164
|
0
|
public CDATASection createCDATASection(String data) throws DomException {
|
165
|
0
|
return new DomCDataSection(this, data);
|
166
|
|
}
|
167
|
|
|
168
|
0
|
public Comment createComment(String aData) {
|
169
|
0
|
return new DomComment(this, aData);
|
170
|
|
}
|
171
|
|
|
172
|
0
|
public DocumentFragment createDocumentFragment() {
|
173
|
0
|
return new DomDocumentFragment(this);
|
174
|
|
}
|
175
|
|
|
176
|
0
|
public Element createElement(String aTagName) throws DomException {
|
177
|
0
|
return new DomElement(this, aTagName);
|
178
|
|
}
|
179
|
|
|
180
|
0
|
public Element createElementNS(String aNamespaceUri, String aQName) throws DomException {
|
181
|
0
|
return new DomElement(this, aNamespaceUri, aQName);
|
182
|
|
}
|
183
|
|
|
184
|
0
|
public EntityReference createEntityReference(String aName) throws DomException {
|
185
|
0
|
DomEntityReference res = new DomEntityReference(this, aName);
|
186
|
0
|
Entity e = getEntity(aName);
|
187
|
0
|
if (null != e) {
|
188
|
0
|
IDomNodeList l = (IDomNodeList)e.getChildNodes();
|
189
|
0
|
for (Iterator i = l.iterNodes(); i.hasNext(); ) {
|
190
|
0
|
IDomNode node = (IDomNode)i.next();
|
191
|
0
|
res.appendChild(node.cloneNode(true));
|
192
|
|
}
|
193
|
|
}
|
194
|
0
|
return res;
|
195
|
|
}
|
196
|
|
|
197
|
0
|
public ProcessingInstruction createProcessingInstruction(String target, String data) throws DomException {
|
198
|
0
|
return new DomProcessingInstruction(this, target, data);
|
199
|
|
}
|
200
|
|
|
201
|
0
|
public Text createTextNode(String data) {
|
202
|
0
|
return new DomText(this, data);
|
203
|
|
}
|
204
|
|
|
205
|
0
|
public Text createTextNode(ITextContentProvider aProvider) {
|
206
|
0
|
return new DomText(this, aProvider);
|
207
|
|
}
|
208
|
|
|
209
|
0
|
public Element getDocumentElement() {
|
210
|
0
|
return (Element)getChildByClass(Element.class);
|
211
|
|
}
|
212
|
|
|
213
|
0
|
public IAnyTypeData getRootData() {
|
214
|
0
|
IAnyTypeData res = null;
|
215
|
0
|
IDomElement element = (IDomElement)getChildByClass(IDomElement.class);
|
216
|
0
|
if (null != element) {
|
217
|
0
|
res = element.getData();
|
218
|
|
}
|
219
|
0
|
return res;
|
220
|
|
}
|
221
|
|
|
222
|
0
|
public Element getElementById(String elementId) {
|
223
|
|
// TODO
|
224
|
|
assert false : "nyi";
|
225
|
0
|
return null;
|
226
|
|
}
|
227
|
|
|
228
|
0
|
public NodeList getElementsByTagName(String aName) {
|
229
|
0
|
ElementCollector v = new ElementCollector(myOwnerDocument, aName);
|
230
|
0
|
visitChildren(v);
|
231
|
0
|
return v.getElements();
|
232
|
|
}
|
233
|
|
|
234
|
0
|
public NodeList getElementsByTagNameNS(String aNamespaceUri, String aLocalName) {
|
235
|
0
|
ElementCollector v = new ElementCollector(myOwnerDocument, aNamespaceUri, aLocalName);
|
236
|
0
|
visitChildren(v);
|
237
|
0
|
return v.getElements();
|
238
|
|
}
|
239
|
|
|
240
|
0
|
public String getEncoding() {
|
241
|
0
|
return myEncoding;
|
242
|
|
}
|
243
|
|
|
244
|
0
|
public String getActualEncoding() {
|
245
|
0
|
return myActualEncoding;
|
246
|
|
}
|
247
|
|
|
248
|
0
|
public void setActualEncoding(String anEncoding) {
|
249
|
0
|
myActualEncoding = anEncoding;
|
250
|
|
}
|
251
|
|
|
252
|
0
|
public DOMImplementation getImplementation() {
|
253
|
0
|
return myDomImplementation;
|
254
|
|
}
|
255
|
|
|
256
|
0
|
public boolean getStandalone() {
|
257
|
0
|
return myStandalone;
|
258
|
|
}
|
259
|
|
|
260
|
0
|
public boolean getStrictErrorChecking() {
|
261
|
0
|
return myStrictErrorChecking;
|
262
|
|
}
|
263
|
|
|
264
|
0
|
public String getVersion() {
|
265
|
0
|
return myVersion;
|
266
|
|
}
|
267
|
|
|
268
|
0
|
public String getTextContent() {
|
269
|
0
|
return null;
|
270
|
|
}
|
271
|
|
|
272
|
0
|
public Node importNode(Node importedNode, boolean deep) throws DomException {
|
273
|
|
// TODO
|
274
|
|
assert false : "nyi";
|
275
|
0
|
return null;
|
276
|
|
}
|
277
|
|
|
278
|
|
// public DOMErrorHandler getErrorHandler() {
|
279
|
|
// // TODO
|
280
|
|
// assert false : "nyi";
|
281
|
|
// return null;
|
282
|
|
// }
|
283
|
|
//
|
284
|
|
// public void setErrorHandler(DOMErrorHandler aHandler) {
|
285
|
|
// // TODO
|
286
|
|
// assert false : "nyi";
|
287
|
|
// }
|
288
|
|
//
|
289
|
0
|
public String getDocumentURI() {
|
290
|
|
// TODO
|
291
|
|
assert false : "nyi";
|
292
|
0
|
return null;
|
293
|
|
}
|
294
|
|
|
295
|
0
|
public void setDocumentURI(String anUri) {
|
296
|
|
// TODO
|
297
|
|
assert false : "nyi";
|
298
|
|
}
|
299
|
|
|
300
|
0
|
public void normalizeDocument() {
|
301
|
|
// TODO
|
302
|
|
assert false : "nyi";
|
303
|
|
}
|
304
|
|
|
305
|
0
|
public boolean canSetNormalizationFeature(String aFeature, boolean anOnOrOff) {
|
306
|
|
// TODO
|
307
|
|
assert false : "nyi";
|
308
|
0
|
return false;
|
309
|
|
}
|
310
|
|
|
311
|
0
|
public void setNormalizationFeature(String aFeature, boolean anOnOrOff) {
|
312
|
|
// TODO
|
313
|
|
assert false : "nyi";
|
314
|
|
}
|
315
|
|
|
316
|
0
|
public boolean getNormalizationFeature(String aFeature) {
|
317
|
|
// TODO
|
318
|
|
assert false : "nyi";
|
319
|
0
|
return false;
|
320
|
|
}
|
321
|
|
|
322
|
0
|
public Node renameNode(Node aNode, String aNamespaceUri, String aQName) {
|
323
|
|
// TODO
|
324
|
|
assert false : "nyi";
|
325
|
0
|
return null;
|
326
|
|
}
|
327
|
|
|
328
|
0
|
public void setEncoding(String anEncoding) {
|
329
|
0
|
myEncoding = anEncoding;
|
330
|
|
}
|
331
|
|
|
332
|
0
|
public void setStandalone(boolean aStandalone) {
|
333
|
0
|
myStandalone = aStandalone;
|
334
|
|
}
|
335
|
|
|
336
|
0
|
public void setStrictErrorChecking(boolean aStrictErrorChecking) {
|
337
|
0
|
myStrictErrorChecking = aStrictErrorChecking;
|
338
|
|
}
|
339
|
|
|
340
|
0
|
public void setVersion(String aVersion) {
|
341
|
0
|
myVersion = aVersion;
|
342
|
|
}
|
343
|
|
|
344
|
|
//
|
345
|
|
// Additional methods
|
346
|
|
//
|
347
|
|
|
348
|
0
|
public Entity getEntity(String aName) {
|
349
|
0
|
Entity res = null;
|
350
|
0
|
DocumentType t = getDoctype();
|
351
|
0
|
if (null != t) {
|
352
|
0
|
NamedNodeMap m = t.getEntities();
|
353
|
0
|
if (null != m) {
|
354
|
0
|
res = (Entity)m.getNamedItem(aName);
|
355
|
|
}
|
356
|
|
}
|
357
|
0
|
return res;
|
358
|
|
}
|
359
|
|
|
360
|
0
|
protected void doBeforeAccept(IDomVisitor aDomVisitor) {
|
361
|
0
|
aDomVisitor.visitDocumentStart(this);
|
362
|
|
}
|
363
|
0
|
protected void doAfterAccept(IDomVisitor aDomVisitor) {
|
364
|
0
|
aDomVisitor.visitDocumentEnd(this);
|
365
|
|
}
|
366
|
|
}
|
367
|
|
|