1 16 package org.apache.html.dom; 17 18 import org.w3c.dom.Node ; 19 import org.w3c.dom.NodeList ; 20 import org.w3c.dom.html.HTMLCollection; 21 import org.w3c.dom.html.HTMLElement; 22 import org.w3c.dom.html.HTMLTableCellElement; 23 import org.w3c.dom.html.HTMLTableElement; 24 import org.w3c.dom.html.HTMLTableRowElement; 25 import org.w3c.dom.html.HTMLTableSectionElement; 26 27 34 public class HTMLTableRowElementImpl 35 extends HTMLElementImpl 36 implements HTMLTableRowElement 37 { 38 39 private static final long serialVersionUID = 3545231444772468278L; 40 41 public int getRowIndex() 42 { 43 Node parent; 44 45 parent = getParentNode(); 46 if ( parent instanceof HTMLTableSectionElement ) 47 parent = parent.getParentNode(); 48 if ( parent instanceof HTMLTableElement ) 49 return getRowIndex( parent );; 50 return -1; 51 } 52 53 54 public void setRowIndex( int rowIndex ) 55 { 56 Node parent; 57 58 parent = getParentNode(); 59 if ( parent instanceof HTMLTableSectionElement ) 60 parent = parent.getParentNode(); 61 if ( parent instanceof HTMLTableElement ) 62 ( (HTMLTableElementImpl) parent ).insertRowX( rowIndex, this ); 63 } 64 65 66 public int getSectionRowIndex() 67 { 68 Node parent; 69 70 parent = getParentNode(); 71 if ( parent instanceof HTMLTableSectionElement ) 72 return getRowIndex( parent ); 73 else 74 return -1; 75 } 76 77 78 public void setSectionRowIndex( int sectionRowIndex ) 79 { 80 Node parent; 81 82 parent = getParentNode(); 83 if ( parent instanceof HTMLTableSectionElement ) 84 ( (HTMLTableSectionElementImpl) parent ).insertRowX( sectionRowIndex, this ); 85 } 86 87 88 int getRowIndex( Node parent ) 89 { 90 NodeList rows; 91 int i; 92 93 rows = ( (HTMLElement) parent ).getElementsByTagName( "TR" ); 97 for ( i = 0 ; i < rows.getLength() ; ++i ) 98 if ( rows.item( i ) == this ) 99 return i; 100 return -1; 101 } 102 103 104 public HTMLCollection getCells() 105 { 106 if ( _cells == null ) 107 _cells = new HTMLCollectionImpl( this, HTMLCollectionImpl.CELL ); 108 return _cells; 109 } 110 111 112 public void setCells( HTMLCollection cells ) 113 { 114 Node child; 115 int i; 116 117 child = getFirstChild(); 118 while ( child != null ) 119 { 120 removeChild( child ); 121 child = child.getNextSibling(); 122 } 123 i = 0; 124 child = cells.item( i ); 125 while ( child != null ) 126 { 127 appendChild ( child ); 128 ++i; 129 child = cells.item( i ); 130 } 131 } 132 133 134 public HTMLElement insertCell( int index ) 135 { 136 Node child; 137 HTMLElement newCell; 138 139 newCell = new HTMLTableCellElementImpl( (HTMLDocumentImpl) getOwnerDocument(), "TD" ); 140 child = getFirstChild(); 141 while ( child != null ) 142 { 143 if ( child instanceof HTMLTableCellElement ) 144 { 145 if ( index == 0 ) 146 { 147 insertBefore( newCell, child ); 148 return newCell; 149 } 150 --index; 151 } 152 child = child.getNextSibling(); 153 } 154 appendChild( newCell ); 155 return newCell; 156 } 157 158 159 public void deleteCell( int index ) 160 { 161 Node child; 162 163 child = getFirstChild(); 164 while ( child != null ) 165 { 166 if ( child instanceof HTMLTableCellElement ) 167 { 168 if ( index == 0 ) 169 { 170 removeChild ( child ); 171 return; 172 } 173 --index; 174 } 175 child = child.getNextSibling(); 176 } 177 } 178 179 180 public String getAlign() 181 { 182 return capitalize( getAttribute( "align" ) ); 183 } 184 185 186 public void setAlign( String align ) 187 { 188 setAttribute( "align", align ); 189 } 190 191 192 public String getBgColor() 193 { 194 return getAttribute( "bgcolor" ); 195 } 196 197 198 public void setBgColor( String bgColor ) 199 { 200 setAttribute( "bgcolor", bgColor ); 201 } 202 203 204 public String getCh() 205 { 206 String ch; 207 208 ch = getAttribute( "char" ); 210 if ( ch != null && ch.length() > 1 ) 211 ch = ch.substring( 0, 1 ); 212 return ch; 213 } 214 215 216 public void setCh( String ch ) 217 { 218 if ( ch != null && ch.length() > 1 ) 220 ch = ch.substring( 0, 1 ); 221 setAttribute( "char", ch ); 222 } 223 224 225 public String getChOff() 226 { 227 return getAttribute( "charoff" ); 228 } 229 230 231 public void setChOff( String chOff ) 232 { 233 setAttribute( "charoff", chOff ); 234 } 235 236 237 public String getVAlign() 238 { 239 return capitalize( getAttribute( "valign" ) ); 240 } 241 242 243 public void setVAlign( String vAlign ) 244 { 245 setAttribute( "valign", vAlign ); 246 } 247 248 252 public Node cloneNode( boolean deep ) { 253 HTMLTableRowElementImpl clonedNode = (HTMLTableRowElementImpl)super.cloneNode( deep ); 254 clonedNode._cells = null; 255 return clonedNode; 256 } 257 258 263 public HTMLTableRowElementImpl( HTMLDocumentImpl owner, String name ) 264 { 265 super( owner, name ); 266 } 267 268 269 HTMLCollection _cells; 270 271 272 } 273 274 | Popular Tags |