KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xdm > nodes > Document


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.xdm.nodes;
21
22 import java.lang.ref.SoftReference JavaDoc;
23 import java.util.Map JavaDoc;
24 import javax.xml.XMLConstants JavaDoc;
25 import org.netbeans.modules.xml.xdm.visitor.FindNamespaceVisitor;
26 import org.netbeans.modules.xml.xdm.visitor.XMLNodeVisitor;
27 import org.w3c.dom.DOMException JavaDoc;
28 import org.w3c.dom.NodeList JavaDoc;
29
30 /**
31  *
32  * @author Ajit
33  */

34 public class Document extends NodeImpl implements Node, org.w3c.dom.Document JavaDoc {
35     
36     /** Creates a new instance of Document */
37     Document() {
38         super();
39         resetNamespaceCache();
40     }
41     
42     public Document clone(boolean cloneContent, boolean cloneAttributes, boolean cloneChildren) {
43         Document ret = (Document) super.clone(cloneContent, cloneAttributes, cloneChildren);
44         ret.resetNamespaceCache();
45         return ret;
46     }
47     
48     void resetNamespaceCache() {
49         fnv = null;
50     }
51     
52     public short getNodeType() {
53         return Node.DOCUMENT_NODE;
54     }
55
56     public String JavaDoc getNodeName() {
57         return "#document"; //NOI18N
58
}
59
60     public void accept(XMLNodeVisitor visitor) {
61         visitor.visit(this);
62     }
63
64     /**
65      * Attempts to adopt a node from another document to this document. If
66      * supported, it changes the <code>ownerDocument</code> of the source
67      * node, its children, as well as the attached attribute nodes if there
68      * are any. If the source node has a parent it is first removed from the
69      * child list of its parent. This effectively allows moving a subtree
70      * from one document to another (unlike <code>importNode()</code> which
71      * create a copy of the source node instead of moving it). When it
72      * fails, applications should use <code>Document.importNode()</code>
73      * instead. Note that if the adopted node is already part of this
74      * document (i.e. the source and target document are the same), this
75      * method still has the effect of removing the source node from the
76      * child list of its parent, if any. The following list describes the
77      * specifics for each type of node.
78      * <dl>
79      * <dt>ATTRIBUTE_NODE</dt>
80      * <dd>The
81      * <code>ownerElement</code> attribute is set to <code>null</code> and
82      * the <code>specified</code> flag is set to <code>true</code> on the
83      * adopted <code>Attr</code>. The descendants of the source
84      * <code>Attr</code> are recursively adopted.</dd>
85      * <dt>DOCUMENT_FRAGMENT_NODE</dt>
86      * <dd>The
87      * descendants of the source node are recursively adopted.</dd>
88      * <dt>DOCUMENT_NODE</dt>
89      * <dd>
90      * <code>Document</code> nodes cannot be adopted.</dd>
91      * <dt>DOCUMENT_TYPE_NODE</dt>
92      * <dd>
93      * <code>DocumentType</code> nodes cannot be adopted.</dd>
94      * <dt>ELEMENT_NODE</dt>
95      * <dd><em>Specified</em> attribute nodes of the source element are adopted. Default attributes
96      * are discarded, though if the document being adopted into defines
97      * default attributes for this element name, those are assigned. The
98      * descendants of the source element are recursively adopted.</dd>
99      * <dt>ENTITY_NODE</dt>
100      * <dd>
101      * <code>Entity</code> nodes cannot be adopted.</dd>
102      * <dt>ENTITY_REFERENCE_NODE</dt>
103      * <dd>Only
104      * the <code>EntityReference</code> node itself is adopted, the
105      * descendants are discarded, since the source and destination documents
106      * might have defined the entity differently. If the document being
107      * imported into provides a definition for this entity name, its value
108      * is assigned.</dd>
109      * <dt>NOTATION_NODE</dt>
110      * <dd><code>Notation</code> nodes cannot be
111      * adopted.</dd>
112      * <dt>PROCESSING_INSTRUCTION_NODE, TEXT_NODE, CDATA_SECTION_NODE,
113      * COMMENT_NODE</dt>
114      * <dd>These nodes can all be adopted. No specifics.</dd>
115      * </dl>
116      * <p ><b>Note:</b> Since it does not create new nodes unlike the
117      * <code>Document.importNode()</code> method, this method does not raise
118      * an <code>INVALID_CHARACTER_ERR</code> exception, and applications
119      * should use the <code>Document.normalizeDocument()</code> method to
120      * check if an imported name is not an XML name according to the XML
121      * version in use.
122      * @param source The node to move into this document.
123      * @return The adopted node, or <code>null</code> if this operation
124      * fails, such as when the source node comes from a different
125      * implementation.
126      * @exception DOMException
127      * NOT_SUPPORTED_ERR: Raised if the source node is of type
128      * <code>DOCUMENT</code>, <code>DOCUMENT_TYPE</code>.
129      * <br>NO_MODIFICATION_ALLOWED_ERR: Raised when the source node is
130      * readonly.
131      * @since DOM Level 3
132      */

133     public org.w3c.dom.Node JavaDoc adoptNode(org.w3c.dom.Node JavaDoc source) {
134         //TODO Implement later
135
return null;
136     }
137
138     /**
139      * Imports a node from another document to this document, without altering
140      * or removing the source node from the original document; this method
141      * creates a new copy of the source node. The returned node has no
142      * parent; (<code>parentNode</code> is <code>null</code>).
143      * <br>For all nodes, importing a node creates a node object owned by the
144      * importing document, with attribute values identical to the source
145      * node's <code>nodeName</code> and <code>nodeType</code>, plus the
146      * attributes related to namespaces (<code>prefix</code>,
147      * <code>localName</code>, and <code>namespaceURI</code>). As in the
148      * <code>cloneNode</code> operation, the source node is not altered.
149      * User data associated to the imported node is not carried over.
150      * However, if any <code>UserDataHandlers</code> has been specified
151      * along with the associated data these handlers will be called with the
152      * appropriate parameters before this method returns.
153      * <br>Additional information is copied as appropriate to the
154      * <code>nodeType</code>, attempting to mirror the behavior expected if
155      * a fragment of XML or HTML source was copied from one document to
156      * another, recognizing that the two documents may have different DTDs
157      * in the XML case. The following list describes the specifics for each
158      * type of node.
159      * <dl>
160      * <dt>ATTRIBUTE_NODE</dt>
161      * <dd>The <code>ownerElement</code> attribute
162      * is set to <code>null</code> and the <code>specified</code> flag is
163      * set to <code>true</code> on the generated <code>Attr</code>. The
164      * descendants of the source <code>Attr</code> are recursively imported
165      * and the resulting nodes reassembled to form the corresponding subtree.
166      * Note that the <code>deep</code> parameter has no effect on
167      * <code>Attr</code> nodes; they always carry their children with them
168      * when imported.</dd>
169      * <dt>DOCUMENT_FRAGMENT_NODE</dt>
170      * <dd>If the <code>deep</code> option
171      * was set to <code>true</code>, the descendants of the source
172      * <code>DocumentFragment</code> are recursively imported and the
173      * resulting nodes reassembled under the imported
174      * <code>DocumentFragment</code> to form the corresponding subtree.
175      * Otherwise, this simply generates an empty
176      * <code>DocumentFragment</code>.</dd>
177      * <dt>DOCUMENT_NODE</dt>
178      * <dd><code>Document</code>
179      * nodes cannot be imported.</dd>
180      * <dt>DOCUMENT_TYPE_NODE</dt>
181      * <dd><code>DocumentType</code>
182      * nodes cannot be imported.</dd>
183      * <dt>ELEMENT_NODE</dt>
184      * <dd><em>Specified</em> attribute nodes of the source element are imported, and the generated
185      * <code>Attr</code> nodes are attached to the generated
186      * <code>Element</code>. Default attributes are <em>not</em> copied, though if the document being imported into defines default
187      * attributes for this element name, those are assigned. If the
188      * <code>importNode</code> <code>deep</code> parameter was set to
189      * <code>true</code>, the descendants of the source element are
190      * recursively imported and the resulting nodes reassembled to form the
191      * corresponding subtree.</dd>
192      * <dt>ENTITY_NODE</dt>
193      * <dd><code>Entity</code> nodes can be
194      * imported, however in the current release of the DOM the
195      * <code>DocumentType</code> is readonly. Ability to add these imported
196      * nodes to a <code>DocumentType</code> will be considered for addition
197      * to a future release of the DOM.On import, the <code>publicId</code>,
198      * <code>systemId</code>, and <code>notationName</code> attributes are
199      * copied. If a <code>deep</code> import is requested, the descendants
200      * of the the source <code>Entity</code> are recursively imported and
201      * the resulting nodes reassembled to form the corresponding subtree.</dd>
202      * <dt>
203      * ENTITY_REFERENCE_NODE</dt>
204      * <dd>Only the <code>EntityReference</code> itself is
205      * copied, even if a <code>deep</code> import is requested, since the
206      * source and destination documents might have defined the entity
207      * differently. If the document being imported into provides a
208      * definition for this entity name, its value is assigned.</dd>
209      * <dt>NOTATION_NODE</dt>
210      * <dd>
211      * <code>Notation</code> nodes can be imported, however in the current
212      * release of the DOM the <code>DocumentType</code> is readonly. Ability
213      * to add these imported nodes to a <code>DocumentType</code> will be
214      * considered for addition to a future release of the DOM.On import, the
215      * <code>publicId</code> and <code>systemId</code> attributes are copied.
216      * Note that the <code>deep</code> parameter has no effect on this type
217      * of nodes since they cannot have any children.</dd>
218      * <dt>
219      * PROCESSING_INSTRUCTION_NODE</dt>
220      * <dd>The imported node copies its
221      * <code>target</code> and <code>data</code> values from those of the
222      * source node.Note that the <code>deep</code> parameter has no effect
223      * on this type of nodes since they cannot have any children.</dd>
224      * <dt>TEXT_NODE,
225      * CDATA_SECTION_NODE, COMMENT_NODE</dt>
226      * <dd>These three types of nodes inheriting
227      * from <code>CharacterData</code> copy their <code>data</code> and
228      * <code>length</code> attributes from those of the source node.Note
229      * that the <code>deep</code> parameter has no effect on these types of
230      * nodes since they cannot have any children.</dd>
231      * </dl>
232      * @param importedNode The node to import.
233      * @param deep If <code>true</code>, recursively import the subtree under
234      * the specified node; if <code>false</code>, import only the node
235      * itself, as explained above. This has no effect on nodes that cannot
236      * have any children, and on <code>Attr</code>, and
237      * <code>EntityReference</code> nodes.
238      * @return The imported node that belongs to this <code>Document</code>.
239      * @exception DOMException
240      * NOT_SUPPORTED_ERR: Raised if the type of node being imported is not
241      * supported.
242      * <br>INVALID_CHARACTER_ERR: Raised if one of the imported names is not
243      * an XML name according to the XML version in use specified in the
244      * <code>Document.xmlVersion</code> attribute. This may happen when
245      * importing an XML 1.1 [<a HREF='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>] element
246      * into an XML 1.0 document, for instance.
247      * @since DOM Level 2
248      */

249     public org.w3c.dom.Node JavaDoc importNode(org.w3c.dom.Node JavaDoc importedNode, boolean deep) {
250         //TODO Implement later
251
return null;
252     }
253
254     /**
255      * Rename an existing node of type <code>ELEMENT_NODE</code> or
256      * <code>ATTRIBUTE_NODE</code>.
257      * <br>When possible this simply changes the name of the given node,
258      * otherwise this creates a new node with the specified name and
259      * replaces the existing node with the new node as described below.
260      * <br>If simply changing the name of the given node is not possible, the
261      * following operations are performed: a new node is created, any
262      * registered event listener is registered on the new node, any user
263      * data attached to the old node is removed from that node, the old node
264      * is removed from its parent if it has one, the children are moved to
265      * the new node, if the renamed node is an <code>Element</code> its
266      * attributes are moved to the new node, the new node is inserted at the
267      * position the old node used to have in its parent's child nodes list
268      * if it has one, the user data that was attached to the old node is
269      * attached to the new node.
270      * <br>When the node being renamed is an <code>Element</code> only the
271      * specified attributes are moved, default attributes originated from
272      * the DTD are updated according to the new element name. In addition,
273      * the implementation may update default attributes from other schemas.
274      * Applications should use <code>Document.normalizeDocument()</code> to
275      * guarantee these attributes are up-to-date.
276      * <br>When the node being renamed is an <code>Attr</code> that is
277      * attached to an <code>Element</code>, the node is first removed from
278      * the <code>Element</code> attributes map. Then, once renamed, either
279      * by modifying the existing node or creating a new one as described
280      * above, it is put back.
281      * <br>In addition,
282      * <ul>
283      * <li> a user data event <code>NODE_RENAMED</code> is fired,
284      * </li>
285      * <li>
286      * when the implementation supports the feature "MutationNameEvents",
287      * each mutation operation involved in this method fires the appropriate
288      * event, and in the end the event {
289      * <code>http://www.w3.org/2001/xml-events</code>,
290      * <code>DOMElementNameChanged</code>} or {
291      * <code>http://www.w3.org/2001/xml-events</code>,
292      * <code>DOMAttributeNameChanged</code>} is fired.
293      * </li>
294      * </ul>
295      * @param n The node to rename.
296      * @param namespaceURI The new namespace URI.
297      * @param qualifiedName The new qualified name.
298      * @return The renamed node. This is either the specified node or the new
299      * node that was created to replace the specified node.
300      * @exception DOMException
301      * NOT_SUPPORTED_ERR: Raised when the type of the specified node is
302      * neither <code>ELEMENT_NODE</code> nor <code>ATTRIBUTE_NODE</code>,
303      * or if the implementation does not support the renaming of the
304      * document element.
305      * <br>INVALID_CHARACTER_ERR: Raised if the new qualified name is not an
306      * XML name according to the XML version in use specified in the
307      * <code>Document.xmlVersion</code> attribute.
308      * <br>WRONG_DOCUMENT_ERR: Raised when the specified node was created
309      * from a different document than this document.
310      * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a
311      * malformed qualified name, if the <code>qualifiedName</code> has a
312      * prefix and the <code>namespaceURI</code> is <code>null</code>, or
313      * if the <code>qualifiedName</code> has a prefix that is "xml" and
314      * the <code>namespaceURI</code> is different from "<a HREF='http://www.w3.org/XML/1998/namespace'>
315      * http://www.w3.org/XML/1998/namespace</a>" [<a HREF='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
316      * . Also raised, when the node being renamed is an attribute, if the
317      * <code>qualifiedName</code>, or its prefix, is XMLNS and the
318      * <code>namespaceURI</code> is different from "<a HREF='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>".
319      * @since DOM Level 3
320      */

321     public org.w3c.dom.Node JavaDoc renameNode(org.w3c.dom.Node JavaDoc n, String JavaDoc namespaceURI, String JavaDoc qualifiedName) {
322         //TODO Implement later
323
return null;
324     }
325
326     /**
327      * Creates a <code>Text</code> node given the specified string.
328      * @param data The data for the node.
329      * @return The new <code>Text</code> object.
330      */

331     public org.w3c.dom.Text JavaDoc createTextNode(String JavaDoc data) {
332         return new Text(data);
333     }
334
335     /**
336      * Creates an <code>EntityReference</code> object. In addition, if the
337      * referenced entity is known, the child list of the
338      * <code>EntityReference</code> node is made the same as that of the
339      * corresponding <code>Entity</code> node.
340      * <p ><b>Note:</b> If any descendant of the <code>Entity</code> node has
341      * an unbound namespace prefix, the corresponding descendant of the
342      * created <code>EntityReference</code> node is also unbound; (its
343      * <code>namespaceURI</code> is <code>null</code>). The DOM Level 2 and
344      * 3 do not support any mechanism to resolve namespace prefixes in this
345      * case.
346      * @param name The name of the entity to reference.Unlike
347      * <code>Document.createElementNS</code> or
348      * <code>Document.createAttributeNS</code>, no namespace well-formed
349      * checking is done on the entity name. Applications should invoke
350      * <code>Document.normalizeDocument()</code> with the parameter "
351      * namespaces" set to <code>true</code> in order to ensure that the
352      * entity name is namespace well-formed.
353      * @return The new <code>EntityReference</code> object.
354      * @exception DOMException
355      * INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
356      * name according to the XML version in use specified in the
357      * <code>Document.xmlVersion</code> attribute.
358      * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
359      */

360     public org.w3c.dom.EntityReference JavaDoc createEntityReference(String JavaDoc name) {
361         //TODO Implement later
362
return null;
363     }
364
365     /**
366      * Creates an element of the type specified. Note that the instance
367      * returned implements the <code>Element</code> interface, so attributes
368      * can be specified directly on the returned object.
369      * <br>In addition, if there are known attributes with default values,
370      * <code>Attr</code> nodes representing them are automatically created
371      * and attached to the element.
372      * <br>To create an element with a qualified name and namespace URI, use
373      * the <code>createElementNS</code> method.
374      * @param tagName The name of the element type to instantiate. For XML,
375      * this is case-sensitive, otherwise it depends on the
376      * case-sensitivity of the markup language in use. In that case, the
377      * name is mapped to the canonical form of that markup by the DOM
378      * implementation.
379      * @return A new <code>Element</code> object with the
380      * <code>nodeName</code> attribute set to <code>tagName</code>, and
381      * <code>localName</code>, <code>prefix</code>, and
382      * <code>namespaceURI</code> set to <code>null</code>.
383      * @exception DOMException
384      * INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
385      * name according to the XML version in use specified in the
386      * <code>Document.xmlVersion</code> attribute.
387      */

388     public org.w3c.dom.Element JavaDoc createElement(String JavaDoc tagName) {
389         return new Element(tagName);
390     }
391
392     /**
393      * Creates a <code>Comment</code> node given the specified string.
394      * @param data The data for the node.
395      * @return The new <code>Comment</code> object.
396      */

397     public org.w3c.dom.Comment JavaDoc createComment(String JavaDoc data) {
398        return new Comment(data);
399     }
400
401     /**
402      * Creates a <code>CDATASection</code> node whose value is the specified
403      * string.
404      * @param data The data for the <code>CDATASection</code> contents.
405      * @return The new <code>CDATASection</code> object.
406      * @exception DOMException
407      * NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
408      */

409     public org.w3c.dom.CDATASection JavaDoc createCDATASection(String JavaDoc data) {
410         return new CData(data);
411     }
412
413     /**
414      * Creates an <code>Attr</code> of the given name. Note that the
415      * <code>Attr</code> instance can then be set on an <code>Element</code>
416      * using the <code>setAttributeNode</code> method.
417      * <br>To create an attribute with a qualified name and namespace URI, use
418      * the <code>createAttributeNS</code> method.
419      * @param name The name of the attribute.
420      * @return A new <code>Attr</code> object with the <code>nodeName</code>
421      * attribute set to <code>name</code>, and <code>localName</code>,
422      * <code>prefix</code>, and <code>namespaceURI</code> set to
423      * <code>null</code>. The value of the attribute is the empty string.
424      * @exception DOMException
425      * INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
426      * name according to the XML version in use specified in the
427      * <code>Document.xmlVersion</code> attribute.
428      */

429     public org.w3c.dom.Attr JavaDoc createAttribute(String JavaDoc name) {
430         return new Attribute(name);
431     }
432
433     /**
434      * Creates a <code>ProcessingInstruction</code> node given the specified
435      * name and data strings.
436      * @param target The target part of the processing instruction.Unlike
437      * <code>Document.createElementNS</code> or
438      * <code>Document.createAttributeNS</code>, no namespace well-formed
439      * checking is done on the target name. Applications should invoke
440      * <code>Document.normalizeDocument()</code> with the parameter "
441      * namespaces" set to <code>true</code> in order to ensure that the
442      * target name is namespace well-formed.
443      * @param data The data for the node.
444      * @return The new <code>ProcessingInstruction</code> object.
445      * @exception DOMException
446      * INVALID_CHARACTER_ERR: Raised if the specified target is not an XML
447      * name according to the XML version in use specified in the
448      * <code>Document.xmlVersion</code> attribute.
449      * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
450      */

451     public org.w3c.dom.ProcessingInstruction JavaDoc createProcessingInstruction(String JavaDoc target, String JavaDoc data) {
452         //TODO Implement later
453
return null;
454     }
455
456     /**
457      * Creates an element of the given qualified name and namespace URI.
458      * <br>Per [<a HREF='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
459      * , applications must use the value <code>null</code> as the
460      * namespaceURI parameter for methods if they wish to have no namespace.
461      * @param namespaceURI The namespace URI of the element to create.
462      * @param qualifiedName The qualified name of the element type to
463      * instantiate.
464      * @return A new <code>Element</code> object with the following
465      * attributes:
466      * <table border='1' cellpadding='3'>
467      * <tr>
468      * <th>Attribute</th>
469      * <th>Value</th>
470      * </tr>
471      * <tr>
472      * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
473      * <td valign='top' rowspan='1' colspan='1'>
474      * <code>qualifiedName</code></td>
475      * </tr>
476      * <tr>
477      * <td valign='top' rowspan='1' colspan='1'><code>Node.namespaceURI</code></td>
478      * <td valign='top' rowspan='1' colspan='1'>
479      * <code>namespaceURI</code></td>
480      * </tr>
481      * <tr>
482      * <td valign='top' rowspan='1' colspan='1'><code>Node.prefix</code></td>
483      * <td valign='top' rowspan='1' colspan='1'>prefix, extracted
484      * from <code>qualifiedName</code>, or <code>null</code> if there is
485      * no prefix</td>
486      * </tr>
487      * <tr>
488      * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
489      * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
490      * <code>qualifiedName</code></td>
491      * </tr>
492      * <tr>
493      * <td valign='top' rowspan='1' colspan='1'><code>Element.tagName</code></td>
494      * <td valign='top' rowspan='1' colspan='1'>
495      * <code>qualifiedName</code></td>
496      * </tr>
497      * </table>
498      * @exception DOMException
499      * INVALID_CHARACTER_ERR: Raised if the specified
500      * <code>qualifiedName</code> is not an XML name according to the XML
501      * version in use specified in the <code>Document.xmlVersion</code>
502      * attribute.
503      * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a
504      * malformed qualified name, if the <code>qualifiedName</code> has a
505      * prefix and the <code>namespaceURI</code> is <code>null</code>, or
506      * if the <code>qualifiedName</code> has a prefix that is "xml" and
507      * the <code>namespaceURI</code> is different from "<a HREF='http://www.w3.org/XML/1998/namespace'>
508      * http://www.w3.org/XML/1998/namespace</a>" [<a HREF='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
509      * , or if the <code>qualifiedName</code> or its prefix is XMLNS and
510      * 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.
511      * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
512      * support the <code>"XML"</code> feature, since namespaces were
513      * defined by XML.
514      * @since DOM Level 2
515      */

516     public org.w3c.dom.Element JavaDoc createElementNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName) {
517         Element ret = new Element(qualifiedName);
518         String JavaDoc prefix = ret.getPrefix();
519         if (prefix != null) {
520             if (namespaceURI == null) {
521                 throw new DOMException JavaDoc(DOMException.NAMESPACE_ERR, null);
522             }
523             ret.appendAttribute(new Attribute("xmlns:"+prefix, namespaceURI)); //NOI18N
524
} else {
525             ret = new Element(ret.getLocalName());
526             if (namespaceURI != null && ! namespaceURI.equals(XMLConstants.NULL_NS_URI)) {
527                 ret.appendAttribute(new Attribute(XMLNS, namespaceURI));
528             }
529         }
530         return ret;
531     }
532
533     /**
534      * Creates an empty <code>DocumentFragment</code> object.
535      * @return A new <code>DocumentFragment</code>.
536      */

