KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom > html > HTMLTableElementImpl


1 /**
2  * org/ozone-db/xml/dom/html/HTMLTableElementImpl.java
3  *
4  * The contents of this file are subject to the OpenXML Public
5  * License Version 1.0; you may not use this file except in compliance
6  * with the License. You may obtain a copy of the License at
7  * http://www.openxml.org/license.html
8  *
9  * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
10  * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
11  * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
12  * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
13  * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
14  * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
15  *
16  * The Initial Developer of this code under the License is Assaf Arkin.
17  * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
18  * All Rights Reserved.
19  */

20
21
22 package org.ozoneDB.xml.dom.html;
23
24
25 import org.ozoneDB.xml.dom.ElementImpl;
26 import org.w3c.dom.Node JavaDoc;
27 import org.w3c.dom.html.*;
28
29
30 /**
31  * @version $Revision: 1.2 $ $Date: 2003/11/20 23:18:42 $
32  * @author <a HREF="mailto:arkin@trendline.co.il">Assaf Arkin</a>
33  * @see org.w3c.dom.html.HTMLAnchorElement
34  * @see ElementImpl
35  */

36 public final class HTMLTableElementImpl extends HTMLElementImpl implements HTMLTableElement {
37
38
39     public synchronized HTMLTableCaptionElement getCaption() {
40         Node JavaDoc 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 JavaDoc( "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 JavaDoc old;
79
80         old = getCaption();
81         if (old != null) {
82             removeChild( old );
83         }
84     }
85
86
87     public synchronized HTMLTableSectionElement getTHead() {
88         Node JavaDoc 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 JavaDoc( "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 JavaDoc old;
127
128         old = getTHead();
129         if (old != null) {
130             removeChild( old );
131         }
132     }
133
134
135     public synchronized HTMLTableSectionElement getTFoot() {
136         Node JavaDoc 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 JavaDoc( "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 JavaDoc 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 JavaDoc getAlign() {
200         return capitalize( getAttribute( "align" ) );
201     }
202
203
204     public void setAlign( String JavaDoc align ) {
205         setAttribute( "align", align );
206     }
207
208
209     public String JavaDoc getBgColor() {
210         return getAttribute( "bgcolor" );
211     }
212
213
214     public void setBgColor( String JavaDoc bgColor ) {
215         setAttribute( "bgcolor", bgColor );
216     }
217
218
219     public String JavaDoc getBorder() {
220         return getAttribute( "border" );
221     }
222
223
224     public void setBorder( String JavaDoc border ) {
225         setAttribute( "border", border );
226     }
227
228
229     public String JavaDoc getCellPadding() {
230         return getAttribute( "cellpadding" );
231     }
232
233
234     public void setCellPadding( String JavaDoc cellPadding ) {
235         setAttribute( "cellpadding", cellPadding );
236     }
237
238
239     public String JavaDoc getCellSpacing() {
240         return getAttribute( "cellspacing" );
241     }
242
243
244     public void setCellSpacing( String JavaDoc cellSpacing ) {
245         setAttribute( "cellspacing", cellSpacing );
246     }
247
248
249     public String JavaDoc getFrame() {
250         return capitalize( getAttribute( "frame" ) );
251     }
252
253
254     public void setFrame( String JavaDoc frame ) {
255         setAttribute( "frame", frame );
256     }
257
258
259     public String JavaDoc getRules() {
260         return capitalize( getAttribute( "rules" ) );
261     }
262
263
264     public void setRules( String JavaDoc rules ) {
265         setAttribute( "rules", rules );
266     }
267
268
269     public String JavaDoc getSummary() {
270         return getAttribute( "summary" );
271     }
272
273
274     public void setSummary( String JavaDoc summary ) {
275         setAttribute( "summary", summary );
276     }
277
278
279     public String JavaDoc getWidth() {
280         return getAttribute( "width" );
281     }
282
283
284     public void setWidth( String JavaDoc 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 JavaDoc child;
301         Node JavaDoc 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 JavaDoc 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     /**
353      * Constructor requires owner document.
354      *
355      * @param owner The owner HTML document
356      */

357     public HTMLTableElementImpl( HTMLDocumentImpl owner, String JavaDoc name ) {
358         super( owner, "TABLE" );
359     }
360
361
362     private HTMLCollectionImpl _rows;
363
364
365     private HTMLCollectionImpl _bodies;
366
367
368 }
369
Popular Tags