1 23 24 package tests.org.enhydra.xml.xhtml.dominfo; 25 26 import java.io.File ; 27 import java.io.FilenameFilter ; 28 import java.util.HashMap ; 29 import java.util.HashSet ; 30 import java.util.Set ; 31 import java.util.StringTokenizer ; 32 33 import org.enhydra.error.FatalExceptionError; 34 import org.enhydra.xml.xhtml.dom.XHTMLAbbrElement; 35 import org.enhydra.xml.xhtml.dom.XHTMLAcronymElement; 36 import org.enhydra.xml.xhtml.dom.XHTMLAddressElement; 37 import org.enhydra.xml.xhtml.dom.XHTMLAnchorElement; 38 import org.enhydra.xml.xhtml.dom.XHTMLAppletElement; 39 import org.enhydra.xml.xhtml.dom.XHTMLAreaElement; 40 import org.enhydra.xml.xhtml.dom.XHTMLBElement; 41 import org.enhydra.xml.xhtml.dom.XHTMLBRElement; 42 import org.enhydra.xml.xhtml.dom.XHTMLBaseElement; 43 import org.enhydra.xml.xhtml.dom.XHTMLBaseFontElement; 44 import org.enhydra.xml.xhtml.dom.XHTMLBdoElement; 45 import org.enhydra.xml.xhtml.dom.XHTMLBigElement; 46 import org.enhydra.xml.xhtml.dom.XHTMLBodyElement; 47 import org.enhydra.xml.xhtml.dom.XHTMLButtonElement; 48 import org.enhydra.xml.xhtml.dom.XHTMLCenterElement; 49 import org.enhydra.xml.xhtml.dom.XHTMLCiteElement; 50 import org.enhydra.xml.xhtml.dom.XHTMLCodeElement; 51 import org.enhydra.xml.xhtml.dom.XHTMLDListElement; 52 import org.enhydra.xml.xhtml.dom.XHTMLDdElement; 53 import org.enhydra.xml.xhtml.dom.XHTMLDfnElement; 54 import org.enhydra.xml.xhtml.dom.XHTMLDirectoryElement; 55 import org.enhydra.xml.xhtml.dom.XHTMLDivElement; 56 import org.enhydra.xml.xhtml.dom.XHTMLDtElement; 57 import org.enhydra.xml.xhtml.dom.XHTMLElement; 58 import org.enhydra.xml.xhtml.dom.XHTMLEmElement; 59 import org.enhydra.xml.xhtml.dom.XHTMLFieldSetElement; 60 import org.enhydra.xml.xhtml.dom.XHTMLFontElement; 61 import org.enhydra.xml.xhtml.dom.XHTMLFormElement; 62 import org.enhydra.xml.xhtml.dom.XHTMLFrameElement; 63 import org.enhydra.xml.xhtml.dom.XHTMLFrameSetElement; 64 import org.enhydra.xml.xhtml.dom.XHTMLHRElement; 65 import org.enhydra.xml.xhtml.dom.XHTMLHeadElement; 66 import org.enhydra.xml.xhtml.dom.XHTMLHeadingElement; 67 import org.enhydra.xml.xhtml.dom.XHTMLHtmlElement; 68 import org.enhydra.xml.xhtml.dom.XHTMLIElement; 69 import org.enhydra.xml.xhtml.dom.XHTMLIFrameElement; 70 import org.enhydra.xml.xhtml.dom.XHTMLImageElement; 71 import org.enhydra.xml.xhtml.dom.XHTMLInputElement; 72 import org.enhydra.xml.xhtml.dom.XHTMLIsIndexElement; 73 import org.enhydra.xml.xhtml.dom.XHTMLKbdElement; 74 import org.enhydra.xml.xhtml.dom.XHTMLLIElement; 75 import org.enhydra.xml.xhtml.dom.XHTMLLabelElement; 76 import org.enhydra.xml.xhtml.dom.XHTMLLegendElement; 77 import org.enhydra.xml.xhtml.dom.XHTMLLinkElement; 78 import org.enhydra.xml.xhtml.dom.XHTMLMapElement; 79 import org.enhydra.xml.xhtml.dom.XHTMLMenuElement; 80 import org.enhydra.xml.xhtml.dom.XHTMLMetaElement; 81 import org.enhydra.xml.xhtml.dom.XHTMLModElement; 82 import org.enhydra.xml.xhtml.dom.XHTMLNoframesElement; 83 import org.enhydra.xml.xhtml.dom.XHTMLNoscriptElement; 84 import org.enhydra.xml.xhtml.dom.XHTMLOListElement; 85 import org.enhydra.xml.xhtml.dom.XHTMLObjectElement; 86 import org.enhydra.xml.xhtml.dom.XHTMLOptGroupElement; 87 import org.enhydra.xml.xhtml.dom.XHTMLOptionElement; 88 import org.enhydra.xml.xhtml.dom.XHTMLParagraphElement; 89 import org.enhydra.xml.xhtml.dom.XHTMLParamElement; 90 import org.enhydra.xml.xhtml.dom.XHTMLPreElement; 91 import org.enhydra.xml.xhtml.dom.XHTMLQuoteElement; 92 import org.enhydra.xml.xhtml.dom.XHTMLSElement; 93 import org.enhydra.xml.xhtml.dom.XHTMLSampElement; 94 import org.enhydra.xml.xhtml.dom.XHTMLScriptElement; 95 import org.enhydra.xml.xhtml.dom.XHTMLSelectElement; 96 import org.enhydra.xml.xhtml.dom.XHTMLSmallElement; 97 import org.enhydra.xml.xhtml.dom.XHTMLSpanElement; 98 import org.enhydra.xml.xhtml.dom.XHTMLStrikeElement; 99 import org.enhydra.xml.xhtml.dom.XHTMLStrongElement; 100 import org.enhydra.xml.xhtml.dom.XHTMLStyleElement; 101 import org.enhydra.xml.xhtml.dom.XHTMLSubElement; 102 import org.enhydra.xml.xhtml.dom.XHTMLSupElement; 103 import org.enhydra.xml.xhtml.dom.XHTMLTableCaptionElement; 104 import org.enhydra.xml.xhtml.dom.XHTMLTableCellElement; 105 import org.enhydra.xml.xhtml.dom.XHTMLTableColElement; 106 import org.enhydra.xml.xhtml.dom.XHTMLTableElement; 107 import org.enhydra.xml.xhtml.dom.XHTMLTableRowElement; 108 import org.enhydra.xml.xhtml.dom.XHTMLTbodyElement; 109 import org.enhydra.xml.xhtml.dom.XHTMLTextAreaElement; 110 import org.enhydra.xml.xhtml.dom.XHTMLTfootElement; 111 import org.enhydra.xml.xhtml.dom.XHTMLTheadElement; 112 import org.enhydra.xml.xhtml.dom.XHTMLTitleElement; 113 import org.enhydra.xml.xhtml.dom.XHTMLTtElement; 114 import org.enhydra.xml.xhtml.dom.XHTMLUElement; 115 import org.enhydra.xml.xhtml.dom.XHTMLUListElement; 116 import org.enhydra.xml.xhtml.dom.XHTMLVarElement; 117 import org.enhydra.xml.xhtml.dom.xerces.XHTMLElementImpl; 118 import org.w3c.dom.html.HTMLAnchorElement; 119 import org.w3c.dom.html.HTMLAppletElement; 120 import org.w3c.dom.html.HTMLAreaElement; 121 import org.w3c.dom.html.HTMLBRElement; 122 import org.w3c.dom.html.HTMLBaseElement; 123 import org.w3c.dom.html.HTMLBaseFontElement; 124 import org.w3c.dom.html.HTMLBodyElement; 125 import org.w3c.dom.html.HTMLButtonElement; 126 import org.w3c.dom.html.HTMLDListElement; 127 import org.w3c.dom.html.HTMLDirectoryElement; 128 import org.w3c.dom.html.HTMLDivElement; 129 import org.w3c.dom.html.HTMLElement; 130 import org.w3c.dom.html.HTMLFieldSetElement; 131 import org.w3c.dom.html.HTMLFontElement; 132 import org.w3c.dom.html.HTMLFormElement; 133 import org.w3c.dom.html.HTMLFrameElement; 134 import org.w3c.dom.html.HTMLFrameSetElement; 135 import org.w3c.dom.html.HTMLHRElement; 136 import org.w3c.dom.html.HTMLHeadElement; 137 import org.w3c.dom.html.HTMLHeadingElement; 138 import org.w3c.dom.html.HTMLHtmlElement; 139 import org.w3c.dom.html.HTMLIFrameElement; 140 import org.w3c.dom.html.HTMLImageElement; 141 import org.w3c.dom.html.HTMLInputElement; 142 import org.w3c.dom.html.HTMLIsIndexElement; 143 import org.w3c.dom.html.HTMLLIElement; 144 import org.w3c.dom.html.HTMLLabelElement; 145 import org.w3c.dom.html.HTMLLegendElement; 146 import org.w3c.dom.html.HTMLLinkElement; 147 import org.w3c.dom.html.HTMLMapElement; 148 import org.w3c.dom.html.HTMLMenuElement; 149 import org.w3c.dom.html.HTMLMetaElement; 150 import org.w3c.dom.html.HTMLModElement; 151 import org.w3c.dom.html.HTMLOListElement; 152 import org.w3c.dom.html.HTMLObjectElement; 153 import org.w3c.dom.html.HTMLOptGroupElement; 154 import org.w3c.dom.html.HTMLOptionElement; 155 import org.w3c.dom.html.HTMLParagraphElement; 156 import org.w3c.dom.html.HTMLParamElement; 157 import org.w3c.dom.html.HTMLPreElement; 158 import org.w3c.dom.html.HTMLQuoteElement; 159 import org.w3c.dom.html.HTMLScriptElement; 160 import org.w3c.dom.html.HTMLSelectElement; 161 import org.w3c.dom.html.HTMLStyleElement; 162 import org.w3c.dom.html.HTMLTableCaptionElement; 163 import org.w3c.dom.html.HTMLTableCellElement; 164 import org.w3c.dom.html.HTMLTableColElement; 165 import org.w3c.dom.html.HTMLTableElement; 166 import org.w3c.dom.html.HTMLTableRowElement; 167 import org.w3c.dom.html.HTMLTableSectionElement; 168 import org.w3c.dom.html.HTMLTextAreaElement; 169 import org.w3c.dom.html.HTMLTitleElement; 170 import org.w3c.dom.html.HTMLUListElement; 171 172 176 class ElementClassMappings { 177 180 private static HashMap fXHTMLInterfaceMap = new HashMap (); 181 private static HashMap fXHTMLClassMap = new HashMap (); 182 private static HashMap fHTMLInterfaceMap = new HashMap (); 183 184 185 188 private static void xhtmlAdd(String tag, 189 Class element) { 190 fXHTMLInterfaceMap.put(tag.toLowerCase(), element); 191 192 String qualName = element.getName(); 194 String pkgName = qualName.substring(0, qualName.lastIndexOf('.')); 195 String unqualName = qualName.substring(qualName.lastIndexOf('.')+1); 196 String implName = pkgName + ".xerces." + unqualName + "Impl"; 197 try { 198 fXHTMLClassMap.put(tag.toLowerCase(), Class.forName(implName)); 199 } catch (ClassNotFoundException except) { 200 throw new FatalExceptionError(except); 201 } 202 } 203 204 208 private static void buildXHTMLTable() { 209 xhtmlAdd("basefont", XHTMLBaseFontElement.class); 210 xhtmlAdd("button", XHTMLButtonElement.class); 211 xhtmlAdd("textarea", XHTMLTextAreaElement.class); 212 xhtmlAdd("em", XHTMLEmElement.class); 213 xhtmlAdd("small", XHTMLSmallElement.class); 214 xhtmlAdd("area", XHTMLAreaElement.class); 215 xhtmlAdd("noframes", XHTMLNoframesElement.class); 216 xhtmlAdd("bdo", XHTMLBdoElement.class); 217 xhtmlAdd("form", XHTMLFormElement.class); 218 xhtmlAdd("link", XHTMLLinkElement.class); 219 xhtmlAdd("label", XHTMLLabelElement.class); 220 xhtmlAdd("dt", XHTMLDtElement.class); 221 xhtmlAdd("span", XHTMLSpanElement.class); 222 xhtmlAdd("isindex", XHTMLIsIndexElement.class); 223 xhtmlAdd("title", XHTMLTitleElement.class); 224 xhtmlAdd("strong", XHTMLStrongElement.class); 225 xhtmlAdd("script", XHTMLScriptElement.class); 226 xhtmlAdd("div", XHTMLDivElement.class); 227 xhtmlAdd("dl", XHTMLDListElement.class); 228 xhtmlAdd("blockquote", XHTMLQuoteElement.class); 229 xhtmlAdd("kbd", XHTMLKbdElement.class); 230 xhtmlAdd("menu", XHTMLMenuElement.class); 231 xhtmlAdd("body", XHTMLBodyElement.class); 232 xhtmlAdd("dir", XHTMLDirectoryElement.class); 233 xhtmlAdd("ins", XHTMLModElement.class); 234 xhtmlAdd("map", XHTMLMapElement.class); 235 xhtmlAdd("dd", XHTMLDdElement.class); 236 xhtmlAdd("fieldset", XHTMLFieldSetElement.class); 237 xhtmlAdd("head", XHTMLHeadElement.class); 238 xhtmlAdd("col", XHTMLTableColElement.class); 239 xhtmlAdd("base", XHTMLBaseElement.class); 240 xhtmlAdd("big", XHTMLBigElement.class); 241 xhtmlAdd("meta", XHTMLMetaElement.class); 242 xhtmlAdd("code", XHTMLCodeElement.class); 243 xhtmlAdd("tbody", XHTMLTbodyElement.class); 244 xhtmlAdd("option", XHTMLOptionElement.class); 245 xhtmlAdd("u", XHTMLUElement.class); 246 xhtmlAdd("s", XHTMLSElement.class); 247 xhtmlAdd("q", XHTMLQuoteElement.class); 248 xhtmlAdd("p", XHTMLParagraphElement.class); 249 xhtmlAdd("ol", XHTMLOListElement.class); 250 xhtmlAdd("thead", XHTMLTheadElement.class); 251 xhtmlAdd("ul", XHTMLUListElement.class); 252 xhtmlAdd("i", XHTMLIElement.class); 253 xhtmlAdd("pre", XHTMLPreElement.class); 254 xhtmlAdd("optgroup", XHTMLOptGroupElement.class); 255 xhtmlAdd("img", XHTMLImageElement.class); 256 xhtmlAdd("caption", XHTMLTableCaptionElement.class); 257 xhtmlAdd("b", XHTMLBElement.class); 258 xhtmlAdd("a", XHTMLAnchorElement.class); 259 xhtmlAdd("frame", XHTMLFrameElement.class); 260 xhtmlAdd("br", XHTMLBRElement.class); 261 xhtmlAdd("style", XHTMLStyleElement.class); 262 xhtmlAdd("hr", XHTMLHRElement.class); 263 xhtmlAdd("param", XHTMLParamElement.class); 264 xhtmlAdd("table", XHTMLTableElement.class); 265 xhtmlAdd("applet", XHTMLAppletElement.class); 266 xhtmlAdd("tt", XHTMLTtElement.class); 267 xhtmlAdd("tr", XHTMLTableRowElement.class); 268 xhtmlAdd("th", XHTMLTableCellElement.class); 269 xhtmlAdd("center", XHTMLCenterElement.class); 270 xhtmlAdd("td", XHTMLTableCellElement.class); 271 xhtmlAdd("samp", XHTMLSampElement.class); 272 xhtmlAdd("tfoot", XHTMLTfootElement.class); 273 xhtmlAdd("font", XHTMLFontElement.class); 274 xhtmlAdd("dfn", XHTMLDfnElement.class); 275 xhtmlAdd("noscript", XHTMLNoscriptElement.class); 276 xhtmlAdd("object", XHTMLObjectElement.class); 277 xhtmlAdd("colgroup", XHTMLTableColElement.class); 278 xhtmlAdd("sup", XHTMLSupElement.class); 279 xhtmlAdd("html", XHTMLHtmlElement.class); 280 xhtmlAdd("h6", XHTMLHeadingElement.class); 281 xhtmlAdd("h5", XHTMLHeadingElement.class); 282 xhtmlAdd("h4", XHTMLHeadingElement.class); 283 xhtmlAdd("h3", XHTMLHeadingElement.class); 284 xhtmlAdd("frameset", XHTMLFrameSetElement.class); 285 xhtmlAdd("h2", XHTMLHeadingElement.class); 286 xhtmlAdd("h1", XHTMLHeadingElement.class); 287 xhtmlAdd("iframe", XHTMLIFrameElement.class); 288 xhtmlAdd("strike", XHTMLStrikeElement.class); 289 xhtmlAdd("sub", XHTMLSubElement.class); 290 xhtmlAdd("acronym", XHTMLAcronymElement.class); 291 xhtmlAdd("select", XHTMLSelectElement.class); 292 xhtmlAdd("del", XHTMLModElement.class); 293 xhtmlAdd("li", XHTMLLIElement.class); 294 xhtmlAdd("cite", XHTMLCiteElement.class); 295 xhtmlAdd("var", XHTMLVarElement.class); 296 xhtmlAdd("legend", XHTMLLegendElement.class); 297 xhtmlAdd("abbr", XHTMLAbbrElement.class); 298 xhtmlAdd("input", XHTMLInputElement.class); 299 xhtmlAdd("address", XHTMLAddressElement.class); 300 } 301 302 305 private static void htmlAdd(String tag, 306 Class element) { 307 fHTMLInterfaceMap.put(tag.toLowerCase(), element); 308 } 309 310 314 private static void buildHTMLTable() { 315 htmlAdd("A", HTMLAnchorElement.class); 316 htmlAdd("APPLET", HTMLAppletElement.class); 317 htmlAdd("AREA", HTMLAreaElement.class); 318 htmlAdd("BASE", HTMLBaseElement.class); 319 htmlAdd("BASEFONT", HTMLBaseFontElement.class); 320 htmlAdd("BLOCKQUOTE", HTMLQuoteElement.class); 321 htmlAdd("BODY", HTMLBodyElement.class); 322 htmlAdd("BR", HTMLBRElement.class); 323 htmlAdd("BUTTON", HTMLButtonElement.class); 324 htmlAdd("DEL", HTMLModElement.class); 325 htmlAdd("DIR", HTMLDirectoryElement.class); 326 htmlAdd("DIV", HTMLDivElement.class); 327 htmlAdd("DL", HTMLDListElement.class); 328 htmlAdd("FIELDSET", HTMLFieldSetElement.class); 329 htmlAdd("FONT", HTMLFontElement.class); 330 htmlAdd("FORM", HTMLFormElement.class); 331 htmlAdd("FRAME", HTMLFrameElement.class); 332 htmlAdd("FRAMESET", HTMLFrameSetElement.class); 333 htmlAdd("HEAD", HTMLHeadElement.class); 334 htmlAdd("H1", HTMLHeadingElement.class); 335 htmlAdd("H2", HTMLHeadingElement.class); 336 htmlAdd("H3", HTMLHeadingElement.class); 337 htmlAdd("H4", HTMLHeadingElement.class); 338 htmlAdd("H5", HTMLHeadingElement.class); 339 htmlAdd("H6", HTMLHeadingElement.class); 340 htmlAdd("HR", HTMLHRElement.class); 341 htmlAdd("HTML", HTMLHtmlElement.class); 342 htmlAdd("IFRAME", HTMLIFrameElement.class); 343 htmlAdd("IMG", HTMLImageElement.class); 344 htmlAdd("INPUT", HTMLInputElement.class); 345 htmlAdd("INS", HTMLModElement.class); 346 htmlAdd("ISINDEX", HTMLIsIndexElement.class); 347 htmlAdd("LABEL", HTMLLabelElement.class); 348 htmlAdd("LEGEND", HTMLLegendElement.class); 349 htmlAdd("LI", HTMLLIElement.class); 350 htmlAdd("LINK", HTMLLinkElement.class); 351 htmlAdd("MAP", HTMLMapElement.class); 352 htmlAdd("MENU", HTMLMenuElement.class); 353 htmlAdd("META", HTMLMetaElement.class); 354 htmlAdd("OBJECT", HTMLObjectElement.class); 355 htmlAdd("OL", HTMLOListElement.class); 356 htmlAdd("OPTGROUP", HTMLOptGroupElement.class); 357 htmlAdd("OPTION", HTMLOptionElement.class); 358 htmlAdd("P", HTMLParagraphElement.class); 359 htmlAdd("PARAM", HTMLParamElement.class); 360 htmlAdd("PRE", HTMLPreElement.class); 361 htmlAdd("Q", HTMLQuoteElement.class); 362 htmlAdd("SCRIPT", HTMLScriptElement.class); 363 htmlAdd("SELECT", HTMLSelectElement.class); 364 htmlAdd("STYLE", HTMLStyleElement.class); 365 htmlAdd("TABLE", HTMLTableElement.class); 366 htmlAdd("CAPTION", HTMLTableCaptionElement.class); 367 htmlAdd("TD", HTMLTableCellElement.class); 368 htmlAdd("TH", HTMLTableCellElement.class); 369 htmlAdd("COL", HTMLTableColElement.class); 370 htmlAdd("COLGROUP", HTMLTableColElement.class); 371 htmlAdd("TR", HTMLTableRowElement.class); 372 htmlAdd("TBODY", HTMLTableSectionElement.class); 373 htmlAdd("THEAD", HTMLTableSectionElement.class); 374 htmlAdd("TFOOT", HTMLTableSectionElement.class); 375 htmlAdd("TEXTAREA", HTMLTextAreaElement.class); 376 htmlAdd("TITLE", HTMLTitleElement.class); 377 htmlAdd("UL", HTMLUListElement.class); 378 } 379 380 383 static { 384 buildXHTMLTable(); 385 buildHTMLTable(); 386 } 387 388 391 public static Class getXHTMLInterface(String tag) { 392 Class cl = (Class )fXHTMLInterfaceMap.get(tag.toLowerCase()); 393 if (cl == null) { 394 cl = XHTMLElement.class; 395 } 396 return cl; 397 } 398 399 402 public static Class getXHTMLImplementation(String tag) { 403 Class cl = (Class )fXHTMLClassMap.get(tag.toLowerCase()); 404 if (cl == null) { 405 cl = XHTMLElementImpl.class; 406 } 407 return cl; 408 } 409 410 413 public static Class getHTMLInterface(String tag) { 414 Class cl = (Class )fHTMLInterfaceMap.get(tag.toLowerCase()); 415 if (cl == null) { 416 cl = HTMLElement.class; 417 } 418 return cl; 419 } 420 421 425 private static void searchClassPathEntry(String pathEntry, 426 String pkgName, 427 String pkgDir, 428 Set classNames) { 429 final String suffix = ".class"; 430 File dirFile = new File (pathEntry + "/" + pkgDir); 431 File [] files = dirFile.listFiles(new FilenameFilter () { 432 public boolean accept(File dir, String name) { 433 return name.regionMatches(name.length()-suffix.length(), suffix, 0, suffix.length()) 435 && (name.indexOf("Element") >= 0); 436 } 437 }); 438 if (files != null) { 440 for (int i = 0; i < files.length; i++) { 441 String name = files[i].getName(); 442 classNames.add(pkgName + "." + name.substring(0, name.length()-suffix.length())); 443 } 444 } 445 } 446 447 453 public static String [] getPackageElementClasses(String pkgName) { 454 HashSet classNames = new HashSet (); 455 String pkgDir = pkgName.replace('.', '/'); 456 String path = System.getProperty("java.class.path"); 457 StringTokenizer tokenizer = new StringTokenizer (path, File.pathSeparator); 458 while (tokenizer.hasMoreTokens()) { 459 searchClassPathEntry((String )tokenizer.nextToken(), pkgName, pkgDir, classNames); 460 } 461 return (String [])classNames.toArray(new String [classNames.size()]); 462 } 463 464 } 465 | Popular Tags |