537     public org.w3c.dom.DocumentFragment JavaDoc createDocumentFragment() {
538         //TODO Implement later
539
return null;
540     }
541
542     /**
543      * Creates an attribute of the given qualified name and namespace URI.
544      * <br>Per [<a HREF='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
545      * , applications must use the value <code>null</code> as the
546      * <code>namespaceURI</code> parameter for methods if they wish to have
547      * no namespace.
548      * @param namespaceURI The namespace URI of the attribute to create.
549      * @param qualifiedName The qualified name of the attribute to
550      * instantiate.
551      * @return A new <code>Attr</code> object with the following attributes:
552      * <table border='1' cellpadding='3'>
553      * <tr>
554      * <th>
555      * Attribute</th>
556      * <th>Value</th>
557      * </tr>
558      * <tr>
559      * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
560      * <td valign='top' rowspan='1' colspan='1'>qualifiedName</td>
561      * </tr>
562      * <tr>
563      * <td valign='top' rowspan='1' colspan='1'>
564      * <code>Node.namespaceURI</code></td>
565      * <td valign='top' rowspan='1' colspan='1'><code>namespaceURI</code></td>
566      * </tr>
567      * <tr>
568      * <td valign='top' rowspan='1' colspan='1'>
569      * <code>Node.prefix</code></td>
570      * <td valign='top' rowspan='1' colspan='1'>prefix, extracted from
571      * <code>qualifiedName</code>, or <code>null</code> if there is no
572      * prefix</td>
573      * </tr>
574      * <tr>
575      * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
576      * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
577      * <code>qualifiedName</code></td>
578      * </tr>
579      * <tr>
580      * <td valign='top' rowspan='1' colspan='1'><code>Attr.name</code></td>
581      * <td valign='top' rowspan='1' colspan='1'>
582      * <code>qualifiedName</code></td>
583      * </tr>
584      * <tr>
585      * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeValue</code></td>
586      * <td valign='top' rowspan='1' colspan='1'>the empty
587      * string</td>
588      * </tr>
589      * </table>
590      * @exception DOMException
591      * INVALID_CHARACTER_ERR: Raised if the specified
592      * <code>qualifiedName</code> is not an XML name according to the XML
593      * version in use specified in the <code>Document.xmlVersion</code>
594      * attribute.
595      * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a
596      * malformed qualified name, if the <code>qualifiedName</code> has a
597      * prefix and the <code>namespaceURI</code> is <code>null</code>, if
598      * the <code>qualifiedName</code> has a prefix that is "xml" and the
599      * <code>namespaceURI</code> is different from "<a HREF='http://www.w3.org/XML/1998/namespace'>
600      * http://www.w3.org/XML/1998/namespace</a>", if the <code>qualifiedName</code> or its prefix is XMLNS and the
601      * <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.
602      * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
603      * support the <code>"XML"</code> feature, since namespaces were
604      * defined by XML.
605      * @since DOM Level 2
606      */

