~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to xml/xdm/src/org/netbeans/modules/xml/xdm/nodes/Document.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.xml.xdm.nodes;
 
43
 
 
44
import java.lang.ref.SoftReference;
 
45
import java.util.Map;
 
46
import javax.xml.XMLConstants;
 
47
import org.netbeans.modules.xml.xdm.visitor.FindNamespaceVisitor;
 
48
import org.netbeans.modules.xml.xdm.visitor.XMLNodeVisitor;
 
49
import org.w3c.dom.DOMException;
 
50
import org.w3c.dom.NodeList;
 
51
 
 
52
/**
 
53
 *
 
54
 * @author Ajit
 
55
 */
 
56
public class Document extends NodeImpl implements Node, org.w3c.dom.Document {
 
57
    
 
58
    /** Creates a new instance of Document */
 
59
    Document() {
 
60
        super();
 
61
        resetNamespaceCache();
 
62
    }
 
63
    
 
64
    public Document clone(boolean cloneContent, boolean cloneAttributes, boolean cloneChildren) {
 
65
        Document ret = (Document) super.clone(cloneContent, cloneAttributes, cloneChildren);
 
66
        ret.resetNamespaceCache();
 
67
        return ret;
 
68
    }
 
69
    
 
70
    void resetNamespaceCache() {
 
71
        fnv = null;
 
72
    }
 
73
    
 
74
    public short getNodeType() {
 
75
        return Node.DOCUMENT_NODE;
 
76
    }
 
77
 
 
78
    public String getNodeName() {
 
79
        return "#document"; //NOI18N
 
80
    }
 
81
 
 
82
        public void accept(XMLNodeVisitor visitor) {
 
83
                visitor.visit(this);
 
84
        }
 
85
 
 
86
    /**
 
87
     *  Attempts to adopt a node from another document to this document. If 
 
88
     * supported, it changes the <code>ownerDocument</code> of the source 
 
89
     * node, its children, as well as the attached attribute nodes if there 
 
90
     * are any. If the source node has a parent it is first removed from the 
 
91
     * child list of its parent. This effectively allows moving a subtree 
 
92
     * from one document to another (unlike <code>importNode()</code> which 
 
93
     * create a copy of the source node instead of moving it). When it 
 
94
     * fails, applications should use <code>Document.importNode()</code> 
 
95
     * instead. Note that if the adopted node is already part of this 
 
96
     * document (i.e. the source and target document are the same), this 
 
97
     * method still has the effect of removing the source node from the 
 
98
     * child list of its parent, if any. The following list describes the 
 
99
     * specifics for each type of node. 
 
100
     * <dl>
 
101
     * <dt>ATTRIBUTE_NODE</dt>
 
102
     * <dd>The 
 
103
     * <code>ownerElement</code> attribute is set to <code>null</code> and 
 
104
     * the <code>specified</code> flag is set to <code>true</code> on the 
 
105
     * adopted <code>Attr</code>. The descendants of the source 
 
106
     * <code>Attr</code> are recursively adopted.</dd>
 
107
     * <dt>DOCUMENT_FRAGMENT_NODE</dt>
 
108
     * <dd>The 
 
109
     * descendants of the source node are recursively adopted.</dd>
 
110
     * <dt>DOCUMENT_NODE</dt>
 
111
     * <dd>
 
112
     * <code>Document</code> nodes cannot be adopted.</dd>
 
113
     * <dt>DOCUMENT_TYPE_NODE</dt>
 
114
     * <dd>
 
115
     * <code>DocumentType</code> nodes cannot be adopted.</dd>
 
116
     * <dt>ELEMENT_NODE</dt>
 
117
     * <dd><em>Specified</em> attribute nodes of the source element are adopted. Default attributes 
 
118
     * are discarded, though if the document being adopted into defines 
 
119
     * default attributes for this element name, those are assigned. The 
 
120
     * descendants of the source element are recursively adopted.</dd>
 
121
     * <dt>ENTITY_NODE</dt>
 
122
     * <dd>
 
123
     * <code>Entity</code> nodes cannot be adopted.</dd>
 
124
     * <dt>ENTITY_REFERENCE_NODE</dt>
 
125
     * <dd>Only 
 
126
     * the <code>EntityReference</code> node itself is adopted, the 
 
127
     * descendants are discarded, since the source and destination documents 
 
128
     * might have defined the entity differently. If the document being 
 
129
     * imported into provides a definition for this entity name, its value 
 
130
     * is assigned.</dd>
 
131
     * <dt>NOTATION_NODE</dt>
 
132
     * <dd><code>Notation</code> nodes cannot be 
 
133
     * adopted.</dd>
 
134
     * <dt>PROCESSING_INSTRUCTION_NODE, TEXT_NODE, CDATA_SECTION_NODE, 
 
135
     * COMMENT_NODE</dt>
 
136
     * <dd>These nodes can all be adopted. No specifics.</dd>
 
137
     * </dl> 
 
138
     * <p ><b>Note:</b>  Since it does not create new nodes unlike the 
 
139
     * <code>Document.importNode()</code> method, this method does not raise 
 
140
     * an <code>INVALID_CHARACTER_ERR</code> exception, and applications 
 
141
     * should use the <code>Document.normalizeDocument()</code> method to 
 
142
     * check if an imported name is not an XML name according to the XML 
 
143
     * version in use. 
 
144
     * @param source The node to move into this document.
 
145
     * @return The adopted node, or <code>null</code> if this operation 
 
146
     *   fails, such as when the source node comes from a different 
 
147
     *   implementation.
 
148
     * @exception DOMException
 
149
     *   NOT_SUPPORTED_ERR: Raised if the source node is of type 
 
150
     *   <code>DOCUMENT</code>, <code>DOCUMENT_TYPE</code>.
 
151
     *   <br>NO_MODIFICATION_ALLOWED_ERR: Raised when the source node is 
 
152
     *   readonly.
 
153
     * @since DOM Level 3
 
154
     */
 
155
    public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) {
 
156
        //TODO Implement later
 
157
        return null;
 
158
    }
 
