1 16 19 20 package org.apache.xalan.xsltc.runtime; 21 22 import java.util.Vector ; 23 24 27 public class AttributeList implements org.xml.sax.Attributes { 28 29 private final static String EMPTYSTRING = ""; 30 private final static String CDATASTRING = "CDATA"; 31 32 private Hashtable _attributes; 33 private Vector _names; 34 private Vector _qnames; 35 private Vector _values; 36 private Vector _uris; 37 private int _length; 38 39 42 public AttributeList() { 43 50 _length = 0; 51 } 52 53 56 public AttributeList(org.xml.sax.Attributes attributes) { 57 this(); 58 if (attributes != null) { 59 final int count = attributes.getLength(); 60 for (int i = 0; i < count; i++) { 61 add(attributes.getQName(i),attributes.getValue(i)); 62 } 63 } 64 } 65 66 72 private void alloc() { 73 _attributes = new Hashtable(); 74 _names = new Vector (); 75 _values = new Vector (); 76 _qnames = new Vector (); 77 _uris = new Vector (); 78 } 79 80 83 public int getLength() { 84 return(_length); 85 } 86 87 90 public String getURI(int index) { 91 if (index < _length) 92 return((String )_uris.elementAt(index)); 93 else 94 return(null); 95 } 96 97 100 public String getLocalName(int index) { 101 if (index < _length) 102 return((String )_names.elementAt(index)); 103 else 104 return(null); 105 } 106 107 110 public String getQName(int pos) { 111 if (pos < _length) 112 return((String )_qnames.elementAt(pos)); 113 else 114 return(null); 115 } 116 117 120 public String getType(int index) { 121 return(CDATASTRING); 122 } 123 124 127 public int getIndex(String namespaceURI, String localPart) { 128 return(-1); 129 } 130 131 134 public int getIndex(String qname) { 135 return(-1); 136 } 137 138 141 public String getType(String uri, String localName) { 142 return(CDATASTRING); 143 } 144 145 148 public String getType(String qname) { 149 return(CDATASTRING); 150 } 151 152 155 public String getValue(int pos) { 156 if (pos < _length) 157 return((String )_values.elementAt(pos)); 158 else 159 return(null); 160 } 161 162 165 public String getValue(String qname) { 166 if (_attributes != null) { 167 final Integer obj = (Integer )_attributes.get(qname); 168 if (obj == null) return null; 169 return(getValue(obj.intValue())); 170 } 171 else 172 return null; 173 } 174 175 178 public String getValue(String uri, String localName) { 179 return(getValue(uri+':'+localName)); 180 } 181 182 185 public void add(String qname, String value) { 186 if (_attributes == null) 188 alloc(); 189 190 Integer obj = (Integer )_attributes.get(qname); 192 if (obj == null) { 193 _attributes.put(qname, obj = new Integer (_length++)); 194 _qnames.addElement(qname); 195 _values.addElement(value); 196 int col = qname.lastIndexOf(':'); 197 if (col > -1) { 198 _uris.addElement(qname.substring(0,col)); 199 _names.addElement(qname.substring(col+1)); 200 } 201 else { 202 _uris.addElement(EMPTYSTRING); 203 _names.addElement(qname); 204 } 205 } 206 else { 207 final int index = obj.intValue(); 208 _values.set(index, value); 209 } 210 } 211 212 215 public void clear() { 216 _length = 0; 217 if (_attributes != null) { 218 _attributes.clear(); 219 _names.removeAllElements(); 220 _values.removeAllElements(); 221 _qnames.removeAllElements(); 222 _uris.removeAllElements(); 223 } 224 } 225 226 } 227 | Popular Tags |