1 6 package org.xml.sax.ext; 7 8 import org.xml.sax.Attributes ; 9 import org.xml.sax.helpers.AttributesImpl ; 10 11 12 38 public class Attributes2Impl extends AttributesImpl implements Attributes2 39 { 40 private boolean declared []; 41 private boolean specified []; 42 43 44 47 public Attributes2Impl () { } 48 49 50 64 public Attributes2Impl (Attributes atts) 65 { 66 super (atts); 67 } 68 69 70 74 75 78 public boolean isDeclared (int index) 80 { 81 if (index < 0 || index >= getLength ()) 82 throw new ArrayIndexOutOfBoundsException ( 83 "No attribute at index: " + index); 84 return declared [index]; 85 } 86 87 88 91 public boolean isDeclared (String uri, String localName) 93 { 94 int index = getIndex (uri, localName); 95 96 if (index < 0) 97 throw new IllegalArgumentException ( 98 "No such attribute: local=" + localName 99 + ", namespace=" + uri); 100 return declared [index]; 101 } 102 103 104 107 public boolean isDeclared (String qName) 109 { 110 int index = getIndex (qName); 111 112 if (index < 0) 113 throw new IllegalArgumentException ( 114 "No such attribute: " + qName); 115 return declared [index]; 116 } 117 118 119 127 public boolean isSpecified (int index) 128 { 129 if (index < 0 || index >= getLength ()) 130 throw new ArrayIndexOutOfBoundsException ( 131 "No attribute at index: " + index); 132 return specified [index]; 133 } 134 135 136 146 public boolean isSpecified (String uri, String localName) 147 { 148 int index = getIndex (uri, localName); 149 150 if (index < 0) 151 throw new IllegalArgumentException ( 152 "No such attribute: local=" + localName 153 + ", namespace=" + uri); 154 return specified [index]; 155 } 156 157 158 166 public boolean isSpecified (String qName) 167 { 168 int index = getIndex (qName); 169 170 if (index < 0) 171 throw new IllegalArgumentException ( 172 "No such attribute: " + qName); 173 return specified [index]; 174 } 175 176 177 181 182 191 public void setAttributes (Attributes atts) 192 { 193 int length = atts.getLength (); 194 195 super.setAttributes (atts); 196 declared = new boolean [length]; 197 specified = new boolean [length]; 198 199 if (atts instanceof Attributes2 ) { 200 Attributes2 a2 = (Attributes2 ) atts; 201 for (int i = 0; i < length; i++) { 202 declared [i] = a2.isDeclared (i); 203 specified [i] = a2.isSpecified (i); 204 } 205 } else { 206 for (int i = 0; i < length; i++) { 207 declared [i] = !"CDATA".equals (atts.getType (i)); 208 specified [i] = true; 209 } 210 } 211 } 212 213 214 225 public void addAttribute (String uri, String localName, String qName, 226 String type, String value) 227 { 228 super.addAttribute (uri, localName, qName, type, value); 229 230 int length = getLength (); 231 232 if (length < specified.length) { 233 boolean newFlags []; 234 235 newFlags = new boolean [length]; 236 System.arraycopy (declared, 0, newFlags, 0, declared.length); 237 declared = newFlags; 238 239 newFlags = new boolean [length]; 240 System.arraycopy (specified, 0, newFlags, 0, specified.length); 241 specified = newFlags; 242 } 243 244 specified [length - 1] = true; 245 declared [length - 1] = !"CDATA".equals (type); 246 } 247 248 249 public void removeAttribute (int index) 251 { 252 int origMax = getLength () - 1; 253 254 super.removeAttribute (index); 255 if (index != origMax) { 256 System.arraycopy (declared, index + 1, declared, index, 257 origMax - index); 258 System.arraycopy (specified, index + 1, specified, index, 259 origMax - index); 260 } 261 } 262 263 264 275 public void setDeclared (int index, boolean value) 276 { 277 if (index < 0 || index >= getLength ()) 278 throw new ArrayIndexOutOfBoundsException ( 279 "No attribute at index: " + index); 280 declared [index] = value; 281 } 282 283 284 294 public void setSpecified (int index, boolean value) 295 { 296 if (index < 0 || index >= getLength ()) 297 throw new ArrayIndexOutOfBoundsException ( 298 "No attribute at index: " + index); 299 specified [index] = value; 300 } 301 } 302 | Popular Tags |