1 16 19 package com.sun.org.apache.xml.internal.serializer.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 40 public final class AttList implements Attributes 41 { 42 43 44 NamedNodeMap m_attrs; 45 46 47 int m_lastIndex; 48 49 52 53 DOM2Helper m_dh; 54 55 69 76 public AttList(NamedNodeMap attrs, DOM2Helper dh) 77 { 78 79 m_attrs = attrs; 80 m_lastIndex = m_attrs.getLength() - 1; 81 m_dh = dh; 82 } 83 84 90 public int getLength() 91 { 92 return m_attrs.getLength(); 93 } 94 95 103 public String getURI(int index) 104 { 105 String ns = m_dh.getNamespaceOfNode(((Attr ) m_attrs.item(index))); 106 if(null == ns) 107 ns = ""; 108 return ns; 109 } 110 111 119 public String getLocalName(int index) 120 { 121 return m_dh.getLocalNameOfNode(((Attr ) m_attrs.item(index))); 122 } 123 124 132 public String getQName(int i) 133 { 134 return ((Attr ) m_attrs.item(i)).getName(); 135 } 136 137 145 public String getType(int i) 146 { 147 return "CDATA"; } 149 150 158 public String getValue(int i) 159 { 160 return ((Attr ) m_attrs.item(i)).getValue(); 161 } 162 163 171 public String getType(String name) 172 { 173 return "CDATA"; } 175 176 186 public String getType(String uri, String localName) 187 { 188 return "CDATA"; } 190 191 199 public String getValue(String name) 200 { 201 Attr attr = ((Attr ) m_attrs.getNamedItem(name)); 202 return (null != attr) 203 ? attr.getValue() : null; 204 } 205 206 215 public String getValue(String uri, String localName) 216 { 217 Node a=m_attrs.getNamedItemNS(uri,localName); 218 return (a==null) ? null : a.getNodeValue(); 219 } 220 221 230 public int getIndex(String uri, String localPart) 231 { 232 for(int i=m_attrs.getLength()-1;i>=0;--i) 233 { 234 Node a=m_attrs.item(i); 235 String u=a.getNamespaceURI(); 236 if( (u==null ? uri==null : u.equals(uri)) 237 && 238 a.getLocalName().equals(localPart) ) 239 return i; 240 } 241 return -1; 242 } 243 244 251 public int getIndex(String qName) 252 { 253 for(int i=m_attrs.getLength()-1;i>=0;--i) 254 { 255 Node a=m_attrs.item(i); 256 if(a.getNodeName().equals(qName) ) 257 return i; 258 } 259 return -1; 260 } 261 } 262 263 | Popular Tags |