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 org.w3c.dom.Node;
  59. import org.w3c.dom.NodeList;
  60. import org.w3c.dom.html.HTMLCollection;
  61. import org.w3c.dom.html.HTMLElement;
  62. import org.w3c.dom.html.HTMLTableCellElement;
  63. import org.w3c.dom.html.HTMLTableElement;
  64. import org.w3c.dom.html.HTMLTableRowElement;
  65. import org.w3c.dom.html.HTMLTableSectionElement;
  66. /**
  67. * @version $Revision: 1.6 $ $Date: 2003/05/08 20:13:09 $
  68. * @author <a href="mailto:arkin@exoffice.com">Assaf Arkin</a>
  69. * @see org.w3c.dom.html.HTMLTableRowElement
  70. * @see com.sun.org.apache.xerces.internal.dom.ElementImpl
  71. */
  72. public class HTMLTableRowElementImpl
  73. extends HTMLElementImpl
  74. implements HTMLTableRowElement
  75. {
  76. public int getRowIndex()
  77. {
  78. Node parent;
  79. parent = getParentNode();
  80. if ( parent instanceof HTMLTableSectionElement )
  81. parent = parent.getParentNode();
  82. if ( parent instanceof HTMLTableElement )
  83. return getRowIndex( parent );;
  84. return -1;
  85. }
  86. public void setRowIndex( int rowIndex )
  87. {
  88. Node parent;
  89. parent = getParentNode();
  90. if ( parent instanceof HTMLTableSectionElement )
  91. parent = parent.getParentNode();
  92. if ( parent instanceof HTMLTableElement )
  93. ( (HTMLTableElementImpl) parent ).insertRowX( rowIndex, this );
  94. }
  95. public int getSectionRowIndex()
  96. {
  97. Node parent;
  98. parent = getParentNode();
  99. if ( parent instanceof HTMLTableSectionElement )
  100. return getRowIndex( parent );
  101. else
  102. return -1;
  103. }
  104. public void setSectionRowIndex( int sectionRowIndex )
  105. {
  106. Node parent;
  107. parent = getParentNode();
  108. if ( parent instanceof HTMLTableSectionElement )
  109. ( (HTMLTableSectionElementImpl) parent ).insertRowX( sectionRowIndex, this );
  110. }
  111. int getRowIndex( Node parent )
  112. {
  113. NodeList rows;
  114. int i;
  115. // Use getElementsByTagName() which creates a snapshot of all the
  116. // TR elements under the TABLE/section. Access to the returned NodeList
  117. // is very fast and the snapshot solves many synchronization problems.
  118. rows = ( (HTMLElement) parent ).getElementsByTagName( "TR" );
  119. for ( i = 0 ; i < rows.getLength() ; ++i )
  120. if ( rows.item( i ) == this )
  121. return i;
  122. return -1;
  123. }
  124. public HTMLCollection getCells()
  125. {
  126. if ( _cells == null )
  127. _cells = new HTMLCollectionImpl( this, HTMLCollectionImpl.CELL );
  128. return _cells;
  129. }
  130. public void setCells( HTMLCollection cells )
  131. {
  132. Node child;
  133. int i;
  134. child = getFirstChild();
  135. while ( child != null )
  136. {
  137. removeChild( child );
  138. child = child.getNextSibling();
  139. }
  140. i = 0;
  141. child = cells.item( i );
  142. while ( child != null )
  143. {
  144. appendChild ( child );
  145. ++i;
  146. child = cells.item( i );
  147. }
  148. }
  149. public HTMLElement insertCell( int index )
  150. {
  151. Node child;
  152. HTMLElement newCell;
  153. newCell = new HTMLTableCellElementImpl( (HTMLDocumentImpl) getOwnerDocument(), "TD" );
  154. child = getFirstChild();
  155. while ( child != null )
  156. {
  157. if ( child instanceof HTMLTableCellElement )
  158. {
  159. if ( index == 0 )
  160. {
  161. insertBefore( newCell, child );
  162. return newCell;
  163. }
  164. --index;
  165. }
  166. child = child.getNextSibling();
  167. }
  168. appendChild( newCell );
  169. return newCell;
  170. }
  171. public void deleteCell( int index )
  172. {
  173. Node child;
  174. child = getFirstChild();
  175. while ( child != null )
  176. {
  177. if ( child instanceof HTMLTableCellElement )
  178. {
  179. if ( index == 0 )
  180. {
  181. removeChild ( child );
  182. return;
  183. }
  184. --index;
  185. }
  186. child = child.getNextSibling();
  187. }
  188. }
  189. public String getAlign()
  190. {
  191. return capitalize( getAttribute( "align" ) );
  192. }
  193. public void setAlign( String align )
  194. {
  195. setAttribute( "align", align );
  196. }
  197. public String getBgColor()
  198. {
  199. return getAttribute( "bgcolor" );
  200. }
  201. public void setBgColor( String bgColor )
  202. {
  203. setAttribute( "bgcolor", bgColor );
  204. }
  205. public String getCh()
  206. {
  207. String ch;
  208. // Make sure that the access key is a single character.
  209. ch = getAttribute( "char" );
  210. if ( ch != null && ch.length() > 1 )
  211. ch = ch.substring( 0, 1 );
  212. return ch;
  213. }
  214. public void setCh( String ch )
  215. {
  216. // Make sure that the access key is a single character.
  217. if ( ch != null && ch.length() > 1 )
  218. ch = ch.substring( 0, 1 );
  219. setAttribute( "char", ch );
  220. }
  221. public String getChOff()
  222. {
  223. return getAttribute( "charoff" );
  224. }
  225. public void setChOff( String chOff )
  226. {
  227. setAttribute( "charoff", chOff );
  228. }
  229. public String getVAlign()
  230. {
  231. return capitalize( getAttribute( "valign" ) );
  232. }
  233. public void setVAlign( String vAlign )
  234. {
  235. setAttribute( "valign", vAlign );
  236. }
  237. /**
  238. * Constructor requires owner document.
  239. *
  240. * @param owner The owner HTML document
  241. */
  242. public HTMLTableRowElementImpl( HTMLDocumentImpl owner, String name )
  243. {
  244. super( owner, name );
  245. }
  246. HTMLCollection _cells;
  247. }