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