19f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 29f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Licensed to the Apache Software Foundation (ASF) under one 39f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or more contributor license agreements. See the NOTICE file 49f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed with this work for additional information 59f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * regarding copyright ownership. The ASF licenses this file 69f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to you under the Apache License, Version 2.0 (the "License"); 79f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * you may not use this file except in compliance with the License. 89f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * You may obtain a copy of the License at 99f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Unless required by applicable law or agreed to in writing, software 139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * See the License for the specific language governing permissions and 169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * limitations under the License. 179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * $Id: DOM2DTMdefaultNamespaceDeclarationNode.java 468653 2006-10-28 07:07:05Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xml.dtm.ref.dom2dtm; 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTMException; 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Attr; 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Document; 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Element; 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.NamedNodeMap; 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Node; 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.NodeList; 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.TypeInfo; 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.UserDataHandler; 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.DOMException; 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** This is a kluge to let us shove a declaration for xml: into the 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DOM2DTM model. Basically, it creates a proxy node in DOM space to 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * carry the additional information. This is _NOT_ a full DOM 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * implementation, and shouldn't be one since it sits alongside the 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DOM rather than becoming part of the DOM model. 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * (This used to be an internal class within DOM2DTM. Moved out because 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * I need to perform an instanceof operation on it to support a temporary 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * workaround in DTMManagerDefault.) 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * %REVIEW% What if the DOM2DTM was built around a DocumentFragment and 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * there isn't a single root element? I think this fails that case... 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * %REVIEW% An alternative solution would be to create the node _only_ 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * in DTM space, but given how DOM2DTM is currently written I think 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * this is simplest. 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * */ 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class DOM2DTMdefaultNamespaceDeclarationNode implements Attr,TypeInfo 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson final String NOT_SUPPORTED_ERR="Unsupported operation on pseudonode"; 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Element pseudoparent; 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String prefix,uri,nodename; 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int handle; 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DOM2DTMdefaultNamespaceDeclarationNode(Element pseudoparent,String prefix,String uri,int handle) 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.pseudoparent=pseudoparent; 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.prefix=prefix; 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.uri=uri; 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.handle=handle; 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.nodename="xmlns:"+prefix; 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getNodeName() {return nodename;} 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getName() {return nodename;} 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getNamespaceURI() {return "http://www.w3.org/2000/xmlns/";} 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getPrefix() {return prefix;} 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getLocalName() {return prefix;} 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getNodeValue() {return uri;} 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getValue() {return uri;} 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Element getOwnerElement() {return pseudoparent;} 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isSupported(String feature, String version) {return false;} 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean hasChildNodes() {return false;} 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean hasAttributes() {return false;} 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node getParentNode() {return null;} 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node getFirstChild() {return null;} 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node getLastChild() {return null;} 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node getPreviousSibling() {return null;} 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node getNextSibling() {return null;} 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean getSpecified() {return false;} 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void normalize() {return;} 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public NodeList getChildNodes() {return null;} 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public NamedNodeMap getAttributes() {return null;} 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public short getNodeType() {return Node.ATTRIBUTE_NODE;} 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setNodeValue(String value) {throw new DTMException(NOT_SUPPORTED_ERR);} 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setValue(String value) {throw new DTMException(NOT_SUPPORTED_ERR);} 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setPrefix(String value) {throw new DTMException(NOT_SUPPORTED_ERR);} 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node insertBefore(Node a, Node b) {throw new DTMException(NOT_SUPPORTED_ERR);} 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node replaceChild(Node a, Node b) {throw new DTMException(NOT_SUPPORTED_ERR);} 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node appendChild(Node a) {throw new DTMException(NOT_SUPPORTED_ERR);} 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node removeChild(Node a) {throw new DTMException(NOT_SUPPORTED_ERR);} 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Document getOwnerDocument() {return pseudoparent.getOwnerDocument();} 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node cloneNode(boolean deep) {throw new DTMException(NOT_SUPPORTED_ERR);} 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** Non-DOM method, part of the temporary kluge 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * %REVIEW% This would be a pruning problem, but since it will always be 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * added to the root element and we prune on elements, we shouldn't have 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to worry. 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getHandleOfNode() 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return handle; 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson //RAMESH: PENDING=> Add proper implementation for the below DOM L3 additions 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.w3c.dom.TypeInfo#getTypeName() 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getTypeName() {return null; } 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see org.w3c.dom.TypeInfo#getTypeNamespace() 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getTypeNamespace() { return null;} 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @see or.gw3c.dom.TypeInfo#isDerivedFrom(String,String,int) 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isDerivedFrom( String ns, String localName, int derivationMethod ) { 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public TypeInfo getSchemaTypeInfo() { return this; } 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isId( ) { return false; } 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Associate an object to a key on this node. The object can later be 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * retrieved from this node by calling <code>getUserData</code> with the 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * same key. 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param key The key to associate the object to. 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param data The object to associate to the given key, or 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>null</code> to remove any existing association to that key. 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param handler The handler to associate to that key, or 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>null</code>. 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Returns the <code>DOMObject</code> previously associated to 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the given key on this node, or <code>null</code> if there was none. 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Object setUserData(String key, 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Object data, 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson UserDataHandler handler) { 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return getOwnerDocument().setUserData( key, data, handler); 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Retrieves the object associated to a key on a this node. The object 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * must first have been set to this node by calling 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>setUserData</code> with the same key. 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param key The key the object is associated to. 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Returns the <code>DOMObject</code> associated to the given key 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * on this node, or <code>null</code> if there was none. 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Object getUserData(String key) { 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return getOwnerDocument().getUserData( key); 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This method returns a specialized object which implements the 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * specialized APIs of the specified feature and version. The 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * specialized object may also be obtained by using binding-specific 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * casting methods but is not necessarily expected to, as discussed in Mixed DOM implementations. 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param feature The name of the feature requested (case-insensitive). 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param version This is the version number of the feature to test. If 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the version is <code>null</code> or the empty string, supporting 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * any version of the feature will cause the method to return an 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * object that supports at least one version of the feature. 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Returns an object which implements the specialized APIs of 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the specified feature and version, if any, or <code>null</code> if 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * there is no object which implements interfaces associated with that 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * feature. If the <code>DOMObject</code> returned by this method 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * implements the <code>Node</code> interface, it must delegate to the 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * primary core <code>Node</code> and not return results inconsistent 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * with the primary core <code>Node</code> such as attributes, 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * childNodes, etc. 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Object getFeature(String feature, String version) { 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // we don't have any alternate node, either this node does the job 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // or we don't have anything that does 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return isSupported(feature, version) ? this : null; 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Tests whether two nodes are equal. 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>This method tests for equality of nodes, not sameness (i.e., 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * whether the two nodes are references to the same object) which can be 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * tested with <code>Node.isSameNode</code>. All nodes that are the same 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * will also be equal, though the reverse may not be true. 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>Two nodes are equal if and only if the following conditions are 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * satisfied: The two nodes are of the same type.The following string 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * attributes are equal: <code>nodeName</code>, <code>localName</code>, 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>namespaceURI</code>, <code>prefix</code>, <code>nodeValue</code> 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * , <code>baseURI</code>. This is: they are both <code>null</code>, or 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * they have the same length and are character for character identical. 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The <code>attributes</code> <code>NamedNodeMaps</code> are equal. 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This is: they are both <code>null</code>, or they have the same 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * length and for each node that exists in one map there is a node that 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * exists in the other map and is equal, although not necessarily at the 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * same index.The <code>childNodes</code> <code>NodeLists</code> are 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * equal. This is: they are both <code>null</code>, or they have the 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * same length and contain equal nodes at the same index. This is true 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * for <code>Attr</code> nodes as for any other type of node. Note that 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * normalization can affect equality; to avoid this, nodes should be 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * normalized before being compared. 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>For two <code>DocumentType</code> nodes to be equal, the following 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * conditions must also be satisfied: The following string attributes 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * are equal: <code>publicId</code>, <code>systemId</code>, 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>internalSubset</code>.The <code>entities</code> 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>NamedNodeMaps</code> are equal.The <code>notations</code> 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>NamedNodeMaps</code> are equal. 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>On the other hand, the following do not affect equality: the 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>ownerDocument</code> attribute, the <code>specified</code> 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * attribute for <code>Attr</code> nodes, the 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>isWhitespaceInElementContent</code> attribute for 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>Text</code> nodes, as well as any user data or event listeners 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * registered on the nodes. 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param arg The node to compare equality with. 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param deep If <code>true</code>, recursively compare the subtrees; if 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>false</code>, compare only the nodes themselves (and its 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * attributes, if it is an <code>Element</code>). 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return If the nodes, and possibly subtrees are equal, 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>true</code> otherwise <code>false</code>. 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isEqualNode(Node arg) { 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (arg == this) { 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return true; 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (arg.getNodeType() != getNodeType()) { 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // in theory nodeName can't be null but better be careful 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // who knows what other implementations may be doing?... 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (getNodeName() == null) { 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (arg.getNodeName() != null) { 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if (!getNodeName().equals(arg.getNodeName())) { 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (getLocalName() == null) { 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (arg.getLocalName() != null) { 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if (!getLocalName().equals(arg.getLocalName())) { 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (getNamespaceURI() == null) { 2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (arg.getNamespaceURI() != null) { 2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if (!getNamespaceURI().equals(arg.getNamespaceURI())) { 2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (getPrefix() == null) { 2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (arg.getPrefix() != null) { 2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if (!getPrefix().equals(arg.getPrefix())) { 2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (getNodeValue() == null) { 2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (arg.getNodeValue() != null) { 2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if (!getNodeValue().equals(arg.getNodeValue())) { 2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /* 2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (getBaseURI() == null) { 2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (((NodeImpl) arg).getBaseURI() != null) { 2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else if (!getBaseURI().equals(((NodeImpl) arg).getBaseURI())) { 2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson*/ 2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return true; 2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DOM Level 3 - Experimental: 3029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Look up the namespace URI associated to the given prefix, starting from this node. 3039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Use lookupNamespaceURI(null) to lookup the default namespace 3049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 3059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param namespaceURI 3069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return th URI for the namespace 3079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 3089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String lookupNamespaceURI(String specifiedPrefix) { 3109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson short type = this.getNodeType(); 3119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson switch (type) { 3129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.ELEMENT_NODE : { 3139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String namespace = this.getNamespaceURI(); 3159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String prefix = this.getPrefix(); 3169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (namespace !=null) { 3179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // REVISIT: is it possible that prefix is empty string? 3189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (specifiedPrefix== null && prefix==specifiedPrefix) { 3199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // looking for default namespace 3209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return namespace; 3219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } else if (prefix != null && prefix.equals(specifiedPrefix)) { 3229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // non default namespace 3239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return namespace; 3249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (this.hasAttributes()) { 3279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NamedNodeMap map = this.getAttributes(); 3289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int length = map.getLength(); 3299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int i=0;i<length;i++) { 3309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Node attr = map.item(i); 3319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String attrPrefix = attr.getPrefix(); 3329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String value = attr.getNodeValue(); 3339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson namespace = attr.getNamespaceURI(); 3349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) { 3359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // at this point we are dealing with DOM Level 2 nodes only 3369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (specifiedPrefix == null && 3379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson attr.getNodeName().equals("xmlns")) { 3389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // default namespace 3399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return value; 3409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } else if (attrPrefix !=null && 3419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson attrPrefix.equals("xmlns") && 3429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson attr.getLocalName().equals(specifiedPrefix)) { 3439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // non default namespace 3449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return value; 3459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /* 3509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NodeImpl ancestor = (NodeImpl)getElementAncestor(this); 3519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (ancestor != null) { 3529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ancestor.lookupNamespaceURI(specifiedPrefix); 3539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 3579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 3619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.DOCUMENT_NODE : { 3629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ; 3639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson*/ 3659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.ENTITY_NODE : 3669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.NOTATION_NODE: 3679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.DOCUMENT_FRAGMENT_NODE: 3689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.DOCUMENT_TYPE_NODE: 3699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // type is unknown 3709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 3719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.ATTRIBUTE_NODE:{ 3729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { 3739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return getOwnerElement().lookupNamespaceURI(specifiedPrefix); 3749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 3779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson default:{ 3799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /* 3809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NodeImpl ancestor = (NodeImpl)getElementAncestor(this); 3819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (ancestor != null) { 3829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ancestor.lookupNamespaceURI(specifiedPrefix); 3839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 3859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 3869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 3919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 3929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DOM Level 3: Experimental 3939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This method checks if the specified <code>namespaceURI</code> is the 3949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * default namespace or not. 3959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param namespaceURI The namespace URI to look for. 3969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return <code>true</code> if the specified <code>namespaceURI</code> 3979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is the default namespace, <code>false</code> otherwise. 3989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 3999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isDefaultNamespace(String namespaceURI){ 4019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /* 4029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // REVISIT: remove casts when DOM L3 becomes REC. 4039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson short type = this.getNodeType(); 4049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson switch (type) { 4059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.ELEMENT_NODE: { 4069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String namespace = this.getNamespaceURI(); 4079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String prefix = this.getPrefix(); 4089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // REVISIT: is it possible that prefix is empty string? 4109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (prefix == null || prefix.length() == 0) { 4119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (namespaceURI == null) { 4129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (namespace == namespaceURI); 4139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return namespaceURI.equals(namespace); 4159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (this.hasAttributes()) { 4179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ElementImpl elem = (ElementImpl)this; 4189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NodeImpl attr = (NodeImpl)elem.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "xmlns"); 4199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (attr != null) { 4209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String value = attr.getNodeValue(); 4219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (namespaceURI == null) { 4229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (namespace == value); 4239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return namespaceURI.equals(value); 4259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NodeImpl ancestor = (NodeImpl)getElementAncestor(this); 4299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (ancestor != null) { 4309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ancestor.isDefaultNamespace(namespaceURI); 4319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 4339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.DOCUMENT_NODE:{ 4359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return((NodeImpl)((Document)this).getDocumentElement()).isDefaultNamespace(namespaceURI); 4369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.ENTITY_NODE : 4399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.NOTATION_NODE: 4409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.DOCUMENT_FRAGMENT_NODE: 4419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.DOCUMENT_TYPE_NODE: 4429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // type is unknown 4439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 4449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.ATTRIBUTE_NODE:{ 4459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (this.ownerNode.getNodeType() == Node.ELEMENT_NODE) { 4469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ownerNode.isDefaultNamespace(namespaceURI); 4479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 4509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson default:{ 4529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NodeImpl ancestor = (NodeImpl)getElementAncestor(this); 4539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (ancestor != null) { 4549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ancestor.isDefaultNamespace(namespaceURI); 4559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 4579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson*/ 4619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return false; 4629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 4679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DOM Level 3 - Experimental: 4699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Look up the prefix associated to the given namespace URI, starting from this node. 4709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 4719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param namespaceURI 4729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return the prefix for the namespace 4739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 4749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String lookupPrefix(String namespaceURI){ 4759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // REVISIT: When Namespaces 1.1 comes out this may not be true 4779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // Prefix can't be bound to null namespace 4789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (namespaceURI == null) { 4799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 4809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson short type = this.getNodeType(); 4839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson switch (type) { 4859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 4869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.ELEMENT_NODE: { 4879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String namespace = this.getNamespaceURI(); // to flip out children 4899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return lookupNamespacePrefix(namespaceURI, (ElementImpl)this); 4909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 4929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.DOCUMENT_NODE:{ 4939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI); 4949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 4959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson*/ 4969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.ENTITY_NODE : 4979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.NOTATION_NODE: 4989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.DOCUMENT_FRAGMENT_NODE: 4999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.DOCUMENT_TYPE_NODE: 5009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // type is unknown 5019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 5029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson case Node.ATTRIBUTE_NODE:{ 5039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { 5049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return getOwnerElement().lookupPrefix(namespaceURI); 5059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 5089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson default:{ 5109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/* 5119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson NodeImpl ancestor = (NodeImpl)getElementAncestor(this); 5129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (ancestor != null) { 5139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return ancestor.lookupPrefix(namespaceURI); 5149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson*/ 5169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 5179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns whether this node is the same node as the given one. 5239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>This method provides a way to determine whether two 5249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>Node</code> references returned by the implementation reference 5259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the same object. When two <code>Node</code> references are references 5269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * to the same object, even if through a proxy, the references may be 5279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * used completely interchangably, such that all attributes have the 5289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * same values and calling the same DOM method on either reference 5299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * always has exactly the same effect. 5309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param other The node to test against. 5319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Returns <code>true</code> if the nodes are the same, 5329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>false</code> otherwise. 5339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 5349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public boolean isSameNode(Node other) { 5369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson // we do not use any wrapper so the answer is obvious 5379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return this == other; 5389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This attribute returns the text content of this node and its 5429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * descendants. When it is defined to be null, setting it has no effect. 5439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When set, any possible children this node may have are removed and 5449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * replaced by a single <code>Text</code> node containing the string 5459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * this attribute is set to. On getting, no serialization is performed, 5469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the returned string does not contain any markup. No whitespace 5479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * normalization is performed, the returned string does not contain the 5489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * element content whitespaces . Similarly, on setting, no parsing is 5499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * performed either, the input string is taken as pure textual content. 5509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>The string returned is made of the text content of this node 5519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * depending on its type, as defined below: 5529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <table border='1'> 5539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <tr> 5549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <th>Node type</th> 5559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <th>Content</th> 5569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </tr> 5579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <tr> 5589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'> 5599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, 5609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DOCUMENT_FRAGMENT_NODE</td> 5619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'>concatenation of the <code>textContent</code> 5629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * attribute value of every child node, excluding COMMENT_NODE and 5639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * PROCESSING_INSTRUCTION_NODE nodes</td> 5649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </tr> 5659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <tr> 5669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'>ATTRIBUTE_NODE, TEXT_NODE, 5679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE</td> 5689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'> 5699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>nodeValue</code></td> 5709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </tr> 5719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <tr> 5729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td> 5739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'> 5749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * null</td> 5759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </tr> 5769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </table> 5779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @exception DOMException 5789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. 5799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @exception DOMException 5809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DOMSTRING_SIZE_ERR: Raised when it would return more characters than 5819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * fit in a <code>DOMString</code> variable on the implementation 5829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * platform. 5839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 5849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 5859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public void setTextContent(String textContent) 5869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws DOMException { 5879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson setNodeValue(textContent); 5889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 5899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 5909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 5919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This attribute returns the text content of this node and its 5929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * descendants. When it is defined to be null, setting it has no effect. 5939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * When set, any possible children this node may have are removed and 5949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * replaced by a single <code>Text</code> node containing the string 5959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * this attribute is set to. On getting, no serialization is performed, 5969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the returned string does not contain any markup. No whitespace 5979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * normalization is performed, the returned string does not contain the 5989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * element content whitespaces . Similarly, on setting, no parsing is 5999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * performed either, the input string is taken as pure textual content. 6009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>The string returned is made of the text content of this node 6019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * depending on its type, as defined below: 6029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <table border='1'> 6039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <tr> 6049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <th>Node type</th> 6059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <th>Content</th> 6069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </tr> 6079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <tr> 6089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'> 6099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, 6109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DOCUMENT_FRAGMENT_NODE</td> 6119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'>concatenation of the <code>textContent</code> 6129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * attribute value of every child node, excluding COMMENT_NODE and 6139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * PROCESSING_INSTRUCTION_NODE nodes</td> 6149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </tr> 6159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <tr> 6169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'>ATTRIBUTE_NODE, TEXT_NODE, 6179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE</td> 6189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'> 6199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>nodeValue</code></td> 6209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </tr> 6219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <tr> 6229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'>DOCUMENT_NODE, DOCUMENT_TYPE_NODE, NOTATION_NODE</td> 6239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <td valign='top' rowspan='1' colspan='1'> 6249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * null</td> 6259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </tr> 6269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * </table> 6279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @exception DOMException 6289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. 6299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @exception DOMException 6309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DOMSTRING_SIZE_ERR: Raised when it would return more characters than 6319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * fit in a <code>DOMString</code> variable on the implementation 6329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * platform. 6339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 6349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 6359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getTextContent() throws DOMException { 6369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return getNodeValue(); // overriden in some subclasses 6379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 6409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Compares a node with this node with regard to their position in the 6419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * document. 6429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param other The node to compare against this node. 6439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return Returns how the given node is positioned relatively to this 6449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * node. 6459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 6469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 6479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public short compareDocumentPosition(Node other) throws DOMException { 6489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return 0; 6499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 6519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 6529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * The absolute base URI of this node or <code>null</code> if undefined. 6539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * This value is computed according to . However, when the 6549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>Document</code> supports the feature "HTML" , the base URI is 6559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * computed using first the value of the href attribute of the HTML BASE 6569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * element if any, and the value of the <code>documentURI</code> 6579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * attribute from the <code>Document</code> interface otherwise. 6589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br> When the node is an <code>Element</code>, a <code>Document</code> 6599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * or a a <code>ProcessingInstruction</code>, this attribute represents 6609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the properties [base URI] defined in . When the node is a 6619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>Notation</code>, an <code>Entity</code>, or an 6629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>EntityReference</code>, this attribute represents the 6639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * properties [declaration base URI] in the . How will this be affected 6649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * by resolution of relative namespace URIs issue?It's not.Should this 6659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * only be on Document, Element, ProcessingInstruction, Entity, and 6669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Notation nodes, according to the infoset? If not, what is it equal to 6679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * on other nodes? Null? An empty string? I think it should be the 6689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * parent's.No.Should this be read-only and computed or and actual 6699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * read-write attribute?Read-only and computed (F2F 19 Jun 2000 and 6709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * teleconference 30 May 2001).If the base HTML element is not yet 6719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * attached to a document, does the insert change the Document.baseURI? 6729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Yes. (F2F 26 Sep 2001) 6739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 3 6749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 6759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public String getBaseURI() { 6769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 6779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 6789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 6799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 680