159
 
 
160
    /**
 
161
     * Imports a node from another document to this document, without altering 
 
162
     * or removing the source node from the original document; this method 
 
163
     * creates a new copy of the source node. The returned node has no 
 
164
     * parent; (<code>parentNode</code> is <code>null</code>).
 
165
     * <br>For all nodes, importing a node creates a node object owned by the 
 
166
     * importing document, with attribute values identical to the source 
 
167
     * node's <code>nodeName</code> and <code>nodeType</code>, plus the 
 
168
     * attributes related to namespaces (<code>prefix</code>, 
 
169
     * <code>localName</code>, and <code>namespaceURI</code>). As in the 
 
170
     * <code>cloneNode</code> operation, the source node is not altered. 
 
171
     * User data associated to the imported node is not carried over. 
 
172
     * However, if any <code>UserDataHandlers</code> has been specified 
 
173
     * along with the associated data these handlers will be called with the 
 
174
     * appropriate parameters before this method returns.
 
175
     * <br>Additional information is copied as appropriate to the 
 
176
     * <code>nodeType</code>, attempting to mirror the behavior expected if 
 
177
     * a fragment of XML or HTML source was copied from one document to 
 
178
     * another, recognizing that the two documents may have different DTDs 
 
179
     * in the XML case. The following list describes the specifics for each 
 
180
     * type of node. 
 
181
     * <dl>
 
182
     * <dt>ATTRIBUTE_NODE</dt>
 
183
     * <dd>The <code>ownerElement</code> attribute 
 
184
     * is set to <code>null</code> and the <code>specified</code> flag is 
 
185
     * set to <code>true</code> on the generated <code>Attr</code>. The 
 
186
     * descendants of the source <code>Attr</code> are recursively imported 
 
187
     * and the resulting nodes reassembled to form the corresponding subtree.
 
188
     * Note that the <code>deep</code> parameter has no effect on 
 
189
     * <code>Attr</code> nodes; they always carry their children with them 
 
190
     * when imported.</dd>
 
191
     * <dt>DOCUMENT_FRAGMENT_NODE</dt>
 
192
     * <dd>If the <code>deep</code> option 
 
193
     * was set to <code>true</code>, the descendants of the source 
 
194
     * <code>DocumentFragment</code> are recursively imported and the 
 
195
     * resulting nodes reassembled under the imported 
 
196
     * <code>DocumentFragment</code> to form the corresponding subtree. 
 
197
     * Otherwise, this simply generates an empty 
 
198
     * <code>DocumentFragment</code>.</dd>
 
199
     * <dt>DOCUMENT_NODE</dt>
 
200
     * <dd><code>Document</code> 
 
201
     * nodes cannot be imported.</dd>
 
202
     * <dt>DOCUMENT_TYPE_NODE</dt>
 
203
     * <dd><code>DocumentType</code> 
 
204
     * nodes cannot be imported.</dd>
 
205
     * <dt>ELEMENT_NODE</dt>
 
206
     * <dd><em>Specified</em> attribute nodes of the source element are imported, and the generated 
 
207
     * <code>Attr</code> nodes are attached to the generated 
 
208
     * <code>Element</code>. Default attributes are <em>not</em> copied, though if the document being imported into defines default 
 
209
     * attributes for this element name, those are assigned. If the 
 
210
     * <code>importNode</code> <code>deep</code> parameter was set to 
 
211
     * <code>true</code>, the descendants of the source element are 
 
212
     * recursively imported and the resulting nodes reassembled to form the 
 
213
     * corresponding subtree.</dd>
 
214
     * <dt>ENTITY_NODE</dt>
 
215
     * <dd><code>Entity</code> nodes can be 
 
216
     * imported, however in the current release of the DOM the 
 
217
     * <code>DocumentType</code> is readonly. Ability to add these imported 
 
218
     * nodes to a <code>DocumentType</code> will be considered for addition 
 
219
     * to a future release of the DOM.On import, the <code>publicId</code>, 
 
220
     * <code>systemId</code>, and <code>notationName</code> attributes are 
 
221
     * copied. If a <code>deep</code> import is requested, the descendants 
 
222
     * of the the source <code>Entity</code> are recursively imported and 
 
223
     * the resulting nodes reassembled to form the corresponding subtree.</dd>
 
224
     * <dt>
 
225
     * ENTITY_REFERENCE_NODE</dt>
 
226
     * <dd>Only the <code>EntityReference</code> itself is 
 
227
     * copied, even if a <code>deep</code> import is requested, since the 
 
228
     * source and destination documents might have defined the entity 
 
229
     * differently. If the document being imported into provides a 
 
230
     * definition for this entity name, its value is assigned.</dd>
 
231
     * <dt>NOTATION_NODE</dt>
 
232
     * <dd>
 
233
     * <code>Notation</code> nodes can be imported, however in the current 
 
234
     * release of the DOM the <code>DocumentType</code> is readonly. Ability 
 
235
     * to add these imported nodes to a <code>DocumentType</code> will be 
 
236
     * considered for addition to a future release of the DOM.On import, the 
 
237
     * <code>publicId</code> and <code>systemId</code> attributes are copied.
 
238
     * Note that the <code>deep</code> parameter has no effect on this type 
 
239
     * of nodes since they cannot have any children.</dd>
 
240
     * <dt>
 
241
     * PROCESSING_INSTRUCTION_NODE</dt>
 
242
     * <dd>The imported node copies its 
 
243
     * <code>target</code> and <code>data</code> values from those of the 
 
244
     * source node.Note that the <code>deep</code> parameter has no effect 
 
245
     * on this type of nodes since they cannot have any children.</dd>
 
246
     * <dt>TEXT_NODE, 
 
247
     * CDATA_SECTION_NODE, COMMENT_NODE</dt>
 
248
     * <dd>These three types of nodes inheriting 
 
249
     * from <code>CharacterData</code> copy their <code>data</code> and 
 
250
     * <code>length</code> attributes from those of the source node.Note 
 
251
     * that the <code>deep</code> parameter has no effect on these types of 
 
252
     * nodes since they cannot have any children.</dd>
 
253
     * </dl> 
 
254
     * @param importedNode The node to import.
 
255
     * @param deep If <code>true</code>, recursively import the subtree under 
 
256
     *   the specified node; if <code>false</code>, import only the node 
 
257
     *   itself, as explained above. This has no effect on nodes that cannot 
 
258
     *   have any children, and on <code>Attr</code>, and 
 
259
     *   <code>EntityReference</code> nodes.
 
260
     * @return The imported node that belongs to this <code>Document</code>.
 
261
     * @exception DOMException
 
262
     *   NOT_SUPPORTED_ERR: Raised if the type of node being imported is not 
 
263
     *   supported.
 
264
     *   <br>INVALID_CHARACTER_ERR: Raised if one of the imported names is not 
 
265
     *   an XML name according to the XML version in use specified in the 
 
266
     *   <code>Document.xmlVersion</code> attribute. This may happen when 
 
267
     *   importing an XML 1.1 [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>] element 
 
268
     *   into an XML 1.0 document, for instance.
 
269
     * @since DOM Level 2
 
270
     */
 
