1 21 24 package org.lobobrowser.html.domimpl; 25 26 import org.lobobrowser.js.*; 27 import org.w3c.dom.*; 28 import java.util.*; 29 30 public class NamedNodeMapImpl extends AbstractScriptableDelegate implements NamedNodeMap { 31 private final Map attributes = new HashMap(); 33 private final ArrayList attributeList = new ArrayList(); 34 35 public NamedNodeMapImpl(Element owner, Map attribs) { 36 Iterator i = attribs.entrySet().iterator(); 37 while(i.hasNext()) { 38 Map.Entry entry = (Map.Entry) i.next(); 39 String name = (String ) entry.getKey(); 40 String value = (String ) entry.getValue(); 41 Attr attr = new AttrImpl(name, value, true, owner, "ID".equals(name)); 43 this.attributes.put(name, attr); 44 this.attributeList.add(attr); 45 } 46 } 47 48 public int getLength() { 49 return this.attributeList.size(); 50 } 51 52 public Node getNamedItem(String name) { 53 return (Node) this.attributes.get(name); 54 } 55 56 59 public Node namedItem(String name) { 60 return this.getNamedItem(name); 62 } 63 64 public Node getNamedItemNS(String namespaceURI, 65 String localName) throws DOMException { 66 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "No namespace support"); 67 } 68 69 public Node item(int index) { 70 try { 71 return (Node) this.attributeList.get(index); 72 } catch(IndexOutOfBoundsException iob) { 73 return null; 74 } 75 } 76 77 public Node removeNamedItem(String name) throws DOMException { 78 return (Node) this.attributes.remove(name); 79 } 80 81 public Node removeNamedItemNS(String namespaceURI, 82 String localName) throws DOMException { 83 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "No namespace support"); 84 } 85 86 public Node setNamedItem(Node arg) throws DOMException { 87 Object prevValue = this.attributes.put(arg.getNodeName(), arg); 88 if(prevValue != null) { 89 this.attributeList.remove(prevValue); 90 } 91 this.attributeList.add(arg); 92 return arg; 93 } 94 95 public Node setNamedItemNS(Node arg) throws DOMException { 96 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "No namespace support"); 97 } 98 } 99 | Popular Tags |