KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > html > dom > HTMLDocumentImpl


1 /*
2  * Copyright 1999,2000,2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.html.dom;
17
18 import java.io.StringWriter JavaDoc;
19 import java.lang.reflect.Constructor JavaDoc;
20 import java.util.Hashtable JavaDoc;
21 import java.util.Locale JavaDoc;
22
23 import org.apache.xerces.dom.DocumentImpl;
24 import org.apache.xerces.dom.NodeImpl;
25 import org.w3c.dom.Attr JavaDoc;
26 import org.w3c.dom.DOMException JavaDoc;
27 import org.w3c.dom.Element JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29 import org.w3c.dom.NodeList JavaDoc;
30 import org.w3c.dom.html.HTMLBodyElement;
31 import org.w3c.dom.html.HTMLCollection;
32 import org.w3c.dom.html.HTMLDocument;
33 import org.w3c.dom.html.HTMLElement;
34 import org.w3c.dom.html.HTMLFrameSetElement;
35 import org.w3c.dom.html.HTMLHeadElement;
36 import org.w3c.dom.html.HTMLHtmlElement;
37 import org.w3c.dom.html.HTMLTitleElement;
38
39 /**
40  * Implements an HTML document. Provides access to the top level element in the
41  * document, its body and title.
42  * <P>
43  * Several methods create new nodes of all basic types (comment, text, element,
44  * etc.). These methods create new nodes but do not place them in the document
45  * tree. The nodes may be placed in the document tree using {@link
46  * org.w3c.dom.Node#appendChild} or {@link org.w3c.dom.Node#insertBefore}, or
47  * they may be placed in some other document tree.
48  * <P>
49  * Note: &lt;FRAMESET&gt; documents are not supported at the moment, neither
50  * are direct document writing ({@link #open}, {@link #write}) and HTTP attribute
51  * methods ({@link #getURL}, {@link #getCookie}).
52  *
53  * @xerces.internal
54  *
55  * @version $Revision: 1.21 $ $Date: 2005/04/18 00:41:07 $
56  * @author <a HREF="mailto:arkin@exoffice.com">Assaf Arkin</a>
57  * @see org.w3c.dom.html.HTMLDocument
58  */

