001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.tax.dom;
043:
044: import java.util.Iterator;
045: import org.w3c.dom.*;
046: import org.netbeans.tax.*;
047: import org.netbeans.tax.TreeObjectList;
048:
049: /**
050: *
051: * @author Petr Kuzel
052: */
053: class DocumentImpl extends NodeImpl implements Document {
054:
055: private final TreeDocumentRoot peer;
056:
057: /** Creates a new instance of AttrImpl */
058: public DocumentImpl(TreeDocumentRoot peer) {
059: this .peer = peer;
060: }
061:
062: /** Creates an <code>Attr</code> of the given name. Note that the
063: * <code>Attr</code> instance can then be set on an <code>Element</code>
064: * using the <code>setAttributeNode</code> method.
065: * <br>To create an attribute with a qualified name and namespace URI, use
066: * the <code>createAttributeNS</code> method.
067: * @param name The name of the attribute.
068: * @return A new <code>Attr</code> object with the <code>nodeName</code>
069: * attribute set to <code>name</code>, and <code>localName</code>,
070: * <code>prefix</code>, and <code>namespaceURI</code> set to
071: * <code>null</code>. The value of the attribute is the empty string.
072: * @exception DOMException
073: * INVALID_CHARACTER_ERR: Raised if the specified name contains an
074: * illegal character.
075: *
076: */
077: public Attr createAttribute(String name) throws DOMException {
078: throw new ROException();
079: }
080:
081: /** Creates an attribute of the given qualified name and namespace URI.
082: * @param namespaceURI The namespace URI of the attribute to create.
083: * @param qualifiedName The qualified name of the attribute to
084: * instantiate.
085: * @return A new <code>Attr</code> object with the following attributes:
086: * <table border='1'>
087: * <tr>
088: * <th>
089: * Attribute</th>
090: * <th>Value</th>
091: * </tr>
092: * <tr>
093: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
094: * <td valign='top' rowspan='1' colspan='1'>qualifiedName</td>
095: * </tr>
096: * <tr>
097: * <td valign='top' rowspan='1' colspan='1'>
098: * <code>Node.namespaceURI</code></td>
099: * <td valign='top' rowspan='1' colspan='1'><code>namespaceURI</code></td>
100: * </tr>
101: * <tr>
102: * <td valign='top' rowspan='1' colspan='1'>
103: * <code>Node.prefix</code></td>
104: * <td valign='top' rowspan='1' colspan='1'>prefix, extracted from
105: * <code>qualifiedName</code>, or <code>null</code> if there is no
106: * prefix</td>
107: * </tr>
108: * <tr>
109: * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
110: * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
111: * <code>qualifiedName</code></td>
112: * </tr>
113: * <tr>
114: * <td valign='top' rowspan='1' colspan='1'><code>Attr.name</code></td>
115: * <td valign='top' rowspan='1' colspan='1'>
116: * <code>qualifiedName</code></td>
117: * </tr>
118: * <tr>
119: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeValue</code></td>
120: * <td valign='top' rowspan='1' colspan='1'>the empty
121: * string</td>
122: * </tr>
123: * </table>
124: * @exception DOMException
125: * INVALID_CHARACTER_ERR: Raised if the specified qualified name
126: * contains an illegal character, per the XML 1.0 specification .
127: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
128: * malformed per the Namespaces in XML specification, if the
129: * <code>qualifiedName</code> has a prefix and the
130: * <code>namespaceURI</code> is <code>null</code>, if the
131: * <code>qualifiedName</code> has a prefix that is "xml" and the
132: * <code>namespaceURI</code> is different from "
133: * http://www.w3.org/XML/1998/namespace", or if the
134: * <code>qualifiedName</code>, or its prefix, is "xmlns" and the
135: * <code>namespaceURI</code> is different from "
136: * http://www.w3.org/2000/xmlns/".
137: * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
138: * support the <code>"XML"</code> feature, since namespaces were
139: * defined by XML.
140: * @since DOM Level 2
141: *
142: */
143: public Attr createAttributeNS(String namespaceURI,
144: String qualifiedName) throws DOMException {
145: throw new ROException();
146: }
147:
148: /** Creates a <code>CDATASection</code> node whose value is the specified
149: * string.
150: * @param data The data for the <code>CDATASection</code> contents.
151: * @return The new <code>CDATASection</code> object.
152: * @exception DOMException
153: * NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
154: *
155: */
156: public CDATASection createCDATASection(String data)
157: throws DOMException {
158: throw new ROException();
159: }
160:
161: /** Creates a <code>Comment</code> node given the specified string.
162: * @param data The data for the node.
163: * @return The new <code>Comment</code> object.
164: *
165: */
166: public Comment createComment(String data) {
167: throw new ROException();
168: }
169:
170: /** Creates an empty <code>DocumentFragment</code> object.
171: * @return A new <code>DocumentFragment</code>.
172: *
173: */
174: public DocumentFragment createDocumentFragment() {
175: throw new ROException();
176: }
177:
178: /** Creates an element of the type specified. Note that the instance
179: * returned implements the <code>Element</code> interface, so attributes
180: * can be specified directly on the returned object.
181: * <br>In addition, if there are known attributes with default values,
182: * <code>Attr</code> nodes representing them are automatically created
183: * and attached to the element.
184: * <br>To create an element with a qualified name and namespace URI, use
185: * the <code>createElementNS</code> method.
186: * @param tagName The name of the element type to instantiate. For XML,
187: * this is case-sensitive. For HTML, the <code>tagName</code>
188: * parameter may be provided in any case, but it must be mapped to the
189: * canonical uppercase form by the DOM implementation.
190: * @return A new <code>Element</code> object with the
191: * <code>nodeName</code> attribute set to <code>tagName</code>, and
192: * <code>localName</code>, <code>prefix</code>, and
193: * <code>namespaceURI</code> set to <code>null</code>.
194: * @exception DOMException
195: * INVALID_CHARACTER_ERR: Raised if the specified name contains an
196: * illegal character.
197: *
198: */
199: public Element createElement(String tagName) throws DOMException {
200: throw new ROException();
201: }
202:
203: /** Creates an element of the given qualified name and namespace URI.
204: * @param namespaceURI The namespace URI of the element to create.
205: * @param qualifiedName The qualified name of the element type to
206: * instantiate.
207: * @return A new <code>Element</code> object with the following
208: * attributes:
209: * <table border='1'>
210: * <tr>
211: * <th>Attribute</th>
212: * <th>Value</th>
213: * </tr>
214: * <tr>
215: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
216: * <td valign='top' rowspan='1' colspan='1'>
217: * <code>qualifiedName</code></td>
218: * </tr>
219: * <tr>
220: * <td valign='top' rowspan='1' colspan='1'><code>Node.namespaceURI</code></td>
221: * <td valign='top' rowspan='1' colspan='1'>
222: * <code>namespaceURI</code></td>
223: * </tr>
224: * <tr>
225: * <td valign='top' rowspan='1' colspan='1'><code>Node.prefix</code></td>
226: * <td valign='top' rowspan='1' colspan='1'>prefix, extracted
227: * from <code>qualifiedName</code>, or <code>null</code> if there is
228: * no prefix</td>
229: * </tr>
230: * <tr>
231: * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
232: * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
233: * <code>qualifiedName</code></td>
234: * </tr>
235: * <tr>
236: * <td valign='top' rowspan='1' colspan='1'><code>Element.tagName</code></td>
237: * <td valign='top' rowspan='1' colspan='1'>
238: * <code>qualifiedName</code></td>
239: * </tr>
240: * </table>
241: * @exception DOMException
242: * INVALID_CHARACTER_ERR: Raised if the specified qualified name
243: * contains an illegal character, per the XML 1.0 specification .
244: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
245: * malformed per the Namespaces in XML specification, if the
246: * <code>qualifiedName</code> has a prefix and the
247: * <code>namespaceURI</code> is <code>null</code>, or if the
248: * <code>qualifiedName</code> has a prefix that is "xml" and the
249: * <code>namespaceURI</code> is different from "
250: * http://www.w3.org/XML/1998/namespace" .
251: * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
252: * support the <code>"XML"</code> feature, since namespaces were
253: * defined by XML.
254: * @since DOM Level 2
255: *
256: */
257: public Element createElementNS(String namespaceURI,
258: String qualifiedName) throws DOMException {
259: throw new ROException();
260: }
261:
262: /** Creates an <code>EntityReference</code> object. In addition, if the
263: * referenced entity is known, the child list of the
264: * <code>EntityReference</code> node is made the same as that of the
265: * corresponding <code>Entity</code> node.If any descendant of the
266: * <code>Entity</code> node has an unbound namespace prefix, the
267: * corresponding descendant of the created <code>EntityReference</code>
268: * node is also unbound; (its <code>namespaceURI</code> is
269: * <code>null</code>). The DOM Level 2 does not support any mechanism to
270: * resolve namespace prefixes.
271: * @param name The name of the entity to reference.
272: * @return The new <code>EntityReference</code> object.
273: * @exception DOMException
274: * INVALID_CHARACTER_ERR: Raised if the specified name contains an
275: * illegal character.
276: * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
277: *
278: */
279: public EntityReference createEntityReference(String name)
280: throws DOMException {
281: throw new ROException();
282: }
283:
284: /** Creates a <code>ProcessingInstruction</code> node given the specified
285: * name and data strings.
286: * @param target The target part of the processing instruction.
287: * @param data The data for the node.
288: * @return The new <code>ProcessingInstruction</code> object.
289: * @exception DOMException
290: * INVALID_CHARACTER_ERR: Raised if the specified target contains an
291: * illegal character.
292: * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
293: *
294: */
295: public ProcessingInstruction createProcessingInstruction(
296: String target, String data) throws DOMException {
297: throw new ROException();
298: }
299:
300: /** Creates a <code>Text</code> node given the specified string.
301: * @param data The data for the node.
302: * @return The new <code>Text</code> object.
303: *
304: */
305: public Text createTextNode(String data) {
306: throw new ROException();
307: }
308:
309: /** The Document Type Declaration (see <code>DocumentType</code>)
310: * associated with this document. For HTML documents as well as XML
311: * documents without a document type declaration this returns
312: * <code>null</code>. The DOM Level 2 does not support editing the
313: * Document Type Declaration. <code>docType</code> cannot be altered in
314: * any way, including through the use of methods inherited from the
315: * <code>Node</code> interface, such as <code>insertNode</code> or
316: * <code>removeNode</code>.
317: *
318: */
319: public DocumentType getDoctype() {
320: return null; //!!!
321: }
322:
323: /** This is a convenience attribute that allows direct access to the child
324: * node that is the root element of the document. For HTML documents,
325: * this is the element with the tagName "HTML".
326: *
327: */
328: public Element getDocumentElement() {
329: Iterator it = peer.getChildNodes().iterator();
330: while (it.hasNext()) {
331: Object next = it.next();
332: if (next instanceof TreeElement) {
333: return Wrapper.wrap((TreeElement) next);
334: }
335: }
336: return null;
337: }
338:
339: /** Returns the <code>Element</code> whose <code>ID</code> is given by
340: * <code>elementId</code>. If no such element exists, returns
341: * <code>null</code>. Behavior is not defined if more than one element
342: * has this <code>ID</code>. The DOM implementation must have
343: * information that says which attributes are of type ID. Attributes
344: * with the name "ID" are not of type ID unless so defined.
345: * Implementations that do not know whether attributes are of type ID or
346: * not are expected to return <code>null</code>.
347: * @param elementId The unique <code>id</code> value for an element.
348: * @return The matching element.
349: * @since DOM Level 2
350: *
351: */
352: public Element getElementById(String elementId) {
353: throw new UOException();
354: }
355:
356: /** Returns a <code>NodeList</code> of all the <code>Elements</code> with a
357: * given tag name in the order in which they are encountered in a
358: * preorder traversal of the <code>Document</code> tree.
359: * @param tagname The name of the tag to match on. The special value "*"
360: * matches all tags.
361: * @return A new <code>NodeList</code> object containing all the matched
362: * <code>Elements</code>.
363: *
364: */
365: public NodeList getElementsByTagName(String tagname) {
366: throw new UOException(); //???
367: }
368:
369: /** Returns a <code>NodeList</code> of all the <code>Elements</code> with a
370: * given local name and namespace URI in the order in which they are
371: * encountered in a preorder traversal of the <code>Document</code> tree.
372: * @param namespaceURI The namespace URI of the elements to match on. The
373: * special value "*" matches all namespaces.
374: * @param localName The local name of the elements to match on. The
375: * special value "*" matches all local names.
376: * @return A new <code>NodeList</code> object containing all the matched
377: * <code>Elements</code>.
378: * @since DOM Level 2
379: *
380: */
381: public NodeList getElementsByTagNameNS(String namespaceURI,
382: String localName) {
383: throw new UOException();
384: }
385:
386: /** The <code>DOMImplementation</code> object that handles this document. A
387: * DOM application may use objects from multiple implementations.
388: *
389: */
390: public DOMImplementation getImplementation() {
391: return new DOMImplementationImpl();
392: }
393:
394: /** The name of this node, depending on its type; see the table above.
395: *
396: */
397: public String getNodeName() {
398: return "#document";
399: }
400:
401: /** A code representing the type of the underlying object, as defined above.
402: *
403: */
404: public short getNodeType() {
405: return Node.DOCUMENT_NODE;
406: }
407:
408: /** The value of this node, depending on its type; see the table above.
409: * When it is defined to be <code>null</code>, setting it has no effect.
410: * @exception DOMException
411: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
412: * @exception DOMException
413: * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
414: * fit in a <code>DOMString</code> variable on the implementation
415: * platform.
416: *
417: */
418: public String getNodeValue() throws DOMException {
419: return null;
420: }
421:
422: /** The parent of this node. All nodes, except <code>Attr</code>,
423: * <code>Document</code>, <code>DocumentFragment</code>,
424: * <code>Entity</code>, and <code>Notation</code> may have a parent.
425: * However, if a node has just been created and not yet added to the
426: * tree, or if it has been removed from the tree, this is
427: * <code>null</code>.
428: *
429: */
430: public Node getParentNode() {
431: return null;
432: }
433:
434: /** Imports a node from another document to this document. The returned
435: * node has no parent; (<code>parentNode</code> is <code>null</code>).
436: * The source node is not altered or removed from the original document;
437: * this method creates a new copy of the source node.
438: * <br>For all nodes, importing a node creates a node object owned by the
439: * importing document, with attribute values identical to the source
440: * node's <code>nodeName</code> and <code>nodeType</code>, plus the
441: * attributes related to namespaces (<code>prefix</code>,
442: * <code>localName</code>, and <code>namespaceURI</code>). As in the
443: * <code>cloneNode</code> operation on a <code>Node</code>, the source
444: * node is not altered.
445: * <br>Additional information is copied as appropriate to the
446: * <code>nodeType</code>, attempting to mirror the behavior expected if
447: * a fragment of XML or HTML source was copied from one document to
448: * another, recognizing that the two documents may have different DTDs
449: * in the XML case. The following list describes the specifics for each
450: * type of node.
451: * <dl>
452: * <dt>ATTRIBUTE_NODE</dt>
453: * <dd>The <code>ownerElement</code> attribute
454: * is set to <code>null</code> and the <code>specified</code> flag is
455: * set to <code>true</code> on the generated <code>Attr</code>. The
456: * descendants of the source <code>Attr</code> are recursively imported
457: * and the resulting nodes reassembled to form the corresponding subtree.
458: * Note that the <code>deep</code> parameter has no effect on
459: * <code>Attr</code> nodes; they always carry their children with them
460: * when imported.</dd>
461: * <dt>DOCUMENT_FRAGMENT_NODE</dt>
462: * <dd>If the <code>deep</code> option
463: * was set to <code>true</code>, the descendants of the source element
464: * are recursively imported and the resulting nodes reassembled to form
465: * the corresponding subtree. Otherwise, this simply generates an empty
466: * <code>DocumentFragment</code>.</dd>
467: * <dt>DOCUMENT_NODE</dt>
468: * <dd><code>Document</code>
469: * nodes cannot be imported.</dd>
470: * <dt>DOCUMENT_TYPE_NODE</dt>
471: * <dd><code>DocumentType</code>
472: * nodes cannot be imported.</dd>
473: * <dt>ELEMENT_NODE</dt>
474: * <dd>Specified attribute nodes of the
475: * source element are imported, and the generated <code>Attr</code>
476: * nodes are attached to the generated <code>Element</code>. Default
477: * attributes are not copied, though if the document being imported into
478: * defines default attributes for this element name, those are assigned.
479: * If the <code>importNode</code> <code>deep</code> parameter was set to
480: * <code>true</code>, the descendants of the source element are
481: * recursively imported and the resulting nodes reassembled to form the
482: * corresponding subtree.</dd>
483: * <dt>ENTITY_NODE</dt>
484: * <dd><code>Entity</code> nodes can be
485: * imported, however in the current release of the DOM the
486: * <code>DocumentType</code> is readonly. Ability to add these imported
487: * nodes to a <code>DocumentType</code> will be considered for addition
488: * to a future release of the DOM.On import, the <code>publicId</code>,
489: * <code>systemId</code>, and <code>notationName</code> attributes are
490: * copied. If a <code>deep</code> import is requested, the descendants
491: * of the the source <code>Entity</code> are recursively imported and
492: * the resulting nodes reassembled to form the corresponding subtree.</dd>
493: * <dt>
494: * ENTITY_REFERENCE_NODE</dt>
495: * <dd>Only the <code>EntityReference</code> itself is
496: * copied, even if a <code>deep</code> import is requested, since the
497: * source and destination documents might have defined the entity
498: * differently. If the document being imported into provides a
499: * definition for this entity name, its value is assigned.</dd>
500: * <dt>NOTATION_NODE</dt>
501: * <dd>
502: * <code>Notation</code> nodes can be imported, however in the current
503: * release of the DOM the <code>DocumentType</code> is readonly. Ability
504: * to add these imported nodes to a <code>DocumentType</code> will be
505: * considered for addition to a future release of the DOM.On import, the
506: * <code>publicId</code> and <code>systemId</code> attributes are copied.
507: * Note that the <code>deep</code> parameter has no effect on
508: * <code>Notation</code> nodes since they never have any children.</dd>
509: * <dt>
510: * PROCESSING_INSTRUCTION_NODE</dt>
511: * <dd>The imported node copies its
512: * <code>target</code> and <code>data</code> values from those of the
513: * source node.</dd>
514: * <dt>TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE</dt>
515: * <dd>These three
516: * types of nodes inheriting from <code>CharacterData</code> copy their
517: * <code>data</code> and <code>length</code> attributes from those of
518: * the source node.</dd>
519: * </dl>
520: * @param importedNode The node to import.
521: * @param deep If <code>true</code>, recursively import the subtree under
522: * the specified node; if <code>false</code>, import only the node
523: * itself, as explained above. This has no effect on <code>Attr</code>
524: * , <code>EntityReference</code>, and <code>Notation</code> nodes.
525: * @return The imported node that belongs to this <code>Document</code>.
526: * @exception DOMException
527: * NOT_SUPPORTED_ERR: Raised if the type of node being imported is not
528: * supported.
529: * @since DOM Level 2
530: *
531: */
532: public Node importNode(Node importedNode, boolean deep)
533: throws DOMException {
534: throw new UOException();
535: }
536:
537: /** The first child of this node. If there is no such node, this returns
538: * <code>null</code>.
539: *
540: */
541: public Node getFirstChild() {
542: return getDocumentElement();
543: }
544:
545: /** The last child of this node. If there is no such node, this returns
546: * <code>null</code>.
547: *
548: */
549: public Node getLastChild() {
550: return getDocumentElement();
551: }
552:
553: /** Returns whether this node has any children.
554: * @return <code>true</code> if this node has any children,
555: * <code>false</code> otherwise.
556: *
557: */
558: public boolean hasChildNodes() {
559: return getDocumentElement() != null;
560: }
561:
562: /** A <code>NodeList</code> that contains all children of this node. If
563: * there are no children, this is a <code>NodeList</code> containing no
564: * nodes.
565: *
566: */
567: public NodeList getChildNodes() {
568: return Wrapper.wrap(peer.getChildNodes());
569: }
570:
571: //
572: // Dom Level 3 methods:
573: //
574:
575: public Node adoptNode(Node a) {
576: throw new UOException();
577: }
578:
579: public String getDocumentURI() {
580: throw new UOException();
581: }
582:
583: public DOMConfiguration getDomConfig() {
584: throw new UOException();
585: }
586:
587: public String getInputEncoding() {
588: throw new UOException();
589: }
590:
591: public boolean getStrictErrorChecking() {
592: throw new UOException();
593: }
594:
595: public String getXmlEncoding() {
596: throw new UOException();
597: }
598:
599: public boolean getXmlStandalone() {
600: throw new UOException();
601: }
602:
603: public String getXmlVersion() {
604: throw new UOException();
605: }
606:
607: public void normalizeDocument() {
608: throw new UOException();
609: }
610:
611: public Node renameNode(Node a, String nb, String c) {
612: throw new UOException();
613: }
614:
615: public void setDocumentURI(String a) {
616: throw new UOException();
617: }
618:
619: public void setStrictErrorChecking(boolean a) {
620: throw new UOException();
621: }
622:
623: public void setXmlStandalone(boolean a) {
624: throw new UOException();
625: }
626:
627: public void setXmlVersion(String a) {
628: throw new UOException();
629: }
630: }
|