271
    public org.w3c.dom.Node importNode(org.w3c.dom.Node importedNode, boolean deep) {
 
272
        //TODO Implement later
 
273
        return null;
 
274
    }
 
275
 
 
276
    /**
 
277
     * Rename an existing node of type <code>ELEMENT_NODE</code> or 
 
278
     * <code>ATTRIBUTE_NODE</code>.
 
279
     * <br>When possible this simply changes the name of the given node, 
 
280
     * otherwise this creates a new node with the specified name and 
 
281
     * replaces the existing node with the new node as described below.
 
282
     * <br>If simply changing the name of the given node is not possible, the 
 
283
     * following operations are performed: a new node is created, any 
 
284
     * registered event listener is registered on the new node, any user 
 
285
     * data attached to the old node is removed from that node, the old node 
 
286
     * is removed from its parent if it has one, the children are moved to 
 
287
     * the new node, if the renamed node is an <code>Element</code> its 
 
288
     * attributes are moved to the new node, the new node is inserted at the 
 
289
     * position the old node used to have in its parent's child nodes list 
 
290
     * if it has one, the user data that was attached to the old node is 
 
291
     * attached to the new node.
 
292
     * <br>When the node being renamed is an <code>Element</code> only the 
 
293
     * specified attributes are moved, default attributes originated from 
 
294
     * the DTD are updated according to the new element name. In addition, 
 
295
     * the implementation may update default attributes from other schemas. 
 
296
     * Applications should use <code>Document.normalizeDocument()</code> to 
 
297
     * guarantee these attributes are up-to-date.
 
298
     * <br>When the node being renamed is an <code>Attr</code> that is 
 
299
     * attached to an <code>Element</code>, the node is first removed from 
 
300
     * the <code>Element</code> attributes map. Then, once renamed, either 
 
301
     * by modifying the existing node or creating a new one as described 
 
302
     * above, it is put back.
 
303
     * <br>In addition,
 
304
     * <ul>
 
305
     * <li> a user data event <code>NODE_RENAMED</code> is fired, 
 
306
     * </li>
 
307
     * <li> 
 
308
     * when the implementation supports the feature "MutationNameEvents", 
 
309
     * each mutation operation involved in this method fires the appropriate 
 
310
     * event, and in the end the event {
 
311
     * <code>http://www.w3.org/2001/xml-events</code>, 
 
312
     * <code>DOMElementNameChanged</code>} or {
 
313
     * <code>http://www.w3.org/2001/xml-events</code>, 
 
314
     * <code>DOMAttributeNameChanged</code>} is fired. 
 
315
     * </li>
 
316
     * </ul>
 
317
     * @param n The node to rename.
 
318
     * @param namespaceURI The new namespace URI.
 
319
     * @param qualifiedName The new qualified name.
 
320
     * @return The renamed node. This is either the specified node or the new 
 
321
     *   node that was created to replace the specified node.
 
322
     * @exception DOMException
 
323
     *   NOT_SUPPORTED_ERR: Raised when the type of the specified node is 
 
324
     *   neither <code>ELEMENT_NODE</code> nor <code>ATTRIBUTE_NODE</code>, 
 
325
     *   or if the implementation does not support the renaming of the 
 
326
     *   document element.
 
327
     *   <br>INVALID_CHARACTER_ERR: Raised if the new qualified name is not an 
 
328
     *   XML name according to the XML version in use specified in the 
 
329
     *   <code>Document.xmlVersion</code> attribute.
 
330
     *   <br>WRONG_DOCUMENT_ERR: Raised when the specified node was created 
 
331
     *   from a different document than this document.
 
332
     *   <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a 
 
333
     *   malformed qualified name, if the <code>qualifiedName</code> has a 
 
334
     *   prefix and the <code>namespaceURI</code> is <code>null</code>, or 
 
335
     *   if the <code>qualifiedName</code> has a prefix that is "xml" and 
 
336
     *   the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
 
337
     *   http://www.w3.org/XML/1998/namespace</a>" [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
 
338
     *   . Also raised, when the node being renamed is an attribute, if the 
 
339
     *   <code>qualifiedName</code>, or its prefix, is XMLNS and the 
 
340
     *   <code>namespaceURI</code> is different from "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>".
 
341
     * @since DOM Level 3
 
342
     */
 
343
    public org.w3c.dom.Node renameNode(org.w3c.dom.Node n, String namespaceURI, String qualifiedName) {
 
344
        //TODO Implement later
 
345
        return null;
 
346
    }
 
347
 
 
348
    /**
 
349
     * Creates a <code>Text</code> node given the specified string.
 
350
     * @param data The data for the node.
 
351
     * @return The new <code>Text</code> object.
 
352
     */
 
353
    public org.w3c.dom.Text createTextNode(String data) {
 
354
        return new Text(data);
 
355
    }
 
356
 
 
357
    /**
 
358
     * Creates an <code>EntityReference</code> object. In addition, if the 
 
359
     * referenced entity is known, the child list of the 
 
360
     * <code>EntityReference</code> node is made the same as that of the 
 
361
     * corresponding <code>Entity</code> node.
 
362
     * <p ><b>Note:</b> If any descendant of the <code>Entity</code> node has 
 
363
     * an unbound namespace prefix, the corresponding descendant of the 
 
364
     * created <code>EntityReference</code> node is also unbound; (its 
 
365
     * <code>namespaceURI</code> is <code>null</code>). The DOM Level 2 and 
 
366
     * 3 do not support any mechanism to resolve namespace prefixes in this 
 
367
     * case.
 
368
     * @param name The name of the entity to reference.Unlike 
 
369
     *   <code>Document.createElementNS</code> or 
 
370
     *   <code>Document.createAttributeNS</code>, no namespace well-formed 
 
371
     *   checking is done on the entity name. Applications should invoke 
 
372
     *   <code>Document.normalizeDocument()</code> with the parameter "
 
373
     *   namespaces" set to <code>true</code> in order to ensure that the 
 
374
     *   entity name is namespace well-formed. 
 
375
     * @return The new <code>EntityReference</code> object.
 
376
     * @exception DOMException
 
377
     *   INVALID_CHARACTER_ERR: Raised if the specified name is not an XML 
 
378
     *   name according to the XML version in use specified in the 
 
379
     *   <code>Document.xmlVersion</code> attribute.
 
380
     *   <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
 
381
     */
 
382
    public org.w3c.dom.EntityReference createEntityReference(String name) {
 
383
        //TODO Implement later
 
384
        return null;
 
385
    }
 