607     public org.w3c.dom.Attr JavaDoc createAttributeNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName) {
608         //TODO validate namespaceURI
609
return new Attribute(qualifiedName);
610     }
611
612     /**
613      * Returns the <code>Element</code> that has an ID attribute with the
614      * given value. If no such element exists, this returns <code>null</code>
615      * . If more than one element has an ID attribute with that value, what
616      * is returned is undefined.
617      * <br> The DOM implementation is expected to use the attribute
618      * <code>Attr.isId</code> to determine if an attribute is of type ID.
619      * <p ><b>Note:</b> Attributes with the name "ID" or "id" are not of type
620      * ID unless so defined.
621      * @param elementId The unique <code>id</code> value for an element.
622      * @return The matching element or <code>null</code> if there is none.
623      * @since DOM Level 2
624      */

625     public org.w3c.dom.Element JavaDoc getElementById(String JavaDoc elementId) {
626         //TODO Implement later
627
return null;
628     }
629
630     /**
631      * Returns a <code>NodeList</code> of all the <code>Elements</code> in
632      * document order with a given tag name and are contained in the
633      * document.
634      * @param tagname The name of the tag to match on. The special value "*"
635      * matches all tags. For XML, the <code>tagname</code> parameter is
636      * case-sensitive, otherwise it depends on the case-sensitivity of the
637      * markup language in use.
638      * @return A new <code>NodeList</code> object containing all the matched
639      * <code>Elements</code>.
640      */

