1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.html.internal.dom;
  58. import java.io.StringWriter;
  59. import java.lang.reflect.Constructor;
  60. import java.util.Hashtable;
  61. import java.util.Locale;
  62. import com.sun.org.apache.xerces.internal.dom.DocumentImpl;
  63. import com.sun.org.apache.xerces.internal.dom.NodeImpl;
  64. import org.w3c.dom.Attr;
  65. import org.w3c.dom.DOMException;
  66. import org.w3c.dom.Element;
  67. import org.w3c.dom.Node;
  68. import org.w3c.dom.NodeList;
  69. import org.w3c.dom.html.HTMLBodyElement;
  70. import org.w3c.dom.html.HTMLCollection;
  71. import org.w3c.dom.html.HTMLDocument;
  72. import org.w3c.dom.html.HTMLElement;
  73. import org.w3c.dom.html.HTMLFrameSetElement;
  74. import org.w3c.dom.html.HTMLHeadElement;
  75. import org.w3c.dom.html.HTMLHtmlElement;
  76. import org.w3c.dom.html.HTMLTitleElement;
  77. /**
  78. * Implements an HTML document. Provides access to the top level element in the
  79. * document, its body and title.
  80. * <P>
  81. * Several methods create new nodes of all basic types (comment, text, element,
  82. * etc.). These methods create new nodes but do not place them in the document
  83. * tree. The nodes may be placed in the document tree using {@link
  84. * org.w3c.dom.Node#appendChild} or {@link org.w3c.dom.Node#insertBefore}, or
  85. * they may be placed in some other document tree.
  86. * <P>
  87. * Note: <FRAMESET> documents are not supported at the moment, neither
  88. * are direct document writing ({@link #open}, {@link #write}) and HTTP attribute
  89. * methods ({@link #getURL}, {@link #getCookie}).
  90. *
  91. *
  92. * @version $Revision: 1.18 $ $Date: 2004/02/17 07:14:48 $
  93. * @author <a href="mailto:arkin@exoffice.com">Assaf Arkin</a>
  94. * @see org.w3c.dom.html.HTMLDocument
  95. */
  96. public class HTMLDocumentImpl
  97. extends DocumentImpl
  98. implements HTMLDocument
  99. {
  100. /**
  101. * Holds {@link HTMLCollectionImpl} object with live collection of all
  102. * anchors in document. This reference is on demand only once.
  103. */
  104. private HTMLCollectionImpl _anchors;
  105. /**
  106. * Holds {@link HTMLCollectionImpl} object with live collection of all
  107. * forms in document. This reference is on demand only once.
  108. */
  109. private HTMLCollectionImpl _forms;
  110. /**
  111. * Holds {@link HTMLCollectionImpl} object with live collection of all
  112. * images in document. This reference is on demand only once.
  113. */
  114. private HTMLCollectionImpl _images;
  115. /**
  116. * Holds {@link HTMLCollectionImpl} object with live collection of all
  117. * links in document. This reference is on demand only once.
  118. */
  119. private HTMLCollectionImpl _links;
  120. /**
  121. * Holds {@link HTMLCollectionImpl} object with live collection of all
  122. * applets in document. This reference is on demand only once.
  123. */
  124. private HTMLCollectionImpl _applets;
  125. /**
  126. * Holds string writer used by direct manipulation operation ({@link #open}.
  127. * {@link #write}, etc) to write new contents into the document and parse
  128. * that text into a document tree.
  129. */
  130. private StringWriter _writer;
  131. /**
  132. * Holds names and classes of HTML element types. When an element with a
  133. * particular tag name is created, the matching {@link java.lang.Class}
  134. * is used to create the element object. For example, <A> matches
  135. * {@link HTMLAnchorElementImpl}. This static table is shared across all
  136. * HTML documents.
  137. *
  138. * @see #createElement
  139. */
  140. private static Hashtable _elementTypesHTML;
  141. /**
  142. * Signature used to locate constructor of HTML element classes. This
  143. * static array is shared across all HTML documents.
  144. *
  145. * @see #createElement
  146. */
  147. private static final Class[] _elemClassSigHTML =
  148. new Class[] { HTMLDocumentImpl.class, String.class };
  149. /**
  150. */
  151. public HTMLDocumentImpl()
  152. {
  153. super();
  154. populateElementTypes();
  155. }
  156. public synchronized Element getDocumentElement()
  157. {
  158. Node html;
  159. Node child;
  160. Node next;
  161. // The document element is the top-level HTML element of the HTML
  162. // document. Only this element should exist at the top level.
  163. // If the HTML element is found, all other elements that might
  164. // precede it are placed inside the HTML element.
  165. html = getFirstChild();
  166. while ( html != null )
  167. {
  168. if ( html instanceof HTMLHtmlElement )
  169. {
  170. // REVISIT: [Q] Why is this code even here? In fact, the
  171. // original code is in error because it will
  172. // try to move ALL nodes to be children of the
  173. // HTML tag. This is not the intended behavior
  174. // for comments and processing instructions
  175. // outside the root element; it will throw a
  176. // hierarchy request error exception for doctype
  177. // nodes; *and* this code shouldn't even be
  178. // needed because the parser should never build
  179. // a document that contains more than a single
  180. // root element, anyway! -Ac
  181. /***
  182. synchronized ( html )
  183. {
  184. child = getFirstChild();
  185. while ( child != null && child != html )
  186. {
  187. next = child.getNextSibling();
  188. html.appendChild( child );
  189. child = next;
  190. }
  191. }
  192. /***/
  193. return (HTMLElement) html;
  194. }
  195. html = html.getNextSibling();
  196. }
  197. // HTML element must exist. Create a new element and dump the
  198. // entire contents of the document into it in the same order as
  199. // they appear now.
  200. html = new HTMLHtmlElementImpl( this, "HTML" );
  201. child = getFirstChild();
  202. while ( child != null )
  203. {
  204. next = child.getNextSibling();
  205. html.appendChild( child );
  206. child = next;
  207. }
  208. appendChild( html );
  209. return (HTMLElement) html;
  210. }
  211. /**
  212. * Obtains the <HEAD> element in the document, creating one if does
  213. * not exist before. The <HEAD> element is the first element in the
  214. * <HTML> in the document. The <HTML> element is obtained by
  215. * calling {@link #getDocumentElement}. If the element does not exist, one
  216. * is created.
  217. * <P>
  218. * Called by {@link #getTitle}, {@link #setTitle}, {@link #getBody} and
  219. * {@link #setBody} to assure the document has the <HEAD> element
  220. * correctly placed.
  221. *
  222. * @return The <HEAD> element
  223. */
  224. public synchronized HTMLElement getHead()
  225. {
  226. Node head;
  227. Node html;
  228. Node child;
  229. Node next;
  230. // Call getDocumentElement() to get the HTML element that is also the
  231. // top-level element in the document. Get the first element in the
  232. // document that is called HEAD. Work with that.
  233. html = getDocumentElement();
  234. synchronized ( html )
  235. {
  236. head = html.getFirstChild();
  237. while ( head != null && ! ( head instanceof HTMLHeadElement ) )
  238. head = head.getNextSibling();
  239. // HEAD exists but might not be first element in HTML: make sure
  240. // it is and return it.
  241. if ( head != null )
  242. {
  243. synchronized ( head )
  244. {
  245. child = html.getFirstChild();
  246. while ( child != null && child != head )
  247. {
  248. next = child.getNextSibling();
  249. head.insertBefore( child, head.getFirstChild() );
  250. child = next;
  251. }
  252. }
  253. return (HTMLElement) head;
  254. }
  255. // Head does not exist, create a new one, place it at the top of the
  256. // HTML element and return it.
  257. head = new HTMLHeadElementImpl( this, "HEAD" );
  258. html.insertBefore( head, html.getFirstChild() );
  259. }
  260. return (HTMLElement) head;
  261. }
  262. public synchronized String getTitle()
  263. {
  264. HTMLElement head;
  265. NodeList list;
  266. Node title;
  267. // Get the HEAD element and look for the TITLE element within.
  268. // When found, make sure the TITLE is a direct child of HEAD,
  269. // and return the title's text (the Text node contained within).
  270. head = getHead();
  271. title = head.getElementsByTagName( "TITLE" ).item( 0 );
  272. list = head.getElementsByTagName( "TITLE" );
  273. if ( list.getLength() > 0 ) {
  274. title = list.item( 0 );
  275. return ( (HTMLTitleElement) title ).getText();
  276. }
  277. // No TITLE found, return an empty string.
  278. return "";
  279. }
  280. public synchronized void setTitle( String newTitle )
  281. {
  282. HTMLElement head;
  283. NodeList list;
  284. Node title;
  285. // Get the HEAD element and look for the TITLE element within.
  286. // When found, make sure the TITLE is a direct child of HEAD,
  287. // and set the title's text (the Text node contained within).
  288. head = getHead();
  289. list = head.getElementsByTagName( "TITLE" );
  290. if ( list.getLength() > 0 ) {
  291. title = list.item( 0 );
  292. if ( title.getParentNode() != head )
  293. head.appendChild( title );
  294. ( (HTMLTitleElement) title ).setText( newTitle );
  295. }
  296. else
  297. {
  298. // No TITLE found, create a new element and place it at the end
  299. // of the HEAD element.
  300. title = new HTMLTitleElementImpl( this, "TITLE" );
  301. ( (HTMLTitleElement) title ).setText( newTitle );
  302. head.appendChild( title );
  303. }
  304. }
  305. public synchronized HTMLElement getBody()
  306. {
  307. Node html;
  308. Node head;
  309. Node body;
  310. Node child;
  311. Node next;
  312. // Call getDocumentElement() to get the HTML element that is also the
  313. // top-level element in the document. Get the first element in the
  314. // document that is called BODY. Work with that.
  315. html = getDocumentElement();
  316. head = getHead();
  317. synchronized ( html )
  318. {
  319. body = head.getNextSibling();
  320. while ( body != null && ! ( body instanceof HTMLBodyElement )
  321. && ! ( body instanceof HTMLFrameSetElement ) )
  322. body = body.getNextSibling();
  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. // BODY does not exist, create a new one, place it in the HTML element
  340. // right after the HEAD and return it.
  341. body = new HTMLBodyElementImpl( this, "BODY" );
  342. html.appendChild( body );
  343. }
  344. return (HTMLElement) body;
  345. }
  346. public synchronized void setBody( HTMLElement newBody )
  347. {
  348. Node html;
  349. Node body;
  350. Node head;
  351. Node child;
  352. NodeList list;
  353. synchronized ( newBody )
  354. {
  355. // Call getDocumentElement() to get the HTML element that is also the
  356. // top-level element in the document. Get the first element in the
  357. // document that is called BODY. Work with that.
  358. html = getDocumentElement();
  359. head = getHead();
  360. synchronized ( html )
  361. {
  362. list = this.getElementsByTagName( "BODY" );
  363. if ( list.getLength() > 0 ) {
  364. // BODY exists but might not follow HEAD in HTML. If not,
  365. // make it so and replce it. Start with the HEAD and make
  366. // sure the BODY is the first element after the HEAD.
  367. body = list.item( 0 );
  368. synchronized ( body )
  369. {
  370. child = head;
  371. while ( child != null )
  372. {
  373. if ( child instanceof Element )
  374. {
  375. if ( child != body )
  376. html.insertBefore( newBody, child );
  377. else
  378. html.replaceChild( newBody, body );
  379. return;
  380. }
  381. child = child.getNextSibling();
  382. }
  383. html.appendChild( newBody );
  384. }
  385. return;
  386. }
  387. // BODY does not exist, place it in the HTML element
  388. // right after the HEAD.
  389. html.appendChild( newBody );
  390. }
  391. }
  392. }
  393. public synchronized Element getElementById( String elementId )
  394. {
  395. return getElementById( elementId, this );
  396. }
  397. public NodeList getElementsByName( String elementName )
  398. {
  399. return new NameNodeListImpl( this, elementName );
  400. }
  401. public final NodeList getElementsByTagName( String tagName )
  402. {
  403. return super.getElementsByTagName( tagName.toUpperCase(Locale.ENGLISH) );
  404. }
  405. public final NodeList getElementsByTagNameNS( String namespaceURI,
  406. String localName )
  407. {
  408. if ( namespaceURI != null && namespaceURI.length() > 0 )
  409. return super.getElementsByTagNameNS( namespaceURI, localName.toUpperCase(Locale.ENGLISH) );
  410. else
  411. return super.getElementsByTagName( localName.toUpperCase(Locale.ENGLISH) );
  412. }
  413. /**
  414. * Xerces-specific constructor. "localName" is passed in, so we don't need
  415. * to create a new String for it.
  416. *
  417. * @param namespaceURI The namespace URI of the element to
  418. * create.
  419. * @param qualifiedName The qualified name of the element type to
  420. * instantiate.
  421. * @param localName The local name of the element to instantiate.
  422. * @return Element A new Element object with the following attributes:
  423. * @throws DOMException INVALID_CHARACTER_ERR: Raised if the specified
  424. * name contains an invalid character.
  425. */
  426. public Element createElementNS(String namespaceURI, String qualifiedName,
  427. String localpart)
  428. throws DOMException
  429. {
  430. return createElementNS(namespaceURI, qualifiedName);
  431. }
  432. public Element createElementNS( String namespaceURI, String qualifiedName )
  433. {
  434. if ( namespaceURI == null || namespaceURI.length() == 0 )
  435. return createElement( qualifiedName );
  436. else {
  437. return super.createElementNS( namespaceURI, qualifiedName );
  438. }
  439. }
  440. public Element createElement( String tagName )
  441. throws DOMException
  442. {
  443. Class elemClass;
  444. Constructor cnst;
  445. // First, make sure tag name is all upper case, next get the associated
  446. // element class. If no class is found, generate a generic HTML element.
  447. // Do so also if an unexpected exception occurs.
  448. tagName = tagName.toUpperCase(Locale.ENGLISH);
  449. elemClass = (Class) _elementTypesHTML.get( tagName );
  450. if ( elemClass != null )
  451. {
  452. // Get the constructor for the element. The signature specifies an
  453. // owner document and a tag name. Use the constructor to instantiate
  454. // a new object and return it.
  455. try
  456. {
  457. cnst = elemClass.getConstructor( _elemClassSigHTML );
  458. return (Element) cnst.newInstance( new Object[] { this, tagName } );
  459. }
  460. catch ( Exception except )
  461. {
  462. Throwable thrw;
  463. if ( except instanceof java.lang.reflect.InvocationTargetException )
  464. thrw = ( (java.lang.reflect.InvocationTargetException) except ).getTargetException();
  465. else
  466. thrw = except;
  467. // System.out.println( "Exception " + thrw.getClass().getName() );
  468. // System.out.println( thrw.getMessage() );
  469. throw new IllegalStateException( "HTM15 Tag '" + tagName + "' associated with an Element class that failed to construct.\n" + tagName);
  470. }
  471. }
  472. return new HTMLElementImpl( this, tagName );
  473. }
  474. /**
  475. * Creates an Attribute having this Document as its OwnerDoc.
  476. * Overrides {@link DocumentImpl#createAttribute} and returns
  477. * and attribute whose name is lower case.
  478. *
  479. * @param name The name of the attribute
  480. * @return An attribute whose name is all lower case
  481. * @throws DOMException(INVALID_NAME_ERR) if the attribute name
  482. * is not acceptable
  483. */
  484. public Attr createAttribute( String name )
  485. throws DOMException
  486. {
  487. return super.createAttribute( name.toLowerCase(Locale.ENGLISH) );
  488. }
  489. public String getReferrer()
  490. {
  491. // Information not available on server side.
  492. return null;
  493. }
  494. public String getDomain()
  495. {
  496. // Information not available on server side.
  497. return null;
  498. }
  499. public String getURL()
  500. {
  501. // Information not available on server side.
  502. return null;
  503. }
  504. public String getCookie()
  505. {
  506. // Information not available on server side.
  507. return null;
  508. }
  509. public void setCookie( String cookie )
  510. {
  511. // Information not available on server side.
  512. }
  513. public HTMLCollection getImages()
  514. {
  515. // For more information see HTMLCollection#collectionMatch
  516. if ( _images == null )
  517. _images = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.IMAGE );
  518. return _images;
  519. }
  520. public HTMLCollection getApplets()
  521. {
  522. // For more information see HTMLCollection#collectionMatch
  523. if ( _applets == null )
  524. _applets = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.APPLET );
  525. return _applets;
  526. }
  527. public HTMLCollection getLinks()
  528. {
  529. // For more information see HTMLCollection#collectionMatch
  530. if ( _links == null )
  531. _links = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.LINK );
  532. return _links;
  533. }
  534. public HTMLCollection getForms()
  535. {
  536. // For more information see HTMLCollection#collectionMatch
  537. if ( _forms == null )
  538. _forms = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.FORM );
  539. return _forms;
  540. }
  541. public HTMLCollection getAnchors()
  542. {
  543. // For more information see HTMLCollection#collectionMatch
  544. if ( _anchors == null )
  545. _anchors = new HTMLCollectionImpl( getBody(), HTMLCollectionImpl.ANCHOR );
  546. return _anchors;
  547. }
  548. public void open()
  549. {
  550. // When called an in-memory is prepared. The document tree is still
  551. // accessible the old way, until this writer is closed.
  552. if ( _writer == null )
  553. _writer = new StringWriter();
  554. }
  555. public void close()
  556. {
  557. // ! NOT IMPLEMENTED, REQUIRES PARSER !
  558. if ( _writer != null )
  559. {
  560. _writer = null;
  561. }
  562. }
  563. public void write( String text )
  564. {
  565. // Write a string into the in-memory writer.
  566. if ( _writer != null )
  567. _writer.write( text );
  568. }
  569. public void writeln( String text )
  570. {
  571. // Write a line into the in-memory writer.
  572. if ( _writer != null )
  573. _writer.write( text + "\n" );
  574. }
  575. public Node cloneNode( boolean deep )
  576. {
  577. HTMLDocumentImpl clone;
  578. NodeImpl node;
  579. clone = new HTMLDocumentImpl();
  580. if ( deep ) {
  581. node = (NodeImpl) getFirstChild();
  582. while ( node != null ) {
  583. clone.appendChild( clone.importNode( node, true ) );
  584. node = (NodeImpl) node.getNextSibling();
  585. }
  586. }
  587. return clone;
  588. }
  589. /**
  590. * Recursive method retreives an element by its <code>id</code> attribute.
  591. * Called by {@link #getElementById(String)}.
  592. *
  593. * @param elementId The <code>id</code> value to look for
  594. * @return The node in which to look for
  595. */
  596. private Element getElementById( String elementId, Node node )
  597. {
  598. Node child;
  599. Element result;
  600. child = node.getFirstChild();
  601. while ( child != null )
  602. {
  603. if ( child instanceof Element )
  604. {
  605. if ( elementId.equals( ( (Element) child ).getAttribute( "id" ) ) )
  606. return (Element) child;
  607. result = getElementById( elementId, child );
  608. if ( result != null )
  609. return result;
  610. }
  611. child = child.getNextSibling();
  612. }
  613. return null;
  614. }
  615. /**
  616. * Called by the constructor to populate the element types list (see {@link
  617. * #_elementTypesHTML}). Will be called multiple times but populate the list
  618. * only the first time. Replacement for static constructor.
  619. */
  620. private synchronized static void populateElementTypes()
  621. {
  622. // This class looks like it is due to some strange
  623. // (read: inconsistent) JVM bugs.
  624. // Initially all this code was placed in the static constructor,
  625. // but that caused some early JVMs (1.1) to go mad, and if a
  626. // class could not be found (as happened during development),
  627. // the JVM would die.
  628. // Bertrand Delacretaz <bdelacretaz@worldcom.ch> pointed out
  629. // several configurations where HTMLAnchorElementImpl.class
  630. // failed, forcing me to revert back to Class.forName().
  631. if ( _elementTypesHTML != null )
  632. return;
  633. _elementTypesHTML = new Hashtable( 63 );
  634. populateElementType( "A", "HTMLAnchorElementImpl" );
  635. populateElementType( "APPLET", "HTMLAppletElementImpl" );
  636. populateElementType( "AREA", "HTMLAreaElementImpl" );
  637. populateElementType( "BASE", "HTMLBaseElementImpl" );
  638. populateElementType( "BASEFONT", "HTMLBaseFontElementImpl" );
  639. populateElementType( "BLOCKQUOTE", "HTMLQuoteElementImpl" );
  640. populateElementType( "BODY", "HTMLBodyElementImpl" );
  641. populateElementType( "BR", "HTMLBRElementImpl" );
  642. populateElementType( "BUTTON", "HTMLButtonElementImpl" );
  643. populateElementType( "DEL", "HTMLModElementImpl" );
  644. populateElementType( "DIR", "HTMLDirectoryElementImpl" );
  645. populateElementType( "DIV", "HTMLDivElementImpl" );
  646. populateElementType( "DL", "HTMLDListElementImpl" );
  647. populateElementType( "FIELDSET", "HTMLFieldSetElementImpl" );
  648. populateElementType( "FONT", "HTMLFontElementImpl" );
  649. populateElementType( "FORM", "HTMLFormElementImpl" );
  650. populateElementType( "FRAME","HTMLFrameElementImpl" );
  651. populateElementType( "FRAMESET", "HTMLFrameSetElementImpl" );
  652. populateElementType( "HEAD", "HTMLHeadElementImpl" );
  653. populateElementType( "H1", "HTMLHeadingElementImpl" );
  654. populateElementType( "H2", "HTMLHeadingElementImpl" );
  655. populateElementType( "H3", "HTMLHeadingElementImpl" );
  656. populateElementType( "H4", "HTMLHeadingElementImpl" );
  657. populateElementType( "H5", "HTMLHeadingElementImpl" );
  658. populateElementType( "H6", "HTMLHeadingElementImpl" );
  659. populateElementType( "HR", "HTMLHRElementImpl" );
  660. populateElementType( "HTML", "HTMLHtmlElementImpl" );
  661. populateElementType( "IFRAME", "HTMLIFrameElementImpl" );
  662. populateElementType( "IMG", "HTMLImageElementImpl" );
  663. populateElementType( "INPUT", "HTMLInputElementImpl" );
  664. populateElementType( "INS", "HTMLModElementImpl" );
  665. populateElementType( "ISINDEX", "HTMLIsIndexElementImpl" );
  666. populateElementType( "LABEL", "HTMLLabelElementImpl" );
  667. populateElementType( "LEGEND", "HTMLLegendElementImpl" );
  668. populateElementType( "LI", "HTMLLIElementImpl" );
  669. populateElementType( "LINK", "HTMLLinkElementImpl" );
  670. populateElementType( "MAP", "HTMLMapElementImpl" );
  671. populateElementType( "MENU", "HTMLMenuElementImpl" );
  672. populateElementType( "META", "HTMLMetaElementImpl" );
  673. populateElementType( "OBJECT", "HTMLObjectElementImpl" );
  674. populateElementType( "OL", "HTMLOListElementImpl" );
  675. populateElementType( "OPTGROUP", "HTMLOptGroupElementImpl" );
  676. populateElementType( "OPTION", "HTMLOptionElementImpl" );
  677. populateElementType( "P", "HTMLParagraphElementImpl" );
  678. populateElementType( "PARAM", "HTMLParamElementImpl" );
  679. populateElementType( "PRE", "HTMLPreElementImpl" );
  680. populateElementType( "Q", "HTMLQuoteElementImpl" );
  681. populateElementType( "SCRIPT", "HTMLScriptElementImpl" );
  682. populateElementType( "SELECT", "HTMLSelectElementImpl" );
  683. populateElementType( "STYLE", "HTMLStyleElementImpl" );
  684. populateElementType( "TABLE", "HTMLTableElementImpl" );
  685. populateElementType( "CAPTION", "HTMLTableCaptionElementImpl" );
  686. populateElementType( "TD", "HTMLTableCellElementImpl" );
  687. populateElementType( "TH", "HTMLTableCellElementImpl" );
  688. populateElementType( "COL", "HTMLTableColElementImpl" );
  689. populateElementType( "COLGROUP", "HTMLTableColElementImpl" );
  690. populateElementType( "TR", "HTMLTableRowElementImpl" );
  691. populateElementType( "TBODY", "HTMLTableSectionElementImpl" );
  692. populateElementType( "THEAD", "HTMLTableSectionElementImpl" );
  693. populateElementType( "TFOOT", "HTMLTableSectionElementImpl" );
  694. populateElementType( "TEXTAREA", "HTMLTextAreaElementImpl" );
  695. populateElementType( "TITLE", "HTMLTitleElementImpl" );
  696. populateElementType( "UL", "HTMLUListElementImpl" );
  697. }
  698. private static void populateElementType( String tagName, String className )
  699. {
  700. try {
  701. _elementTypesHTML.put( tagName,
  702. ObjectFactory.findProviderClass("com.sun.org.apache.html.internal.dom." + className,
  703. HTMLDocumentImpl.class.getClassLoader(), true) );
  704. } catch ( Exception except ) {
  705. new RuntimeException( "HTM019 OpenXML Error: Could not find or execute class " + className + " implementing HTML element " + tagName
  706. + "\n" + className + "\t" + tagName);
  707. }
  708. }
  709. }