001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057: package org.apache.html.dom;
058:
059: import org.w3c.dom.*;
060: import org.w3c.dom.html.*;
061:
062: /**
063: * @version $Revision: 1.7 $ $Date: 2001/01/30 23:58:05 $
064: * @author <a href="mailto:arkin@exoffice.com">Assaf Arkin</a>
065: * @see org.w3c.dom.html.HTMLAnchorElement
066: * @see ElementImpl
067: */
068: public class HTMLTableElementImpl extends HTMLElementImpl implements
069: HTMLTableElement {
070:
071: public synchronized HTMLTableCaptionElement getCaption() {
072: Node child;
073:
074: child = getFirstChild();
075: while (child != null) {
076: if (child instanceof HTMLTableCaptionElement
077: && child.getNodeName().equals("CAPTION"))
078: return (HTMLTableCaptionElement) child;
079: child = child.getNextSibling();
080: }
081: return null;
082: }
083:
084: public synchronized void setCaption(HTMLTableCaptionElement caption) {
085: if (caption != null && !caption.getTagName().equals("CAPTION"))
086: throw new IllegalArgumentException(
087: "HTM016 Argument 'caption' is not an element of type <CAPTION>.");
088: deleteCaption();
089: if (caption != null)
090: appendChild(caption);
091: }
092:
093: public synchronized HTMLElement createCaption() {
094: HTMLElement section;
095:
096: section = getCaption();
097: if (section != null)
098: return section;
099: section = new HTMLTableCaptionElementImpl(
100: (HTMLDocumentImpl) getOwnerDocument(), "CAPTION");
101: appendChild(section);
102: return section;
103: }
104:
105: public synchronized void deleteCaption() {
106: Node old;
107:
108: old = getCaption();
109: if (old != null)
110: removeChild(old);
111: }
112:
113: public synchronized HTMLTableSectionElement getTHead() {
114: Node child;
115:
116: child = getFirstChild();
117: while (child != null) {
118: if (child instanceof HTMLTableSectionElement
119: && child.getNodeName().equals("THEAD"))
120: return (HTMLTableSectionElement) child;
121: child = child.getNextSibling();
122: }
123: return null;
124: }
125:
126: public synchronized void setTHead(HTMLTableSectionElement tHead) {
127: if (tHead != null && !tHead.getTagName().equals("THEAD"))
128: throw new IllegalArgumentException(
129: "HTM017 Argument 'tHead' is not an element of type <THEAD>.");
130: deleteTHead();
131: if (tHead != null)
132: appendChild(tHead);
133: }
134:
135: public synchronized HTMLElement createTHead() {
136: HTMLElement section;
137:
138: section = getTHead();
139: if (section != null)
140: return section;
141: section = new HTMLTableSectionElementImpl(
142: (HTMLDocumentImpl) getOwnerDocument(), "THEAD");
143: appendChild(section);
144: return section;
145: }
146:
147: public synchronized void deleteTHead() {
148: Node old;
149:
150: old = getTHead();
151: if (old != null)
152: removeChild(old);
153: }
154:
155: public synchronized HTMLTableSectionElement getTFoot() {
156: Node child;
157:
158: child = getFirstChild();
159: while (child != null) {
160: if (child instanceof HTMLTableSectionElement
161: && child.getNodeName().equals("TFOOT"))
162: return (HTMLTableSectionElement) child;
163: child = child.getNextSibling();
164: }
165: return null;
166: }
167:
168: public synchronized void setTFoot(HTMLTableSectionElement tFoot) {
169: if (tFoot != null && !tFoot.getTagName().equals("TFOOT"))
170: throw new IllegalArgumentException(
171: "HTM018 Argument 'tFoot' is not an element of type <TFOOT>.");
172: deleteTFoot();
173: if (tFoot != null)
174: appendChild(tFoot);
175: }
176:
177: public synchronized HTMLElement createTFoot() {
178: HTMLElement section;
179:
180: section = getTFoot();
181: if (section != null)
182: return section;
183: section = new HTMLTableSectionElementImpl(
184: (HTMLDocumentImpl) getOwnerDocument(), "TFOOT");
185: appendChild(section);
186: return section;
187: }
188:
189: public synchronized void deleteTFoot() {
190: Node old;
191:
192: old = getTFoot();
193: if (old != null)
194: removeChild(old);
195: }
196:
197: public HTMLCollection getRows() {
198: if (_rows == null)
199: _rows = new HTMLCollectionImpl(this , HTMLCollectionImpl.ROW);
200: return _rows;
201: }
202:
203: public HTMLCollection getTBodies() {
204: if (_bodies == null)
205: _bodies = new HTMLCollectionImpl(this ,
206: HTMLCollectionImpl.TBODY);
207: return _bodies;
208: }
209:
210: public String getAlign() {
211: return capitalize(getAttribute("align"));
212: }
213:
214: public void setAlign(String align) {
215: setAttribute("align", align);
216: }
217:
218: public String getBgColor() {
219: return getAttribute("bgcolor");
220: }
221:
222: public void setBgColor(String bgColor) {
223: setAttribute("bgcolor", bgColor);
224: }
225:
226: public String getBorder() {
227: return getAttribute("border");
228: }
229:
230: public void setBorder(String border) {
231: setAttribute("border", border);
232: }
233:
234: public String getCellPadding() {
235: return getAttribute("cellpadding");
236: }
237:
238: public void setCellPadding(String cellPadding) {
239: setAttribute("cellpadding", cellPadding);
240: }
241:
242: public String getCellSpacing() {
243: return getAttribute("cellspacing");
244: }
245:
246: public void setCellSpacing(String cellSpacing) {
247: setAttribute("cellspacing", cellSpacing);
248: }
249:
250: public String getFrame() {
251: return capitalize(getAttribute("frame"));
252: }
253:
254: public void setFrame(String frame) {
255: setAttribute("frame", frame);
256: }
257:
258: public String getRules() {
259: return capitalize(getAttribute("rules"));
260: }
261:
262: public void setRules(String rules) {
263: setAttribute("rules", rules);
264: }
265:
266: public String getSummary() {
267: return getAttribute("summary");
268: }
269:
270: public void setSummary(String summary) {
271: setAttribute("summary", summary);
272: }
273:
274: public String getWidth() {
275: return getAttribute("width");
276: }
277:
278: public void setWidth(String width) {
279: setAttribute("width", width);
280: }
281:
282: public HTMLElement insertRow(int index) {
283: HTMLTableRowElementImpl newRow;
284:
285: newRow = new HTMLTableRowElementImpl(
286: (HTMLDocumentImpl) getOwnerDocument(), "TR");
287: //newRow.insertCell( 0 );
288: insertRowX(index, newRow);
289: return newRow;
290: }
291:
292: void insertRowX(int index, HTMLTableRowElementImpl newRow) {
293: Node child;
294: Node lastSection = null;
295:
296: child = getFirstChild();
297: while (child != null) {
298: if (child instanceof HTMLTableRowElement) {
299: if (index == 0) {
300: insertBefore(newRow, child);
301: return;
302: }
303: } else if (child instanceof HTMLTableSectionElementImpl) {
304: lastSection = child;
305: index = ((HTMLTableSectionElementImpl) child)
306: .insertRowX(index, newRow);
307: if (index < 0)
308: return;
309: }
310: child = child.getNextSibling();
311: }
312: if (lastSection != null)
313: lastSection.appendChild(newRow);
314: else
315: appendChild(newRow);
316: }
317:
318: public synchronized void deleteRow(int index) {
319: Node child;
320:
321: child = getFirstChild();
322: while (child != null) {
323: if (child instanceof HTMLTableRowElement) {
324: if (index == 0) {
325: removeChild(child);
326: return;
327: }
328: } else if (child instanceof HTMLTableSectionElementImpl) {
329: index = ((HTMLTableSectionElementImpl) child)
330: .deleteRowX(index);
331: if (index < 0)
332: return;
333: }
334: child = child.getNextSibling();
335: }
336: }
337:
338: /**
339: * Constructor requires owner document.
340: *
341: * @param owner The owner HTML document
342: */
343: public HTMLTableElementImpl(HTMLDocumentImpl owner, String name) {
344: super (owner, name);
345: }
346:
347: private HTMLCollectionImpl _rows;
348:
349: private HTMLCollectionImpl _bodies;
350:
351: }
|