641     public org.w3c.dom.NodeList JavaDoc getElementsByTagName(String JavaDoc tagname) {
642         //TODO Implement later
643
return null;
644     }
645
646     /**
647      * Returns a <code>NodeList</code> of all the <code>Elements</code> with a
648      * given local name and namespace URI in document order.
649      * @param namespaceURI The namespace URI of the elements to match on. The
650      * special value <code>"*"</code> matches all namespaces.
651      * @param localName The local name of the elements to match on. The
652      * special value "*" matches all local names.
653      * @return A new <code>NodeList</code> object containing all the matched
654      * <code>Elements</code>.
655      * @since DOM Level 2
656      */

657     public org.w3c.dom.NodeList JavaDoc getElementsByTagNameNS(String JavaDoc namespaceURI, String JavaDoc localName) {
658         //TODO Implement later
659
return null;
660     }
661
662     /**
663      * This method acts as if the document was going through a save and load
664      * cycle, putting the document in a "normal" form. As a consequence,
665      * this method updates the replacement tree of
666      * <code>EntityReference</code> nodes and normalizes <code>Text</code>
667      * nodes, as defined in the method <code>Node.normalize()</code>.
668      * <br> Otherwise, the actual result depends on the features being set on
669      * the <code>Document.domConfig</code> object and governing what
670      * operations actually take place. Noticeably this method could also
671      * make the document namespace well-formed according to the algorithm
672      * described in , check the character normalization, remove the
673      * <code>CDATASection</code> nodes, etc. See
674      * <code>DOMConfiguration</code> for details.
675      * <pre>// Keep in the document
676      * the information defined // in the XML Information Set (Java example)
677      * DOMConfiguration docConfig = myDocument.getDomConfig();
678      * docConfig.setParameter("infoset", Boolean.TRUE);
679      * myDocument.normalizeDocument();</pre>
680      *
681      * <br>Mutation events, when supported, are generated to reflect the
682      * changes occurring on the document.
683      * <br> If errors occur during the invocation of this method, such as an
684      * attempt to update a read-only node or a <code>Node.nodeName</code>
685      * contains an invalid character according to the XML version in use,
686      * errors or warnings (<code>DOMError.SEVERITY_ERROR</code> or
687      * <code>DOMError.SEVERITY_WARNING</code>) will be reported using the
688      * <code>DOMErrorHandler</code> object associated with the "error-handler
689      * " parameter. Note this method might also report fatal errors (
690      * <code>DOMError.SEVERITY_FATAL_ERROR</code>) if an implementation
691      * cannot recover from an error.
692      * @since DOM Level 3
693      */