59 public class HTMLDocumentImpl
60     extends DocumentImpl
61     implements HTMLDocument
62 {
63
64     private static final long serialVersionUID = 3258132457579427892L;
65
66     /**
67      * Holds {@link HTMLCollectionImpl} object with live collection of all
68      * anchors in document. This reference is on demand only once.
69      */

70     private HTMLCollectionImpl _anchors;
71
72
73     /**
74      * Holds {@link HTMLCollectionImpl} object with live collection of all
75      * forms in document. This reference is on demand only once.
76      */

77     private HTMLCollectionImpl _forms;
78
79
80     /**
81      * Holds {@link HTMLCollectionImpl} object with live collection of all
82      * images in document. This reference is on demand only once.
83      */

84     private HTMLCollectionImpl _images;
85
86
87     /**
88      * Holds {@link HTMLCollectionImpl} object with live collection of all
89      * links in document. This reference is on demand only once.
90      */

91     private HTMLCollectionImpl _links;
92
93
94     /**
95      * Holds {@link HTMLCollectionImpl} object with live collection of all
96      * applets in document. This reference is on demand only once.
97      */

98     private HTMLCollectionImpl _applets;
99
100
101     /**
102      * Holds string writer used by direct manipulation operation ({@link #open}.
103      * {@link #write}, etc) to write new contents into the document and parse
104      * that text into a document tree.
105      */

106     private StringWriter JavaDoc _writer;
107
108
109     /**
110      * Holds names and classes of HTML element types. When an element with a
111      * particular tag name is created, the matching {@link java.lang.Class}
112      * is used to create the element object. For example, &lt;A&gt; matches
113      * {@link HTMLAnchorElementImpl}. This static table is shared across all
114      * HTML documents.
115      *
116      * @see #createElement
117      */

118     private static Hashtable JavaDoc _elementTypesHTML;
119
120
121     /**
122      * Signature used to locate constructor of HTML element classes. This
123      * static array is shared across all HTML documents.
124      *
125      * @see #createElement
126      */

127     private static final Class JavaDoc[] _elemClassSigHTML =
128                 new Class JavaDoc[] { HTMLDocumentImpl.class, String JavaDoc.class };
129
130
131     /**
132      */

133     public HTMLDocumentImpl()
134     {
135         super();
136         populateElementTypes();
137     }
138
139
140     public synchronized Element JavaDoc getDocumentElement()
141     {
142         Node JavaDoc html;
143         Node JavaDoc child;
144         Node JavaDoc next;
145
146         // The document element is the top-level HTML element of the HTML
147
// document. Only this element should exist at the top level.
148
// If the HTML element is found, all other elements that might
149
// precede it are placed inside the HTML element.
150
html = getFirstChild();
151         while ( html != null )
152         {
153             if ( html instanceof HTMLHtmlElement )
154             {
155                 // REVISIT: [Q] Why is this code even here? In fact, the
156
// original code is in error because it will
157
// try to move ALL nodes to be children of the
158
// HTML tag. This is not the intended behavior
159
// for comments and processing instructions
160
// outside the root element; it will throw a
161
// hierarchy request error exception for doctype
162
// nodes; *and* this code shouldn't even be
163
// needed because the parser should never build
164
// a document that contains more than a single
165
// root element, anyway! -Ac
166
/***
167                 synchronized ( html )
168                 {
169                     child = getFirstChild();
170                     while ( child != null && child != html )
171                     {
172                         next = child.getNextSibling();
173                         html.appendChild( child );
174                         child = next;
175                     }
176                 }
177                 /***/

178                 return (HTMLElement) html;
179             }
180             html = html.getNextSibling();
181         }
182
183         // HTML element must exist. Create a new element and dump the
184
// entire contents of the document into it in the same order as
185
// they appear now.
186
html = new HTMLHtmlElementImpl( this, "HTML" );
187         child = getFirstChild();
188         while ( child != null )
189         {
190             next = child.getNextSibling();
191             html.appendChild( child );
192             child = next;
193         }
194         appendChild( html );
195         return (HTMLElement) html;
196     }
197
198
199     /**
200      * Obtains the &lt;HEAD&gt; element in the document, creating one if does
201      * not exist before. The &lt;HEAD&gt; element is the first element in the
202      * &lt;HTML&gt; in the document. The &lt;HTML&gt; element is obtained by
203      * calling {@link #getDocumentElement}. If the element does not exist, one
204      * is created.
205      * <P>
206      * Called by {@link #getTitle}, {@link #setTitle}, {@link #getBody} and
207      * {@link #setBody} to assure the document has the &lt;HEAD&gt; element
208      * correctly placed.
209      *
210      * @return The &lt;HEAD&gt; element
211      */

212     public synchronized HTMLElement getHead()
213     {
214         Node JavaDoc head;
215         Node JavaDoc html;
216         Node JavaDoc child;
217         Node JavaDoc next;
218
219         // Call getDocumentElement() to get the HTML element that is also the
220
// top-level element in the document. Get the first element in the
221
// document that is called HEAD. Work with that.
222
html = getDocumentElement();
223         synchronized ( html )
224         {
225             head = html.getFirstChild();
226             while ( head != null && ! ( head instanceof HTMLHeadElement ) )
227                 head = head.getNextSibling();
228             // HEAD exists but might not be first element in HTML: make sure
229
// it is and return it.
230
if ( head != null )
231             {
232                 synchronized ( head )
233                 {
234                     child = html.getFirstChild();
235                     while ( child != null && child != head )
236                     {
237                         next = child.getNextSibling();
238                         head.insertBefore( child, head.getFirstChild() );
239                         child = next;
240                     }
241                 }
242                 return (HTMLElement) head;
243             }
244
245             // Head does not exist, create a new one, place it at the top of the
246
// HTML element and return it.
247
head = new HTMLHeadElementImpl( this, "HEAD" );
248             html.insertBefore( head, html.getFirstChild() );
249         }
250         return (HTMLElement) head;
251     }
252
253
254     public synchronized String JavaDoc getTitle()
255     {
256         HTMLElement head;
257         NodeList JavaDoc list;
258         Node JavaDoc title;
259
260         // Get the HEAD element and look for the TITLE element within.
261
// When found, make sure the TITLE is a direct child of HEAD,
262
// and return the title's text (the Text node contained within).
263
head = getHead();
264         title = head.getElementsByTagName( "TITLE" ).item( 0 );
265         list = head.getElementsByTagName( "TITLE" );
266         if ( list.getLength() > 0 ) {
267             title = list.item( 0 );
268             return ( (HTMLTitleElement) title ).getText();
269         }
270         // No TITLE found, return an empty string.
271
return "";
272     }
273
274
275     public synchronized void setTitle( String JavaDoc newTitle )
276     {
277         HTMLElement head;
278         NodeList JavaDoc list;
279         Node JavaDoc title;
280
281         // Get the HEAD element and look for the TITLE element within.
282
// When found, make sure the TITLE is a direct child of HEAD,
283
// and set the title's text (the Text node contained within).
284
head = getHead();
285         list = head.getElementsByTagName( "TITLE" );
286         if ( list.getLength() > 0 ) {
287             title = list.item( 0 );
288             if ( title.getParentNode() != head )
289                 head.appendChild( title );
290             ( (HTMLTitleElement) title ).setText( newTitle );
291         }
292         else
293         {
294             // No TITLE found, create a new element and place it at the end
295
// of the HEAD element.
296
title = new HTMLTitleElementImpl( this, "TITLE" );
297             ( (HTMLTitleElement) title ).setText( newTitle );
298             head.appendChild( title );
299         }
300     }
301
302
303     public synchronized HTMLElement getBody()
304     {
305         Node JavaDoc html;
306         Node JavaDoc head;
307         Node JavaDoc body;
308         Node JavaDoc child;
309         Node JavaDoc next;
310
311         // Call getDocumentElement() to get the HTML element that is also the
312
// top-level element in the document. Get the first element in the
313
// document that is called BODY. Work with that.
314
html = getDocumentElement();
315         head = getHead();
316         synchronized ( html )
317         {
318             body = head.getNextSibling();
319             while ( body != null && ! ( body instanceof HTMLBodyElement )
320                     && ! ( body instanceof HTMLFrameSetElement ) )
321                 body = body.getNextSibling();
322
323             // BODY/FRAMESET exists but might not be second element in HTML
324
// (after HEAD): make sure it is and return it.
325
if ( body != null )
326             {
327                 synchronized ( body )
328                 {
329                     child = head.getNextSibling();
330                     while ( child != null && child != body )
331                     {
332                         next = child.getNextSibling();
333                         body.insertBefore( child, body.getFirstChild() );
334                         child = next;
335                     }
336                 }
337                 return (HTMLElement) body;
338             }
339
340             // BODY does not exist, create a new one, place it in the HTML element
341
// right after the HEAD and return it.
342
body = new HTMLBodyElementImpl( this, "BODY" );
343             html.appendChild( body );
344         }
345         return (HTMLElement) body;
346     }
347
348
349     public synchronized void setBody( HTMLElement newBody )
350     {
351         Node JavaDoc html;
352         Node JavaDoc body;
353         Node JavaDoc head;
354         Node JavaDoc child;
355         NodeList JavaDoc list;
356
357         synchronized ( newBody )
358         {
359             // Call getDocumentElement() to get the HTML element that is also the
360
// top-level element in the document. Get the first element in the
361
// document that is called BODY. Work with that.
362
html = getDocumentElement();
363             head = getHead();
364             synchronized ( html )
365             {
366                 list = this.getElementsByTagName( "BODY" );
367                 if ( list.getLength() > 0 ) {
368                     // BODY exists but might not follow HEAD in HTML. If not,
369
// make it so and replce it. Start with the HEAD and make
370
// sure the BODY is the first element after the HEAD.
371
body = list.item( 0 );
372                     synchronized ( body )
373                     {
374                         child = head;
375                         while ( child != null )
376                         {
377                             if ( child instanceof Element JavaDoc )
378                             {
379                                 if ( child != body )
380                                     html.insertBefore( newBody, child );
381                                 else
382                                     html.replaceChild( newBody, body );
383                                 return;
384                             }
385                             child = child.getNextSibling();
386                         }
387                         html.appendChild( newBody );
388                     }
389                     return;
390                 }
391                 // BODY does not exist, place it in the HTML element
392
// right after the HEAD.
393
html.appendChild( newBody );
394             }
395         }
396     }
397
398
399     public synchronized Element JavaDoc getElementById( String JavaDoc elementId )
400     {
401         return getElementById( elementId, this );
402     }
403
404
405     public NodeList JavaDoc getElementsByName( String JavaDoc elementName )
406     {
407         return new NameNodeListImpl( this, elementName );
408     }
409
410
411     public final NodeList JavaDoc getElementsByTagName( String JavaDoc tagName )
412     {
413         return super.getElementsByTagName( tagName.toUpperCase(Locale.ENGLISH) );
414     }
415
416
417     public final NodeList JavaDoc getElementsByTagNameNS( String JavaDoc namespaceURI,
418                                                   String JavaDoc localName )
419     {
420         if ( namespaceURI != null && namespaceURI.length() > 0 )
421             return super.getElementsByTagNameNS( namespaceURI, localName.toUpperCase(Locale.ENGLISH) );
422         else
423             return super.getElementsByTagName( localName.toUpperCase(Locale.ENGLISH) );
424     }
425
426
427     /**
428      * Xerces-specific constructor. "localName" is passed in, so we don't need
429      * to create a new String for it.
430      *
431      * @param namespaceURI The namespace URI of the element to
432      * create.
433      * @param qualifiedName The qualified name of the element type to
434      * instantiate.
435      * @param localName The local name of the element to instantiate.
436      * @return Element A new Element object with the following attributes:
437      * @throws DOMException INVALID_CHARACTER_ERR: Raised if the specified
438      * name contains an invalid character.
439      */

440     public Element JavaDoc createElementNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName,
441                                    String JavaDoc localpart)
442         throws DOMException JavaDoc
443     {
444         return createElementNS(namespaceURI, qualifiedName);
445     }
446
447     public Element JavaDoc createElementNS( String JavaDoc namespaceURI, String JavaDoc qualifiedName )
448     {
449         if ( namespaceURI == null || namespaceURI.length() == 0 )
450             return createElement( qualifiedName );
451         else {
452             return super.createElementNS( namespaceURI, qualifiedName );
453         }
454     }
455
456
457     public Element JavaDoc createElement( String JavaDoc tagName )
458         throws DOMException JavaDoc
459     {
460         Class JavaDoc elemClass;
461         Constructor JavaDoc cnst;
462
463         // First, make sure tag name is all upper case, next get the associated
464
// element class. If no class is found, generate a generic HTML element.
465
// Do so also if an unexpected exception occurs.
466
tagName = tagName.toUpperCase(Locale.ENGLISH);
467         elemClass = (Class JavaDoc) _elementTypesHTML.get( tagName );
468         if ( elemClass != null )
469         {
470             // Get the constructor for the element. The signature specifies an
471
// owner document and a tag name. Use the constructor to instantiate
472
// a new object and return it.
473
try
474             {
475                 cnst = elemClass.getConstructor( _elemClassSigHTML );
476                 return (Element JavaDoc) cnst.newInstance( new Object JavaDoc[] { this, tagName } );
477             }
478             catch ( Exception JavaDoc except )
479             {
480                 Throwable JavaDoc thrw;
481
482                 if ( except instanceof java.lang.reflect.InvocationTargetException JavaDoc )
483                     thrw = ( (java.lang.reflect.InvocationTargetException JavaDoc) except ).getTargetException();
484                 else
485                     thrw = except;
486 // System.out.println( "Exception " + thrw.getClass().getName() );
487
// System.out.println( thrw.getMessage() );
488

489                 throw new IllegalStateException JavaDoc( "HTM15 Tag '" + tagName + "' associated with an Element class that failed to construct.\n" + tagName);
490             }
491         }
492         return new HTMLElementImpl( this, tagName );
493     }
494
495
496     /**
497      * Creates an Attribute having this Document as its OwnerDoc.
498      * Overrides {@link DocumentImpl#createAttribute} and returns
499      * and attribute whose name is lower case.
500      *
501      * @param name The name of the attribute
502      * @return An attribute whose name is all lower case
503      * @throws DOMException(INVALID_NAME_ERR) if the attribute name
504      * is not acceptable
505      */

