KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > lazydom > html > LazyHTMLDocument


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

23 /*
24  * The Apache Software License, Version 1.1
25  *
26  *
27  * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
28  * reserved.
29  *
30  * Redistribution and use in source and binary forms, with or without
31  * modification, are permitted provided that the following conditions
32  * are met:
33  *
34  * 1. Redistributions of source code must retain the above copyright
35  * notice, this list of conditions and the following disclaimer.
36  *
37  * 2. Redistributions in binary form must reproduce the above copyright
38  * notice, this list of conditions and the following disclaimer in
39  * the documentation and/or other materials provided with the
40  * distribution.
41  *
42  * 3. The end-user documentation included with the redistribution,
43  * if any, must include the following acknowledgment:
44  * "This product includes software developed by the
45  * Apache Software Foundation (http://www.apache.org/)."
46  * Alternately, this acknowledgment may appear in the software itself,
47  * if and wherever such third-party acknowledgments normally appear.
48  *
49  * 4. The names "Xerces" and "Apache Software Foundation" must
50  * not be used to endorse or promote products derived from this
51  * software without prior written permission. For written
52  * permission, please contact apache@apache.org.
53  *
54  * 5. Products derived from this software may not be called "Apache",
55  * nor may "Apache" appear in their name, without prior written
56  * permission of the Apache Software Foundation.
57  *
58  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
59  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
61  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
62  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
63  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
64  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
65  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
66  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
67  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
68  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69  * SUCH DAMAGE.
70  * ====================================================================
71  *
72  * This software consists of voluntary contributions made by many
73  * individuals on behalf of the Apache Software Foundation and was
74  * originally based on software copyright (c) 1999, International
75  * Business Machines, Inc., http://www.apache.org. For more
76  * information on the Apache Software Foundation, please see
77  * <http://www.apache.org/>.
78  */

79 package org.enhydra.xml.lazydom.html;
80
81 import java.io.StringWriter JavaDoc;
82 import java.lang.reflect.Constructor JavaDoc;
83 import java.util.HashMap JavaDoc;
84
85 import org.enhydra.xml.dom.DOMAccess;
86 import org.enhydra.xml.lazydom.LazyDocument;
87 import org.enhydra.xml.lazydom.LazyElement;
88 import org.enhydra.xml.lazydom.LazyNode;
89 import org.enhydra.xml.lazydom.TemplateDOM;
90 import org.w3c.dom.Attr JavaDoc;
91 import org.w3c.dom.DOMException JavaDoc;
92 import org.w3c.dom.DOMImplementation JavaDoc;
93 import org.w3c.dom.Document JavaDoc;
94 import org.w3c.dom.Element JavaDoc;
95 import org.w3c.dom.Node JavaDoc;
96 import org.w3c.dom.NodeList JavaDoc;
97 import org.w3c.dom.html.HTMLCollection;
98 import org.w3c.dom.html.HTMLDocument;
99 import org.w3c.dom.html.HTMLElement;
100 import org.w3c.dom.html.HTMLTitleElement;
101
102 /*
103  * LazyDOM: This is a modified version of org.apache.html.dom.HTMLDocumentImpl
104  * modified to implement the LazyDOM. While most of the HTMLElement classes
105  * are created automatically using a sed script, this was a bit complex for
106  * this class, so it was done by hand. A diff with the Xerces class should
107  * make an upgrade of this class easy.
108  */

109
110
111 /**
112  * Implements an HTML document. Provides access to the top level element in the
113  * document, its body and title.
114  * <P>
115  * Several methods create new nodes of all basic types (comment, text, element,
116  * etc.). These methods create new nodes but do not place them in the document
117  * tree. The nodes may be placed in the document tree using {@link
118  * org.w3c.dom.Node#appendChild} or {@link org.w3c.dom.Node#insertBefore}, or
119  * they may be placed in some other document tree.
120  * <P>
121  * Note: &lt;FRAMESET&gt; documents are not supported at the moment, neither
122  * are direct document writing ({@link #open}, {@link #write}) and HTTP attribute
123  * methods ({@link #getURL}, {@link #getCookie}).
124  *
125  *
126  * @version $Revision: 1.4 $ $Date: 2005/01/26 08:29:24 $
127  * @author <a HREF="mailto:arkin@exoffice.com">Assaf Arkin</a>
128  * @see org.w3c.dom.html.HTMLDocument
129  */

