0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017: package org.apache.cocoon.xml.dom;
0018:
0019: import org.apache.cocoon.ProcessingException;
0020: import org.apache.cocoon.xml.XMLUtils;
0021:
0022: import org.apache.excalibur.xml.sax.XMLizable;
0023:
0024: import org.w3c.dom.Attr;
0025: import org.w3c.dom.CDATASection;
0026: import org.w3c.dom.Comment;
0027: import org.w3c.dom.DOMConfiguration;
0028: import org.w3c.dom.DOMException;
0029: import org.w3c.dom.DOMImplementation;
0030: import org.w3c.dom.Document;
0031: import org.w3c.dom.DocumentFragment;
0032: import org.w3c.dom.DocumentType;
0033: import org.w3c.dom.Element;
0034: import org.w3c.dom.EntityReference;
0035: import org.w3c.dom.NamedNodeMap;
0036: import org.w3c.dom.Node;
0037: import org.w3c.dom.NodeList;
0038: import org.w3c.dom.ProcessingInstruction;
0039: import org.w3c.dom.Text;
0040: import org.w3c.dom.UserDataHandler;
0041: import org.xml.sax.SAXException;
0042:
0043: /**
0044: * Wraps an org.w3c.dom.Document and offers additional interfaces
0045: * like XMLizable and a toString() method.
0046: *
0047: * @author <a href="mailto:haul@apache.org">Christian Haul</a>
0048: * @version CVS $Id: DocumentWrapper.java 433543 2006-08-22 06:22:54Z crossley $
0049: */
0050: public class DocumentWrapper implements org.w3c.dom.Document, XMLizable {
0051:
0052: protected final static String DOMLEVEL3_ERR_MSG = "This method was just added for providing future compatibility to JDK 1.5's DOM level 3 Document interface.";
0053:
0054: protected final Document document;
0055:
0056: /** Creates a new instance of DocmentWrapper */
0057: public DocumentWrapper(Document doc) {
0058: this .document = doc;
0059: }
0060:
0061: /**
0062: * Generates SAX events representing the object's state.<br/>
0063: * <b>NOTE</b> : if the implementation can produce lexical events,
0064: * care should be taken that <code>handler</code> can actually be
0065: * a {@link org.apache.cocoon.xml.XMLConsumer} that accepts such
0066: * events.
0067: */
0068: public void toSAX(org.xml.sax.ContentHandler handler)
0069: throws SAXException {
0070:
0071: DOMStreamer ds = new DOMStreamer(handler);
0072: ds.stream(this .document.getDocumentElement());
0073: }
0074:
0075: public String toString() {
0076: try {
0077: return XMLUtils.serializeNode(this .document, XMLUtils
0078: .createPropertiesForXML(false));
0079: } catch (ProcessingException e) {
0080: }
0081: return "";
0082: }
0083:
0084: /** Adds the node <code>newChild</code> to the end of the list of children
0085: * of this node. If the <code>newChild</code> is already in the tree, it
0086: * is first removed.
0087: * @param newChild The node to add.If it is a
0088: * <code>DocumentFragment</code> object, the entire contents of the
0089: * document fragment are moved into the child list of this node
0090: * @return The node added.
0091: * @exception DOMException
0092: * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
0093: * allow children of the type of the <code>newChild</code> node, or if
0094: * the node to append is one of this node's ancestors or this node
0095: * itself.
0096: * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
0097: * from a different document than the one that created this node.
0098: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or
0099: * if the previous parent of the node being inserted is readonly.
0100: *
0101: */
0102: public Node appendChild(Node newChild) throws DOMException {
0103: return this .document.appendChild(newChild);
0104: }
0105:
0106: /** Returns a duplicate of this node, i.e., serves as a generic copy
0107: * constructor for nodes. The duplicate node has no parent; (
0108: * <code>parentNode</code> is <code>null</code>.).
0109: * <br>Cloning an <code>Element</code> copies all attributes and their
0110: * values, including those generated by the XML processor to represent
0111: * defaulted attributes, but this method does not copy any text it
0112: * contains unless it is a deep clone, since the text is contained in a
0113: * child <code>Text</code> node. Cloning an <code>Attribute</code>
0114: * directly, as opposed to be cloned as part of an <code>Element</code>
0115: * cloning operation, returns a specified attribute (
0116: * <code>specified</code> is <code>true</code>). Cloning any other type
0117: * of node simply returns a copy of this node.
0118: * <br>Note that cloning an immutable subtree results in a mutable copy,
0119: * but the children of an <code>EntityReference</code> clone are readonly
0120: * . In addition, clones of unspecified <code>Attr</code> nodes are
0121: * specified. And, cloning <code>Document</code>,
0122: * <code>DocumentType</code>, <code>Entity</code>, and
0123: * <code>Notation</code> nodes is implementation dependent.
0124: * @param deep If <code>true</code>, recursively clone the subtree under
0125: * the specified node; if <code>false</code>, clone only the node
0126: * itself (and its attributes, if it is an <code>Element</code>).
0127: * @return The duplicate node.
0128: *
0129: */
0130: public Node cloneNode(boolean deep) {
0131: return this .document.cloneNode(deep);
0132: }
0133:
0134: /** Creates an <code>Attr</code> of the given name. Note that the
0135: * <code>Attr</code> instance can then be set on an <code>Element</code>
0136: * using the <code>setAttributeNode</code> method.
0137: * <br>To create an attribute with a qualified name and namespace URI, use
0138: * the <code>createAttributeNS</code> method.
0139: * @param name The name of the attribute.
0140: * @return A new <code>Attr</code> object with the <code>nodeName</code>
0141: * attribute set to <code>name</code>, and <code>localName</code>,
0142: * <code>prefix</code>, and <code>namespaceURI</code> set to
0143: * <code>null</code>. The value of the attribute is the empty string.
0144: * @exception DOMException
0145: * INVALID_CHARACTER_ERR: Raised if the specified name contains an
0146: * illegal character.
0147: *
0148: */
0149: public Attr createAttribute(String name) throws DOMException {
0150: return this .document.createAttribute(name);
0151: }
0152:
0153: /** Creates an attribute of the given qualified name and namespace URI.
0154: * @param namespaceURI The namespace URI of the attribute to create.
0155: * @param qualifiedName The qualified name of the attribute to
0156: * instantiate.
0157: * @return A new <code>Attr</code> object with the following attributes:
0158: * <table border='1'>
0159: * <tr>
0160: * <th>
0161: * Attribute</th>
0162: * <th>Value</th>
0163: * </tr>
0164: * <tr>
0165: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
0166: * <td valign='top' rowspan='1' colspan='1'>qualifiedName</td>
0167: * </tr>
0168: * <tr>
0169: * <td valign='top' rowspan='1' colspan='1'>
0170: * <code>Node.namespaceURI</code></td>
0171: * <td valign='top' rowspan='1' colspan='1'><code>namespaceURI</code></td>
0172: * </tr>
0173: * <tr>
0174: * <td valign='top' rowspan='1' colspan='1'>
0175: * <code>Node.prefix</code></td>
0176: * <td valign='top' rowspan='1' colspan='1'>prefix, extracted from
0177: * <code>qualifiedName</code>, or <code>null</code> if there is no
0178: * prefix</td>
0179: * </tr>
0180: * <tr>
0181: * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
0182: * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
0183: * <code>qualifiedName</code></td>
0184: * </tr>
0185: * <tr>
0186: * <td valign='top' rowspan='1' colspan='1'><code>Attr.name</code></td>
0187: * <td valign='top' rowspan='1' colspan='1'>
0188: * <code>qualifiedName</code></td>
0189: * </tr>
0190: * <tr>
0191: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeValue</code></td>
0192: * <td valign='top' rowspan='1' colspan='1'>the empty
0193: * string</td>
0194: * </tr>
0195: * </table>
0196: * @exception DOMException
0197: * INVALID_CHARACTER_ERR: Raised if the specified qualified name
0198: * contains an illegal character, per the XML 1.0 specification .
0199: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
0200: * malformed per the Namespaces in XML specification, if the
0201: * <code>qualifiedName</code> has a prefix and the
0202: * <code>namespaceURI</code> is <code>null</code>, if the
0203: * <code>qualifiedName</code> has a prefix that is "xml" and the
0204: * <code>namespaceURI</code> is different from "
0205: * http://www.w3.org/XML/1998/namespace", or if the
0206: * <code>qualifiedName</code>, or its prefix, is "xmlns" and the
0207: * <code>namespaceURI</code> is different from "
0208: * http://www.w3.org/2000/xmlns/".
0209: * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
0210: * support the <code>"XML"</code> feature, since namespaces were
0211: * defined by XML.
0212: * @since DOM Level 2
0213: *
0214: */
0215: public Attr createAttributeNS(String namespaceURI,
0216: String qualifiedName) throws DOMException {
0217: return this .document.createAttributeNS(namespaceURI,
0218: qualifiedName);
0219: }
0220:
0221: /** Creates a <code>CDATASection</code> node whose value is the specified
0222: * string.
0223: * @param data The data for the <code>CDATASection</code> contents.
0224: * @return The new <code>CDATASection</code> object.
0225: * @exception DOMException
0226: * NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
0227: *
0228: */
0229: public CDATASection createCDATASection(String data)
0230: throws DOMException {
0231: return this .document.createCDATASection(data);
0232: }
0233:
0234: /** Creates a <code>Comment</code> node given the specified string.
0235: * @param data The data for the node.
0236: * @return The new <code>Comment</code> object.
0237: *
0238: */
0239: public Comment createComment(String data) {
0240: return this .document.createComment(data);
0241: }
0242:
0243: /** Creates an empty <code>DocumentFragment</code> object.
0244: * @return A new <code>DocumentFragment</code>.
0245: *
0246: */
0247: public DocumentFragment createDocumentFragment() {
0248: return this .document.createDocumentFragment();
0249: }
0250:
0251: /** Creates an element of the type specified. Note that the instance
0252: * returned implements the <code>Element</code> interface, so attributes
0253: * can be specified directly on the returned object.
0254: * <br>In addition, if there are known attributes with default values,
0255: * <code>Attr</code> nodes representing them are automatically created
0256: * and attached to the element.
0257: * <br>To create an element with a qualified name and namespace URI, use
0258: * the <code>createElementNS</code> method.
0259: * @param tagName The name of the element type to instantiate. For XML,
0260: * this is case-sensitive. For HTML, the <code>tagName</code>
0261: * parameter may be provided in any case, but it must be mapped to the
0262: * canonical uppercase form by the DOM implementation.
0263: * @return A new <code>Element</code> object with the
0264: * <code>nodeName</code> attribute set to <code>tagName</code>, and
0265: * <code>localName</code>, <code>prefix</code>, and
0266: * <code>namespaceURI</code> set to <code>null</code>.
0267: * @exception DOMException
0268: * INVALID_CHARACTER_ERR: Raised if the specified name contains an
0269: * illegal character.
0270: *
0271: */
0272: public Element createElement(String tagName) throws DOMException {
0273: return this .document.createElement(tagName);
0274: }
0275:
0276: /** Creates an element of the given qualified name and namespace URI.
0277: * @param namespaceURI The namespace URI of the element to create.
0278: * @param qualifiedName The qualified name of the element type to
0279: * instantiate.
0280: * @return A new <code>Element</code> object with the following
0281: * attributes:
0282: * <table border='1'>
0283: * <tr>
0284: * <th>Attribute</th>
0285: * <th>Value</th>
0286: * </tr>
0287: * <tr>
0288: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
0289: * <td valign='top' rowspan='1' colspan='1'>
0290: * <code>qualifiedName</code></td>
0291: * </tr>
0292: * <tr>
0293: * <td valign='top' rowspan='1' colspan='1'><code>Node.namespaceURI</code></td>
0294: * <td valign='top' rowspan='1' colspan='1'>
0295: * <code>namespaceURI</code></td>
0296: * </tr>
0297: * <tr>
0298: * <td valign='top' rowspan='1' colspan='1'><code>Node.prefix</code></td>
0299: * <td valign='top' rowspan='1' colspan='1'>prefix, extracted
0300: * from <code>qualifiedName</code>, or <code>null</code> if there is
0301: * no prefix</td>
0302: * </tr>
0303: * <tr>
0304: * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
0305: * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
0306: * <code>qualifiedName</code></td>
0307: * </tr>
0308: * <tr>
0309: * <td valign='top' rowspan='1' colspan='1'><code>Element.tagName</code></td>
0310: * <td valign='top' rowspan='1' colspan='1'>
0311: * <code>qualifiedName</code></td>
0312: * </tr>
0313: * </table>
0314: * @exception DOMException
0315: * INVALID_CHARACTER_ERR: Raised if the specified qualified name
0316: * contains an illegal character, per the XML 1.0 specification .
0317: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is
0318: * malformed per the Namespaces in XML specification, if the
0319: * <code>qualifiedName</code> has a prefix and the
0320: * <code>namespaceURI</code> is <code>null</code>, or if the
0321: * <code>qualifiedName</code> has a prefix that is "xml" and the
0322: * <code>namespaceURI</code> is different from "
0323: * http://www.w3.org/XML/1998/namespace" .
0324: * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
0325: * support the <code>"XML"</code> feature, since namespaces were
0326: * defined by XML.
0327: * @since DOM Level 2
0328: *
0329: */
0330: public Element createElementNS(String namespaceURI,
0331: String qualifiedName) throws DOMException {
0332: return this .document.createElementNS(namespaceURI,
0333: qualifiedName);
0334: }
0335:
0336: /** Creates an <code>EntityReference</code> object. In addition, if the
0337: * referenced entity is known, the child list of the
0338: * <code>EntityReference</code> node is made the same as that of the
0339: * corresponding <code>Entity</code> node.If any descendant of the
0340: * <code>Entity</code> node has an unbound namespace prefix, the
0341: * corresponding descendant of the created <code>EntityReference</code>
0342: * node is also unbound; (its <code>namespaceURI</code> is
0343: * <code>null</code>). The DOM Level 2 does not support any mechanism to
0344: * resolve namespace prefixes.
0345: * @param name The name of the entity to reference.
0346: * @return The new <code>EntityReference</code> object.
0347: * @exception DOMException
0348: * INVALID_CHARACTER_ERR: Raised if the specified name contains an
0349: * illegal character.
0350: * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
0351: *
0352: */
0353: public EntityReference createEntityReference(String name)
0354: throws DOMException {
0355: return this .document.createEntityReference(name);
0356: }
0357:
0358: /** Creates a <code>ProcessingInstruction</code> node given the specified
0359: * name and data strings.
0360: * @param target The target part of the processing instruction.
0361: * @param data The data for the node.
0362: * @return The new <code>ProcessingInstruction</code> object.
0363: * @exception DOMException
0364: * INVALID_CHARACTER_ERR: Raised if the specified target contains an
0365: * illegal character.
0366: * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
0367: *
0368: */
0369: public ProcessingInstruction createProcessingInstruction(
0370: String target, String data) throws DOMException {
0371: return this .document.createProcessingInstruction(target, data);
0372: }
0373:
0374: /** Creates a <code>Text</code> node given the specified string.
0375: * @param data The data for the node.
0376: * @return The new <code>Text</code> object.
0377: *
0378: */
0379: public Text createTextNode(String data) {
0380: return this .document.createTextNode(data);
0381: }
0382:
0383: /** A <code>NamedNodeMap</code> containing the attributes of this node (if
0384: * it is an <code>Element</code>) or <code>null</code> otherwise.
0385: *
0386: */
0387: public NamedNodeMap getAttributes() {
0388: return this .document.getAttributes();
0389: }
0390:
0391: /** A <code>NodeList</code> that contains all children of this node. If
0392: * there are no children, this is a <code>NodeList</code> containing no
0393: * nodes.
0394: *
0395: */
0396: public NodeList getChildNodes() {
0397: return this .document.getChildNodes();
0398: }
0399:
0400: /** The Document Type Declaration (see <code>DocumentType</code>)
0401: * associated with this document. For HTML documents as well as XML
0402: * documents without a document type declaration this returns
0403: * <code>null</code>. The DOM Level 2 does not support editing the
0404: * Document Type Declaration. <code>docType</code> cannot be altered in
0405: * any way, including through the use of methods inherited from the
0406: * <code>Node</code> interface, such as <code>insertNode</code> or
0407: * <code>removeNode</code>.
0408: *
0409: */
0410: public DocumentType getDoctype() {
0411: return this .document.getDoctype();
0412: }
0413:
0414: /** This is a convenience attribute that allows direct access to the child
0415: * node that is the root element of the document. For HTML documents,
0416: * this is the element with the tagName "HTML".
0417: *
0418: */
0419: public Element getDocumentElement() {
0420: return this .document.getDocumentElement();
0421: }
0422:
0423: /** Returns the <code>Element</code> whose <code>ID</code> is given by
0424: * <code>elementId</code>. If no such element exists, returns
0425: * <code>null</code>. Behavior is not defined if more than one element
0426: * has this <code>ID</code>. The DOM implementation must have
0427: * information that says which attributes are of type ID. Attributes
0428: * with the name "ID" are not of type ID unless so defined.
0429: * Implementations that do not know whether attributes are of type ID or
0430: * not are expected to return <code>null</code>.
0431: * @param elementId The unique <code>id</code> value for an element.
0432: * @return The matching element.
0433: * @since DOM Level 2
0434: *
0435: */
0436: public Element getElementById(String elementId) {
0437: return this .document.getElementById(elementId);
0438: }
0439:
0440: /** Returns a <code>NodeList</code> of all the <code>Elements</code> with a
0441: * given tag name in the order in which they are encountered in a
0442: * preorder traversal of the <code>Document</code> tree.
0443: * @param tagname The name of the tag to match on. The special value "*"
0444: * matches all tags.
0445: * @return A new <code>NodeList</code> object containing all the matched
0446: * <code>Elements</code>.
0447: *
0448: */
0449: public NodeList getElementsByTagName(String tagname) {
0450: return this .document.getElementsByTagName(tagname);
0451: }
0452:
0453: /** Returns a <code>NodeList</code> of all the <code>Elements</code> with a
0454: * given local name and namespace URI in the order in which they are
0455: * encountered in a preorder traversal of the <code>Document</code> tree.
0456: * @param namespaceURI The namespace URI of the elements to match on. The
0457: * special value "*" matches all namespaces.
0458: * @param localName The local name of the elements to match on. The
0459: * special value "*" matches all local names.
0460: * @return A new <code>NodeList</code> object containing all the matched
0461: * <code>Elements</code>.
0462: * @since DOM Level 2
0463: *
0464: */
0465: public NodeList getElementsByTagNameNS(String namespaceURI,
0466: String localName) {
0467: return this .document.getElementsByTagNameNS(namespaceURI,
0468: localName);
0469: }
0470:
0471: /** The first child of this node. If there is no such node, this returns
0472: * <code>null</code>.
0473: *
0474: */
0475: public Node getFirstChild() {
0476: return this .document.getFirstChild();
0477: }
0478:
0479: /** The <code>DOMImplementation</code> object that handles this document. A
0480: * DOM application may use objects from multiple implementations.
0481: *
0482: */
0483: public DOMImplementation getImplementation() {
0484: return this .document.getImplementation();
0485: }
0486:
0487: /** The last child of this node. If there is no such node, this returns
0488: * <code>null</code>.
0489: *
0490: */
0491: public Node getLastChild() {
0492: return this .document.getLastChild();
0493: }
0494:
0495: /** Returns the local part of the qualified name of this node.
0496: * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
0497: * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
0498: * method, such as <code>createElement</code> from the
0499: * <code>Document</code> interface, this is always <code>null</code>.
0500: * @since DOM Level 2
0501: *
0502: */
0503: public String getLocalName() {
0504: return this .document.getLocalName();
0505: }
0506:
0507: /** The namespace URI of this node, or <code>null</code> if it is
0508: * unspecified.
0509: * <br>This is not a computed value that is the result of a namespace
0510: * lookup based on an examination of the namespace declarations in
0511: * scope. It is merely the namespace URI given at creation time.
0512: * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
0513: * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
0514: * method, such as <code>createElement</code> from the
0515: * <code>Document</code> interface, this is always <code>null</code>.Per
0516: * the Namespaces in XML Specification an attribute does not inherit
0517: * its namespace from the element it is attached to. If an attribute is
0518: * not explicitly given a namespace, it simply has no namespace.
0519: * @since DOM Level 2
0520: *
0521: */
0522: public String getNamespaceURI() {
0523: return this .document.getNamespaceURI();
0524: }
0525:
0526: /** The node immediately following this node. If there is no such node,
0527: * this returns <code>null</code>.
0528: *
0529: */
0530: public Node getNextSibling() {
0531: return this .document.getNextSibling();
0532: }
0533:
0534: /** The name of this node, depending on its type; see the table above.
0535: *
0536: */
0537: public String getNodeName() {
0538: return this .document.getNodeName();
0539: }
0540:
0541: /** A code representing the type of the underlying object, as defined above.
0542: *
0543: */
0544: public short getNodeType() {
0545: return this .document.getNodeType();
0546: }
0547:
0548: /** The value of this node, depending on its type; see the table above.
0549: * When it is defined to be <code>null</code>, setting it has no effect.
0550: * @exception DOMException
0551: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
0552: * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
0553: * fit in a <code>DOMString</code> variable on the implementation
0554: * platform.
0555: *
0556: */
0557: public String getNodeValue() throws DOMException {
0558: return this .document.getNodeValue();
0559: }
0560:
0561: /** The <code>Document</code> object associated with this node. This is
0562: * also the <code>Document</code> object used to create new nodes. When
0563: * this node is a <code>Document</code> or a <code>DocumentType</code>
0564: * which is not used with any <code>Document</code> yet, this is
0565: * <code>null</code>.
0566: * @since DOM Level 2
0567: *
0568: */
0569: public Document getOwnerDocument() {
0570: return this .document.getOwnerDocument();
0571: }
0572:
0573: /** The parent of this node. All nodes, except <code>Attr</code>,
0574: * <code>Document</code>, <code>DocumentFragment</code>,
0575: * <code>Entity</code>, and <code>Notation</code> may have a parent.
0576: * However, if a node has just been created and not yet added to the
0577: * tree, or if it has been removed from the tree, this is
0578: * <code>null</code>.
0579: *
0580: */
0581: public Node getParentNode() {
0582: return this .document.getParentNode();
0583: }
0584:
0585: /** The namespace prefix of this node, or <code>null</code> if it is
0586: * unspecified.
0587: * <br>Note that setting this attribute, when permitted, changes the
0588: * <code>nodeName</code> attribute, which holds the qualified name, as
0589: * well as the <code>tagName</code> and <code>name</code> attributes of
0590: * the <code>Element</code> and <code>Attr</code> interfaces, when
0591: * applicable.
0592: * <br>Note also that changing the prefix of an attribute that is known to
0593: * have a default value, does not make a new attribute with the default
0594: * value and the original prefix appear, since the
0595: * <code>namespaceURI</code> and <code>localName</code> do not change.
0596: * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
0597: * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
0598: * method, such as <code>createElement</code> from the
0599: * <code>Document</code> interface, this is always <code>null</code>.
0600: * @exception DOMException
0601: * INVALID_CHARACTER_ERR: Raised if the specified prefix contains an
0602: * illegal character, per the XML 1.0 specification .
0603: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
0604: * <br>NAMESPACE_ERR: Raised if the specified <code>prefix</code> is
0605: * malformed per the Namespaces in XML specification, if the
0606: * <code>namespaceURI</code> of this node is <code>null</code>, if the
0607: * specified prefix is "xml" and the <code>namespaceURI</code> of this
0608: * node is different from "http://www.w3.org/XML/1998/namespace", if
0609: * this node is an attribute and the specified prefix is "xmlns" and
0610: * the <code>namespaceURI</code> of this node is different from "
0611: * http://www.w3.org/2000/xmlns/", or if this node is an attribute and
0612: * the <code>qualifiedName</code> of this node is "xmlns" .
0613: * @since DOM Level 2
0614: *
0615: */
0616: public String getPrefix() {
0617: return this .document.getPrefix();
0618: }
0619:
0620: /** The node immediately preceding this node. If there is no such node,
0621: * this returns <code>null</code>.
0622: *
0623: */
0624: public Node getPreviousSibling() {
0625: return this .document.getPreviousSibling();
0626: }
0627:
0628: /** Returns whether this node (if it is an element) has any attributes.
0629: * @return <code>true</code> if this node has any attributes,
0630: * <code>false</code> otherwise.
0631: * @since DOM Level 2
0632: *
0633: */
0634: public boolean hasAttributes() {
0635: return this .document.hasAttributes();
0636: }
0637:
0638: /** Returns whether this node has any children.
0639: * @return <code>true</code> if this node has any children,
0640: * <code>false</code> otherwise.
0641: *
0642: */
0643: public boolean hasChildNodes() {
0644: return this .document.hasChildNodes();
0645: }
0646:
0647: /** Imports a node from another document to this document. The returned
0648: * node has no parent; (<code>parentNode</code> is <code>null</code>).
0649: * The source node is not altered or removed from the original document;
0650: * this method creates a new copy of the source node.
0651: * <br>For all nodes, importing a node creates a node object owned by the
0652: * importing document, with attribute values identical to the source
0653: * node's <code>nodeName</code> and <code>nodeType</code>, plus the
0654: * attributes related to namespaces (<code>prefix</code>,
0655: * <code>localName</code>, and <code>namespaceURI</code>). As in the
0656: * <code>cloneNode</code> operation on a <code>Node</code>, the source
0657: * node is not altered.
0658: * <br>Additional information is copied as appropriate to the
0659: * <code>nodeType</code>, attempting to mirror the behavior expected if
0660: * a fragment of XML or HTML source was copied from one document to
0661: * another, recognizing that the two documents may have different DTDs
0662: * in the XML case. The following list describes the specifics for each
0663: * type of node.
0664: * <dl>
0665: * <dt>ATTRIBUTE_NODE</dt>
0666: * <dd>The <code>ownerElement</code> attribute
0667: * is set to <code>null</code> and the <code>specified</code> flag is
0668: * set to <code>true</code> on the generated <code>Attr</code>. The
0669: * descendants of the source <code>Attr</code> are recursively imported
0670: * and the resulting nodes reassembled to form the corresponding subtree.
0671: * Note that the <code>deep</code> parameter has no effect on
0672: * <code>Attr</code> nodes; they always carry their children with them
0673: * when imported.</dd>
0674: * <dt>DOCUMENT_FRAGMENT_NODE</dt>
0675: * <dd>If the <code>deep</code> option
0676: * was set to <code>true</code>, the descendants of the source element
0677: * are recursively imported and the resulting nodes reassembled to form
0678: * the corresponding subtree. Otherwise, this simply generates an empty
0679: * <code>DocumentFragment</code>.</dd>
0680: * <dt>DOCUMENT_NODE</dt>
0681: * <dd><code>Document</code>
0682: * nodes cannot be imported.</dd>
0683: * <dt>DOCUMENT_TYPE_NODE</dt>
0684: * <dd><code>DocumentType</code>
0685: * nodes cannot be imported.</dd>
0686: * <dt>ELEMENT_NODE</dt>
0687: * <dd>Specified attribute nodes of the
0688: * source element are imported, and the generated <code>Attr</code>
0689: * nodes are attached to the generated <code>Element</code>. Default
0690: * attributes are not copied, though if the document being imported into
0691: * defines default attributes for this element name, those are assigned.
0692: * If the <code>importNode</code> <code>deep</code> parameter was set to
0693: * <code>true</code>, the descendants of the source element are
0694: * recursively imported and the resulting nodes reassembled to form the
0695: * corresponding subtree.</dd>
0696: * <dt>ENTITY_NODE</dt>
0697: * <dd><code>Entity</code> nodes can be
0698: * imported, however in the current release of the DOM the
0699: * <code>DocumentType</code> is readonly. Ability to add these imported
0700: * nodes to a <code>DocumentType</code> will be considered for addition
0701: * to a future release of the DOM.On import, the <code>publicId</code>,
0702: * <code>systemId</code>, and <code>notationName</code> attributes are
0703: * copied. If a <code>deep</code> import is requested, the descendants
0704: * of the the source <code>Entity</code> are recursively imported and
0705: * the resulting nodes reassembled to form the corresponding subtree.</dd>
0706: * <dt>
0707: * ENTITY_REFERENCE_NODE</dt>
0708: * <dd>Only the <code>EntityReference</code> itself is
0709: * copied, even if a <code>deep</code> import is requested, since the
0710: * source and destination documents might have defined the entity
0711: * differently. If the document being imported into provides a
0712: * definition for this entity name, its value is assigned.</dd>
0713: * <dt>NOTATION_NODE</dt>
0714: * <dd>
0715: * <code>Notation</code> nodes can be imported, however in the current
0716: * release of the DOM the <code>DocumentType</code> is readonly. Ability
0717: * to add these imported nodes to a <code>DocumentType</code> will be
0718: * considered for addition to a future release of the DOM.On import, the
0719: * <code>publicId</code> and <code>systemId</code> attributes are copied.
0720: * Note that the <code>deep</code> parameter has no effect on
0721: * <code>Notation</code> nodes since they never have any children.</dd>
0722: * <dt>
0723: * PROCESSING_INSTRUCTION_NODE</dt>
0724: * <dd>The imported node copies its
0725: * <code>target</code> and <code>data</code> values from those of the
0726: * source node.</dd>
0727: * <dt>TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE</dt>
0728: * <dd>These three
0729: * types of nodes inheriting from <code>CharacterData</code> copy their
0730: * <code>data</code> and <code>length</code> attributes from those of
0731: * the source node.</dd>
0732: * </dl>
0733: * @param importedNode The node to import.
0734: * @param deep If <code>true</code>, recursively import the subtree under
0735: * the specified node; if <code>false</code>, import only the node
0736: * itself, as explained above. This has no effect on <code>Attr</code>
0737: * , <code>EntityReference</code>, and <code>Notation</code> nodes.
0738: * @return The imported node that belongs to this <code>Document</code>.
0739: * @exception DOMException
0740: * NOT_SUPPORTED_ERR: Raised if the type of node being imported is not
0741: * supported.
0742: * @since DOM Level 2
0743: *
0744: */
0745: public Node importNode(Node importedNode, boolean deep)
0746: throws DOMException {
0747: return this .document.importNode(importedNode, deep);
0748: }
0749:
0750: /** Inserts the node <code>newChild</code> before the existing child node
0751: * <code>refChild</code>. If <code>refChild</code> is <code>null</code>,
0752: * insert <code>newChild</code> at the end of the list of children.
0753: * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
0754: * all of its children are inserted, in the same order, before
0755: * <code>refChild</code>. If the <code>newChild</code> is already in the
0756: * tree, it is first removed.
0757: * @param newChild The node to insert.
0758: * @param refChild The reference node, i.e., the node before which the
0759: * new node must be inserted.
0760: * @return The node being inserted.
0761: * @exception DOMException
0762: * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
0763: * allow children of the type of the <code>newChild</code> node, or if
0764: * the node to insert is one of this node's ancestors or this node
0765: * itself.
0766: * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
0767: * from a different document than the one that created this node.
0768: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or
0769: * if the parent of the node being inserted is readonly.
0770: * <br>NOT_FOUND_ERR: Raised if <code>refChild</code> is not a child of
0771: * this node.
0772: *
0773: */
0774: public Node insertBefore(Node newChild, Node refChild)
0775: throws DOMException {
0776: return this .document.insertBefore(newChild, refChild);
0777: }
0778:
0779: /** Tests whether the DOM implementation implements a specific feature and
0780: * that feature is supported by this node.
0781: * @param feature The name of the feature to test. This is the same name
0782: * which can be passed to the method <code>hasFeature</code> on
0783: * <code>DOMImplementation</code>.
0784: * @param version This is the version number of the feature to test. In
0785: * Level 2, version 1, this is the string "2.0". If the version is not
0786: * specified, supporting any version of the feature will cause the
0787: * method to return <code>true</code>.
0788: * @return Returns <code>true</code> if the specified feature is
0789: * supported on this node, <code>false</code> otherwise.
0790: * @since DOM Level 2
0791: *
0792: */
0793: public boolean isSupported(String feature, String version) {
0794: return this .document.isSupported(feature, version);
0795: }
0796:
0797: /** Puts all <code>Text</code> nodes in the full depth of the sub-tree
0798: * underneath this <code>Node</code>, including attribute nodes, into a
0799: * "normal" form where only structure (e.g., elements, comments,
0800: * processing instructions, CDATA sections, and entity references)
0801: * separates <code>Text</code> nodes, i.e., there are neither adjacent
0802: * <code>Text</code> nodes nor empty <code>Text</code> nodes. This can
0803: * be used to ensure that the DOM view of a document is the same as if
0804: * it were saved and re-loaded, and is useful when operations (such as
0805: * XPointer lookups) that depend on a particular document tree
0806: * structure are to be used.In cases where the document contains
0807: * <code>CDATASections</code>, the normalize operation alone may not be
0808: * sufficient, since XPointers do not differentiate between
0809: * <code>Text</code> nodes and <code>CDATASection</code> nodes.
0810: * @since DOM Level 2
0811: *
0812: */
0813: public void normalize() {
0814: this .document.normalize();
0815: }
0816:
0817: /** Removes the child node indicated by <code>oldChild</code> from the list
0818: * of children, and returns it.
0819: * @param oldChild The node being removed.
0820: * @return The node removed.
0821: * @exception DOMException
0822: * NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
0823: * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
0824: * this node.
0825: *
0826: */
0827: public Node removeChild(Node oldChild) throws DOMException {
0828: return this .document.removeChild(oldChild);
0829: }
0830:
0831: /** Replaces the child node <code>oldChild</code> with <code>newChild</code>
0832: * in the list of children, and returns the <code>oldChild</code> node.
0833: * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
0834: * <code>oldChild</code> is replaced by all of the
0835: * <code>DocumentFragment</code> children, which are inserted in the
0836: * same order. If the <code>newChild</code> is already in the tree, it
0837: * is first removed.
0838: * @param newChild The new node to put in the child list.
0839: * @param oldChild The node being replaced in the list.
0840: * @return The node replaced.
0841: * @exception DOMException
0842: * HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not
0843: * allow children of the type of the <code>newChild</code> node, or if
0844: * the node to put in is one of this node's ancestors or this node
0845: * itself.
0846: * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created
0847: * from a different document than the one that created this node.
0848: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of
0849: * the new node is readonly.
0850: * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of
0851: * this node.
0852: *
0853: */
0854: public Node replaceChild(Node newChild, Node oldChild)
0855: throws DOMException {
0856: return this .document.replaceChild(newChild, oldChild);
0857: }
0858:
0859: /** The value of this node, depending on its type; see the table above.
0860: * When it is defined to be <code>null</code>, setting it has no effect.
0861: * @exception DOMException
0862: * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
0863: * DOMSTRING_SIZE_ERR: Raised when it would return more characters than
0864: * fit in a <code>DOMString</code> variable on the implementation
0865: * platform.
0866: *
0867: */
0868: public void setNodeValue(String nodeValue) throws DOMException {
0869: this .document.setNodeValue(nodeValue);
0870: }
0871:
0872: /** The namespace prefix of this node, or <code>null</code> if it is
0873: * unspecified.
0874: * <br>Note that setting this attribute, when permitted, changes the
0875: * <code>nodeName</code> attribute, which holds the qualified name, as
0876: * well as the <code>tagName</code> and <code>name</code> attributes of
0877: * the <code>Element</code> and <code>Attr</code> interfaces, when
0878: * applicable.
0879: * <br>Note also that changing the prefix of an attribute that is known to
0880: * have a default value, does not make a new attribute with the default
0881: * value and the original prefix appear, since the
0882: * <code>namespaceURI</code> and <code>localName</code> do not change.
0883: * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
0884: * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
0885: * method, such as <code>createElement</code> from the
0886: * <code>Document</code> interface, this is always <code>null</code>.
0887: * @exception DOMException
0888: * INVALID_CHARACTER_ERR: Raised if the specified prefix contains an
0889: * illegal character, per the XML 1.0 specification .
0890: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
0891: * <br>NAMESPACE_ERR: Raised if the specified <code>prefix</code> is
0892: * malformed per the Namespaces in XML specification, if the
0893: * <code>namespaceURI</code> of this node is <code>null</code>, if the
0894: * specified prefix is "xml" and the <code>namespaceURI</code> of this
0895: * node is different from "http://www.w3.org/XML/1998/namespace", if
0896: * this node is an attribute and the specified prefix is "xmlns" and
0897: * the <code>namespaceURI</code> of this node is different from "
0898: * http://www.w3.org/2000/xmlns/", or if this node is an attribute and
0899: * the <code>qualifiedName</code> of this node is "xmlns" .
0900: * @since DOM Level 2
0901: *
0902: */
0903: public void setPrefix(String prefix) throws DOMException {
0904: this .document.setPrefix(prefix);
0905: }
0906:
0907: /**
0908: * @since DOM Level 3
0909: */
0910: public Node renameNode(Node node, String namespaceURI,
0911: String qualifiedName) throws DOMException {
0912: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0913: }
0914:
0915: /**
0916: * @since DOM Level 3
0917: */
0918: public void normalizeDocument() {
0919: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0920: }
0921:
0922: /**
0923: * @since DOM Level 3
0924: */
0925: public DOMConfiguration getDomConfig() {
0926: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0927: }
0928:
0929: /**
0930: * @since DOM Level 3
0931: */
0932: public Node adoptNode(Node source) {
0933: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0934: }
0935:
0936: /**
0937: * @since DOM Level 3
0938: */
0939: public void setDocumentURI(String uri) {
0940: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0941: }
0942:
0943: /**
0944: * @since DOM Level 3
0945: */
0946: public String getDocumentURI() {
0947: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0948: }
0949:
0950: /**
0951: * @since DOM Level 3
0952: */
0953: public void setStrictErrorChecking(boolean value) {
0954: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0955: }
0956:
0957: /**
0958: * @since DOM Level 3
0959: */
0960: public boolean getStrictErrorChecking() {
0961: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0962: }
0963:
0964: /**
0965: * @since DOM Level 3
0966: */
0967: public void setXmlVersion(String version) {
0968: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0969: }
0970:
0971: /**
0972: * @since DOM Level 3
0973: */
0974: public String getXmlVersion() {
0975: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0976: }
0977:
0978: /**
0979: * @since DOM Level 3
0980: */
0981: public void setXmlStandalone(boolean value) {
0982: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0983: }
0984:
0985: /**
0986: * @since DOM Level 3
0987: */
0988: public boolean getXmlStandalone() {
0989: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0990: }
0991:
0992: /**
0993: * @since DOM Level 3
0994: */
0995: public void setXmlEncoding(String version) {
0996: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
0997: }
0998:
0999: /**
1000: * @since DOM Level 3
1001: */
1002: public String getXmlEncoding() {
1003: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1004: }
1005:
1006: /**
1007: * @since DOM Level 3
1008: */
1009: public String getInputEncoding() {
1010: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1011: }
1012:
1013: /**
1014: * @since DOM Level 3
1015: */
1016: public Object getUserData(String key) {
1017: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1018: }
1019:
1020: /**
1021: * @since DOM Level 3
1022: */
1023: public Object setUserData(String key, Object value,
1024: UserDataHandler handler) {
1025: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1026: }
1027:
1028: /**
1029: * @since DOM Level 3
1030: */
1031: public Object getFeature(String feature, String version) {
1032: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1033: }
1034:
1035: /**
1036: * @since DOM Level 3
1037: */
1038: public short compareDocumentPosition(Node other)
1039: throws DOMException {
1040: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1041: }
1042:
1043: /**
1044: * @since DOM Level 3
1045: */
1046: public String getBaseURI() {
1047: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1048: }
1049:
1050: /**
1051: * @since DOM Level 3
1052: */
1053: public String getTextContent() throws DOMException {
1054: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1055: }
1056:
1057: /**
1058: * @since DOM Level 3
1059: */
1060: public boolean isDefaultNamespace(String namespaceURI) {
1061: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1062: }
1063:
1064: /**
1065: * @since DOM Level 3
1066: */
1067: public boolean isEqualNode(Node arg) {
1068: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1069: }
1070:
1071: /**
1072: * @since DOM Level 3
1073: */
1074: public boolean isSameNode(Node other) {
1075: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1076: }
1077:
1078: /**
1079: * @since DOM Level 3
1080: */
1081: public String lookupNamespaceURI(String prefix) {
1082: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1083: }
1084:
1085: /**
1086: * @since DOM Level 3
1087: */
1088: public String lookupPrefix(String namespaceURI) {
1089: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1090: }
1091:
1092: /**
1093: * @since DOM Level 3
1094: */
1095: public void setTextContent(String textContent) throws DOMException {
1096: throw new UnsupportedOperationException(DOMLEVEL3_ERR_MSG);
1097: }
1098: }
|