694     public void normalizeDocument() {
695          //TODO Implement later
696
}
697
698     /**
699      * This is a convenience attribute that allows direct access to the child
700      * node that is the document element of the document.
701      */

702     public org.w3c.dom.Element JavaDoc getDocumentElement() {
703         if(hasChildNodes()) {
704             NodeList JavaDoc childNodes = getChildNodes();
705             for (int i=0;i<childNodes.getLength(); i++) {
706                 Node child = (Node)childNodes.item(i);
707                 if (child instanceof org.w3c.dom.Element JavaDoc)
708                     return (org.w3c.dom.Element JavaDoc)child;
709             }
710         }
711         return null;
712     }
713
714     /**
715      * The Document Type Declaration (see <code>DocumentType</code>)
716      * associated with this document. For XML documents without a document
717      * type declaration this returns <code>null</code>. For HTML documents,
718      * a <code>DocumentType</code> object may be returned, independently of
719      * the presence or absence of document type declaration in the HTML
720      * document.
721      * <br>This provides direct access to the <code>DocumentType</code> node,
722      * child node of this <code>Document</code>. This node can be set at
723      * document creation time and later changed through the use of child
724      * nodes manipulation methods, such as <code>Node.insertBefore</code>,
725      * or <code>Node.replaceChild</code>. Note, however, that while some
726      * implementations may instantiate different types of
727      * <code>Document</code> objects supporting additional features than the
728      * "Core", such as "HTML" [<a HREF='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
729      * , based on the <code>DocumentType</code> specified at creation time,
730      * changing it afterwards is very unlikely to result in a change of the
731      * features supported.
732      * @version DOM Level 3
733      */