130 public class LazyHTMLDocument
131     extends LazyDocument
132     implements HTMLDocument
133 {
134
135
136     /**
137      * Holds {@link HTMLCollectionImpl} object with live collection of all
138      * anchors in document. This reference is on demand only once.
139      */

140     private HTMLCollectionImpl _anchors;
141
142
143     /**
144      * Holds {@link HTMLCollectionImpl} object with live collection of all
145      * forms in document. This reference is on demand only once.
146      */

147     private HTMLCollectionImpl _forms;
148
149
150     /**
151      * Holds {@link HTMLCollectionImpl} object with live collection of all
152      * images in document. This reference is on demand only once.
153      */

154     private HTMLCollectionImpl _images;
155
156
157     /**
158      * Holds {@link HTMLCollectionImpl} object with live collection of all
159      * links in document. This reference is on demand only once.
160      */

161     private HTMLCollectionImpl _links;
162
163
164     /**
165      * Holds {@link HTMLCollectionImpl} object with live collection of all
166      * applets in document. This reference is on demand only once.
167      */

168     private HTMLCollectionImpl _applets;
169
170
171     /**
172      * Holds string writer used by direct manipulation operation ({@link #open}.
173      * {@link #write}, etc) to write new contents into the document and parse
174      * that text into a document tree.
175      */

176     private StringWriter JavaDoc _writer;
177
178
179     /**
180      * Holds names and classes of HTML element type constructors. When
181      * an element with a particular tag name is created, the matching
182      * {@link java.lang.reflect.Constructor} is used to create the element
183      * object. For example, &lt;A&gt; matches the constructor for
184      * {@link HTMLAnchorElementImpl}. This static table is shared across all
185      * HTML documents.
186      *
187      * @see #createElement
188      */

189     private static HashMap JavaDoc _elementConstHTML;
190     private static HashMap JavaDoc _tmpElementConstHTML;
191
192
193     /**
194      * Signature used to locate constructor of HTML element classes. This
195      * static array is shared across all HTML documents.
196      *
197      * @see #createElement
198      */

199     private static final Class JavaDoc[] _elemClassSigHTML =
200         new Class JavaDoc[] { LazyHTMLDocument.class, LazyElement.class, String JavaDoc.class };
201
202
203     /**
204      * @see Document#getImplementation
205      */

206     public DOMImplementation JavaDoc getImplementation() {
207         return LazyHTMLDOMImplementation.getDOMImplementation();
208     }
209     
210
211    /**
212      * Find the direct child element of a node given its name.
213      */

214     private Node getDirectChildElement(String JavaDoc name,
215                                        Node root) {
216         for (Node child = root.getFirstChild(); child != null;
217              child = child.getNextSibling()) {
218             if (child.getNodeName().equals(name)) {
219                 return child;
220             }
221         }
222         return null;
223     }
224
225
226     public synchronized Element getDocumentElement() {
227         // Enhydra modified: Original Xerces code tried to reorder nodes to
228
// make things right, which moved around comments to weird locations.
229
// Throwing an error would be more appropriate, but we were afraid of
230
// breaking existing code, so just get the node.
231

232         Element html = (Element)getDirectChildElement("HTML", this);
233         if (html == null) {
234             // Create, HTML element must exist as a child of the document.
235
html = new HTMLHtmlElementImpl(this, null, "HTML");
236             appendChild(html);
237         }
238         return html;
239     }
240     
241     /**
242      * Obtains the &lt;HEAD&gt; element in the document, creating one if does
243      * not exist before. The &lt;HEAD&gt; element is the first element in the
244      * &lt;HTML&gt; in the document. The &lt;HTML&gt; element is obtained by
245      * calling {@link #getDocumentElement}. If the element does not exist, one
246      * is created.
247      * <P>
248      * Called by {@link #getTitle}, {@link #setTitle}, {@link #getBody} and
249      * {@link #setBody} to assure the document has the &lt;HEAD&gt; element
250      * correctly placed.
251      *
252      * @return The &lt;HEAD&gt; element
253      */

254     public synchronized HTMLElement getHead() {
255         // Enhydra modified: Original Xerces code tried to reorder nodes to
256
// make things right, which moved around comments to weird locations.
257
// Throwing an error would be more appropriate, but we were afraid of
258
// breaking existing code, so just get the node.
259

260         // Search for HEAD under HTML element.
261
Element html = getDocumentElement();
262         HTMLElement head
263             = (HTMLElement)getDirectChildElement("HEAD", html);
264         if (head == null) {
265             // Head does not exist, create a new one.
266
head = new HTMLHeadElementImpl(this, null, "HEAD");
267             html.insertBefore(head, html.getFirstChild());
268         }
269         return head;
270     }
271
272     public synchronized String JavaDoc getTitle() {
273         // Enhydra modified: Original Xerces code is some what strange, it
274
// called getElementsByTagName() twice, but only used the second
275
// result. We assume it' a direct child of HEAD (although more
276
// error checking might be better).
277

278         HTMLTitleElement title
279             = (HTMLTitleElement)getDirectChildElement("TITLE", getHead());
280         if (title == null) {
281             return ""; // No TITLE found, return an empty string.
282
} else {
283             return title.getText();
284         }
285     }
286
287
288     public synchronized void setTitle(String JavaDoc newTitle) {
289         // Enhydra modified: Original Xerces code used getElementsByTagName()
290
// to find the title. We assume it' a direct child of HEAD (although
291
// more error checking might be better).
292

293         HTMLElement head = getHead();
294         HTMLTitleElement title
295             = (HTMLTitleElement)getDirectChildElement("TITLE", head);
296         if (title == null) {
297             title = new HTMLTitleElementImpl(this, null, "TITLE");
298         }
299         title.setText(newTitle);
300     }
301
302     /**
303      * Find a BODY or FRAMESET element.
304      */

305     private HTMLElement findBody(Element html) {
306         HTMLElement body = (HTMLElement)getDirectChildElement("BODY", html);
307         if (body == null) {
308             body = (HTMLElement)getDirectChildElement("FRAMESET", html);
309         }
310         return body;
311     }
312
313     public synchronized HTMLElement getBody() {
314         // Enhydra modified: Original Xerces code tried to reorder nodes to
315
// make things right, which moved around comments to weird locations.
316
// Throwing an error would be more appropriate, but we were afraid of
317
// breaking existing code, so just get the node.
318

319         // Find BODY or FRAMESET
320
Element html = getDocumentElement();
321         HTMLElement body = findBody(html);
322         if (body == null) {
323             // Create new body, and place it a the end of the HTML element.
324
body = new HTMLBodyElementImpl(this, null, "BODY");
325             html.appendChild(body);
326         }
327         return body;
328     }
329
330
331     public synchronized void setBody(HTMLElement newBody) {
332         // Enhydra modified: Original Xerces code tried to reorder nodes to
333
// make things right, which moved around comments to weird locations.
334
// Throwing an error would be more appropriate, but we were afraid of
335
// breaking existing code, so just get the node.
336

337         // Find BODY or FRAMESET
338
Element html = getDocumentElement();
339         HTMLElement body = findBody(html);
340         if (body == null) {
341             html.appendChild(newBody);
342         } else {
343             html.replaceChild(newBody, body);
344         }
345     }
346
347
348     public synchronized Element getElementById( String JavaDoc elementId )
349     {
350         return getElementById( elementId, this );
351     }
352
353
354     public NodeList JavaDoc getElementsByName( String JavaDoc elementName )
355     {
356         return new NameNodeListImpl( this, elementName );
357     }
358
359
360     public final NodeList JavaDoc getElementsByTagName( String JavaDoc tagName )
361     {
362         return super.getElementsByTagName( tagName.toUpperCase() );
363     }
364
365
366     public final NodeList JavaDoc getElementsByTagNameNS( String JavaDoc namespaceURI,
367                                                   String JavaDoc localName )
368     {
369         if ( namespaceURI != null && namespaceURI.length() > 0 )
370             return super.getElementsByTagNameNS( namespaceURI, localName.toUpperCase() );
371         else
372             return super.getElementsByTagName( localName.toUpperCase() );
373     }
374
375
376     public Element createElementNS( String JavaDoc namespaceURI, String JavaDoc qualifiedName )
377     {
378         if ( namespaceURI == null || namespaceURI.length() == 0 )
379             return createElement( qualifiedName );
380         else
381             return super.createElementNS( namespaceURI, qualifiedName );
382     }
383
384
385     public Element createElement( LazyElement template, String JavaDoc tagName )
386         throws DOMException JavaDoc
387     {
388         Constructor JavaDoc cnst;
389
390         // First, make sure tag name is all upper case, next get the associated
391
// element class. If no class is found, generate a generic HTML element.
392
// Do so also if an unexpected exception occurs.
393
tagName = tagName.toUpperCase();
394         cnst = (Constructor JavaDoc) _elementConstHTML.get( tagName );
395         if ( cnst != null )
396         {
397             // Get the constructor for the element. The signature specifies an
398
// owner document and a tag name. Use the constructor to instantiate
399
// a new object and return it.
400
try
401             {
402                 return (Element) cnst.newInstance( new Object JavaDoc[] { this, template, tagName } );
403             }
404             catch ( Exception JavaDoc except )
405             {
406                 Throwable JavaDoc thrw;
407
408                 if ( except instanceof java.lang.reflect.InvocationTargetException JavaDoc )
409                     thrw = ( (java.lang.reflect.InvocationTargetException JavaDoc) except ).getTargetException();
410                 else
411                     thrw = except;
412
413                 throw new IllegalStateException JavaDoc( "HTM15 Tag '" + tagName + "' associated with an Element class that failed to construct.\n" + tagName);
414             }
415         }
416         return new LazyHTMLElement( this, template, tagName );
417     }
418
419
420     /**
421      * Creates an Attribute having this Document as its OwnerDoc.
422      * Overrides {@link org.enhydra.apache.xerces.dom.DocumentImpl#createAttribute} and returns
423      * and attribute whose name is lower case.
424      *
425      * @param name The name of the attribute
426      * @return An attribute whose name is all lower case
427      * @throws DOMException(INVALID_NAME_ERR) if the attribute name
428      * is not acceptable
429      */

430     public Attr JavaDoc createAttribute( String JavaDoc name )
431         throws DOMException JavaDoc
432     {
433         return super.createAttribute( name.toLowerCase() );
434     }
435
436
437     public String JavaDoc getReferrer()
438     {
439         // Information not available on server side.
440
return null;
441     }
442
443
444     public String JavaDoc getDomain()
445     {
446         // Information not available on server side.
447
return null;
448     }
449
450
451     public String JavaDoc getURL()
452     {
453         // Information not available on server side.
454
return null;
455     }
456
457
458     public String JavaDoc getCookie()
459     {
460         // Information not available on server side.
461
return null;
462     }
463
464
465     public void setCookie( String JavaDoc cookie )
466     {
467         // Information not available on server side.
468
}
469
470
471     public HTMLCollection getImages()
472     {
473         // For more information see HTMLCollection#collectionMatch
474
if ( _images == null )
475             _images = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.IMAGE );
476         return _images;
477     }
478
479
480     public HTMLCollection getApplets()
481     {
482         // For more information see HTMLCollection#collectionMatch
483
if ( _applets == null )
484             _applets = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.APPLET );
485         return _applets;
486     }
487
488
489     public HTMLCollection getLinks()
490     {
491         // For more information see HTMLCollection#collectionMatch
492
if ( _links == null )
493             _links = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.LINK );
494         return _links;
495     }
496
497
498     public HTMLCollection getForms()
499     {
500         // For more information see HTMLCollection#collectionMatch
501
if ( _forms == null )
502             _forms = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.FORM );
503         return _forms;
504     }
505
506
507     public HTMLCollection getAnchors()
508     {
509         // For more information see HTMLCollection#collectionMatch
510
if ( _anchors == null )
511             _anchors = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.ANCHOR );
512         return _anchors;
513     }
514
515
516     public void open()
517     {
518         // When called an in-memory is prepared. The document tree is still
519
// accessible the old way, until this writer is closed.
520
if ( _writer == null )
521             _writer = new StringWriter JavaDoc();
522     }
523
524
525     public void close()
526     {
527         // ! NOT IMPLEMENTED, REQUIRES PARSER !
528
if ( _writer != null )
529         {
530             _writer = null;
531         }
532     }
533
534
535     public void write( String JavaDoc text )
536     {
537         // Write a string into the in-memory writer.
538
if ( _writer != null )
539             _writer.write( text );
540     }
541
542
543     public void writeln( String JavaDoc text )
544     {
545         // Write a line into the in-memory writer.
546
if ( _writer != null )
547             _writer.write( text + "\n" );
548     }
549
550
551     public Node cloneNode( boolean deep )
552     {
553         LazyHTMLDocument clone;
554         LazyNode node;
555         
556         clone = new LazyHTMLDocument();
557         if ( deep ) {
558             node = (LazyNode) getFirstChild();
559             while ( node != null ) {
560                 clone.appendChild( clone.importNode( node, true ) );
561                 node = (LazyNode) node.getNextSibling();
562             }
563         }
564         return clone;
565     }
566
567
568     /**
569      * Recursive method retreives an element by its <code>id</code> attribute.
570      * This is LazyDOM aware and will not expand elements during search.
571      *
572      * @param elementId The <code>id</code> value to look for
573      * @return The node in which to look for
574      */