506     public Attr JavaDoc createAttribute( String JavaDoc name )
507         throws DOMException JavaDoc
508     {
509         return super.createAttribute( name.toLowerCase(Locale.ENGLISH) );
510     }
511
512
513     public String JavaDoc getReferrer()
514     {
515         // Information not available on server side.
516
return null;
517     }
518
519
520     public String JavaDoc getDomain()
521     {
522         // Information not available on server side.
523
return null;
524     }
525
526
527     public String JavaDoc getURL()
528     {
529         // Information not available on server side.
530
return null;
531     }
532
533
534     public String JavaDoc getCookie()
535     {
536         // Information not available on server side.
537
return null;
538     }
539
540
541     public void setCookie( String JavaDoc cookie )
542     {
543         // Information not available on server side.
544
}
545
546
547     public HTMLCollection getImages()
548     {
549         // For more information see HTMLCollection#collectionMatch
550
if ( _images == null )
551             _images = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.IMAGE );
552         return _images;
553     }
554
555
556     public HTMLCollection getApplets()
557     {
558         // For more information see HTMLCollection#collectionMatch
559
if ( _applets == null )
560             _applets = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.APPLET );
561         return _applets;
562     }
563
564
565     public HTMLCollection getLinks()
566     {
567         // For more information see HTMLCollection#collectionMatch
568
if ( _links == null )
569             _links = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.LINK );
570         return _links;
571     }
572
573
574     public HTMLCollection getForms()
575     {
576         // For more information see HTMLCollection#collectionMatch
577
if ( _forms == null )
578             _forms = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.FORM );
579         return _forms;
580     }
581
582
583     public HTMLCollection getAnchors()
584     {
585         // For more information see HTMLCollection#collectionMatch
586
if ( _anchors == null )
587             _anchors = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.ANCHOR );
588         return _anchors;
589     }
590
591
592     public void open()
593     {
594         // When called an in-memory is prepared. The document tree is still
595
// accessible the old way, until this writer is closed.
596
if ( _writer == null )
597             _writer = new StringWriter JavaDoc();
598     }
599
600
601     public void close()
602     {
603         // ! NOT IMPLEMENTED, REQUIRES PARSER !
604
if ( _writer != null )
605         {
606             _writer = null;
607         }
608     }
609
610
611     public void write( String JavaDoc text )
612     {
613         // Write a string into the in-memory writer.
614
if ( _writer != null )
615             _writer.write( text );
616     }
617
618
619     public void writeln( String JavaDoc text )
620     {
621         // Write a line into the in-memory writer.
622
if ( _writer != null )
623             _writer.write( text + "\n" );
624     }
625
626
627     public Node JavaDoc cloneNode( boolean deep )
628     {
629         HTMLDocumentImpl clone;
630         NodeImpl node;
631
632         clone = new HTMLDocumentImpl();
633         if ( deep ) {
634             node = (NodeImpl) getFirstChild();
635             while ( node != null ) {
636                 clone.appendChild( clone.importNode( node, true ) );
637                 node = (NodeImpl) node.getNextSibling();
638             }
639         }
640         return clone;
641     }
642
643
644     /**
645      * Recursive method retreives an element by its <code>id</code> attribute.
646      * Called by {@link #getElementById(String)}.
647      *
648      * @param elementId The <code>id</code> value to look for
649      * @return The node in which to look for
650      */