386
 
 
387
    /**
 
388
     * Creates an element of the type specified. Note that the instance 
 
389
     * returned implements the <code>Element</code> interface, so attributes 
 
390
     * can be specified directly on the returned object.
 
391
     * <br>In addition, if there are known attributes with default values, 
 
392
     * <code>Attr</code> nodes representing them are automatically created 
 
393
     * and attached to the element.
 
394
     * <br>To create an element with a qualified name and namespace URI, use 
 
395
     * the <code>createElementNS</code> method.
 
396
     * @param tagName The name of the element type to instantiate. For XML, 
 
397
     *   this is case-sensitive, otherwise it depends on the 
 
398
     *   case-sensitivity of the markup language in use. In that case, the 
 
399
     *   name is mapped to the canonical form of that markup by the DOM 
 
400
     *   implementation.
 
401
     * @return A new <code>Element</code> object with the 
 
402
     *   <code>nodeName</code> attribute set to <code>tagName</code>, and 
 
403
     *   <code>localName</code>, <code>prefix</code>, and 
 
404
     *   <code>namespaceURI</code> set to <code>null</code>.
 
405
     * @exception DOMException
 
406
     *   INVALID_CHARACTER_ERR: Raised if the specified name is not an XML 
 
407
     *   name according to the XML version in use specified in the 
 
408
     *   <code>Document.xmlVersion</code> attribute.
 
409
     */
 
410
    public org.w3c.dom.Element createElement(String tagName) {
 
411
        return new Element(tagName);
 
412
    }
 
413
 
 
414
    /**
 
415
     * Creates a <code>Comment</code> node given the specified string.
 
416
     * @param data The data for the node.
 
417
     * @return The new <code>Comment</code> object.
 
418
     */
 
419
    public org.w3c.dom.Comment createComment(String data) {
 
420
       return new Comment(data);
 
421
    }
 
422
 
 
423
    /**
 
424
     * Creates a <code>CDATASection</code> node whose value is the specified 
 
425
     * string.
 
426
     * @param data The data for the <code>CDATASection</code> contents.
 
427
     * @return The new <code>CDATASection</code> object.
 
428
     * @exception DOMException
 
429
     *   NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
 
430
     */
 
431
    public org.w3c.dom.CDATASection createCDATASection(String data) {
 
432
        return new CData(data);
 
433
    }
 
434
 
 
435
    /**
 
436
     * Creates an <code>Attr</code> of the given name. Note that the 
 
437
     * <code>Attr</code> instance can then be set on an <code>Element</code> 
 
438
     * using the <code>setAttributeNode</code> method. 
 
439
     * <br>To create an attribute with a qualified name and namespace URI, use 
 
440
     * the <code>createAttributeNS</code> method.
 
441
     * @param name The name of the attribute.
 
442
     * @return A new <code>Attr</code> object with the <code>nodeName</code> 
 
443
     *   attribute set to <code>name</code>, and <code>localName</code>, 
 
444
     *   <code>prefix</code>, and <code>namespaceURI</code> set to 
 
445
     *   <code>null</code>. The value of the attribute is the empty string.
 
446
     * @exception DOMException
 
447
     *   INVALID_CHARACTER_ERR: Raised if the specified name is not an XML 
 
448
     *   name according to the XML version in use specified in the 
 
449
     *   <code>Document.xmlVersion</code> attribute.
 
450
     */
 
451
    public org.w3c.dom.Attr createAttribute(String name) {
 
452
        return new Attribute(name);
 
453
    }
 
454
 
 
455
    /**
 
456
     * Creates a <code>ProcessingInstruction</code> node given the specified 
 
457
     * name and data strings.
 
458
     * @param target The target part of the processing instruction.Unlike 
 
459
     *   <code>Document.createElementNS</code> or 
 
460
     *   <code>Document.createAttributeNS</code>, no namespace well-formed 
 
461
     *   checking is done on the target name. Applications should invoke 
 
462
     *   <code>Document.normalizeDocument()</code> with the parameter "
 
463
     *   namespaces" set to <code>true</code> in order to ensure that the 
 
464
     *   target name is namespace well-formed. 
 
465
     * @param data The data for the node.
 
466
     * @return The new <code>ProcessingInstruction</code> object.
 
467
     * @exception DOMException
 
468
     *   INVALID_CHARACTER_ERR: Raised if the specified target is not an XML 
 
469
     *   name according to the XML version in use specified in the 
 
470
     *   <code>Document.xmlVersion</code> attribute.
 
471
     *   <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
 
472
     */
 
473
    public org.w3c.dom.ProcessingInstruction createProcessingInstruction(String target, String data) {
 
474
        //TODO Implement later
 
475
        return null;
 
476
    }
 
477
 
 
478
    /**
 
479
     * Creates an element of the given qualified name and namespace URI.
 
480
     * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
 
481
     * , applications must use the value <code>null</code> as the 
 
482
     * namespaceURI parameter for methods if they wish to have no namespace.
 
483
     * @param namespaceURI The namespace URI of the element to create.
 
484
     * @param qualifiedName The qualified name of the element type to 
 
485
     *   instantiate.
 
486
     * @return A new <code>Element</code> object with the following 
 
487
     *   attributes:
 
488
     * <table border='1' cellpadding='3'>
 
489
     * <tr>
 
490
     * <th>Attribute</th>
 
491
     * <th>Value</th>
 
492
     * </tr>
 
493
     * <tr>
 
494
     * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
 
495
     * <td valign='top' rowspan='1' colspan='1'>
 
496
     *   <code>qualifiedName</code></td>
 
497
     * </tr>
 
498
     * <tr>
 
499
     * <td valign='top' rowspan='1' colspan='1'><code>Node.namespaceURI</code></td>
 
500
     * <td valign='top' rowspan='1' colspan='1'>
 
501
     *   <code>namespaceURI</code></td>
 
502
     * </tr>
 
503
     * <tr>
 
504
     * <td valign='top' rowspan='1' colspan='1'><code>Node.prefix</code></td>
 
505
     * <td valign='top' rowspan='1' colspan='1'>prefix, extracted 
 
506
     *   from <code>qualifiedName</code>, or <code>null</code> if there is 
 
507
     *   no prefix</td>
 
508
     * </tr>
 
509
     * <tr>
 
510
     * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
 
511
     * <td valign='top' rowspan='1' colspan='1'>local name, extracted from 
 
512
     *   <code>qualifiedName</code></td>
 
513
     * </tr>
 
514
     * <tr>
 
515
     * <td valign='top' rowspan='1' colspan='1'><code>Element.tagName</code></td>
 
516
     * <td valign='top' rowspan='1' colspan='1'>
 
517
     *   <code>qualifiedName</code></td>
 
518
     * </tr>
 
519
     * </table>
 
520
     * @exception DOMException
 
521
     *   INVALID_CHARACTER_ERR: Raised if the specified 
 
522
     *   <code>qualifiedName</code> is not an XML name according to the XML 
 
523
     *   version in use specified in the <code>Document.xmlVersion</code> 
 
524
     *   attribute.
 
525
     *   <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a 
 
526
     *   malformed qualified name, if the <code>qualifiedName</code> has a 
 
527
     *   prefix and the <code>namespaceURI</code> is <code>null</code>, or 
 
528
     *   if the <code>qualifiedName</code> has a prefix that is "xml" and 
 
529
     *   the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
 
530
     *   http://www.w3.org/XML/1998/namespace</a>" [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
 
531
     *   , or if the <code>qualifiedName</code> or its prefix is XMLNS and 
 
532
     *   the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>", or if the <code>namespaceURI</code> is "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>" and neither the <code>qualifiedName</code> nor its prefix is XMLNS.
 
533
     *   <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not 
 
534
     *   support the <code>"XML"</code> feature, since namespaces were 
 
535
     *   defined by XML.
 
536
     * @since DOM Level 2
 
537
     */
 
