KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tests > org > enhydra > xml > xhtml > dominfo > ElementClassMappings


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: ElementClassMappings.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package tests.org.enhydra.xml.xhtml.dominfo;
25
26 import java.io.File JavaDoc;
27 import java.io.FilenameFilter JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.HashSet JavaDoc;
30 import java.util.Set JavaDoc;
31 import java.util.StringTokenizer JavaDoc;
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 /**
173  * Tables containing the element-class mappings for XHTML and HTML.
174  * Also has routines to find the list of classes that are available.
175  */

176 class ElementClassMappings {
177     /**
178      * Table of element name to interface mappings.
179      */

180     private static HashMap JavaDoc fXHTMLInterfaceMap = new HashMap JavaDoc();
181     private static HashMap JavaDoc fXHTMLClassMap = new HashMap JavaDoc();
182     private static HashMap JavaDoc fHTMLInterfaceMap = new HashMap JavaDoc();
183
184
185     /**
186      * Add an XHTML interface and implementation to the map.
187      */

188     private static void xhtmlAdd(String JavaDoc tag,
189                                  Class JavaDoc element) {
190         fXHTMLInterfaceMap.put(tag.toLowerCase(), element);
191
192         // Construct the interface name and get the class
193
String JavaDoc qualName = element.getName();
194         String JavaDoc pkgName = qualName.substring(0, qualName.lastIndexOf('.'));
195         String JavaDoc unqualName = qualName.substring(qualName.lastIndexOf('.')+1);
196         String JavaDoc implName = pkgName + ".xerces." + unqualName + "Impl";
197         try {
198             fXHTMLClassMap.put(tag.toLowerCase(), Class.forName(implName));
199         } catch (ClassNotFoundException JavaDoc except) {
200             throw new FatalExceptionError(except);
201         }
202     }
203
204     /**
205      * Build table for XHTML. This code taken from
206      * org.enhydra.xml.xhtml.dom.xerces.XHTMLDocumentImpl.
207      */

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     /**
303      * Add an HTML interface to the map.
304      */

305     private static void htmlAdd(String JavaDoc tag,
306                                 Class JavaDoc element) {
307         fHTMLInterfaceMap.put(tag.toLowerCase(), element);
308     }
309     
310     /**
311      * Build table for HTML. This code taken from
312      * org.apache.html.dom.HTMLDocumentImpl.
313      */

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     /**
381      * Class initializer.
382      */

383     static {
384         buildXHTMLTable();
385         buildHTMLTable();
386     }
387
388     /**
389      * Get a XHTML interface given a tag name.
390      */

391     public static Class JavaDoc getXHTMLInterface(String JavaDoc tag) {
392         Class JavaDoc cl = (Class JavaDoc)fXHTMLInterfaceMap.get(tag.toLowerCase());
393         if (cl == null) {
394             cl = XHTMLElement.class;
395         }
396         return cl;
397     }
398
399     /**
400      * Get a XHTML implementation given a tag name.
401      */

402     public static Class JavaDoc getXHTMLImplementation(String JavaDoc tag) {
403         Class JavaDoc cl = (Class JavaDoc)fXHTMLClassMap.get(tag.toLowerCase());
404         if (cl == null) {
405             cl = XHTMLElementImpl.class;
406         }
407         return cl;
408     }
409
410     /**
411      * Get a HTML interface given a tag name.
412      */

413     public static Class JavaDoc getHTMLInterface(String JavaDoc tag) {
414         Class JavaDoc cl = (Class JavaDoc)fHTMLInterfaceMap.get(tag.toLowerCase());
415         if (cl == null) {
416             cl = HTMLElement.class;
417         }
418         return cl;
419     }
420
421     /**
422      * Search a class path entry for all class files in a package that containg
423      * the string `Element'.
424      */

425     private static void searchClassPathEntry(String JavaDoc pathEntry,
426                                              String JavaDoc pkgName,
427                                              String JavaDoc pkgDir,
428                                              Set JavaDoc classNames) {
429         final String JavaDoc suffix = ".class";
430         File JavaDoc dirFile = new File JavaDoc(pathEntry + "/" + pkgDir);
431         File JavaDoc[] files = dirFile.listFiles(new FilenameFilter JavaDoc() {
432                 public boolean accept(File JavaDoc dir, String JavaDoc name) {
433                     // Is the name in the form ".*Element*.class"?
434
return name.regionMatches(name.length()-suffix.length(), suffix, 0, suffix.length())
435                         && (name.indexOf("Element") >= 0);
436                 }
437             });
438         // Convert to class names
439
if (files != null) {
440             for (int i = 0; i < files.length; i++) {
441                 String JavaDoc name = files[i].getName();
442                 classNames.add(pkgName + "." + name.substring(0, name.length()-suffix.length()));
443             }
444         }
445     }
446
447     /**
448      * Search the CLASSPATH for all classes in the specified package
449      * that containg the string `Element'.
450      * FIXME: doesn't currently handle jars
451      * @returns a list of class names.
452      */

453     public static String JavaDoc[] getPackageElementClasses(String JavaDoc pkgName) {
454         HashSet JavaDoc classNames = new HashSet JavaDoc();
455         String JavaDoc pkgDir = pkgName.replace('.', '/');
456         String JavaDoc path = System.getProperty("java.class.path");
457         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(path, File.pathSeparator);
458         while (tokenizer.hasMoreTokens()) {
459             searchClassPathEntry((String JavaDoc)tokenizer.nextToken(), pkgName, pkgDir, classNames);
460         }
461         return (String JavaDoc[])classNames.toArray(new String JavaDoc[classNames.size()]);
462     }
463
464 }
465
Popular Tags