734     public org.w3c.dom.DocumentType JavaDoc getDoctype() {
735         //TODO Implement later
736
return null;
737     }
738
739     /**
740      * The location of the document or <code>null</code> if undefined or if
741      * the <code>Document</code> was created using
742      * <code>DOMImplementation.createDocument</code>. No lexical checking is
743      * performed when setting this attribute; this could result in a
744      * <code>null</code> value returned when using <code>Node.baseURI</code>
745      * .
746      * <br> Beware that when the <code>Document</code> supports the feature
747      * "HTML" [<a HREF='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
748      * , the href attribute of the HTML BASE element takes precedence over
749      * this attribute when computing <code>Node.baseURI</code>.
750      * @since DOM Level 3
751      */

752     public void setDocumentURI(String JavaDoc documentURI) {
753     }
754
755     /**
756      * The location of the document or <code>null</code> if undefined or if
757      * the <code>Document</code> was created using
758      * <code>DOMImplementation.createDocument</code>. No lexical checking is
759      * performed when setting this attribute; this could result in a
760      * <code>null</code> value returned when using <code>Node.baseURI</code>
761      * .
762      * <br> Beware that when the <code>Document</code> supports the feature
763      * "HTML" [<a HREF='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
764      * , the href attribute of the HTML BASE element takes precedence over
765      * this attribute when computing <code>Node.baseURI</code>.
766      * @since DOM Level 3
767      */