538
    public org.w3c.dom.Element createElementNS(String namespaceURI, String qualifiedName) {
 
539
        Element ret = new Element(qualifiedName);
 
540
        String prefix = ret.getPrefix();
 
541
        if (prefix != null) {
 
542
            if (namespaceURI == null) {
 
543
                throw new DOMException(DOMException.NAMESPACE_ERR, null);
 
544
            }
 
545
            ret.appendAttribute(new Attribute("xmlns:"+prefix, namespaceURI)); //NOI18N
 
546
        } else {
 
547
            ret = new Element(ret.getLocalName());
 
548
            if (namespaceURI != null && ! namespaceURI.equals(XMLConstants.NULL_NS_URI)) {
 
549
                ret.appendAttribute(new Attribute(XMLNS, namespaceURI)); 
 
550
            }
 
551
        }
 
552
        return ret;
 
553
    }
 
554
 
 
555
    /**
 
556
     * Creates an empty <code>DocumentFragment</code> object.
 
557
     * @return A new <code>DocumentFragment</code>.
 
558
     */
 
559
    public org.w3c.dom.DocumentFragment createDocumentFragment() {
 
560
        //TODO Implement later
 
561
        return null;
 
562
    }
 
563
 
 
564
    /**
 
565
     * Creates an attribute of the given qualified name and namespace URI.
 
566
     * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
 
567
     * , applications must use the value <code>null</code> as the 
 
568
     * <code>namespaceURI</code> parameter for methods if they wish to have 
 
569
     * no namespace.
 
570
     * @param namespaceURI The namespace URI of the attribute to create.
 
571
     * @param qualifiedName The qualified name of the attribute to 
 
572
     *   instantiate.
 
573
     * @return A new <code>Attr</code> object with the following attributes:
 
574
     * <table border='1' cellpadding='3'>
 
575
     * <tr>
 
576
     * <th>
 
577
     *   Attribute</th>
 
578
     * <th>Value</th>
 
579
     * </tr>
 
580
     * <tr>
 
581
     * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
 
582
     * <td valign='top' rowspan='1' colspan='1'>qualifiedName</td>
 
583
     * </tr>
 
584
     * <tr>
 
585
     * <td valign='top' rowspan='1' colspan='1'>
 
586
     *   <code>Node.namespaceURI</code></td>
 
587
     * <td valign='top' rowspan='1' colspan='1'><code>namespaceURI</code></td>
 
588
     * </tr>
 
589
     * <tr>
 
590
     * <td valign='top' rowspan='1' colspan='1'>
 
591
     *   <code>Node.prefix</code></td>
 
592
     * <td valign='top' rowspan='1' colspan='1'>prefix, extracted from 
 
593
     *   <code>qualifiedName</code>, or <code>null</code> if there is no 
 
594
     *   prefix</td>
 
595
     * </tr>
 
596
     * <tr>
 
597
     * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
 
598
     * <td valign='top' rowspan='1' colspan='1'>local name, extracted from 
 
599
     *   <code>qualifiedName</code></td>
 
600
     * </tr>
 
601
     * <tr>
 
602
     * <td valign='top' rowspan='1' colspan='1'><code>Attr.name</code></td>
 
603
     * <td valign='top' rowspan='1' colspan='1'>
 
604
     *   <code>qualifiedName</code></td>
 
605
     * </tr>
 
606
     * <tr>
 
607
     * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeValue</code></td>
 
608
     * <td valign='top' rowspan='1' colspan='1'>the empty 
 
609
     *   string</td>
 
610
     * </tr>
 
611
     * </table>
 
612
     * @exception DOMException
 
613
     *   INVALID_CHARACTER_ERR: Raised if the specified 
 
614
     *   <code>qualifiedName</code> is not an XML name according to the XML 
 
615
     *   version in use specified in the <code>Document.xmlVersion</code> 
 
616
     *   attribute.
 
617
     *   <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a 
 
618
     *   malformed qualified name, if the <code>qualifiedName</code> has a 
 
619
     *   prefix and the <code>namespaceURI</code> is <code>null</code>, if 
 
620
     *   the <code>qualifiedName</code> has a prefix that is "xml" and the 
 
621
     *   <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
 
622
     *   http://www.w3.org/XML/1998/namespace</a>", if the <code>qualifiedName</code> or its prefix is XMLNS and the 
 
623
     *   <code>namespaceURI</code> is different from "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>", or if the <code>namespaceURI</code> is "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>" and neither the <code>qualifiedName</code> nor its prefix is XMLNS.
 
624
     *   <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not 
 
625
     *   support the <code>"XML"</code> feature, since namespaces were 
 
626
     *   defined by XML.
 
627
     * @since DOM Level 2
 
628
     */
 
629
    public org.w3c.dom.Attr createAttributeNS(String namespaceURI, String qualifiedName) {
 
630
        //TODO validate namespaceURI
 
631
        return new Attribute(qualifiedName);
 
632
    }
 
