1 16 19 package com.sun.org.apache.xml.internal.utils; 20 21 import org.w3c.dom.Attr ; 22 import org.w3c.dom.NamedNodeMap ; 23 import org.w3c.dom.Node ; 24 25 import org.xml.sax.Attributes ; 26 27 31 public class AttList implements Attributes 32 { 33 34 35 NamedNodeMap m_attrs; 36 37 38 int m_lastIndex; 39 40 43 44 DOMHelper m_dh; 45 46 60 67 public AttList(NamedNodeMap attrs, DOMHelper dh) 68 { 69 70 m_attrs = attrs; 71 m_lastIndex = m_attrs.getLength() - 1; 72 m_dh = dh; 73 } 74 75 81 public int getLength() 82 { 83 return m_attrs.getLength(); 84 } 85 86 94 public String getURI(int index) 95 { 96 String ns = m_dh.getNamespaceOfNode(((Attr ) m_attrs.item(index))); 97 if(null == ns) 98 ns = ""; 99 return ns; 100 } 101 102 110 public String getLocalName(int index) 111 { 112 return m_dh.getLocalNameOfNode(((Attr ) m_attrs.item(index))); 113 } 114 115 123 public String getQName(int i) 124 { 125 return ((Attr ) m_attrs.item(i)).getName(); 126 } 127 128 136 public String getType(int i) 137 { 138 return "CDATA"; } 140 141 149 public String getValue(int i) 150 { 151 return ((Attr ) m_attrs.item(i)).getValue(); 152 } 153 154 162 public String getType(String name) 163 { 164 return "CDATA"; } 166 167 177 public String getType(String uri, String localName) 178 { 179 return "CDATA"; } 181 182 190 public String getValue(String name) 191 { 192 Attr attr = ((Attr ) m_attrs.getNamedItem(name)); 193 return (null != attr) 194 ? attr.getValue() : null; 195 } 196 197 206 public String getValue(String uri, String localName) 207 { 208 Node a=m_attrs.getNamedItemNS(uri,localName); 209 return (a==null) ? null : a.getNodeValue(); 210 } 211 212 221 public int getIndex(String uri, String localPart) 222 { 223 for(int i=m_attrs.getLength()-1;i>=0;--i) 224 { 225 Node a=m_attrs.item(i); 226 String u=a.getNamespaceURI(); 227 if( (u==null ? uri==null : u.equals(uri)) 228 && 229 a.getLocalName().equals(localPart) ) 230 return i; 231 } 232 return -1; 233 } 234 235 242 public int getIndex(String qName) 243 { 244 for(int i=m_attrs.getLength()-1;i>=0;--i) 245 { 246 Node a=m_attrs.item(i); 247 if(a.getNodeName().equals(qName) ) 248 return i; 249 } 250 return -1; 251 } 252 } 253 254 | Popular Tags |