768     public String JavaDoc getDocumentURI() {
769         //TODO Implement later
770
return null;
771     }
772
773     /**
774      * The configuration used when <code>Document.normalizeDocument()</code>
775      * is invoked.
776      * @since DOM Level 3
777      */

778     public org.w3c.dom.DOMConfiguration JavaDoc getDomConfig() {
779         //TODO Implement later
780
return null;
781     }
782
783     /**
784      * The <code>DOMImplementation</code> object that handles this document. A
785      * DOM application may use objects from multiple implementations.
786      */

787     public org.w3c.dom.DOMImplementation JavaDoc getImplementation() {
788         //TODO Implement later
789
return null;
790     }
791
792     /**
793      * An attribute specifying the encoding used for this document at the time
794      * of the parsing. This is <code>null</code> when it is not known, such
795      * as when the <code>Document</code> was created in memory.
796      * @since DOM Level 3
797      */

798     public String JavaDoc getInputEncoding() {
799         //TODO Implement later
800
return null;
801     }
802
803     /**
804      * An attribute specifying whether error checking is enforced or not. When
805      * set to <code>false</code>, the implementation is free to not test
806      * every possible error case normally defined on DOM operations, and not
807      * raise any <code>DOMException</code> on DOM operations or report
808      * errors while using <code>Document.normalizeDocument()</code>. In case
809      * of error, the behavior is undefined. This attribute is
810      * <code>true</code> by default.
811      * @since DOM Level 3
812      */

813     public void setStrictErrorChecking(boolean strictErrorChecking) {
814     }
815
816     /**
817      * An attribute specifying whether error checking is enforced or not. When
818      * set to <code>false</code>, the implementation is free to not test
819      * every possible error case normally defined on DOM operations, and not
820      * raise any <code>DOMException</code> on DOM operations or report
821      * errors while using <code>Document.normalizeDocument()</code>. In case
822      * of error, the behavior is undefined. This attribute is
823      * <code>true</code> by default.
824      * @since DOM Level 3
825      */

826     public boolean getStrictErrorChecking() {
827         //TODO Implement later
828
return false;
829     }
830
831     /**
832      * 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
833      * unspecified or when it is not known, such as when the
834      * <code>Document</code> was created in memory.
835      * @since DOM Level 3
836      */

837     public String JavaDoc getXmlEncoding() {
838         for (Token token : super.getTokens()) {
839             if(token.getType() == TokenType.TOKEN_PI_VAL) {
840                 String JavaDoc versionImage = token.getValue();
841                 int versionIndex = versionImage.indexOf("encoding");
842                 if(versionIndex == -1) return null;
843                 versionIndex = versionImage.indexOf('=',versionIndex);
844                 if(versionIndex == -1) return null;
845                 versionImage = versionImage.substring(versionIndex+1).trim();
846                 if(versionImage.startsWith("\"")) {
847                     int versionEndIndex = versionImage.indexOf('"',1);
848                     if(versionEndIndex == -1) return null;
849                     return versionImage.substring(1,versionEndIndex);
850                 } else if(versionImage.startsWith("'")) {
851                     int versionEndIndex = versionImage.indexOf('\'',1);
852                     if(versionEndIndex == -1) return null;
853                     return versionImage.substring(1,versionEndIndex);
854                 }
855             }
856         }
857         return null;
858     }
859
860     /**
861      * 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
862      * unspecified.
863      * <p ><b>Note:</b> No verification is done on the value when setting
864      * this attribute. Applications should use
865      * <code>Document.normalizeDocument()</code> with the "validate"
866      * parameter to verify if the value matches the <a HREF='http://www.w3.org/TR/2004/REC-xml-20040204#sec-rmd'>validity
867      * constraint for standalone document declaration</a> as defined in [<a HREF='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>].
868      * @exception DOMException
869      * NOT_SUPPORTED_ERR: Raised if this document does not support the
870      * "XML" feature.
871      * @since DOM Level 3
872      */

873     public void setXmlStandalone(boolean xmlStandalone) {
874         //TODO Implement later
875
}
876
877     /**
878      * 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
879      * unspecified.
880      * <p ><b>Note:</b> No verification is done on the value when setting
881      * this attribute. Applications should use
882      * <code>Document.normalizeDocument()</code> with the "validate"
883      * parameter to verify if the value matches the <a HREF='http://www.w3.org/TR/2004/REC-xml-20040204#sec-rmd'>validity
884      * constraint for standalone document declaration</a> as defined in [<a HREF='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>].
885      * @since DOM Level 3
886      */

