| 1 package com.quadcap.text.sax; 2 3 40 41 46 public class AttributeList implements org.xml.sax.AttributeList { 47 int length = 0; 48 String [] name = new String [8]; 49 String [] value = new String [8]; 50 String [] type = new String [8]; 51 52 62 public final int getLength() { 63 return length; 64 } 65 66 67 83 public final String getName(int i) { 84 try { 85 return name[i]; 86 } catch (ArrayIndexOutOfBoundsException e) { 87 return null; 88 } 89 } 90 91 92 113 public final String getType(int i) { 114 try { 115 return type[i]; 116 } catch (ArrayIndexOutOfBoundsException e) { 117 return null; 118 } 119 } 120 121 134 public final String getValue (int i) { 135 try { 136 return value[i]; 137 } catch (ArrayIndexOutOfBoundsException e) { 138 return null; 139 } 140 } 141 142 143 144 158 public final String getType(String name) { 159 return getType(getAttribute(name)); 160 } 161 162 176 public final String getValue(String n) { 177 return getValue(getAttribute(n)); 178 } 179 180 final int getAttribute(String n) { 181 for (int i = 0; i < length; i++) { 182 if (name[i].equals(n)) return i; 183 } 184 return -1; 185 } 186 187 final String [] resize(String [] v, int len) { 188 String [] n = new String [len]; 189 System.arraycopy(v, 0, n, 0, v.length); 190 return n; 191 } 192 193 final void addAttribute(String n, String t, String v) { 194 if (length >= name.length) { 195 name = resize(name, length + (length >> 2) + 4); 196 type = resize(type, length + (length >> 2) + 4); 197 value = resize(value, length + (length >> 2) + 4); 198 } 199 name[length] = n; 200 type[length] = t; 201 value[length] = v; 202 length++; 203 } 204 205 final void clear() { 206 length = 0; 207 } 208 209 public static AttributeList copy(org.xml.sax.AttributeList a) { 210 AttributeList c = new AttributeList(); 211 for (int i = 0; i < a.getLength(); i++) { 212 c.addAttribute(a.getName(i), a.getType(i), a.getValue(i)); 213 } 214 return c; 215 } 216 217 public static String toString(org.xml.sax.AttributeList attributes) { 218 StringBuffer sb = new StringBuffer (); 219 if (attributes != null) { 220 for (int i = 0; i < attributes.getLength(); i++) { 221 sb.append(' '); 222 sb.append(attributes.getName(i)); 223 sb.append("=\""); 224 sb.append(attributes.getValue(i)); 225 sb.append("\""); 226 } 227 } 228 return sb.toString(); 229 } 230 231 public String toString() { 232 return toString(this); 233 } 234 } 235 | Popular Tags |