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