633
 
 
634
    /**
 
635
     * Returns the <code>Element</code> that has an ID attribute with the 
 
636
     * given value. If no such element exists, this returns <code>null</code>
 
637
     * . If more than one element has an ID attribute with that value, what 
 
638
     * is returned is undefined. 
 
639
     * <br> The DOM implementation is expected to use the attribute 
 
640
     * <code>Attr.isId</code> to determine if an attribute is of type ID. 
 
641
     * <p ><b>Note:</b> Attributes with the name "ID" or "id" are not of type 
 
642
     * ID unless so defined.
 
643
     * @param elementId The unique <code>id</code> value for an element.
 
644
     * @return The matching element or <code>null</code> if there is none.
 
645
     * @since DOM Level 2
 
646
     */
 
647
    public org.w3c.dom.Element getElementById(String elementId) {
 
648
        //TODO Implement later
 
649
        return null;
 
650
    }
 
651
 
 
652
    /**
 
653
     * Returns a <code>NodeList</code> of all the <code>Elements</code> in 
 
654
     * document order with a given tag name and are contained in the 
 
655
     * document.
 
656
     * @param tagname  The name of the tag to match on. The special value "*" 
 
657
     *   matches all tags. For XML, the <code>tagname</code> parameter is 
 
658
     *   case-sensitive, otherwise it depends on the case-sensitivity of the 
 
659
     *   markup language in use. 
 
660
     * @return A new <code>NodeList</code> object containing all the matched 
 
661
     *   <code>Elements</code>.
 
662
     */
 
663
    public org.w3c.dom.NodeList getElementsByTagName(String tagname) {
 
664
        //TODO Implement later
 
665
        return null;
 
666
    }
 
667
 
 
668
    /**
 
669
     * Returns a <code>NodeList</code> of all the <code>Elements</code> with a 
 
670
     * given local name and namespace URI in document order.
 
671
     * @param namespaceURI The namespace URI of the elements to match on. The 
 
672
     *   special value <code>"*"</code> matches all namespaces.
 
673
     * @param localName The local name of the elements to match on. The 
 
674
     *   special value "*" matches all local names.
 
675
     * @return A new <code>NodeList</code> object containing all the matched 
 
676
     *   <code>Elements</code>.
 
677
     * @since DOM Level 2
 
678
     */
 
679
    public org.w3c.dom.NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
 
680
        //TODO Implement later
 
681
        return null;
 
682
    }
 
683
 
 
684
    /**
 
685
     *  This method acts as if the document was going through a save and load 
 
686
     * cycle, putting the document in a "normal" form. As a consequence, 
 
687
     * this method updates the replacement tree of 
 
688
     * <code>EntityReference</code> nodes and normalizes <code>Text</code> 
 
689
     * nodes, as defined in the method <code>Node.normalize()</code>. 
 
690
     * <br> Otherwise, the actual result depends on the features being set on 
 
691
     * the <code>Document.domConfig</code> object and governing what 
 
692
     * operations actually take place. Noticeably this method could also 
 
693
     * make the document namespace well-formed according to the algorithm 
 
694
     * described in , check the character normalization, remove the 
 
695
     * <code>CDATASection</code> nodes, etc. See 
 
696
     * <code>DOMConfiguration</code> for details. 
 
697
     * <pre>// Keep in the document 
 
698
     * the information defined // in the XML Information Set (Java example) 
 
699
     * DOMConfiguration docConfig = myDocument.getDomConfig(); 
 
700
     * docConfig.setParameter("infoset", Boolean.TRUE); 
 
701
     * myDocument.normalizeDocument();</pre>
 
702
     * 
 
703
     * <br>Mutation events, when supported, are generated to reflect the 
 
704
     * changes occurring on the document.
 
705
     * <br> If errors occur during the invocation of this method, such as an 
 
706
     * attempt to update a read-only node or a <code>Node.nodeName</code> 
 
707
     * contains an invalid character according to the XML version in use, 
 
708
     * errors or warnings (<code>DOMError.SEVERITY_ERROR</code> or 
 
709
     * <code>DOMError.SEVERITY_WARNING</code>) will be reported using the 
 
710
     * <code>DOMErrorHandler</code> object associated with the "error-handler
 
711
     * " parameter. Note this method might also report fatal errors (
 
712
     * <code>DOMError.SEVERITY_FATAL_ERROR</code>) if an implementation 
 
713
     * cannot recover from an error. 
 
714
     * @since DOM Level 3
 
715
     */
 
716
    public void normalizeDocument() {
 
717
         //TODO Implement later
 
718
   }
 
719
 
 
720
    /**
 
721
     * This is a convenience attribute that allows direct access to the child 
 
722
     * node that is the document element of the document.
 
723
     */
 
724
    public org.w3c.dom.Element getDocumentElement() {
 
725
        if(hasChildNodes()) {
 
726
            NodeList childNodes = getChildNodes();
 
727
            for (int i=0;i<childNodes.getLength(); i++) {
 
728
                Node child = (Node)childNodes.item(i);
 
729
                if (child instanceof org.w3c.dom.Element)
 
730
                    return (org.w3c.dom.Element)child;
 
731
            }
 
732
        }
 
733
        return null;
 
734
    }
 
735
 
 
736
    /**
 
737
     * The Document Type Declaration (see <code>DocumentType</code>) 
 
738
     * associated with this document. For XML documents without a document 
 
739
     * type declaration this returns <code>null</code>. For HTML documents, 
 
740
     * a <code>DocumentType</code> object may be returned, independently of 
 
741
     * the presence or absence of document type declaration in the HTML 
 
742
     * document.
 
743
     * <br>This provides direct access to the <code>DocumentType</code> node, 
 
744
     * child node of this <code>Document</code>. This node can be set at 
 
745
     * document creation time and later changed through the use of child 
 
746
     * nodes manipulation methods, such as <code>Node.insertBefore</code>, 
 
747
     * or <code>Node.replaceChild</code>. Note, however, that while some 
 
748
     * implementations may instantiate different types of 
 
749
     * <code>Document</code> objects supporting additional features than the 
 
750
     * "Core", such as "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
 
751
     * , based on the <code>DocumentType</code> specified at creation time, 
 
752
     * changing it afterwards is very unlikely to result in a change of the 
 
753
     * features supported.
 
754
     * @version DOM Level 3
 
755
     */
 
756
    public org.w3c.dom.DocumentType getDoctype() {
 
757
        //TODO Implement later
 
758
        return null;
 
759
    }
 
760
 
 
761
    /**
 
762
     *  The location of the document or <code>null</code> if undefined or if 
 
763
     * the <code>Document</code> was created using 
 
764
     * <code>DOMImplementation.createDocument</code>. No lexical checking is 
 
765
     * performed when setting this attribute; this could result in a 
 
766
     * <code>null</code> value returned when using <code>Node.baseURI</code>
 
767
     * . 
 
768
     * <br> Beware that when the <code>Document</code> supports the feature 
 
769
     * "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
 
770
     * , the href attribute of the HTML BASE element takes precedence over 
 
771
     * this attribute when computing <code>Node.baseURI</code>. 
 
772
     * @since DOM Level 3
 
773
     */
 
