1 16 package org.apache.html.dom; 17 18 import org.w3c.dom.Node ; 19 import org.w3c.dom.html.HTMLCollection; 20 import org.w3c.dom.html.HTMLElement; 21 import org.w3c.dom.html.HTMLTableCaptionElement; 22 import org.w3c.dom.html.HTMLTableElement; 23 import org.w3c.dom.html.HTMLTableRowElement; 24 import org.w3c.dom.html.HTMLTableSectionElement; 25 26 33 public class HTMLTableElementImpl 34 extends HTMLElementImpl 35 implements HTMLTableElement 36 { 37 38 private static final long serialVersionUID = 3977585787963651891L; 39 40 public synchronized HTMLTableCaptionElement getCaption() 41 { 42 Node child; 43 44 child = getFirstChild(); 45 while ( child != null ) 46 { 47 if ( child instanceof HTMLTableCaptionElement && 48 child.getNodeName().equals( "CAPTION" ) ) 49 return (HTMLTableCaptionElement) child; 50 child = child.getNextSibling(); 51 } 52 return null; 53 } 54 55 56 public synchronized void setCaption( HTMLTableCaptionElement caption ) 57 { 58 if ( caption != null && ! caption.getTagName().equals( "CAPTION" ) ) 59 throw new IllegalArgumentException ( "HTM016 Argument 'caption' is not an element of type <CAPTION>." ); 60 deleteCaption(); 61 if ( caption != null ) 62 appendChild( caption ); 63 } 64 65 66 public synchronized HTMLElement createCaption() 67 { 68 HTMLElement section; 69 70 section = getCaption(); 71 if ( section != null ) 72 return section; 73 section = new HTMLTableCaptionElementImpl( (HTMLDocumentImpl) getOwnerDocument(), "CAPTION" ); 74 appendChild( section ); 75 return section; 76 } 77 78 79 public synchronized void deleteCaption() 80 { 81 Node old; 82 83 old = getCaption(); 84 if ( old != null ) 85 removeChild ( old ); 86 } 87 88 public synchronized HTMLTableSectionElement getTHead() 89 { 90 Node child; 91 92 child = getFirstChild(); 93 while ( child != null ) 94 { 95 if ( child instanceof HTMLTableSectionElement && 96 child.getNodeName().equals( "THEAD" ) ) 97 return (HTMLTableSectionElement) child; 98 child = child.getNextSibling(); 99 } 100 return null; 101 } 102 103 104 public synchronized void setTHead( HTMLTableSectionElement tHead ) 105 { 106 if ( tHead != null && ! tHead.getTagName().equals( "THEAD" ) ) 107 throw new IllegalArgumentException ( "HTM017 Argument 'tHead' is not an element of type <THEAD>." ); 108 deleteTHead(); 109 if ( tHead != null ) 110 appendChild( tHead ); 111 } 112 113 114 public synchronized HTMLElement createTHead() 115 { 116 HTMLElement section; 117 118 section = getTHead(); 119 if ( section != null ) 120 return section; 121 section = new HTMLTableSectionElementImpl( (HTMLDocumentImpl) getOwnerDocument(), "THEAD" ); 122 appendChild( section ); 123 return section; 124 } 125 126 127 public synchronized void deleteTHead() 128 { 129 Node old; 130 131 old = getTHead(); 132 if ( old != null ) 133 removeChild ( old ); 134 } 135 136 public synchronized HTMLTableSectionElement getTFoot() 137 { 138 Node child; 139 140 child = getFirstChild(); 141 while ( child != null ) 142 { 143 if ( child instanceof HTMLTableSectionElement && 144 child.getNodeName().equals( "TFOOT" ) ) 145 return (HTMLTableSectionElement) child; 146 child = child.getNextSibling(); 147 } 148 return null; 149 } 150 151 152 public synchronized void setTFoot( HTMLTableSectionElement tFoot ) 153 { 154 if ( tFoot != null && ! tFoot.getTagName().equals( "TFOOT" ) ) 155 throw new IllegalArgumentException ( "HTM018 Argument 'tFoot' is not an element of type <TFOOT>." ); 156 deleteTFoot(); 157 if ( tFoot != null ) 158 appendChild( tFoot ); 159 } 160 161 162 public synchronized HTMLElement createTFoot() 163 { 164 HTMLElement section; 165 166 section = getTFoot(); 167 if ( section != null ) 168 return section; 169 section = new HTMLTableSectionElementImpl( (HTMLDocumentImpl) getOwnerDocument(), "TFOOT" ); 170 appendChild( section ); 171 return section; 172 } 173 174 175 public synchronized void deleteTFoot() 176 { 177 Node old; 178 179 old = getTFoot(); 180 if ( old != null ) 181 removeChild ( old ); 182 } 183 184 public HTMLCollection getRows() 185 { 186 if ( _rows == null ) 187 _rows = new HTMLCollectionImpl( this, HTMLCollectionImpl.ROW ); 188 return _rows; 189 } 190 191 192 public HTMLCollection getTBodies() 193 { 194 if ( _bodies == null ) 195 _bodies = new HTMLCollectionImpl( this, HTMLCollectionImpl.TBODY ); 196 return _bodies; 197 } 198 199 200 public String getAlign() 201 { 202 return capitalize( getAttribute( "align" ) ); 203 } 204 205 206 public void setAlign( String align ) 207 { 208 setAttribute( "align", align ); 209 } 210 211 212 public String getBgColor() 213 { 214 return getAttribute( "bgcolor" ); 215 } 216 217 218 public void setBgColor( String bgColor ) 219 { 220 setAttribute( "bgcolor", bgColor ); 221 } 222 223 224 public String getBorder() 225 { 226 return getAttribute( "border" ); 227 } 228 229 230 public void setBorder( String border ) 231 { 232 setAttribute( "border", border ); 233 } 234 235 236 public String getCellPadding() 237 { 238 return getAttribute( "cellpadding" ); 239 } 240 241 242 public void setCellPadding( String cellPadding ) 243 { 244 setAttribute( "cellpadding", cellPadding ); 245 } 246 247 248 public String getCellSpacing() 249 { 250 return getAttribute( "cellspacing" ); 251 } 252 253 254 public void setCellSpacing( String cellSpacing ) 255 { 256 setAttribute( "cellspacing", cellSpacing ); 257 } 258 259 260 public String getFrame() 261 { 262 return capitalize( getAttribute( "frame" ) ); 263 } 264 265 266 public void setFrame( String frame ) 267 { 268 setAttribute( "frame", frame ); 269 } 270 271 272 public String getRules() 273 { 274 return capitalize( getAttribute( "rules" ) ); 275 } 276 277 278 public void setRules( String rules ) 279 { 280 setAttribute( "rules", rules ); 281 } 282 283 284 public String getSummary() 285 { 286 return getAttribute( "summary" ); 287 } 288 289 290 public void setSummary( String summary ) 291 { 292 setAttribute( "summary", summary ); 293 } 294 295 296 public String getWidth() 297 { 298 return getAttribute( "width" ); 299 } 300 301 302 public void setWidth( String width ) 303 { 304 setAttribute( "width", width ); 305 } 306 307 308 public HTMLElement insertRow( int index ) 309 { 310 HTMLTableRowElementImpl newRow; 311 312 newRow = new HTMLTableRowElementImpl( (HTMLDocumentImpl) getOwnerDocument(), "TR" ); 313 insertRowX( index, newRow ); 315 return newRow; 316 } 317 318 319 void insertRowX( int index, HTMLTableRowElementImpl newRow ) 320 { 321 Node child; 322 Node lastSection = null; 323 324 child = getFirstChild(); 325 while ( child != null ) 326 { 327 if ( child instanceof HTMLTableRowElement ) 328 { 329 if ( index == 0 ) 330 { 331 insertBefore( newRow, child ); 332 return; 333 } 334 } 335 else 336 if ( child instanceof HTMLTableSectionElementImpl ) 337 { 338 lastSection = child; 339 index = ( (HTMLTableSectionElementImpl) child ).insertRowX( index, newRow ); 340 if ( index < 0 ) 341 return; 342 } 343 child = child.getNextSibling(); 344 } 345 if ( lastSection != null ) 346 lastSection.appendChild( newRow ); 347 else 348 appendChild( newRow ); 349 } 350 351 352 public synchronized void deleteRow( int index ) 353 { 354 Node child; 355 356 child = getFirstChild(); 357 while ( child != null ) 358 { 359 if ( child instanceof HTMLTableRowElement ) 360 { 361 if ( index == 0 ) 362 { 363 removeChild ( child ); 364 return; 365 } 366 --index; 367 } 368 else 369 if ( child instanceof HTMLTableSectionElementImpl ) 370 { 371 index = ( (HTMLTableSectionElementImpl) child ).deleteRowX( index ); 372 if ( index < 0 ) 373 return; 374 } 375 child = child.getNextSibling(); 376 } 377 } 378 379 383 public Node cloneNode( boolean deep ) { 384 HTMLTableElementImpl clonedNode = (HTMLTableElementImpl)super.cloneNode( deep ); 385 clonedNode._rows = null; 386 clonedNode._bodies = null; 387 return clonedNode; 388 } 389 390 395 public HTMLTableElementImpl( HTMLDocumentImpl owner, String name ) 396 { 397 super( owner, name ); 398 } 399 400 401 private HTMLCollectionImpl _rows; 402 403 404 private HTMLCollectionImpl _bodies; 405 406 407 } 408 409 | Popular Tags |