0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: package org.netbeans.modules.xml.xdm.nodes;
0043:
0044: import java.lang.ref.SoftReference;
0045: import java.util.Map;
0046: import javax.xml.XMLConstants;
0047: import org.netbeans.modules.xml.xdm.visitor.FindNamespaceVisitor;
0048: import org.netbeans.modules.xml.xdm.visitor.XMLNodeVisitor;
0049: import org.w3c.dom.DOMException;
0050: import org.w3c.dom.NodeList;
0051:
0052: /**
0053: *
0054: * @author Ajit
0055: */
0056: public class Document extends NodeImpl implements Node,
0057: org.w3c.dom.Document {
0058:
0059: /** Creates a new instance of Document */
0060: Document() {
0061: super ();
0062: resetNamespaceCache();
0063: }
0064:
0065: public Document clone(boolean cloneContent,
0066: boolean cloneAttributes, boolean cloneChildren) {
0067: Document ret = (Document) super .clone(cloneContent,
0068: cloneAttributes, cloneChildren);
0069: ret.resetNamespaceCache();
0070: return ret;
0071: }
0072:
0073: void resetNamespaceCache() {
0074: fnv = null;
0075: }
0076:
0077: public short getNodeType() {
0078: return Node.DOCUMENT_NODE;
0079: }
0080:
0081: public String getNodeName() {
0082: return "#document"; //NOI18N
0083: }
0084:
0085: public void accept(XMLNodeVisitor visitor) {
0086: visitor.visit(this );
0087: }
0088:
0089: /**
0090: * Attempts to adopt a node from another document to this document. If
0091: * supported, it changes the <code>ownerDocument</code> of the source
0092: * node, its children, as well as the attached attribute nodes if there
0093: * are any. If the source node has a parent it is first removed from the
0094: * child list of its parent. This effectively allows moving a subtree
0095: * from one document to another (unlike <code>importNode()</code> which
0096: * create a copy of the source node instead of moving it). When it
0097: * fails, applications should use <code>Document.importNode()</code>
0098: * instead. Note that if the adopted node is already part of this
0099: * document (i.e. the source and target document are the same), this
0100: * method still has the effect of removing the source node from the
0101: * child list of its parent, if any. The following list describes the
0102: * specifics for each type of node.
0103: * <dl>
0104: * <dt>ATTRIBUTE_NODE</dt>
0105: * <dd>The
0106: * <code>ownerElement</code> attribute is set to <code>null</code> and
0107: * the <code>specified</code> flag is set to <code>true</code> on the
0108: * adopted <code>Attr</code>. The descendants of the source
0109: * <code>Attr</code> are recursively adopted.</dd>
0110: * <dt>DOCUMENT_FRAGMENT_NODE</dt>
0111: * <dd>The
0112: * descendants of the source node are recursively adopted.</dd>
0113: * <dt>DOCUMENT_NODE</dt>
0114: * <dd>
0115: * <code>Document</code> nodes cannot be adopted.</dd>
0116: * <dt>DOCUMENT_TYPE_NODE</dt>
0117: * <dd>
0118: * <code>DocumentType</code> nodes cannot be adopted.</dd>
0119: * <dt>ELEMENT_NODE</dt>
0120: * <dd><em>Specified</em> attribute nodes of the source element are adopted. Default attributes
0121: * are discarded, though if the document being adopted into defines
0122: * default attributes for this element name, those are assigned. The
0123: * descendants of the source element are recursively adopted.</dd>
0124: * <dt>ENTITY_NODE</dt>
0125: * <dd>
0126: * <code>Entity</code> nodes cannot be adopted.</dd>
0127: * <dt>ENTITY_REFERENCE_NODE</dt>
0128: * <dd>Only
0129: * the <code>EntityReference</code> node itself is adopted, the
0130: * descendants are discarded, since the source and destination documents
0131: * might have defined the entity differently. If the document being
0132: * imported into provides a definition for this entity name, its value
0133: * is assigned.</dd>
0134: * <dt>NOTATION_NODE</dt>
0135: * <dd><code>Notation</code> nodes cannot be
0136: * adopted.</dd>
0137: * <dt>PROCESSING_INSTRUCTION_NODE, TEXT_NODE, CDATA_SECTION_NODE,
0138: * COMMENT_NODE</dt>
0139: * <dd>These nodes can all be adopted. No specifics.</dd>
0140: * </dl>
0141: * <p ><b>Note:</b> Since it does not create new nodes unlike the
0142: * <code>Document.importNode()</code> method, this method does not raise
0143: * an <code>INVALID_CHARACTER_ERR</code> exception, and applications
0144: * should use the <code>Document.normalizeDocument()</code> method to
0145: * check if an imported name is not an XML name according to the XML
0146: * version in use.
0147: * @param source The node to move into this document.
0148: * @return The adopted node, or <code>null</code> if this operation
0149: * fails, such as when the source node comes from a different
0150: * implementation.
0151: * @exception DOMException
0152: * NOT_SUPPORTED_ERR: Raised if the source node is of type
0153: * <code>DOCUMENT</code>, <code>DOCUMENT_TYPE</code>.
0154: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised when the source node is
0155: * readonly.
0156: * @since DOM Level 3
0157: */
0158: public org.w3c.dom.Node adoptNode(org.w3c.dom.Node source) {
0159: //TODO Implement later
0160: return null;
0161: }
0162:
0163: /**
0164: * Imports a node from another document to this document, without altering
0165: * or removing the source node from the original document; this method
0166: * creates a new copy of the source node. The returned node has no
0167: * parent; (<code>parentNode</code> is <code>null</code>).
0168: * <br>For all nodes, importing a node creates a node object owned by the
0169: * importing document, with attribute values identical to the source
0170: * node's <code>nodeName</code> and <code>nodeType</code>, plus the
0171: * attributes related to namespaces (<code>prefix</code>,
0172: * <code>localName</code>, and <code>namespaceURI</code>). As in the
0173: * <code>cloneNode</code> operation, the source node is not altered.
0174: * User data associated to the imported node is not carried over.
0175: * However, if any <code>UserDataHandlers</code> has been specified
0176: * along with the associated data these handlers will be called with the
0177: * appropriate parameters before this method returns.
0178: * <br>Additional information is copied as appropriate to the
0179: * <code>nodeType</code>, attempting to mirror the behavior expected if
0180: * a fragment of XML or HTML source was copied from one document to
0181: * another, recognizing that the two documents may have different DTDs
0182: * in the XML case. The following list describes the specifics for each
0183: * type of node.
0184: * <dl>
0185: * <dt>ATTRIBUTE_NODE</dt>
0186: * <dd>The <code>ownerElement</code> attribute
0187: * is set to <code>null</code> and the <code>specified</code> flag is
0188: * set to <code>true</code> on the generated <code>Attr</code>. The
0189: * descendants of the source <code>Attr</code> are recursively imported
0190: * and the resulting nodes reassembled to form the corresponding subtree.
0191: * Note that the <code>deep</code> parameter has no effect on
0192: * <code>Attr</code> nodes; they always carry their children with them
0193: * when imported.</dd>
0194: * <dt>DOCUMENT_FRAGMENT_NODE</dt>
0195: * <dd>If the <code>deep</code> option
0196: * was set to <code>true</code>, the descendants of the source
0197: * <code>DocumentFragment</code> are recursively imported and the
0198: * resulting nodes reassembled under the imported
0199: * <code>DocumentFragment</code> to form the corresponding subtree.
0200: * Otherwise, this simply generates an empty
0201: * <code>DocumentFragment</code>.</dd>
0202: * <dt>DOCUMENT_NODE</dt>
0203: * <dd><code>Document</code>
0204: * nodes cannot be imported.</dd>
0205: * <dt>DOCUMENT_TYPE_NODE</dt>
0206: * <dd><code>DocumentType</code>
0207: * nodes cannot be imported.</dd>
0208: * <dt>ELEMENT_NODE</dt>
0209: * <dd><em>Specified</em> attribute nodes of the source element are imported, and the generated
0210: * <code>Attr</code> nodes are attached to the generated
0211: * <code>Element</code>. Default attributes are <em>not</em> copied, though if the document being imported into defines default
0212: * attributes for this element name, those are assigned. If the
0213: * <code>importNode</code> <code>deep</code> parameter was set to
0214: * <code>true</code>, the descendants of the source element are
0215: * recursively imported and the resulting nodes reassembled to form the
0216: * corresponding subtree.</dd>
0217: * <dt>ENTITY_NODE</dt>
0218: * <dd><code>Entity</code> nodes can be
0219: * imported, however in the current release of the DOM the
0220: * <code>DocumentType</code> is readonly. Ability to add these imported
0221: * nodes to a <code>DocumentType</code> will be considered for addition
0222: * to a future release of the DOM.On import, the <code>publicId</code>,
0223: * <code>systemId</code>, and <code>notationName</code> attributes are
0224: * copied. If a <code>deep</code> import is requested, the descendants
0225: * of the the source <code>Entity</code> are recursively imported and
0226: * the resulting nodes reassembled to form the corresponding subtree.</dd>
0227: * <dt>
0228: * ENTITY_REFERENCE_NODE</dt>
0229: * <dd>Only the <code>EntityReference</code> itself is
0230: * copied, even if a <code>deep</code> import is requested, since the
0231: * source and destination documents might have defined the entity
0232: * differently. If the document being imported into provides a
0233: * definition for this entity name, its value is assigned.</dd>
0234: * <dt>NOTATION_NODE</dt>
0235: * <dd>
0236: * <code>Notation</code> nodes can be imported, however in the current
0237: * release of the DOM the <code>DocumentType</code> is readonly. Ability
0238: * to add these imported nodes to a <code>DocumentType</code> will be
0239: * considered for addition to a future release of the DOM.On import, the
0240: * <code>publicId</code> and <code>systemId</code> attributes are copied.
0241: * Note that the <code>deep</code> parameter has no effect on this type
0242: * of nodes since they cannot have any children.</dd>
0243: * <dt>
0244: * PROCESSING_INSTRUCTION_NODE</dt>
0245: * <dd>The imported node copies its
0246: * <code>target</code> and <code>data</code> values from those of the
0247: * source node.Note that the <code>deep</code> parameter has no effect
0248: * on this type of nodes since they cannot have any children.</dd>
0249: * <dt>TEXT_NODE,
0250: * CDATA_SECTION_NODE, COMMENT_NODE</dt>
0251: * <dd>These three types of nodes inheriting
0252: * from <code>CharacterData</code> copy their <code>data</code> and
0253: * <code>length</code> attributes from those of the source node.Note
0254: * that the <code>deep</code> parameter has no effect on these types of
0255: * nodes since they cannot have any children.</dd>
0256: * </dl>
0257: * @param importedNode The node to import.
0258: * @param deep If <code>true</code>, recursively import the subtree under
0259: * the specified node; if <code>false</code>, import only the node
0260: * itself, as explained above. This has no effect on nodes that cannot
0261: * have any children, and on <code>Attr</code>, and
0262: * <code>EntityReference</code> nodes.
0263: * @return The imported node that belongs to this <code>Document</code>.
0264: * @exception DOMException
0265: * NOT_SUPPORTED_ERR: Raised if the type of node being imported is not
0266: * supported.
0267: * <br>INVALID_CHARACTER_ERR: Raised if one of the imported names is not
0268: * an XML name according to the XML version in use specified in the
0269: * <code>Document.xmlVersion</code> attribute. This may happen when
0270: * importing an XML 1.1 [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>] element
0271: * into an XML 1.0 document, for instance.
0272: * @since DOM Level 2
0273: */
0274: public org.w3c.dom.Node importNode(org.w3c.dom.Node importedNode,
0275: boolean deep) {
0276: //TODO Implement later
0277: return null;
0278: }
0279:
0280: /**
0281: * Rename an existing node of type <code>ELEMENT_NODE</code> or
0282: * <code>ATTRIBUTE_NODE</code>.
0283: * <br>When possible this simply changes the name of the given node,
0284: * otherwise this creates a new node with the specified name and
0285: * replaces the existing node with the new node as described below.
0286: * <br>If simply changing the name of the given node is not possible, the
0287: * following operations are performed: a new node is created, any
0288: * registered event listener is registered on the new node, any user
0289: * data attached to the old node is removed from that node, the old node
0290: * is removed from its parent if it has one, the children are moved to
0291: * the new node, if the renamed node is an <code>Element</code> its
0292: * attributes are moved to the new node, the new node is inserted at the
0293: * position the old node used to have in its parent's child nodes list
0294: * if it has one, the user data that was attached to the old node is
0295: * attached to the new node.
0296: * <br>When the node being renamed is an <code>Element</code> only the
0297: * specified attributes are moved, default attributes originated from
0298: * the DTD are updated according to the new element name. In addition,
0299: * the implementation may update default attributes from other schemas.
0300: * Applications should use <code>Document.normalizeDocument()</code> to
0301: * guarantee these attributes are up-to-date.
0302: * <br>When the node being renamed is an <code>Attr</code> that is
0303: * attached to an <code>Element</code>, the node is first removed from
0304: * the <code>Element</code> attributes map. Then, once renamed, either
0305: * by modifying the existing node or creating a new one as described
0306: * above, it is put back.
0307: * <br>In addition,
0308: * <ul>
0309: * <li> a user data event <code>NODE_RENAMED</code> is fired,
0310: * </li>
0311: * <li>
0312: * when the implementation supports the feature "MutationNameEvents",
0313: * each mutation operation involved in this method fires the appropriate
0314: * event, and in the end the event {
0315: * <code>http://www.w3.org/2001/xml-events</code>,
0316: * <code>DOMElementNameChanged</code>} or {
0317: * <code>http://www.w3.org/2001/xml-events</code>,
0318: * <code>DOMAttributeNameChanged</code>} is fired.
0319: * </li>
0320: * </ul>
0321: * @param n The node to rename.
0322: * @param namespaceURI The new namespace URI.
0323: * @param qualifiedName The new qualified name.
0324: * @return The renamed node. This is either the specified node or the new
0325: * node that was created to replace the specified node.
0326: * @exception DOMException
0327: * NOT_SUPPORTED_ERR: Raised when the type of the specified node is
0328: * neither <code>ELEMENT_NODE</code> nor <code>ATTRIBUTE_NODE</code>,
0329: * or if the implementation does not support the renaming of the
0330: * document element.
0331: * <br>INVALID_CHARACTER_ERR: Raised if the new qualified name is not an
0332: * XML name according to the XML version in use specified in the
0333: * <code>Document.xmlVersion</code> attribute.
0334: * <br>WRONG_DOCUMENT_ERR: Raised when the specified node was created
0335: * from a different document than this document.
0336: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a
0337: * malformed qualified name, if the <code>qualifiedName</code> has a
0338: * prefix and the <code>namespaceURI</code> is <code>null</code>, or
0339: * if the <code>qualifiedName</code> has a prefix that is "xml" and
0340: * the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
0341: * http://www.w3.org/XML/1998/namespace</a>" [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
0342: * . Also raised, when the node being renamed is an attribute, if the
0343: * <code>qualifiedName</code>, or its prefix, is XMLNS and the
0344: * <code>namespaceURI</code> is different from "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>".
0345: * @since DOM Level 3
0346: */
0347: public org.w3c.dom.Node renameNode(org.w3c.dom.Node n,
0348: String namespaceURI, String qualifiedName) {
0349: //TODO Implement later
0350: return null;
0351: }
0352:
0353: /**
0354: * Creates a <code>Text</code> node given the specified string.
0355: * @param data The data for the node.
0356: * @return The new <code>Text</code> object.
0357: */
0358: public org.w3c.dom.Text createTextNode(String data) {
0359: return new Text(data);
0360: }
0361:
0362: /**
0363: * Creates an <code>EntityReference</code> object. In addition, if the
0364: * referenced entity is known, the child list of the
0365: * <code>EntityReference</code> node is made the same as that of the
0366: * corresponding <code>Entity</code> node.
0367: * <p ><b>Note:</b> If any descendant of the <code>Entity</code> node has
0368: * an unbound namespace prefix, the corresponding descendant of the
0369: * created <code>EntityReference</code> node is also unbound; (its
0370: * <code>namespaceURI</code> is <code>null</code>). The DOM Level 2 and
0371: * 3 do not support any mechanism to resolve namespace prefixes in this
0372: * case.
0373: * @param name The name of the entity to reference.Unlike
0374: * <code>Document.createElementNS</code> or
0375: * <code>Document.createAttributeNS</code>, no namespace well-formed
0376: * checking is done on the entity name. Applications should invoke
0377: * <code>Document.normalizeDocument()</code> with the parameter "
0378: * namespaces" set to <code>true</code> in order to ensure that the
0379: * entity name is namespace well-formed.
0380: * @return The new <code>EntityReference</code> object.
0381: * @exception DOMException
0382: * INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
0383: * name according to the XML version in use specified in the
0384: * <code>Document.xmlVersion</code> attribute.
0385: * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
0386: */
0387: public org.w3c.dom.EntityReference createEntityReference(String name) {
0388: //TODO Implement later
0389: return null;
0390: }
0391:
0392: /**
0393: * Creates an element of the type specified. Note that the instance
0394: * returned implements the <code>Element</code> interface, so attributes
0395: * can be specified directly on the returned object.
0396: * <br>In addition, if there are known attributes with default values,
0397: * <code>Attr</code> nodes representing them are automatically created
0398: * and attached to the element.
0399: * <br>To create an element with a qualified name and namespace URI, use
0400: * the <code>createElementNS</code> method.
0401: * @param tagName The name of the element type to instantiate. For XML,
0402: * this is case-sensitive, otherwise it depends on the
0403: * case-sensitivity of the markup language in use. In that case, the
0404: * name is mapped to the canonical form of that markup by the DOM
0405: * implementation.
0406: * @return A new <code>Element</code> object with the
0407: * <code>nodeName</code> attribute set to <code>tagName</code>, and
0408: * <code>localName</code>, <code>prefix</code>, and
0409: * <code>namespaceURI</code> set to <code>null</code>.
0410: * @exception DOMException
0411: * INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
0412: * name according to the XML version in use specified in the
0413: * <code>Document.xmlVersion</code> attribute.
0414: */
0415: public org.w3c.dom.Element createElement(String tagName) {
0416: return new Element(tagName);
0417: }
0418:
0419: /**
0420: * Creates a <code>Comment</code> node given the specified string.
0421: * @param data The data for the node.
0422: * @return The new <code>Comment</code> object.
0423: */
0424: public org.w3c.dom.Comment createComment(String data) {
0425: return new Comment(data);
0426: }
0427:
0428: /**
0429: * Creates a <code>CDATASection</code> node whose value is the specified
0430: * string.
0431: * @param data The data for the <code>CDATASection</code> contents.
0432: * @return The new <code>CDATASection</code> object.
0433: * @exception DOMException
0434: * NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
0435: */
0436: public org.w3c.dom.CDATASection createCDATASection(String data) {
0437: return new CData(data);
0438: }
0439:
0440: /**
0441: * Creates an <code>Attr</code> of the given name. Note that the
0442: * <code>Attr</code> instance can then be set on an <code>Element</code>
0443: * using the <code>setAttributeNode</code> method.
0444: * <br>To create an attribute with a qualified name and namespace URI, use
0445: * the <code>createAttributeNS</code> method.
0446: * @param name The name of the attribute.
0447: * @return A new <code>Attr</code> object with the <code>nodeName</code>
0448: * attribute set to <code>name</code>, and <code>localName</code>,
0449: * <code>prefix</code>, and <code>namespaceURI</code> set to
0450: * <code>null</code>. The value of the attribute is the empty string.
0451: * @exception DOMException
0452: * INVALID_CHARACTER_ERR: Raised if the specified name is not an XML
0453: * name according to the XML version in use specified in the
0454: * <code>Document.xmlVersion</code> attribute.
0455: */
0456: public org.w3c.dom.Attr createAttribute(String name) {
0457: return new Attribute(name);
0458: }
0459:
0460: /**
0461: * Creates a <code>ProcessingInstruction</code> node given the specified
0462: * name and data strings.
0463: * @param target The target part of the processing instruction.Unlike
0464: * <code>Document.createElementNS</code> or
0465: * <code>Document.createAttributeNS</code>, no namespace well-formed
0466: * checking is done on the target name. Applications should invoke
0467: * <code>Document.normalizeDocument()</code> with the parameter "
0468: * namespaces" set to <code>true</code> in order to ensure that the
0469: * target name is namespace well-formed.
0470: * @param data The data for the node.
0471: * @return The new <code>ProcessingInstruction</code> object.
0472: * @exception DOMException
0473: * INVALID_CHARACTER_ERR: Raised if the specified target is not an XML
0474: * name according to the XML version in use specified in the
0475: * <code>Document.xmlVersion</code> attribute.
0476: * <br>NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
0477: */
0478: public org.w3c.dom.ProcessingInstruction createProcessingInstruction(
0479: String target, String data) {
0480: //TODO Implement later
0481: return null;
0482: }
0483:
0484: /**
0485: * Creates an element of the given qualified name and namespace URI.
0486: * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
0487: * , applications must use the value <code>null</code> as the
0488: * namespaceURI parameter for methods if they wish to have no namespace.
0489: * @param namespaceURI The namespace URI of the element to create.
0490: * @param qualifiedName The qualified name of the element type to
0491: * instantiate.
0492: * @return A new <code>Element</code> object with the following
0493: * attributes:
0494: * <table border='1' cellpadding='3'>
0495: * <tr>
0496: * <th>Attribute</th>
0497: * <th>Value</th>
0498: * </tr>
0499: * <tr>
0500: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
0501: * <td valign='top' rowspan='1' colspan='1'>
0502: * <code>qualifiedName</code></td>
0503: * </tr>
0504: * <tr>
0505: * <td valign='top' rowspan='1' colspan='1'><code>Node.namespaceURI</code></td>
0506: * <td valign='top' rowspan='1' colspan='1'>
0507: * <code>namespaceURI</code></td>
0508: * </tr>
0509: * <tr>
0510: * <td valign='top' rowspan='1' colspan='1'><code>Node.prefix</code></td>
0511: * <td valign='top' rowspan='1' colspan='1'>prefix, extracted
0512: * from <code>qualifiedName</code>, or <code>null</code> if there is
0513: * no prefix</td>
0514: * </tr>
0515: * <tr>
0516: * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
0517: * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
0518: * <code>qualifiedName</code></td>
0519: * </tr>
0520: * <tr>
0521: * <td valign='top' rowspan='1' colspan='1'><code>Element.tagName</code></td>
0522: * <td valign='top' rowspan='1' colspan='1'>
0523: * <code>qualifiedName</code></td>
0524: * </tr>
0525: * </table>
0526: * @exception DOMException
0527: * INVALID_CHARACTER_ERR: Raised if the specified
0528: * <code>qualifiedName</code> is not an XML name according to the XML
0529: * version in use specified in the <code>Document.xmlVersion</code>
0530: * attribute.
0531: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a
0532: * malformed qualified name, if the <code>qualifiedName</code> has a
0533: * prefix and the <code>namespaceURI</code> is <code>null</code>, or
0534: * if the <code>qualifiedName</code> has a prefix that is "xml" and
0535: * the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
0536: * http://www.w3.org/XML/1998/namespace</a>" [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
0537: * , or if the <code>qualifiedName</code> or its prefix is XMLNS and
0538: * 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.
0539: * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
0540: * support the <code>"XML"</code> feature, since namespaces were
0541: * defined by XML.
0542: * @since DOM Level 2
0543: */
0544: public org.w3c.dom.Element createElementNS(String namespaceURI,
0545: String qualifiedName) {
0546: Element ret = new Element(qualifiedName);
0547: String prefix = ret.getPrefix();
0548: if (prefix != null) {
0549: if (namespaceURI == null) {
0550: throw new DOMException(DOMException.NAMESPACE_ERR, null);
0551: }
0552: ret.appendAttribute(new Attribute("xmlns:" + prefix,
0553: namespaceURI)); //NOI18N
0554: } else {
0555: ret = new Element(ret.getLocalName());
0556: if (namespaceURI != null
0557: && !namespaceURI.equals(XMLConstants.NULL_NS_URI)) {
0558: ret.appendAttribute(new Attribute(XMLNS, namespaceURI));
0559: }
0560: }
0561: return ret;
0562: }
0563:
0564: /**
0565: * Creates an empty <code>DocumentFragment</code> object.
0566: * @return A new <code>DocumentFragment</code>.
0567: */
0568: public org.w3c.dom.DocumentFragment createDocumentFragment() {
0569: //TODO Implement later
0570: return null;
0571: }
0572:
0573: /**
0574: * Creates an attribute of the given qualified name and namespace URI.
0575: * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
0576: * , applications must use the value <code>null</code> as the
0577: * <code>namespaceURI</code> parameter for methods if they wish to have
0578: * no namespace.
0579: * @param namespaceURI The namespace URI of the attribute to create.
0580: * @param qualifiedName The qualified name of the attribute to
0581: * instantiate.
0582: * @return A new <code>Attr</code> object with the following attributes:
0583: * <table border='1' cellpadding='3'>
0584: * <tr>
0585: * <th>
0586: * Attribute</th>
0587: * <th>Value</th>
0588: * </tr>
0589: * <tr>
0590: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
0591: * <td valign='top' rowspan='1' colspan='1'>qualifiedName</td>
0592: * </tr>
0593: * <tr>
0594: * <td valign='top' rowspan='1' colspan='1'>
0595: * <code>Node.namespaceURI</code></td>
0596: * <td valign='top' rowspan='1' colspan='1'><code>namespaceURI</code></td>
0597: * </tr>
0598: * <tr>
0599: * <td valign='top' rowspan='1' colspan='1'>
0600: * <code>Node.prefix</code></td>
0601: * <td valign='top' rowspan='1' colspan='1'>prefix, extracted from
0602: * <code>qualifiedName</code>, or <code>null</code> if there is no
0603: * prefix</td>
0604: * </tr>
0605: * <tr>
0606: * <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
0607: * <td valign='top' rowspan='1' colspan='1'>local name, extracted from
0608: * <code>qualifiedName</code></td>
0609: * </tr>
0610: * <tr>
0611: * <td valign='top' rowspan='1' colspan='1'><code>Attr.name</code></td>
0612: * <td valign='top' rowspan='1' colspan='1'>
0613: * <code>qualifiedName</code></td>
0614: * </tr>
0615: * <tr>
0616: * <td valign='top' rowspan='1' colspan='1'><code>Node.nodeValue</code></td>
0617: * <td valign='top' rowspan='1' colspan='1'>the empty
0618: * string</td>
0619: * </tr>
0620: * </table>
0621: * @exception DOMException
0622: * INVALID_CHARACTER_ERR: Raised if the specified
0623: * <code>qualifiedName</code> is not an XML name according to the XML
0624: * version in use specified in the <code>Document.xmlVersion</code>
0625: * attribute.
0626: * <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a
0627: * malformed qualified name, if the <code>qualifiedName</code> has a
0628: * prefix and the <code>namespaceURI</code> is <code>null</code>, if
0629: * the <code>qualifiedName</code> has a prefix that is "xml" and the
0630: * <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
0631: * http://www.w3.org/XML/1998/namespace</a>", if the <code>qualifiedName</code> or its prefix is XMLNS and the
0632: * <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.
0633: * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
0634: * support the <code>"XML"</code> feature, since namespaces were
0635: * defined by XML.
0636: * @since DOM Level 2
0637: */
0638: public org.w3c.dom.Attr createAttributeNS(String namespaceURI,
0639: String qualifiedName) {
0640: //TODO validate namespaceURI
0641: return new Attribute(qualifiedName);
0642: }
0643:
0644: /**
0645: * Returns the <code>Element</code> that has an ID attribute with the
0646: * given value. If no such element exists, this returns <code>null</code>
0647: * . If more than one element has an ID attribute with that value, what
0648: * is returned is undefined.
0649: * <br> The DOM implementation is expected to use the attribute
0650: * <code>Attr.isId</code> to determine if an attribute is of type ID.
0651: * <p ><b>Note:</b> Attributes with the name "ID" or "id" are not of type
0652: * ID unless so defined.
0653: * @param elementId The unique <code>id</code> value for an element.
0654: * @return The matching element or <code>null</code> if there is none.
0655: * @since DOM Level 2
0656: */
0657: public org.w3c.dom.Element getElementById(String elementId) {
0658: //TODO Implement later
0659: return null;
0660: }
0661:
0662: /**
0663: * Returns a <code>NodeList</code> of all the <code>Elements</code> in
0664: * document order with a given tag name and are contained in the
0665: * document.
0666: * @param tagname The name of the tag to match on. The special value "*"
0667: * matches all tags. For XML, the <code>tagname</code> parameter is
0668: * case-sensitive, otherwise it depends on the case-sensitivity of the
0669: * markup language in use.
0670: * @return A new <code>NodeList</code> object containing all the matched
0671: * <code>Elements</code>.
0672: */
0673: public org.w3c.dom.NodeList getElementsByTagName(String tagname) {
0674: //TODO Implement later
0675: return null;
0676: }
0677:
0678: /**
0679: * Returns a <code>NodeList</code> of all the <code>Elements</code> with a
0680: * given local name and namespace URI in document order.
0681: * @param namespaceURI The namespace URI of the elements to match on. The
0682: * special value <code>"*"</code> matches all namespaces.
0683: * @param localName The local name of the elements to match on. The
0684: * special value "*" matches all local names.
0685: * @return A new <code>NodeList</code> object containing all the matched
0686: * <code>Elements</code>.
0687: * @since DOM Level 2
0688: */
0689: public org.w3c.dom.NodeList getElementsByTagNameNS(
0690: String namespaceURI, String localName) {
0691: //TODO Implement later
0692: return null;
0693: }
0694:
0695: /**
0696: * This method acts as if the document was going through a save and load
0697: * cycle, putting the document in a "normal" form. As a consequence,
0698: * this method updates the replacement tree of
0699: * <code>EntityReference</code> nodes and normalizes <code>Text</code>
0700: * nodes, as defined in the method <code>Node.normalize()</code>.
0701: * <br> Otherwise, the actual result depends on the features being set on
0702: * the <code>Document.domConfig</code> object and governing what
0703: * operations actually take place. Noticeably this method could also
0704: * make the document namespace well-formed according to the algorithm
0705: * described in , check the character normalization, remove the
0706: * <code>CDATASection</code> nodes, etc. See
0707: * <code>DOMConfiguration</code> for details.
0708: * <pre>// Keep in the document
0709: * the information defined // in the XML Information Set (Java example)
0710: * DOMConfiguration docConfig = myDocument.getDomConfig();
0711: * docConfig.setParameter("infoset", Boolean.TRUE);
0712: * myDocument.normalizeDocument();</pre>
0713: *
0714: * <br>Mutation events, when supported, are generated to reflect the
0715: * changes occurring on the document.
0716: * <br> If errors occur during the invocation of this method, such as an
0717: * attempt to update a read-only node or a <code>Node.nodeName</code>
0718: * contains an invalid character according to the XML version in use,
0719: * errors or warnings (<code>DOMError.SEVERITY_ERROR</code> or
0720: * <code>DOMError.SEVERITY_WARNING</code>) will be reported using the
0721: * <code>DOMErrorHandler</code> object associated with the "error-handler
0722: * " parameter. Note this method might also report fatal errors (
0723: * <code>DOMError.SEVERITY_FATAL_ERROR</code>) if an implementation
0724: * cannot recover from an error.
0725: * @since DOM Level 3
0726: */
0727: public void normalizeDocument() {
0728: //TODO Implement later
0729: }
0730:
0731: /**
0732: * This is a convenience attribute that allows direct access to the child
0733: * node that is the document element of the document.
0734: */
0735: public org.w3c.dom.Element getDocumentElement() {
0736: if (hasChildNodes()) {
0737: NodeList childNodes = getChildNodes();
0738: for (int i = 0; i < childNodes.getLength(); i++) {
0739: Node child = (Node) childNodes.item(i);
0740: if (child instanceof org.w3c.dom.Element)
0741: return (org.w3c.dom.Element) child;
0742: }
0743: }
0744: return null;
0745: }
0746:
0747: /**
0748: * The Document Type Declaration (see <code>DocumentType</code>)
0749: * associated with this document. For XML documents without a document
0750: * type declaration this returns <code>null</code>. For HTML documents,
0751: * a <code>DocumentType</code> object may be returned, independently of
0752: * the presence or absence of document type declaration in the HTML
0753: * document.
0754: * <br>This provides direct access to the <code>DocumentType</code> node,
0755: * child node of this <code>Document</code>. This node can be set at
0756: * document creation time and later changed through the use of child
0757: * nodes manipulation methods, such as <code>Node.insertBefore</code>,
0758: * or <code>Node.replaceChild</code>. Note, however, that while some
0759: * implementations may instantiate different types of
0760: * <code>Document</code> objects supporting additional features than the
0761: * "Core", such as "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
0762: * , based on the <code>DocumentType</code> specified at creation time,
0763: * changing it afterwards is very unlikely to result in a change of the
0764: * features supported.
0765: * @version DOM Level 3
0766: */
0767: public org.w3c.dom.DocumentType getDoctype() {
0768: //TODO Implement later
0769: return null;
0770: }
0771:
0772: /**
0773: * The location of the document or <code>null</code> if undefined or if
0774: * the <code>Document</code> was created using
0775: * <code>DOMImplementation.createDocument</code>. No lexical checking is
0776: * performed when setting this attribute; this could result in a
0777: * <code>null</code> value returned when using <code>Node.baseURI</code>
0778: * .
0779: * <br> Beware that when the <code>Document</code> supports the feature
0780: * "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
0781: * , the href attribute of the HTML BASE element takes precedence over
0782: * this attribute when computing <code>Node.baseURI</code>.
0783: * @since DOM Level 3
0784: */
0785: public void setDocumentURI(String documentURI) {
0786: }
0787:
0788: /**
0789: * The location of the document or <code>null</code> if undefined or if
0790: * the <code>Document</code> was created using
0791: * <code>DOMImplementation.createDocument</code>. No lexical checking is
0792: * performed when setting this attribute; this could result in a
0793: * <code>null</code> value returned when using <code>Node.baseURI</code>
0794: * .
0795: * <br> Beware that when the <code>Document</code> supports the feature
0796: * "HTML" [<a href='http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109'>DOM Level 2 HTML</a>]
0797: * , the href attribute of the HTML BASE element takes precedence over
0798: * this attribute when computing <code>Node.baseURI</code>.
0799: * @since DOM Level 3
0800: */
0801: public String getDocumentURI() {
0802: //TODO Implement later
0803: return null;
0804: }
0805:
0806: /**
0807: * The configuration used when <code>Document.normalizeDocument()</code>
0808: * is invoked.
0809: * @since DOM Level 3
0810: */
0811: public org.w3c.dom.DOMConfiguration getDomConfig() {
0812: //TODO Implement later
0813: return null;
0814: }
0815:
0816: /**
0817: * The <code>DOMImplementation</code> object that handles this document. A
0818: * DOM application may use objects from multiple implementations.
0819: */
0820: public org.w3c.dom.DOMImplementation getImplementation() {
0821: //TODO Implement later
0822: return null;
0823: }
0824:
0825: /**
0826: * An attribute specifying the encoding used for this document at the time
0827: * of the parsing. This is <code>null</code> when it is not known, such
0828: * as when the <code>Document</code> was created in memory.
0829: * @since DOM Level 3
0830: */
0831: public String getInputEncoding() {
0832: //TODO Implement later
0833: return null;
0834: }
0835:
0836: /**
0837: * An attribute specifying whether error checking is enforced or not. When
0838: * set to <code>false</code>, the implementation is free to not test
0839: * every possible error case normally defined on DOM operations, and not
0840: * raise any <code>DOMException</code> on DOM operations or report
0841: * errors while using <code>Document.normalizeDocument()</code>. In case
0842: * of error, the behavior is undefined. This attribute is
0843: * <code>true</code> by default.
0844: * @since DOM Level 3
0845: */
0846: public void setStrictErrorChecking(boolean strictErrorChecking) {
0847: }
0848:
0849: /**
0850: * An attribute specifying whether error checking is enforced or not. When
0851: * set to <code>false</code>, the implementation is free to not test
0852: * every possible error case normally defined on DOM operations, and not
0853: * raise any <code>DOMException</code> on DOM operations or report
0854: * errors while using <code>Document.normalizeDocument()</code>. In case
0855: * of error, the behavior is undefined. This attribute is
0856: * <code>true</code> by default.
0857: * @since DOM Level 3
0858: */
0859: public boolean getStrictErrorChecking() {
0860: //TODO Implement later
0861: return false;
0862: }
0863:
0864: /**
0865: * 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
0866: * unspecified or when it is not known, such as when the
0867: * <code>Document</code> was created in memory.
0868: * @since DOM Level 3
0869: */
0870: public String getXmlEncoding() {
0871: for (Token token : super .getTokens()) {
0872: if (token.getType() == TokenType.TOKEN_PI_VAL) {
0873: String versionImage = token.getValue();
0874: int versionIndex = versionImage.indexOf("encoding");
0875: if (versionIndex == -1)
0876: return null;
0877: versionIndex = versionImage.indexOf('=', versionIndex);
0878: if (versionIndex == -1)
0879: return null;
0880: versionImage = versionImage.substring(versionIndex + 1)
0881: .trim();
0882: if (versionImage.startsWith("\"")) {
0883: int versionEndIndex = versionImage.indexOf('"', 1);
0884: if (versionEndIndex == -1)
0885: return null;
0886: return versionImage.substring(1, versionEndIndex);
0887: } else if (versionImage.startsWith("'")) {
0888: int versionEndIndex = versionImage.indexOf('\'', 1);
0889: if (versionEndIndex == -1)
0890: return null;
0891: return versionImage.substring(1, versionEndIndex);
0892: }
0893: }
0894: }
0895: return null;
0896: }
0897:
0898: /**
0899: * 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
0900: * unspecified.
0901: * <p ><b>Note:</b> No verification is done on the value when setting
0902: * this attribute. Applications should use
0903: * <code>Document.normalizeDocument()</code> with the "validate"
0904: * parameter to verify if the value matches the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#sec-rmd'>validity
0905: * constraint for standalone document declaration</a> as defined in [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>].
0906: * @exception DOMException
0907: * NOT_SUPPORTED_ERR: Raised if this document does not support the
0908: * "XML" feature.
0909: * @since DOM Level 3
0910: */
0911: public void setXmlStandalone(boolean xmlStandalone) {
0912: //TODO Implement later
0913: }
0914:
0915: /**
0916: * 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
0917: * unspecified.
0918: * <p ><b>Note:</b> No verification is done on the value when setting
0919: * this attribute. Applications should use
0920: * <code>Document.normalizeDocument()</code> with the "validate"
0921: * parameter to verify if the value matches the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#sec-rmd'>validity
0922: * constraint for standalone document declaration</a> as defined in [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>].
0923: * @since DOM Level 3
0924: */
0925: public boolean getXmlStandalone() {
0926: for (Token token : super .getTokens()) {
0927: if (token.getType() == TokenType.TOKEN_PI_VAL) {
0928: String versionImage = token.getValue();
0929: int versionIndex = versionImage.indexOf("standalone");
0930: if (versionIndex == -1)
0931: return false;
0932: versionIndex = versionImage.indexOf('=', versionIndex);
0933: if (versionIndex == -1)
0934: return false;
0935: versionImage = versionImage.substring(versionIndex + 1)
0936: .trim();
0937: if (versionImage.startsWith("\"")) {
0938: int versionEndIndex = versionImage.indexOf('"', 1);
0939: if (versionEndIndex == -1)
0940: return false;
0941: return versionImage.substring(1, versionEndIndex)
0942: .equals("yes");
0943: } else if (versionImage.startsWith("'")) {
0944: int versionEndIndex = versionImage.indexOf('\'', 1);
0945: if (versionEndIndex == -1)
0946: return false;
0947: return versionImage.substring(1, versionEndIndex)
0948: .equals("yes");
0949: }
0950: }
0951: }
0952: return false;
0953: }
0954:
0955: /**
0956: * 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
0957: * this document supports the "XML" feature, the value is
0958: * <code>"1.0"</code>. If this document does not support the "XML"
0959: * feature, the value is always <code>null</code>. Changing this
0960: * attribute will affect methods that check for invalid characters in
0961: * XML names. Application should invoke
0962: * <code>Document.normalizeDocument()</code> in order to check for
0963: * invalid characters in the <code>Node</code>s that are already part of
0964: * this <code>Document</code>.
0965: * <br> DOM applications may use the
0966: * <code>DOMImplementation.hasFeature(feature, version)</code> method
0967: * with parameter values "XMLVersion" and "1.0" (respectively) to
0968: * determine if an implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. DOM
0969: * applications may use the same method with parameter values
0970: * "XMLVersion" and "1.1" (respectively) to determine if an
0971: * implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. In both
0972: * cases, in order to support XML, an implementation must also support
0973: * the "XML" feature defined in this specification. <code>Document</code>
0974: * objects supporting a version of the "XMLVersion" feature must not
0975: * raise a <code>NOT_SUPPORTED_ERR</code> exception for the same version
0976: * number when using <code>Document.xmlVersion</code>.
0977: * @exception DOMException
0978: * NOT_SUPPORTED_ERR: Raised if the version is set to a value that is
0979: * not supported by this <code>Document</code> or if this document
0980: * does not support the "XML" feature.
0981: * @since DOM Level 3
0982: */
0983: public void setXmlVersion(String xmlVersion) {
0984: //TODO Implement later
0985: }
0986:
0987: /**
0988: * 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
0989: * this document supports the "XML" feature, the value is
0990: * <code>"1.0"</code>. If this document does not support the "XML"
0991: * feature, the value is always <code>null</code>. Changing this
0992: * attribute will affect methods that check for invalid characters in
0993: * XML names. Application should invoke
0994: * <code>Document.normalizeDocument()</code> in order to check for
0995: * invalid characters in the <code>Node</code>s that are already part of
0996: * this <code>Document</code>.
0997: * <br> DOM applications may use the
0998: * <code>DOMImplementation.hasFeature(feature, version)</code> method
0999: * with parameter values "XMLVersion" and "1.0" (respectively) to
1000: * determine if an implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml-20040204'>XML 1.0</a>]. DOM
1001: * applications may use the same method with parameter values
1002: * "XMLVersion" and "1.1" (respectively) to determine if an
1003: * implementation supports [<a href='http://www.w3.org/TR/2004/REC-xml11-20040204/'>XML 1.1</a>]. In both
1004: * cases, in order to support XML, an implementation must also support
1005: * the "XML" feature defined in this specification. <code>Document</code>
1006: * objects supporting a version of the "XMLVersion" feature must not
1007: * raise a <code>NOT_SUPPORTED_ERR</code> exception for the same version
1008: * number when using <code>Document.xmlVersion</code>.
1009: * @since DOM Level 3
1010: */
1011: public String getXmlVersion() {
1012: for (Token token : super .getTokens()) {
1013: if (token.getType() == TokenType.TOKEN_PI_VAL) {
1014: String versionImage = token.getValue();
1015: int versionIndex = versionImage.indexOf("version");
1016: if (versionIndex == -1)
1017: return null;
1018: versionIndex = versionImage.indexOf('=', versionIndex);
1019: if (versionIndex == -1)
1020: return null;
1021: versionImage = versionImage.substring(versionIndex + 1)
1022: .trim();
1023: if (versionImage.startsWith("\"")) {
1024: int versionEndIndex = versionImage.indexOf('"', 1);
1025: if (versionEndIndex == -1)
1026: return null;
1027: return versionImage.substring(1, versionEndIndex);
1028: } else if (versionImage.startsWith("'")) {
1029: int versionEndIndex = versionImage.indexOf('\'', 1);
1030: if (versionEndIndex == -1)
1031: return null;
1032: return versionImage.substring(1, versionEndIndex);
1033: }
1034: }
1035: }
1036: return null;
1037: }
1038:
1039: /**
1040: * This api returns the namespaceuri of specified node.
1041: * @param node The node which namespace to find.
1042: * @return The namespaceuri of given node.
1043: */
1044: public String getNamespaceURI(Node node) {
1045: return getNamespaceCache().findNamespace(node);
1046: }
1047:
1048: private FindNamespaceVisitor getNamespaceCache() {
1049: if (fnv == null || fnv.get() == null) {
1050: fnv = new SoftReference<FindNamespaceVisitor>(
1051: new FindNamespaceVisitor(this ));
1052: }
1053: return fnv.get();
1054: }
1055:
1056: Map<Integer, String> getNamespaceMap() {
1057: return getNamespaceCache().getNamespaceMap();
1058: }
1059:
1060: /**
1061: * Namespace finder visitor
1062: */
1063: private SoftReference<FindNamespaceVisitor> fnv;
1064: }
|