774
    public void setDocumentURI(String documentURI) {
 
775
    }
 
776
 
 
777
    /**
 
778
     *  The location of the document or <code>null</code> if undefined or if 
 
779
     * the <code>Document</code> was created using 
 
780
     * <code>DOMImplementation.createDocument</code>. No lexical checking is 
 
781
     * performed when setting this attribute; this could result in a 
 
782
     * <code>null</code> value returned when using <code>Node.baseURI</code>
 
783
     * . 
 
784
     * <br> Beware that when the <code>Document</code> supports the feature 
 
785
     * "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
 
786
     * , the href attribute of the HTML BASE element takes precedence over 
 
787
     * this attribute when computing <code>Node.baseURI</code>. 
 
788
     * @since DOM Level 3
 
789
     */
 
790
    public String getDocumentURI() {
 
791
        //TODO Implement later
 
792
        return null;
 
793
    }
 
794
 
 
795
    /**
 
796
     *  The configuration used when <code>Document.normalizeDocument()</code> 
 
797
     * is invoked. 
 
798
     * @since DOM Level 3
 
799
     */
 
800
    public org.w3c.dom.DOMConfiguration getDomConfig() {
 
801
        //TODO Implement later
 
802
        return null;
 
803
    }
 
804
 
 
805
    /**
 
806
     * The <code>DOMImplementation</code> object that handles this document. A 
 
807
     * DOM application may use objects from multiple implementations.
 
808
     */
 
809
    public org.w3c.dom.DOMImplementation getImplementation() {
 
810
        //TODO Implement later
 
811
        return null;
 
812
    }
 
813
 
 
814
    /**
 
815
     * An attribute specifying the encoding used for this document at the time 
 
816
     * of the parsing. This is <code>null</code> when it is not known, such 
 
817
     * as when the <code>Document</code> was created in memory.
 
818
     * @since DOM Level 3
 
819
     */
 
820
    public String getInputEncoding() {
 
821
        //TODO Implement later
 
822
        return null;
 
823
    }
 
824
 
 
825
    /**
 
826
     * An attribute specifying whether error checking is enforced or not. When 
 
827
     * set to <code>false</code>, the implementation is free to not test 
 
828
     * every possible error case normally defined on DOM operations, and not 
 
829
     * raise any <code>DOMException</code> on DOM operations or report 
 
830
     * errors while using <code>Document.normalizeDocument()</code>. In case 
 
831
     * of error, the behavior is undefined. This attribute is 
 
832
     * <code>true</code> by default.
 
833
     * @since DOM Level 3
 
834
     */
 
835
    public void setStrictErrorChecking(boolean strictErrorChecking) {
 
836
    }
 
837
 
 
838
    /**
 
839
     * An attribute specifying whether error checking is enforced or not. When 
 
840
     * set to <code>false</code>, the implementation is free to not test 
 
841
     * every possible error case normally defined on DOM operations, and not 
 
842
     * raise any <code>DOMException</code> on DOM operations or report 
 
843
     * errors while using <code>Document.normalizeDocument()</code>. In case 
 
844
     * of error, the behavior is undefined. This attribute is 
 
845
     * <code>true</code> by default.
 
846
     * @since DOM Level 3
 
847
     */
 
848
    public boolean getStrictErrorChecking() {
 
849
        //TODO Implement later
 
850
        return false;
 
851
    }
 
852
 
 
853
    /**
 
854
     * An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, the encoding of this document. This is <code>null</code> when 
 
855
     * unspecified or when it is not known, such as when the 
 
856
     * <code>Document</code> was created in memory.
 
857
     * @since DOM Level 3
 
858
     */
 
859
    public String getXmlEncoding() {
 
860
        for (Token token : super.getTokens()) {
 
861
            if(token.getType() == TokenType.TOKEN_PI_VAL) {
 
862
                String versionImage = token.getValue();
 
863
                int versionIndex = versionImage.indexOf("encoding");
 
864
                if(versionIndex == -1) return null;
 
865
                versionIndex = versionImage.indexOf('=',versionIndex);
 
866
                if(versionIndex == -1) return null;
 
867
                versionImage = versionImage.substring(versionIndex+1).trim();
 
868
                if(versionImage.startsWith("\"")) {
 
869
                    int versionEndIndex = versionImage.indexOf('"',1);
 
870
                    if(versionEndIndex == -1) return null;
 
871
                    return versionImage.substring(1,versionEndIndex);
 
872
                } else if(versionImage.startsWith("'")) {
 
873
                    int versionEndIndex = versionImage.indexOf('\'',1);
 
874
                    if(versionEndIndex == -1) return null;
 
875
                    return versionImage.substring(1,versionEndIndex);
 
876
                }
 
877
            }
 
878
        }
 
879
        return null;
 
880
    }
 
881
 
 
882
    /**
 
883
     * An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, whether this document is standalone. This is <code>false</code> when 
 
884
     * unspecified.
 
885
     * <p ><b>Note:</b>  No verification is done on the value when setting 
 
886
     * this attribute. Applications should use 
 
887
     * <code>Document.normalizeDocument()</code> with the "validate" 
 
888
     * parameter to verify if the value matches the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#sec-rmd'>validity 
 
889
     * constraint for standalone document declaration</a> as defined in [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. 
 
890
     * @exception DOMException
 
891
     *    NOT_SUPPORTED_ERR: Raised if this document does not support the 
 
892
     *   "XML" feature. 
 
893
     * @since DOM Level 3
 
894
     */
 
895
    public void setXmlStandalone(boolean xmlStandalone) {
 
896
        //TODO Implement later
 
897
    }
 
898
 
 
899
    /**
 
900
     * An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, whether this document is standalone. This is <code>false</code> when 
 
901
     * unspecified.
 
902
     * <p ><b>Note:</b>  No verification is done on the value when setting 
 
903
     * this attribute. Applications should use 
 
904
     * <code>Document.normalizeDocument()</code> with the "validate" 
 
905
     * parameter to verify if the value matches the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#sec-rmd'>validity 
 
906
     * constraint for standalone document declaration</a> as defined in [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. 
 
907
     * @since DOM Level 3
 
908
     */
 
