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