651     private Element JavaDoc getElementById( String JavaDoc elementId, Node JavaDoc node )
652     {
653         Node JavaDoc child;
654         Element JavaDoc result;
655
656         child = node.getFirstChild();
657         while ( child != null )
658         {
659             if ( child instanceof Element JavaDoc )
660             {
661                 if ( elementId.equals( ( (Element JavaDoc) child ).getAttribute( "id" ) ) )
662                     return (Element JavaDoc) child;
663                 result = getElementById( elementId, child );
664                 if ( result != null )
665                     return result;
666             }
667             child = child.getNextSibling();
668         }
669         return null;
670     }
671
672
673     /**
674      * Called by the constructor to populate the element types list (see {@link
675      * #_elementTypesHTML}). Will be called multiple times but populate the list
676      * only the first time. Replacement for static constructor.
677      */

678     private synchronized static void populateElementTypes()
679     {
680         // This class looks like it is due to some strange
681
// (read: inconsistent) JVM bugs.
682
// Initially all this code was placed in the static constructor,
683
// but that caused some early JVMs (1.1) to go mad, and if a
684
// class could not be found (as happened during development),
685
// the JVM would die.
686
// Bertrand Delacretaz <bdelacretaz@worldcom.ch> pointed out
687
// several configurations where HTMLAnchorElementImpl.class
688
// failed, forcing me to revert back to Class.forName().
689

690         if ( _elementTypesHTML != null )
691             return;
692         _elementTypesHTML = new Hashtable JavaDoc( 63 );
693         populateElementType( "A", "HTMLAnchorElementImpl" );
694         populateElementType( "APPLET", "HTMLAppletElementImpl" );
695         populateElementType( "AREA", "HTMLAreaElementImpl" );
696         populateElementType( "BASE", "HTMLBaseElementImpl" );
697         populateElementType( "BASEFONT", "HTMLBaseFontElementImpl" );
698         populateElementType( "BLOCKQUOTE", "HTMLQuoteElementImpl" );
699         populateElementType( "BODY", "HTMLBodyElementImpl" );
700         populateElementType( "BR", "HTMLBRElementImpl" );
701         populateElementType( "BUTTON", "HTMLButtonElementImpl" );
702         populateElementType( "DEL", "HTMLModElementImpl" );
703         populateElementType( "DIR", "HTMLDirectoryElementImpl" );
704         populateElementType( "DIV", "HTMLDivElementImpl" );
705         populateElementType( "DL", "HTMLDListElementImpl" );
706         populateElementType( "FIELDSET", "HTMLFieldSetElementImpl" );
707         populateElementType( "FONT", "HTMLFontElementImpl" );
708         populateElementType( "FORM", "HTMLFormElementImpl" );
709         populateElementType( "FRAME","HTMLFrameElementImpl" );
710         populateElementType( "FRAMESET", "HTMLFrameSetElementImpl" );
711         populateElementType( "HEAD", "HTMLHeadElementImpl" );
712         populateElementType( "H1", "HTMLHeadingElementImpl" );
713         populateElementType( "H2", "HTMLHeadingElementImpl" );
714         populateElementType( "H3", "HTMLHeadingElementImpl" );
715         populateElementType( "H4", "HTMLHeadingElementImpl" );
716         populateElementType( "H5", "HTMLHeadingElementImpl" );
717         populateElementType( "H6", "HTMLHeadingElementImpl" );
718         populateElementType( "HR", "HTMLHRElementImpl" );
719         populateElementType( "HTML", "HTMLHtmlElementImpl" );
720         populateElementType( "IFRAME", "HTMLIFrameElementImpl" );
721         populateElementType( "IMG", "HTMLImageElementImpl" );
722         populateElementType( "INPUT", "HTMLInputElementImpl" );
723         populateElementType( "INS", "HTMLModElementImpl" );
724         populateElementType( "ISINDEX", "HTMLIsIndexElementImpl" );
725         populateElementType( "LABEL", "HTMLLabelElementImpl" );
726         populateElementType( "LEGEND", "HTMLLegendElementImpl" );
727         populateElementType( "LI", "HTMLLIElementImpl" );
728         populateElementType( "LINK", "HTMLLinkElementImpl" );
729         populateElementType( "MAP", "HTMLMapElementImpl" );
730         populateElementType( "MENU", "HTMLMenuElementImpl" );
731         populateElementType( "META", "HTMLMetaElementImpl" );
732         populateElementType( "OBJECT", "HTMLObjectElementImpl" );
733         populateElementType( "OL", "HTMLOListElementImpl" );
734         populateElementType( "OPTGROUP", "HTMLOptGroupElementImpl" );
735         populateElementType( "OPTION", "HTMLOptionElementImpl" );
736         populateElementType( "P", "HTMLParagraphElementImpl" );
737         populateElementType( "PARAM", "HTMLParamElementImpl" );
738         populateElementType( "PRE", "HTMLPreElementImpl" );
739         populateElementType( "Q", "HTMLQuoteElementImpl" );
740         populateElementType( "SCRIPT", "HTMLScriptElementImpl" );
741         populateElementType( "SELECT", "HTMLSelectElementImpl" );
742         populateElementType( "STYLE", "HTMLStyleElementImpl" );
743         populateElementType( "TABLE", "HTMLTableElementImpl" );
744         populateElementType( "CAPTION", "HTMLTableCaptionElementImpl" );
745         populateElementType( "TD", "HTMLTableCellElementImpl" );
746         populateElementType( "TH", "HTMLTableCellElementImpl" );
747         populateElementType( "COL", "HTMLTableColElementImpl" );
748         populateElementType( "COLGROUP", "HTMLTableColElementImpl" );
749         populateElementType( "TR", "HTMLTableRowElementImpl" );
750         populateElementType( "TBODY", "HTMLTableSectionElementImpl" );
751         populateElementType( "THEAD", "HTMLTableSectionElementImpl" );
752         populateElementType( "TFOOT", "HTMLTableSectionElementImpl" );
753         populateElementType( "TEXTAREA", "HTMLTextAreaElementImpl" );
754         populateElementType( "TITLE", "HTMLTitleElementImpl" );
755         populateElementType( "UL", "HTMLUListElementImpl" );
756     }
757
758
759     private static void populateElementType( String JavaDoc tagName, String JavaDoc className )
760     {
761         try {
762             _elementTypesHTML.put( tagName,
763                 ObjectFactory.findProviderClass("org.apache.html.dom." + className,
764                     HTMLDocumentImpl.class.getClassLoader(), true) );
765         } catch ( Exception JavaDoc except ) {
766             new RuntimeException JavaDoc( "HTM019 OpenXML Error: Could not find or execute class " + className + " implementing HTML element " + tagName
767                                   + "\n" + className + "\t" + tagName);
768         }
769     }
770
771
772 }
773
774
Popular Tags