909
    public boolean getXmlStandalone() {
 
910
        for (Token token : super.getTokens()) {
 
911
            if(token.getType() == TokenType.TOKEN_PI_VAL) {
 
912
                String versionImage = token.getValue();
 
913
                int versionIndex = versionImage.indexOf("standalone");
 
914
                if(versionIndex == -1) return false;
 
915
                versionIndex = versionImage.indexOf('=',versionIndex);
 
916
                if(versionIndex == -1) return false;
 
917
                versionImage = versionImage.substring(versionIndex+1).trim();
 
918
                if(versionImage.startsWith("\"")) {
 
919
                    int versionEndIndex = versionImage.indexOf('"',1);
 
920
                    if(versionEndIndex == -1) return false;
 
921
                    return versionImage.substring(1,versionEndIndex).equals("yes");
 
922
                } else if(versionImage.startsWith("'")) {
 
923
                    int versionEndIndex = versionImage.indexOf('\'',1);
 
924
                    if(versionEndIndex == -1) return false;
 
925
                    return versionImage.substring(1,versionEndIndex).equals("yes");
 
926
                }
 
927
            }
 
928
        }
 
929
        return false;
 
930
    }
 
931
 
 
932
    /**
 
933
     *  An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, the version number of this document. If there is no declaration and if 
 
934
     * this document supports the "XML" feature, the value is 
 
935
     * <code>"1.0"</code>. If this document does not support the "XML" 
 
936
     * feature, the value is always <code>null</code>. Changing this 
 
937
     * attribute will affect methods that check for invalid characters in 
 
938
     * XML names. Application should invoke 
 
939
     * <code>Document.normalizeDocument()</code> in order to check for 
 
940
     * invalid characters in the <code>Node</code>s that are already part of 
 
941
     * this <code>Document</code>. 
 
942
     * <br> DOM applications may use the 
 
943
     * <code>DOMImplementation.hasFeature(feature, version)</code> method 
 
944
     * with parameter values "XMLVersion" and "1.0" (respectively) to 
 
945
     * determine if an implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. DOM 
 
946
     * applications may use the same method with parameter values 
 
947
     * "XMLVersion" and "1.1" (respectively) to determine if an 
 
948
     * implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. In both 
 
949
     * cases, in order to support XML, an implementation must also support 
 
950
     * the "XML" feature defined in this specification. <code>Document</code>
 
951
     *  objects supporting a version of the "XMLVersion" feature must not 
 
952
     * raise a <code>NOT_SUPPORTED_ERR</code> exception for the same version 
 
953
     * number when using <code>Document.xmlVersion</code>. 
 
954
     * @exception DOMException
 
955
     *    NOT_SUPPORTED_ERR: Raised if the version is set to a value that is 
 
956
     *   not supported by this <code>Document</code> or if this document 
 
957
     *   does not support the "XML" feature. 
 
958
     * @since DOM Level 3
 
959
     */
 
960
    public void setXmlVersion(String xmlVersion) {
 
961
        //TODO Implement later
 
962
    }
 
963
 
 
964
    /**
 
965
     *  An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, the version number of this document. If there is no declaration and if 
 
966
     * this document supports the "XML" feature, the value is 
 
967
     * <code>"1.0"</code>. If this document does not support the "XML" 
 
968
     * feature, the value is always <code>null</code>. Changing this 
 
969
     * attribute will affect methods that check for invalid characters in 
 
970
     * XML names. Application should invoke 
 
971
     * <code>Document.normalizeDocument()</code> in order to check for 
 
972
     * invalid characters in the <code>Node</code>s that are already part of 
 
973
     * this <code>Document</code>. 
 
974
     * <br> DOM applications may use the 
 
975
     * <code>DOMImplementation.hasFeature(feature, version)</code> method 
 
976
     * with parameter values "XMLVersion" and "1.0" (respectively) to 
 
977
     * determine if an implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. DOM 
 
978
     * applications may use the same method with parameter values 
 
979
     * "XMLVersion" and "1.1" (respectively) to determine if an 
 
980
     * implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. In both 
 
981
     * cases, in order to support XML, an implementation must also support 
 
982
     * the "XML" feature defined in this specification. <code>Document</code>
 
983
     *  objects supporting a version of the "XMLVersion" feature must not 
 
984
     * raise a <code>NOT_SUPPORTED_ERR</code> exception for the same version 
 
985
     * number when using <code>Document.xmlVersion</code>. 
 
986
     * @since DOM Level 3
 
987
     */
 
988
    public String getXmlVersion() {
 
989
        for (Token token : super.getTokens()) {
 
990
            if(token.getType() == TokenType.TOKEN_PI_VAL) {
 
991
                String versionImage = token.getValue();
 
992
                int versionIndex = versionImage.indexOf("version");
 
993
                if(versionIndex == -1) return null;
 
994
                versionIndex = versionImage.indexOf('=',versionIndex);
 
995
                if(versionIndex == -1) return null;
 
996
                versionImage = versionImage.substring(versionIndex+1).trim();
 
997
                if(versionImage.startsWith("\"")) {
 
998
                    int versionEndIndex = versionImage.indexOf('"',1);
 
999
                    if(versionEndIndex == -1) return null;
 
1000
                    return versionImage.substring(1,versionEndIndex);
 
1001
                } else if(versionImage.startsWith("'")) {
 
1002
                    int versionEndIndex = versionImage.indexOf('\'',1);
 
1003
                    if(versionEndIndex == -1) return null;
 
1004
                    return versionImage.substring(1,versionEndIndex);
 
1005
                }
 
1006
            }
 
1007
        }
 
1008
        return null;
 
1009
    }
 
1010
 
 
1011
    /**
 
1012
     * This api returns the namespaceuri of specified node.
 
1013
     * @param node The node which namespace to find.
 
1014
     * @return The namespaceuri of given node.
 
1015
     */
 
1016
    public String getNamespaceURI(Node node) {
 
1017
        return getNamespaceCache().findNamespace(node);
 
1018
    }   
 
1019
 
 
1020
    private FindNamespaceVisitor getNamespaceCache() {
 
1021
        if (fnv == null || fnv.get() == null) {
 
1022
            fnv = new SoftReference<FindNamespaceVisitor>(new FindNamespaceVisitor(this));
 
1023
        }
 
1024
        return fnv.get();
 
1025
    }
 
1026
    
 
1027
    Map<Integer,String> getNamespaceMap() {
 
1028
        return getNamespaceCache().getNamespaceMap();
 
1029
    }
 
1030
    
 
1031
    /**
 
1032
     * Namespace finder visitor
 
1033
     */
 
1034
    private SoftReference<FindNamespaceVisitor> fnv;
 
1035
}