887     public boolean getXmlStandalone() {
888         for (Token token : super.getTokens()) {
889             if(token.getType() == TokenType.TOKEN_PI_VAL) {
890                 String JavaDoc versionImage = token.getValue();
891                 int versionIndex = versionImage.indexOf("standalone");
892                 if(versionIndex == -1) return false;
893                 versionIndex = versionImage.indexOf('=',versionIndex);
894                 if(versionIndex == -1) return false;
895                 versionImage = versionImage.substring(versionIndex+1).trim();
896                 if(versionImage.startsWith("\"")) {
897                     int versionEndIndex = versionImage.indexOf('"',1);
898                     if(versionEndIndex == -1) return false;
899                     return versionImage.substring(1,versionEndIndex).equals("yes");
900                 } else if(versionImage.startsWith("'")) {
901                     int versionEndIndex = versionImage.indexOf('\'',1);
902                     if(versionEndIndex == -1) return false;
903                     return versionImage.substring(1,versionEndIndex).equals("yes");
904                 }
905             }
906         }
907         return false;
908     }
909
910     /**
911      * 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
912      * this document supports the "XML" feature, the value is
913      * <code>"1.0"</code>. If this document does not support the "XML"
914      * feature, the value is always <code>null</code>. Changing this
915      * attribute will affect methods that check for invalid characters in
916      * XML names. Application should invoke
917      * <code>Document.normalizeDocument()</code> in order to check for
918      * invalid characters in the <code>Node</code>s that are already part of
919      * this <code>Document</code>.
920      * <br> DOM applications may use the
921      * <code>DOMImplementation.hasFeature(feature, version)</code> method
922      * with parameter values "XMLVersion" and "1.0" (respectively) to
923      * determine if an implementation supports [<a HREF='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. DOM
924      * applications may use the same method with parameter values
925      * "XMLVersion" and "1.1" (respectively) to determine if an
926      * implementation supports [<a HREF='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. In both
927      * cases, in order to support XML, an implementation must also support
928      * the "XML" feature defined in this specification. <code>Document</code>
929      * objects supporting a version of the "XMLVersion" feature must not
930      * raise a <code>NOT_SUPPORTED_ERR</code> exception for the same version
931      * number when using <code>Document.xmlVersion</code>.
932      * @exception DOMException
933      * NOT_SUPPORTED_ERR: Raised if the version is set to a value that is
934      * not supported by this <code>Document</code> or if this document
935      * does not support the "XML" feature.
936      * @since DOM Level 3
937      */

938     public void setXmlVersion(String JavaDoc xmlVersion) {
939         //TODO Implement later
940
}
941
942     /**
943      * 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
944      * this document supports the "XML" feature, the value is
945      * <code>"1.0"</code>. If this document does not support the "XML"
946      * feature, the value is always <code>null</code>. Changing this
947      * attribute will affect methods that check for invalid characters in
948      * XML names. Application should invoke
949      * <code>Document.normalizeDocument()</code> in order to check for
950      * invalid characters in the <code>Node</code>s that are already part of
951      * this <code>Document</code>.
952      * <br> DOM applications may use the
953      * <code>DOMImplementation.hasFeature(feature, version)</code> method
954      * with parameter values "XMLVersion" and "1.0" (respectively) to
955      * determine if an implementation supports [<a HREF='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. DOM
956      * applications may use the same method with parameter values
957      * "XMLVersion" and "1.1" (respectively) to determine if an
958      * implementation supports [<a HREF='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. In both
959      * cases, in order to support XML, an implementation must also support
960      * the "XML" feature defined in this specification. <code>Document</code>
961      * objects supporting a version of the "XMLVersion" feature must not
962      * raise a <code>NOT_SUPPORTED_ERR</code> exception for the same version
963      * number when using <code>Document.xmlVersion</code>.
964      * @since DOM Level 3
965      */

966     public String JavaDoc getXmlVersion() {
967         for (Token token : super.getTokens()) {
968             if(token.getType() == TokenType.TOKEN_PI_VAL) {
969                 String JavaDoc versionImage = token.getValue();
970                 int versionIndex = versionImage.indexOf("version");
971                 if(versionIndex == -1) return null;
972                 versionIndex = versionImage.indexOf('=',versionIndex);
973                 if(versionIndex == -1) return null;
974                 versionImage = versionImage.substring(versionIndex+1).trim();
975                 if(versionImage.startsWith("\"")) {
976                     int versionEndIndex = versionImage.indexOf('"',1);
977                     if(versionEndIndex == -1) return null;
978                     return versionImage.substring(1,versionEndIndex);
979                 } else if(versionImage.startsWith("'")) {
980                     int versionEndIndex = versionImage.indexOf('\'',1);
981                     if(versionEndIndex == -1) return null;
982                     return versionImage.substring(1,versionEndIndex);
983                 }
984             }
985         }
986         return null;
987     }
988
989     /**
990      * This api returns the namespaceuri of specified node.
991      * @param node The node which namespace to find.
992      * @return The namespaceuri of given node.
993      */

994     public String JavaDoc getNamespaceURI(Node node) {
995         return getNamespaceCache().findNamespace(node);
996     }
997
998     private FindNamespaceVisitor getNamespaceCache() {
999         if (fnv == null || fnv.get() == null) {
1000            fnv = new SoftReference JavaDoc(new FindNamespaceVisitor(this));
1001        }
1002        return fnv.get();
1003    }
1004    
1005    Map JavaDoc<Integer JavaDoc,String JavaDoc> getNamespaceMap() {
1006        return getNamespaceCache().getNamespaceMap();
1007    }
1008    
1009    /**
1010     * Namespace finder visitor
1011     */

1012    private SoftReference JavaDoc<FindNamespaceVisitor> fnv;
1013}
1014
Popular Tags