KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > dom > HTMLDomFactoryMethods


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: HTMLDomFactoryMethods.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.dom;
25
26 import java.util.HashSet JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28
29 import org.w3c.dom.Element JavaDoc;
30
31 /**
32  * Support for implementing DOM factories for HTML. Since a HTML
33  * DOM factory normally extends the XML DOM factory, there isn't
34  * a base class for HTML support.
35  */

36 public final class HTMLDomFactoryMethods {
37     /**
38      * HTML URL attributes.
39      */

40     private static String JavaDoc[] URL_ATTRIBUTES = {
41         "action", "archive", "background", "cite", "classid", "codebase",
42         "data", "href", "longdesc", "onblur", "onchange", "onclick",
43         "ondblclick", "onfocus", "onkeydown", "onkeypress", "onkeyup",
44         "onload", "onmousedown", "onmousemove", "onmouseout", "onmouseover",
45         "onmouseup","onreset", "onselect", "onsubmit", "onunload", "profile",
46         "src", "usemap"
47     };
48
49     /**
50      * HashSet built from URL_ATTRIBUTES.
51      */

52     private static final HashSet JavaDoc urlAttributes;
53
54     /**
55      * Class initializer.
56      */

57     static {
58         urlAttributes = new HashSet JavaDoc(URL_ATTRIBUTES.length);
59         for (int idx = 0; idx < URL_ATTRIBUTES.length; idx++) {
60             urlAttributes.add(URL_ATTRIBUTES[idx]);
61         }
62     }
63         
64     /**
65      * @see XMLCDomFactory#getBaseClassName
66      */

67     public static final String JavaDoc getBaseClassName() {
68         return "org.enhydra.xml.xmlc.html.HTMLObjectImpl";
69     }
70
71     /**
72      * @see XMLCDomFactory#getInterfaceNames
73      */

74     public static final String JavaDoc[] getInterfaceNames() {
75         return new String JavaDoc[] {"org.enhydra.xml.xmlc.html.HTMLObject"};
76     }
77
78     /**
79      * @see XMLCDomFactory#getElementClassNames
80      */

81     public static final String JavaDoc[] getElementClassNames(Element JavaDoc element) {
82         //FIXME: This code would be real useful in XMLCUtil or HTMLObject.
83
String JavaDoc classNames = element.getAttribute("class");
84         if ((classNames == null) || (classNames.length() ==0)) {
85             return null;
86         } else {
87             // Parse the class name.
88
StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc(classNames);
89             String JavaDoc[] names = new String JavaDoc[tokens.countTokens()];
90             for (int idx = 0; idx < names.length; idx++) {
91                 names[idx] = tokens.nextToken();
92             }
93             return names;
94         }
95     }
96
97
98     /**
99      * @see XMLCDomFactory#isURLAttribute
100      */

101     public static final boolean isURLAttribute(Element JavaDoc element,
102                                                String JavaDoc attrName) {
103         return urlAttributes.contains(attrName);
104     }
105 }
106
Popular Tags