KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > wireless > chtml > dom > xerces > CHTMLDocumentImpl


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  * Contributor(s):
15  *
16  * $Id: CHTMLDocumentImpl.java,v 1.5 2005/01/26 08:28:45 jkjome Exp $
17  */

18
19 package org.enhydra.wireless.chtml.dom.xerces;
20
21 import java.lang.reflect.Constructor JavaDoc;
22 import java.util.HashMap JavaDoc;
23
24 import org.enhydra.apache.html.dom.HTMLAnchorElementImpl;
25 import org.enhydra.apache.html.dom.HTMLBRElementImpl;
26 import org.enhydra.apache.html.dom.HTMLBaseElementImpl;
27 import org.enhydra.apache.html.dom.HTMLBodyElementImpl;
28 import org.enhydra.apache.html.dom.HTMLDListElementImpl;
29 import org.enhydra.apache.html.dom.HTMLDOMImplementationImpl;
30 import org.enhydra.apache.html.dom.HTMLDirectoryElementImpl;
31 import org.enhydra.apache.html.dom.HTMLDivElementImpl;
32 import org.enhydra.apache.html.dom.HTMLDocumentImpl;
33 import org.enhydra.apache.html.dom.HTMLElementImpl;
34 import org.enhydra.apache.html.dom.HTMLFontElementImpl;
35 import org.enhydra.apache.html.dom.HTMLFormElementImpl;
36 import org.enhydra.apache.html.dom.HTMLHRElementImpl;
37 import org.enhydra.apache.html.dom.HTMLHeadElementImpl;
38 import org.enhydra.apache.html.dom.HTMLHeadingElementImpl;
39 import org.enhydra.apache.html.dom.HTMLHtmlElementImpl;
40 import org.enhydra.apache.html.dom.HTMLImageElementImpl;
41 import org.enhydra.apache.html.dom.HTMLInputElementImpl;
42 import org.enhydra.apache.html.dom.HTMLLIElementImpl;
43 import org.enhydra.apache.html.dom.HTMLMenuElementImpl;
44 import org.enhydra.apache.html.dom.HTMLMetaElementImpl;
45 import org.enhydra.apache.html.dom.HTMLOListElementImpl;
46 import org.enhydra.apache.html.dom.HTMLOptionElementImpl;
47 import org.enhydra.apache.html.dom.HTMLParagraphElementImpl;
48 import org.enhydra.apache.html.dom.HTMLPreElementImpl;
49 import org.enhydra.apache.html.dom.HTMLQuoteElementImpl;
50 import org.enhydra.apache.html.dom.HTMLSelectElementImpl;
51 import org.enhydra.apache.html.dom.HTMLTextAreaElementImpl;
52 import org.enhydra.apache.html.dom.HTMLTitleElementImpl;
53 import org.enhydra.apache.html.dom.HTMLUListElementImpl;
54 import org.enhydra.wireless.chtml.dom.CHTMLDocument;
55 import org.enhydra.xml.xmlc.XMLObject;
56 import org.enhydra.xml.xmlc.XMLObjectLink;
57 import org.w3c.dom.DOMException JavaDoc;
58 import org.w3c.dom.DOMImplementation JavaDoc;
59 import org.w3c.dom.Element JavaDoc;
60
61 /**
62  * CHTML Document interfaces. This implements a subset of the HTML DOM that
63  * corresponds to CHTML defined by DoCoMo. See
64  * <a HREF="http://www.nttdocomo.com/">CHTML specification</a>
65  * for details.
66  *
67  * @see org.w3c.dom.html.HTMLDocument
68  */

