1 27 package org.htmlparser.sax; 28 29 import java.util.Vector ; 30 31 import org.htmlparser.Attribute; 32 import org.htmlparser.Tag; 33 import org.xml.sax.helpers.NamespaceSupport ; 34 35 38 public class Attributes 39 implements 40 org.xml.sax.Attributes  41 { 42 45 protected Tag mTag; 46 47 50 protected NamespaceSupport mSupport; 51 52 56 protected String [] mParts; 57 58 64 public Attributes (Tag tag, NamespaceSupport support, String [] parts) 65 { 66 mTag = tag; 67 mSupport = support; 68 mParts = parts; 69 } 70 71 72 76 77 90 public int getLength () 91 { 92 return (mTag.getAttributesEx ().size () - 1); 93 } 94 95 96 105 public String getURI (int index) 106 { 107 mSupport.processName (getQName (index), mParts, true); 108 return (mParts[0]); 109 } 110 111 112 121 public String getLocalName (int index) 122 { 123 mSupport.processName (getQName (index), mParts, true); 124 return (mParts[1]); 125 } 126 127 128 137 public String getQName (int index) 138 { 139 Attribute attribute; 140 String ret; 141 142 attribute = (Attribute)(mTag.getAttributesEx ().elementAt (index + 1)); 143 if (attribute.isWhitespace ()) 144 ret = "#text"; 145 else 146 ret = attribute.getName (); 147 148 return (ret); 149 } 150 151 171 public String getType (int index) 172 { 173 return ("CDATA"); 174 } 175 176 177 190 public String getValue (int index) 191 { 192 Attribute attribute; 193 String ret; 194 195 attribute = (Attribute)(mTag.getAttributesEx ().elementAt (index + 1)); 196 ret = attribute.getValue (); 197 if (null == ret) 198 ret = ""; 199 200 return (ret); 201 } 202 203 204 208 209 218 public int getIndex (String uri, String localName) 219 { 220 Vector attributes; 221 int size; 222 Attribute attribute; 223 String string; 224 int ret; 225 226 ret = -1; 227 228 attributes = mTag.getAttributesEx (); 229 if (null != attributes) 230 { 231 size = attributes.size (); 232 for (int i = 1; i < size; i++) 233 { 234 attribute = (Attribute)attributes.elementAt (i); 235 string = attribute.getName (); 236 if (null != string) { 238 mSupport.processName (string, mParts, true); 239 if ( uri.equals (mParts[0]) 240 & localName.equalsIgnoreCase (mParts[1])) 241 { 242 ret = i; 243 i = size; } 245 } 246 } 247 } 248 249 return (ret); 250 } 251 252 253 260 public int getIndex (String qName) 261 { 262 mSupport.processName (qName, mParts, true); 263 return (getIndex (mParts[0], mParts[1])); 264 } 265 266 267 280 public String getType (String uri, String localName) 281 { 282 return (null); 283 } 284 285 286 297 public String getType (String qName) 298 { 299 return (null); 300 } 301 302 303 315 public String getValue (String uri, String localName) 316 { 317 return (mTag.getAttribute (localName)); 318 } 319 320 321 332 public String getValue (String qName) 333 { 334 mSupport.processName (qName, mParts, true); 335 return (getValue (mParts[0], mParts[1])); 336 } 337 } 338
| Popular Tags
|