KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > html > internal > dom > HTMLTableElementImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57 package com.sun.org.apache.html.internal.dom;
58
59
60 import org.w3c.dom.Node JavaDoc;
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 /**
70  * @version $Revision: 1.10 $ $Date: 2003/07/05 18:38:14 $
71  * @author <a HREF="mailto:arkin@exoffice.com">Assaf Arkin</a>
72  * @see org.w3c.dom.html.HTMLAnchorElement
73  * @see com.sun.org.apache.xerces.internal.dom.ElementImpl
74  */

75 public class HTMLTableElementImpl
76     extends HTMLElementImpl
77     implements HTMLTableElement
78 {
79     
80     
81     public synchronized HTMLTableCaptionElement getCaption()
82     {
83         Node JavaDoc 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 JavaDoc( "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 JavaDoc old;
123         
124         old = getCaption();
125         if ( old != null )
126             removeChild ( old );
127     }
128     
129     public synchronized HTMLTableSectionElement getTHead()
130     {
131         Node JavaDoc 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 JavaDoc( "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 JavaDoc old;
171         
172         old = getTHead();
173         if ( old != null )
174             removeChild ( old );
175     }
176     
177     public synchronized HTMLTableSectionElement getTFoot()
178     {
179         Node JavaDoc 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 JavaDoc( "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 JavaDoc 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 JavaDoc getAlign()
242     {
243         return capitalize( getAttribute( "align" ) );
244     }
245     
246     
247     public void setAlign( String JavaDoc align )
248     {
249         setAttribute( "align", align );
250     }
251   
252     
253     public String JavaDoc getBgColor()
254     {
255         return getAttribute( "bgcolor" );
256     }
257     
258     
259     public void setBgColor( String JavaDoc bgColor )
260     {
261         setAttribute( "bgcolor", bgColor );
262     }
263   
264   
265     public String JavaDoc getBorder()
266     {
267         return getAttribute( "border" );
268     }
269     
270     
271     public void setBorder( String JavaDoc border )
272     {
273         setAttribute( "border", border );
274     }
275
276     
277     public String JavaDoc getCellPadding()
278     {
279         return getAttribute( "cellpadding" );
280     }
281     
282     
283     public void setCellPadding( String JavaDoc cellPadding )
284     {
285         setAttribute( "cellpadding", cellPadding );
286     }
287     
288     
289     public String JavaDoc getCellSpacing()
290     {
291         return getAttribute( "cellspacing" );
292     }
293     
294     
295     public void setCellSpacing( String JavaDoc cellSpacing )
296     {
297         setAttribute( "cellspacing", cellSpacing );
298     }
299     
300     
301     public String JavaDoc getFrame()
302     {
303         return capitalize( getAttribute( "frame" ) );
304     }
305     
306     
307     public void setFrame( String JavaDoc frame )
308     {
309         setAttribute( "frame", frame );
310     }
311     
312     
313     public String JavaDoc getRules()
314     {
315         return capitalize( getAttribute( "rules" ) );
316     }
317     
318     
319     public void setRules( String JavaDoc rules )
320     {
321         setAttribute( "rules", rules );
322     }
323     
324     
325     public String JavaDoc getSummary()
326     {
327         return getAttribute( "summary" );
328     }
329     
330     
331     public void setSummary( String JavaDoc summary )
332     {
333         setAttribute( "summary", summary );
334     }
335
336   
337       public String JavaDoc getWidth()
338     {
339         return getAttribute( "width" );
340     }
341     
342     
343     public void setWidth( String JavaDoc 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         //newRow.insertCell( 0 );
355
insertRowX( index, newRow );
356         return newRow;
357     }
358         
359         
360     void insertRowX( int index, HTMLTableRowElementImpl newRow )
361     {
362         Node JavaDoc child;
363         Node JavaDoc 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 JavaDoc 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     /**
422      * Constructor requires owner document.
423      *
424      * @param owner The owner HTML document
425      */

426     public HTMLTableElementImpl( HTMLDocumentImpl owner, String JavaDoc 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