1 27 package org.htmlparser.tags; 28 29 import java.util.Enumeration ; 30 import java.util.Hashtable ; 31 import java.util.Vector ; 32 33 import org.htmlparser.Attribute; 34 import org.htmlparser.Node; 35 import org.htmlparser.Tag; 36 import org.htmlparser.nodes.TextNode; 37 import org.htmlparser.nodes.TagNode; 38 import org.htmlparser.util.NodeList; 39 import org.htmlparser.util.SimpleNodeIterator; 40 41 46 public class ObjectTag extends CompositeTag 47 { 48 51 private static final String [] mIds = new String [] {"OBJECT"}; 52 53 56 private static final String [] mEndTagEnders = new String [] {"BODY", "HTML"}; 57 58 61 public ObjectTag () 62 { 63 } 64 65 69 public String [] getIds () 70 { 71 return (mIds); 72 } 73 74 78 public String [] getEndTagEnders () 79 { 80 return (mEndTagEnders); 81 } 82 83 87 public Hashtable createObjectParamsTable () 88 { 89 NodeList kids; 90 Node node; 91 Tag tag; 92 String paramName; 93 String paramValue; 94 Hashtable ret; 95 96 ret = new Hashtable (); 97 kids = getChildren (); 98 if (null != kids) 99 for (int i = 0; i < kids.size (); i++) 100 { 101 node = children.elementAt(i); 102 if (node instanceof Tag) 103 { 104 tag = (Tag)node; 105 if (tag.getTagName().equals ("PARAM")) 106 { 107 paramName = tag.getAttribute ("NAME"); 108 if (null != paramName && 0 != paramName.length ()) 109 { 110 paramValue = tag.getAttribute ("VALUE"); 111 ret.put (paramName.toUpperCase(),paramValue); 112 } 113 } 114 } 115 } 116 117 return (ret); 118 } 119 120 124 public String getObjectClassId () 125 { 126 return getAttribute ("CLASSID"); 127 } 128 129 133 public String getObjectCodeBase () 134 { 135 return getAttribute ("CODEBASE"); 136 } 137 138 142 public String getObjectCodeType () 143 { 144 return getAttribute ("CODETYPE"); 145 } 146 147 151 public String getObjectData () 152 { 153 return getAttribute ("DATA"); 154 } 155 156 160 public String getObjectHeight () 161 { 162 return getAttribute ("HEIGHT"); 163 } 164 165 169 public String getObjectStandby () 170 { 171 return getAttribute ("STANDBY"); 172 } 173 174 178 public String getObjectType () 179 { 180 return getAttribute ("TYPE"); 181 } 182 183 187 public String getObjectWidth () 188 { 189 return getAttribute ("WIDTH"); 190 } 191 192 196 public Hashtable getObjectParams () 197 { 198 return createObjectParamsTable (); 199 } 200 201 206 public String getParameter (String key) 207 { 208 return ((String )(getObjectParams ().get (key.toUpperCase ()))); 209 } 210 211 215 public Enumeration getParameterNames () 216 { 217 return getObjectParams ().keys (); 218 } 219 220 224 public void setObjectClassId (String newClassId) 225 { 226 setAttribute ("CLASSID", newClassId); 227 } 228 229 233 public void setObjectCodeBase (String newCodeBase) 234 { 235 setAttribute ("CODEBASE", newCodeBase); 236 } 237 238 242 public void setObjectCodeType (String newCodeType) 243 { 244 setAttribute ("CODETYPE", newCodeType); 245 } 246 247 251 public void setObjectData (String newData) 252 { 253 setAttribute ("DATA", newData); 254 } 255 256 260 public void setObjectHeight (String newHeight) 261 { 262 setAttribute ("HEIGHT", newHeight); 263 } 264 265 269 public void setObjectStandby (String newStandby) 270 { 271 setAttribute ("STANDBY", newStandby); 272 } 273 274 278 public void setObjectType (String newType) 279 { 280 setAttribute ("TYPE", newType); 281 } 282 283 287 public void setObjectWidth (String newWidth) 288 { 289 setAttribute ("WIDTH", newWidth); 290 } 291 292 296 public void setObjectParams (Hashtable newObjectParams) 297 { 298 NodeList kids; 299 Node node; 300 Tag tag; 301 String paramName; 302 String paramValue; 303 Vector attributes; 304 TextNode string; 305 306 kids = getChildren (); 307 if (null == kids) 308 kids = new NodeList (); 309 else 310 for (int i = 0; i < kids.size (); ) 312 { 313 node = kids.elementAt (i); 314 if (node instanceof Tag) 315 if (((Tag)node).getTagName ().equals ("PARAM")) 316 { 317 kids.remove (i); 318 if (i < kids.size ()) 320 { 321 node = kids.elementAt (i); 322 if (node instanceof TextNode) 323 { 324 string = (TextNode)node; 325 if (0 == string.getText ().trim ().length ()) 326 kids.remove (i); 327 } 328 } 329 } 330 else 331 i++; 332 else 333 i++; 334 } 335 336 for (Enumeration e = newObjectParams.keys (); e.hasMoreElements (); ) 338 { 339 attributes = new Vector (); paramName = (String )e.nextElement (); 341 paramValue = (String )newObjectParams.get (paramName); 342 attributes.addElement (new Attribute ("PARAM", null)); 343 attributes.addElement (new Attribute (" ")); 344 attributes.addElement (new Attribute ("VALUE", paramValue, '"')); 345 attributes.addElement (new Attribute (" ")); 346 attributes.addElement (new Attribute ("NAME", paramName.toUpperCase (), '"')); 347 tag = new TagNode (null, 0, 0, attributes); 348 kids.add (tag); 349 } 350 351 setChildren (kids); 353 } 354 355 359 public String toString () 360 { 361 Hashtable parameters; 362 Enumeration params; 363 String paramName; 364 String paramValue; 365 boolean found; 366 Node node; 367 StringBuffer ret; 368 369 ret = new StringBuffer (500); 370 ret.append ("Object Tag\n"); 371 ret.append ("**********\n"); 372 ret.append ("ClassId = "); 373 ret.append (getObjectClassId ()); 374 ret.append ("\n"); 375 ret.append ("CodeBase = "); 376 ret.append (getObjectCodeBase ()); 377 ret.append ("\n"); 378 ret.append ("CodeType = "); 379 ret.append (getObjectCodeType ()); 380 ret.append ("\n"); 381 ret.append ("Data = "); 382 ret.append (getObjectData ()); 383 ret.append ("\n"); 384 ret.append ("Height = "); 385 ret.append (getObjectHeight ()); 386 ret.append ("\n"); 387 ret.append ("Standby = "); 388 ret.append (getObjectStandby ()); 389 ret.append ("\n"); 390 ret.append ("Type = "); 391 ret.append (getObjectType ()); 392 ret.append ("\n"); 393 ret.append ("Width = "); 394 ret.append (getObjectWidth ()); 395 ret.append ("\n"); 396 parameters = getObjectParams (); 397 params = parameters.keys (); 398 if (null == params) 399 ret.append ("No Params found.\n"); 400 else 401 for (int cnt = 0; params.hasMoreElements (); cnt++) 402 { 403 paramName = (String )params.nextElement (); 404 paramValue = (String )parameters.get (paramName); 405 ret.append (cnt); 406 ret.append (": Parameter name = "); 407 ret.append (paramName); 408 ret.append (", Parameter value = "); 409 ret.append (paramValue); 410 ret.append ("\n"); 411 } 412 found = false; 413 for (SimpleNodeIterator e = children (); e.hasMoreNodes ();) 414 { 415 node = e.nextNode (); 416 if (node instanceof Tag) 417 if (((Tag)node).getTagName ().equals ("PARAM")) 418 continue; 419 if (!found) 420 ret.append ("Miscellaneous items :\n"); 421 else 422 ret.append (" "); 423 found = true; 424 ret.append (node.toString ()); 425 } 426 if (found) 427 ret.append ("\n"); 428 ret.append ("End of Object Tag\n"); 429 ret.append ("*****************\n"); 430 431 return (ret.toString ()); 432 } 433 } 434 | Popular Tags |