69 public class CHTMLDocumentImpl extends HTMLDocumentImpl
70     implements CHTMLDocument, XMLObjectLink {
71
72     /**
73      * Names and classes of HTML element types.
74      */

75     private static HashMap JavaDoc fElementTypes;
76
77     /**
78      * Signature used to locate constructor of HTML element classes.
79      */

80     private static final Class JavaDoc[] fElemClassSig = new Class JavaDoc[] {
81     HTMLDocumentImpl.class, String JavaDoc.class
82     };
83
84
85     /**
86      * overload in order to return the correct dom implementation for cHTML (actually HTML)
87      * @see org.enhydra.apache.xerces.dom.DocumentImpl#getImplementation
88      */

89     public DOMImplementation JavaDoc getImplementation() {
90         return HTMLDOMImplementationImpl.getDOMImplementation();
91     }
92
93     /**
94      * @see HTMLDocumentImpl#createElementNS
95      */

96     public Element JavaDoc createElementNS(String JavaDoc namespaceURI,
97                    String JavaDoc qualifiedName) throws DOMException JavaDoc {
98         if ((namespaceURI == null) || (namespaceURI.length() == 0)) {
99             return createElement(qualifiedName);
100         } else {
101             return super.createElementNS(namespaceURI, qualifiedName);
102         }
103     }
104
105     /**
106      * @see HTMLDocumentImpl#createElement
107      */

108     public Element JavaDoc createElement(String JavaDoc tagName) throws DOMException JavaDoc {
109     Class JavaDoc elemClass;
110     Constructor JavaDoc cnst;
111
112     elemClass = (Class JavaDoc)fElementTypes.get(tagName.toUpperCase());
113     if (elemClass != null) {
114         try {
115         cnst = elemClass.getConstructor(fElemClassSig);
116
117         return (Element JavaDoc)cnst.newInstance(new Object JavaDoc[] {
118             this, tagName
119         });
120         } catch (Exception JavaDoc except) {
121         Throwable JavaDoc thrw;
122
123         if (except instanceof java.lang.reflect.InvocationTargetException JavaDoc) {
124             thrw =
125             ((java.lang.reflect.InvocationTargetException JavaDoc) except).getTargetException();
126         } else {
127             thrw = except;
128         }
129
130         throw new IllegalStateException JavaDoc("HTM15 Tag '" + tagName
131                         + "' associated with an Element class that failed to construct.\n"
132                         + thrw.getClass().getName() + " " + thrw.getMessage());
133         }
134     }
135
136     return new HTMLElementImpl(this, tagName);
137     }
138
139     /**
140      * Class initializer.
141      */

142     static {
143     fElementTypes = new HashMap JavaDoc();
144
145         fElementTypes.put("A", HTMLAnchorElementImpl.class);
146         fElementTypes.put("BASE", HTMLBaseElementImpl.class);
147         fElementTypes.put("BLOCKQUOTE", HTMLQuoteElementImpl.class);
148         fElementTypes.put("BODY", HTMLBodyElementImpl.class);
149         fElementTypes.put("BR", HTMLBRElementImpl.class);
150         fElementTypes.put("DIR", HTMLDirectoryElementImpl.class);
151         fElementTypes.put("DIV", HTMLDivElementImpl.class);
152         fElementTypes.put("DL", HTMLDListElementImpl.class);
153         fElementTypes.put("FONT", HTMLFontElementImpl.class);
154         fElementTypes.put("FORM", HTMLFormElementImpl.class);
155         fElementTypes.put("H1", HTMLHeadingElementImpl.class);
156         fElementTypes.put("H2", HTMLHeadingElementImpl.class);
157         fElementTypes.put("H3", HTMLHeadingElementImpl.class);
158         fElementTypes.put("H4", HTMLHeadingElementImpl.class);
159         fElementTypes.put("H5", HTMLHeadingElementImpl.class);
160         fElementTypes.put("H6", HTMLHeadingElementImpl.class);
161         fElementTypes.put("HEAD", HTMLHeadElementImpl.class);
162         fElementTypes.put("HEADING", HTMLHeadingElementImpl.class);
163         fElementTypes.put("HR", HTMLHRElementImpl.class);
164         fElementTypes.put("HTML", HTMLHtmlElementImpl.class);
165         fElementTypes.put("IMG", HTMLImageElementImpl.class);
166         fElementTypes.put("INPUT", HTMLInputElementImpl.class);
167         fElementTypes.put("LI", HTMLLIElementImpl.class);
168         fElementTypes.put("MENU", HTMLMenuElementImpl.class);
169         fElementTypes.put("META", HTMLMetaElementImpl.class);
170         fElementTypes.put("OL", HTMLOListElementImpl.class);
171         fElementTypes.put("OPTION", HTMLOptionElementImpl.class);
172         fElementTypes.put("P", HTMLParagraphElementImpl.class);
173         fElementTypes.put("PLAINTEXT", HTMLPreElementImpl.class);
174         fElementTypes.put("PRE", HTMLPreElementImpl.class);
175         fElementTypes.put("SELECT", HTMLSelectElementImpl.class);
176         fElementTypes.put("TEXTAREA", HTMLTextAreaElementImpl.class);
177         fElementTypes.put("TITLE", HTMLTitleElementImpl.class);
178         fElementTypes.put("UL", HTMLUListElementImpl.class);
179     }
180
181     //-------------------------------------------------------------------------
182
// XMLObjectLink implementation
183
//-------------------------------------------------------------------------
184

185     /**
186      * Reference to XMLObject containing this Document.
187      */

188     private XMLObject fXmlObjectLink;
189
190     /**
191      * @see XMLObjectLink#setXMLObject
192      */

193     public void setXMLObject(XMLObject xmlObject) {
194         fXmlObjectLink = xmlObject;
195     }
196
197     /**
198      * @see XMLObjectLink#getXMLObject
199      */

200     public XMLObject getXMLObject() {
201         return fXmlObjectLink;
202     }
203
204 }
205
Popular Tags