575     private Element getElementById(String JavaDoc elementId,
576                                    Node node){
577         Node child;
578         Element element;
579
580         child = DOMAccess.accessFirstChild(this, node);
581         while (child != null) {
582             if (child instanceof Element) {
583                 element = (Element)child;
584                 Attr JavaDoc attr = DOMAccess.accessAttribute(this, (Element)child, null, "id");
585                 if ((attr != null)
586                     && elementId.equals(DOMAccess.accessAttributeValue(this, attr))) {
587                     return DOMAccess.getExpandedElement(this, element);
588                 }
589                 // Recurse
590
element = getElementById(elementId, child);
591                 if (element != null) {
592                     return DOMAccess.getExpandedElement(this, element);
593                 }
594             }
595             child = DOMAccess.accessNextSibling(this, child);
596         }
597         return null;
598     }
599
600
601     /**
602      * Called by the constructor to populate the element constructor list
603      * (see {@link #_elementConstHTML}). Will be called multiple times but
604      * populate the list * only the first time. Replacement for static
605      * constructor.
606      */

607     private static void populateElementTypes()
608     {
609         // This class looks like it is due to some strange
610
// (read: inconsistent) JVM bugs.
611
// Initially all this code was placed in the static constructor,
612
// but that caused some early JVMs (1.1) to go mad, and if a
613
// class could not be found (as happened during development),
614
// the JVM would die.
615
// Bertrand Delacretaz <bdelacretaz@worldcom.ch> pointed out
616
// several configurations where HTMLAnchorElementImpl.class
617
// failed, forcing me to revert back to Class.forName().
618

619         if ( _elementConstHTML != null )
620             return;
621         _tmpElementConstHTML = new HashMap JavaDoc( 63 );
622         populateElementType( "A", "HTMLAnchorElementImpl" );
623         populateElementType( "APPLET", "HTMLAppletElementImpl" );
624         populateElementType( "AREA", "HTMLAreaElementImpl" );
625         populateElementType( "BASE", "HTMLBaseElementImpl" );
626         populateElementType( "BASEFONT", "HTMLBaseFontElementImpl" );
627         populateElementType( "BLOCKQUOTE", "HTMLQuoteElementImpl" );
628         populateElementType( "BODY", "HTMLBodyElementImpl" );
629         populateElementType( "BR", "HTMLBRElementImpl" );
630         populateElementType( "BUTTON", "HTMLButtonElementImpl" );
631         populateElementType( "DEL", "HTMLModElementImpl" );
632         populateElementType( "DIR", "HTMLDirectoryElementImpl" );
633         populateElementType( "DIV", "HTMLDivElementImpl" );
634         populateElementType( "DL", "HTMLDListElementImpl" );
635         populateElementType( "FIELDSET", "HTMLFieldSetElementImpl" );
636         populateElementType( "FONT", "HTMLFontElementImpl" );
637         populateElementType( "FORM", "HTMLFormElementImpl" );
638         populateElementType( "FRAME","HTMLFrameElementImpl" );
639         populateElementType( "FRAMESET", "HTMLFrameSetElementImpl" );
640         populateElementType( "HEAD", "HTMLHeadElementImpl" );
641         populateElementType( "H1", "HTMLHeadingElementImpl" );
642         populateElementType( "H2", "HTMLHeadingElementImpl" );
643         populateElementType( "H3", "HTMLHeadingElementImpl" );
644         populateElementType( "H4", "HTMLHeadingElementImpl" );
645         populateElementType( "H5", "HTMLHeadingElementImpl" );
646         populateElementType( "H6", "HTMLHeadingElementImpl" );
647         populateElementType( "HR", "HTMLHRElementImpl" );
648         populateElementType( "HTML", "HTMLHtmlElementImpl" );
649         populateElementType( "IFRAME", "HTMLIFrameElementImpl" );
650         populateElementType( "IMG", "HTMLImageElementImpl" );
651         populateElementType( "INPUT", "HTMLInputElementImpl" );
652         populateElementType( "INS", "HTMLModElementImpl" );
653         populateElementType( "ISINDEX", "HTMLIsIndexElementImpl" );
654         populateElementType( "LABEL", "HTMLLabelElementImpl" );
655         populateElementType( "LEGEND", "HTMLLegendElementImpl" );
656         populateElementType( "LI", "HTMLLIElementImpl" );
657         populateElementType( "LINK", "HTMLLinkElementImpl" );
658         populateElementType( "MAP", "HTMLMapElementImpl" );
659         populateElementType( "MENU", "HTMLMenuElementImpl" );
660         populateElementType( "META", "HTMLMetaElementImpl" );
661         populateElementType( "OBJECT", "HTMLObjectElementImpl" );
662         populateElementType( "OL", "HTMLOListElementImpl" );
663         populateElementType( "OPTGROUP", "HTMLOptGroupElementImpl" );
664         populateElementType( "OPTION", "HTMLOptionElementImpl" );
665         populateElementType( "P", "HTMLParagraphElementImpl" );
666         populateElementType( "PARAM", "HTMLParamElementImpl" );
667         populateElementType( "PRE", "HTMLPreElementImpl" );
668         populateElementType( "Q", "HTMLQuoteElementImpl" );
669         populateElementType( "SCRIPT", "HTMLScriptElementImpl" );
670         populateElementType( "SELECT", "HTMLSelectElementImpl" );
671         populateElementType( "STYLE", "HTMLStyleElementImpl" );
672         populateElementType( "TABLE", "HTMLTableElementImpl" );
673         populateElementType( "CAPTION", "HTMLTableCaptionElementImpl" );
674         populateElementType( "TD", "HTMLTableCellElementImpl" );
675         populateElementType( "TH", "HTMLTableCellElementImpl" );
676         populateElementType( "COL", "HTMLTableColElementImpl" );
677         populateElementType( "COLGROUP", "HTMLTableColElementImpl" );
678         populateElementType( "TR", "HTMLTableRowElementImpl" );
679         populateElementType( "TBODY", "HTMLTableSectionElementImpl" );
680         populateElementType( "THEAD", "HTMLTableSectionElementImpl" );
681         populateElementType( "TFOOT", "HTMLTableSectionElementImpl" );
682         populateElementType( "TEXTAREA", "HTMLTextAreaElementImpl" );
683         populateElementType( "TITLE", "HTMLTitleElementImpl" );
684         populateElementType( "UL", "HTMLUListElementImpl" );
685         _elementConstHTML = _tmpElementConstHTML;
686     }
687     
688     
689     private static void populateElementType(String JavaDoc tagName, String JavaDoc className )
690     {
691         try {
692         Class JavaDoc cl = Class.forName( "org.enhydra.xml.lazydom.html." + className );
693         _tmpElementConstHTML.put( tagName, cl.getConstructor( _elemClassSigHTML ));
694     } catch ( ClassNotFoundException JavaDoc except ) {
695             new RuntimeException JavaDoc( "HTM019 OpenXML Error: Could not find class " + className + " implementing HTML element " + tagName
696                                   + "\n" + className + "\t" + tagName);
697     } catch ( NoSuchMethodException JavaDoc except ) {
698             new RuntimeException JavaDoc( "HTM019 OpenXML Error: Could not find constructor for class " + className + " implementing HTML element " + tagName
699                                   + "\n" + className + "\t" + tagName);
700         }
701     }
702
703     /**
704      * Constructor with no template.
705      */

706     public LazyHTMLDocument()
707     {
708         super();
709         populateElementTypes();
710     }
711
712     /**
713      * LazyDOM: Constructor with TemplateDOM.
714      */

715     public LazyHTMLDocument(TemplateDOM templateDOM) {
716         super(null, templateDOM);
717         populateElementTypes();
718     }
719
720     /**
721      * LazyDOM: standard createElement method, passes null template element.
722      */

723     public Element createElement(String JavaDoc tagName) throws DOMException JavaDoc {
724         return createElement(null, tagName);
725     }
726
727     /*
728      * Lazy DOM override to pick up HTML elements.
729      */

730     public LazyElement createElement(int nodeId) throws DOMException JavaDoc {
731         LazyElement template = (LazyElement)getTemplateNode(nodeId);
732         return (LazyElement)createElement(template, template.getNodeName());
733     }
734 }
735
736
Popular Tags