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: DTMNamedNodeMap.java 468653 2006-10-28 07:07:05Z minchau $ 209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpackage org.apache.xml.dtm.ref; 229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.apache.xml.dtm.DTM; 249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.DOMException; 269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.NamedNodeMap; 279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonimport org.w3c.dom.Node; 289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson/** 309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DTMNamedNodeMap is a quickie (as opposed to quick) implementation of the DOM's 319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NamedNodeMap interface, intended to support DTMProxy's getAttributes() 329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * call. 339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p> 349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * ***** Note: this does _not_ current attempt to cache any of the data; 359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * if you ask for attribute 27 and then 28, you'll have to rescan the first 369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 27. It should probably at least keep track of the last one retrieved, 379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and possibly buffer the whole array. 389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <p> 399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * ***** Also note that there's no fastpath for the by-name query; we search 409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * linearly until we find it or fail to find it. Again, that could be 419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * optimized at some cost in object creation/storage. 429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilsonpublic class DTMNamedNodeMap implements NamedNodeMap 459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson{ 469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** The DTM for this node. */ 489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson DTM dtm; 499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** The DTM element handle. */ 519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int element; 529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** The number of nodes in this map. */ 549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson short m_count = -1; 559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Create a getAttributes NamedNodeMap for a given DTM element node 589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param dtm The DTM Reference, must be non-null. 609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param element The DTM element handle. 619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public DTMNamedNodeMap(DTM dtm, int element) 639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.dtm = dtm; 659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson this.element = element; 669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Return the number of Attributes on this Element 709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The number of nodes in this map. 729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public int getLength() 749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (m_count == -1) 779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson short count = 0; 799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int n = dtm.getFirstAttribute(element); n != -1; 819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson n = dtm.getNextAttribute(n)) 829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ++count; 849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson m_count = count; 879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return (int) m_count; 909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Retrieves a node specified by name. 949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param name The <code>nodeName</code> of a node to retrieve. 959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A <code>Node</code> (of any type) with the specified 969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>nodeName</code>, or <code>null</code> if it does not identify 979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * any node in this map. 989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node getNamedItem(String name) 1009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int n = dtm.getFirstAttribute(element); n != DTM.NULL; 1039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson n = dtm.getNextAttribute(n)) 1049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (dtm.getNodeName(n).equals(name)) 1069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return dtm.getNode(n); 1079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 1109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Returns the <code>index</code>th item in the map. If <code>index</code> 1149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is greater than or equal to the number of nodes in this map, this 1159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * returns <code>null</code>. 1169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param i The index of the requested item. 1179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The node at the <code>index</code>th position in the map, or 1189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>null</code> if that is not a valid index. 1199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node item(int i) 1219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson int count = 0; 1249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int n = dtm.getFirstAttribute(element); n != -1; 1269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson n = dtm.getNextAttribute(n)) 1279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (count == i) 1299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return dtm.getNode(n); 1309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson else 1319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson ++count; 1329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return null; 1359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Adds a node using its <code>nodeName</code> attribute. If a node with 1399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * that name is already present in this map, it is replaced by the new 1409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * one. 1419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>As the <code>nodeName</code> attribute is used to derive the name 1429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * which the node must be stored under, multiple nodes of certain types 1439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * (those that have a "special" string value) cannot be stored as the 1449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * names would clash. This is seen as preferable to allowing nodes to be 1459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * aliased. 1469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param newNode node to store in this map. The node will later be 1479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * accessible using the value of its <code>nodeName</code> attribute. 1489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return If the new <code>Node</code> replaces an existing node the 1509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * replaced <code>Node</code> is returned, otherwise <code>null</code> 1519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is returned. 1529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @exception DOMException 1539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WRONG_DOCUMENT_ERR: Raised if <code>arg</code> was created from a 1549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * different document than the one that created this map. 1559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly. 1569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>arg</code> is an 1579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>Attr</code> that is already an attribute of another 1589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>Element</code> object. The DOM user must explicitly clone 1599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>Attr</code> nodes to re-use them in other elements. 1609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node setNamedItem(Node newNode) 1629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new DTMException(DTMException.NO_MODIFICATION_ALLOWED_ERR); 1649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Removes a node specified by name. When this map contains the attributes 1689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * attached to an element, if the removed attribute is known to have a 1699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * default value, an attribute immediately appears containing the 1709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * default value as well as the corresponding namespace URI, local name, 1719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * and prefix when applicable. 1729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param name The <code>nodeName</code> of the node to remove. 1739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The node removed from this map if a node with such a name 1759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * exists. 1769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @exception DOMException 1779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NOT_FOUND_ERR: Raised if there is no node named <code>name</code> in 1789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * this map. 1799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly. 1809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node removeNamedItem(String name) 1829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new DTMException(DTMException.NO_MODIFICATION_ALLOWED_ERR); 1849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 1859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 1869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 1879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Retrieves a node specified by local name and namespace URI. HTML-only 1889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * DOM implementations do not need to implement this method. 1899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param namespaceURI The namespace URI of the node to retrieve. 1909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param localName The local name of the node to retrieve. 1919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 1929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return A <code>Node</code> (of any type) with the specified local 1939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * name and namespace URI, or <code>null</code> if they do not 1949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * identify any node in this map. 1959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 2 1969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 1979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node getNamedItemNS(String namespaceURI, String localName) 1989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 1999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson Node retNode = null; 2009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson for (int n = dtm.getFirstAttribute(element); n != DTM.NULL; 2019f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson n = dtm.getNextAttribute(n)) 2029f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2039f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if (localName.equals(dtm.getLocalName(n))) 2049f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2059f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson String nsURI = dtm.getNamespaceURI(n); 2069f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson if ((namespaceURI == null && nsURI == null) 2079f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson || (namespaceURI != null && namespaceURI.equals(nsURI))) 2089f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2099f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson retNode = dtm.getNode(n); 2109f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson break; 2119f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2129f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2139f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2149f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson return retNode; 2159f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2169f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2179f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2189f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Adds a node using its <code>namespaceURI</code> and 2199f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>localName</code>. If a node with that namespace URI and that 2209f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * local name is already present in this map, it is replaced by the new 2219f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * one. 2229f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>HTML-only DOM implementations do not need to implement this method. 2239f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param arg A node to store in this map. The node will later be 2249f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * accessible using the value of its <code>namespaceURI</code> and 2259f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>localName</code> attributes. 2269f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2279f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return If the new <code>Node</code> replaces an existing node the 2289f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * replaced <code>Node</code> is returned, otherwise <code>null</code> 2299f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * is returned. 2309f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @exception DOMException 2319f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * WRONG_DOCUMENT_ERR: Raised if <code>arg</code> was created from a 2329f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * different document than the one that created this map. 2339f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly. 2349f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>arg</code> is an 2359f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>Attr</code> that is already an attribute of another 2369f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>Element</code> object. The DOM user must explicitly clone 2379f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>Attr</code> nodes to re-use them in other elements. 2389f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 2 2399f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2409f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node setNamedItemNS(Node arg) throws DOMException 2419f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2429f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new DTMException(DTMException.NO_MODIFICATION_ALLOWED_ERR); 2439f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2449f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2459f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2469f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Removes a node specified by local name and namespace URI. A removed 2479f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * attribute may be known to have a default value when this map contains 2489f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * the attributes attached to an element, as returned by the attributes 2499f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * attribute of the <code>Node</code> interface. If so, an attribute 2509f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * immediately appears containing the default value as well as the 2519f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * corresponding namespace URI, local name, and prefix when applicable. 2529f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>HTML-only DOM implementations do not need to implement this method. 2539f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2549f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param namespaceURI The namespace URI of the node to remove. 2559f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param localName The local name of the node to remove. 2569f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2579f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @return The node removed from this map if a node with such a local 2589f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * name and namespace URI exists. 2599f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @exception DOMException 2609f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * NOT_FOUND_ERR: Raised if there is no node with the specified 2619f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <code>namespaceURI</code> and <code>localName</code> in this map. 2629f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly. 2639f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @since DOM Level 2 2649f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2659f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public Node removeNamedItemNS(String namespaceURI, String localName) 2669f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throws DOMException 2679f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2689f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson throw new DTMException(DTMException.NO_MODIFICATION_ALLOWED_ERR); 2699f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2709f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2719f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2729f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Simple implementation of DOMException. 2739f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @xsl.usage internal 2749f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2759f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public class DTMException extends org.w3c.dom.DOMException 2769f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2779f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson static final long serialVersionUID = -8290238117162437678L; 2789f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2799f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Constructs a DOM/DTM exception. 2809f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2819f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param code 2829f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param message 2839f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2849f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public DTMException(short code, String message) 2859f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2869f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson super(code, message); 2879f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2889f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson 2899f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson /** 2909f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * Constructor DTMException 2919f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2929f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * 2939f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson * @param code 2949f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson */ 2959f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson public DTMException(short code) 2969f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson { 2979f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson super(code, ""); 2989f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 2999f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson } 3009f8118474e9513f7a5b7d2a05e4a0fb15d1a6569Jesse Wilson} 301