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.Text; 37 import org.htmlparser.nodes.TagNode; 38 import org.htmlparser.util.NodeList; 39 import org.htmlparser.util.SimpleNodeIterator; 40 41 46 public class AppletTag 47 extends 48 CompositeTag 49 { 50 53 private static final String [] mIds = new String [] {"APPLET"}; 54 55 58 private static final String [] mEndTagEnders = new String [] {"BODY", "HTML"}; 59 60 63 public AppletTag () 64 { 65 } 66 67 71 public String [] getIds () 72 { 73 return (mIds); 74 } 75 76 80 public String [] getEndTagEnders () 81 { 82 return (mEndTagEnders); 83 } 84 85 89 public Hashtable createAppletParamsTable () 90 { 91 NodeList kids; 92 Node node; 93 Tag tag; 94 String paramName; 95 String paramValue; 96 Hashtable ret; 97 98 ret = new Hashtable (); 99 kids = getChildren (); 100 if (null != kids) 101 for (int i = 0; i < kids.size (); i++) 102 { 103 node = children.elementAt(i); 104 if (node instanceof Tag) 105 { 106 tag = (Tag)node; 107 if (tag.getTagName().equals ("PARAM")) 108 { 109 paramName = tag.getAttribute ("NAME"); 110 if (null != paramName && 0 != paramName.length ()) 111 { 112 paramValue = tag.getAttribute ("VALUE"); 113 ret.put (paramName,paramValue); 114 } 115 } 116 } 117 } 118 119 return (ret); 120 } 121 122 126 public String getAppletClass () 127 { 128 return (getAttribute ("CODE")); 129 } 130 131 135 public Hashtable getAppletParams () 136 { 137 return (createAppletParamsTable ()); 138 } 139 140 144 public String getArchive() 145 { 146 return (getAttribute ("ARCHIVE")); 147 } 148 149 153 public String getCodeBase() 154 { 155 return (getAttribute ("CODEBASE")); 156 } 157 158 164 public String getParameter (String key) 165 { 166 return ((String )(getAppletParams ().get (key))); 167 } 168 169 173 public Enumeration getParameterNames () 174 { 175 return (getAppletParams ().keys ()); 176 } 177 178 182 public void setAppletClass (String newAppletClass) 183 { 184 setAttribute ("CODE", newAppletClass); 185 } 186 187 191 public void setAppletParams (Hashtable newAppletParams) 192 { 193 NodeList kids; 194 Node node; 195 Tag tag; 196 String paramName; 197 String paramValue; 198 Vector attributes; 199 Text string; 200 201 kids = getChildren (); 202 if (null == kids) 203 kids = new NodeList (); 204 else 205 for (int i = 0; i < kids.size (); ) 207 { 208 node = kids.elementAt (i); 209 if (node instanceof Tag) 210 if (((Tag)node).getTagName ().equals ("PARAM")) 211 { 212 kids.remove (i); 213 if (i < kids.size ()) 215 { 216 node = kids.elementAt (i); 217 if (node instanceof Text) 218 { 219 string = (Text)node; 220 if (0 == string.getText ().trim ().length ()) 221 kids.remove (i); 222 } 223 } 224 } 225 else 226 i++; 227 else 228 i++; 229 } 230 231 for (Enumeration e = newAppletParams.keys (); e.hasMoreElements (); ) 233 { 234 attributes = new Vector (); paramName = (String )e.nextElement (); 236 paramValue = (String )newAppletParams.get (paramName); 237 attributes.addElement (new Attribute ("PARAM", null)); 238 attributes.addElement (new Attribute (" ")); 239 attributes.addElement (new Attribute ("VALUE", paramValue, '"')); 240 attributes.addElement (new Attribute (" ")); 241 attributes.addElement (new Attribute ("NAME", paramName, '"')); 242 tag = new TagNode (null, 0, 0, attributes); 243 kids.add (tag); 244 } 245 246 setChildren (kids); 248 } 249 250 254 public void setArchive (String newArchive) 255 { 256 setAttribute ("ARCHIVE", newArchive); 257 } 258 259 263 public void setCodeBase (String newCodeBase) 264 { 265 setAttribute ("CODEBASE", newCodeBase); 266 } 267 268 272 public String toString () 273 { 274 Hashtable parameters; 275 Enumeration params; 276 String paramName; 277 String paramValue; 278 boolean found; 279 Node node; 280 StringBuffer ret; 281 282 ret = new StringBuffer (500); 283 ret.append ("Applet Tag\n"); 284 ret.append ("**********\n"); 285 ret.append ("Class Name = "); 286 ret.append (getAppletClass ()); 287 ret.append ("\n"); 288 ret.append ("Archive = "); 289 ret.append (getArchive ()); 290 ret.append ("\n"); 291 ret.append ("Codebase = "); 292 ret.append (getCodeBase ()); 293 ret.append ("\n"); 294 parameters = getAppletParams (); 295 params = parameters.keys (); 296 if (null == params) 297 ret.append ("No Params found.\n"); 298 else 299 for (int cnt = 0; params.hasMoreElements (); cnt++) 300 { 301 paramName = (String )params.nextElement (); 302 paramValue = (String )parameters.get (paramName); 303 ret.append (cnt); 304 ret.append (": Parameter name = "); 305 ret.append (paramName); 306 ret.append (", Parameter value = "); 307 ret.append (paramValue); 308 ret.append ("\n"); 309 } 310 found = false; 311 for (SimpleNodeIterator e = children (); e.hasMoreNodes ();) 312 { 313 node = e.nextNode (); 314 if (node instanceof Tag) 315 if (((Tag)node).getTagName ().equals ("PARAM")) 316 continue; 317 if (!found) 318 ret.append ("Miscellaneous items :\n"); 319 else 320 ret.append (" "); 321 found = true; 322 ret.append (node.toString ()); 323 } 324 if (found) 325 ret.append ("\n"); 326 ret.append ("End of Applet Tag\n"); 327 ret.append ("*****************\n"); 328 329 return (ret.toString ()); 330 } 331 } 332 | Popular Tags |