001: /**
002: * org/ozone-db/xml/dom/html/HTMLTableElementImpl.java
003: *
004: * The contents of this file are subject to the OpenXML Public
005: * License Version 1.0; you may not use this file except in compliance
006: * with the License. You may obtain a copy of the License at
007: * http://www.openxml.org/license.html
008: *
009: * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
010: * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
011: * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
012: * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
013: * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
014: * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
015: *
016: * The Initial Developer of this code under the License is Assaf Arkin.
017: * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
018: * All Rights Reserved.
019: */package org.ozoneDB.xml.dom.html;
020:
021: import org.ozoneDB.xml.dom.*;
022: import org.w3c.dom.*;
023: import org.w3c.dom.html.*;
024:
025: /**
026: * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
027: * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a>
028: * @see org.w3c.dom.html.HTMLAnchorElement
029: * @see ElementImpl
030: */
031: public final class HTMLTableElementImpl extends HTMLElementImpl
032: implements HTMLTableElement {
033:
034: public synchronized HTMLTableCaptionElement getCaption() {
035: Node child;
036:
037: child = getFirstChild();
038: while (child != null) {
039: if (child instanceof HTMLTableCaptionElement
040: && child.getNodeName().equals("CAPTION")) {
041: return (HTMLTableCaptionElement) child;
042: }
043: child = child.getNextSibling();
044: }
045: return null;
046: }
047:
048: public synchronized void setCaption(HTMLTableCaptionElement caption) {
049: if (caption != null && !caption.getTagName().equals("CAPTION")) {
050: throw new IllegalArgumentException(
051: "Argument 'caption' is not an element of type <CAPTION>.");
052: }
053: deleteCaption();
054: if (caption != null) {
055: appendChild(caption);
056: }
057: }
058:
059: public synchronized HTMLElement createCaption() {
060: HTMLElement section;
061:
062: section = getCaption();
063: if (section != null) {
064: return section;
065: }
066: section = new HTMLTableSectionElementImpl(
067: (HTMLDocumentImpl) getOwnerDocument(), "CAPTION");
068: appendChild(section);
069: return section;
070: }
071:
072: public synchronized void deleteCaption() {
073: Node old;
074:
075: old = getCaption();
076: if (old != null) {
077: removeChild(old);
078: }
079: }
080:
081: public synchronized HTMLTableSectionElement getTHead() {
082: Node child;
083:
084: child = getFirstChild();
085: while (child != null) {
086: if (child instanceof HTMLTableSectionElement
087: && child.getNodeName().equals("THEAD")) {
088: return (HTMLTableSectionElement) child;
089: }
090: child = child.getNextSibling();
091: }
092: return null;
093: }
094:
095: public synchronized void setTHead(HTMLTableSectionElement tHead) {
096: if (tHead != null && !tHead.getTagName().equals("THEAD")) {
097: throw new IllegalArgumentException(
098: "Argument 'tHead' is not an element of type <THEAD>.");
099: }
100: deleteTHead();
101: if (tHead != null) {
102: appendChild(tHead);
103: }
104: }
105:
106: public synchronized HTMLElement createTHead() {
107: HTMLElement section;
108:
109: section = getTHead();
110: if (section != null) {
111: return section;
112: }
113: section = new HTMLTableSectionElementImpl(
114: (HTMLDocumentImpl) getOwnerDocument(), "THEAD");
115: appendChild(section);
116: return section;
117: }
118:
119: public synchronized void deleteTHead() {
120: Node old;
121:
122: old = getTHead();
123: if (old != null) {
124: removeChild(old);
125: }
126: }
127:
128: public synchronized HTMLTableSectionElement getTFoot() {
129: Node child;
130:
131: child = getFirstChild();
132: while (child != null) {
133: if (child instanceof HTMLTableSectionElement
134: && child.getNodeName().equals("TFOOT")) {
135: return (HTMLTableSectionElement) child;
136: }
137: child = child.getNextSibling();
138: }
139: return null;
140: }
141:
142: public synchronized void setTFoot(HTMLTableSectionElement tFoot) {
143: if (tFoot != null && !tFoot.getTagName().equals("TFOOT")) {
144: throw new IllegalArgumentException(
145: "Argument 'tFoot' is not an element of type <TFOOT>.");
146: }
147: deleteTFoot();
148: if (tFoot != null) {
149: appendChild(tFoot);
150: }
151: }
152:
153: public synchronized HTMLElement createTFoot() {
154: HTMLElement section;
155:
156: section = getTFoot();
157: if (section != null) {
158: return section;
159: }
160: section = new HTMLTableSectionElementImpl(
161: (HTMLDocumentImpl) getOwnerDocument(), "TFOOT");
162: appendChild(section);
163: return section;
164: }
165:
166: public synchronized void deleteTFoot() {
167: Node old;
168:
169: old = getTFoot();
170: if (old != null) {
171: removeChild(old);
172: }
173: }
174:
175: public HTMLCollection getRows() {
176: if (_rows == null) {
177: _rows = new HTMLCollectionImpl(this , HTMLCollectionImpl.ROW);
178: }
179: return _rows;
180: }
181:
182: public HTMLCollection getTBodies() {
183: if (_bodies == null) {
184: _bodies = new HTMLCollectionImpl(this ,
185: HTMLCollectionImpl.TBODY);
186: }
187: return _bodies;
188: }
189:
190: public String getAlign() {
191: return capitalize(getAttribute("align"));
192: }
193:
194: public void setAlign(String align) {
195: setAttribute("align", align);
196: }
197:
198: public String getBgColor() {
199: return getAttribute("bgcolor");
200: }
201:
202: public void setBgColor(String bgColor) {
203: setAttribute("bgcolor", bgColor);
204: }
205:
206: public String getBorder() {
207: return getAttribute("border");
208: }
209:
210: public void setBorder(String border) {
211: setAttribute("border", border);
212: }
213:
214: public String getCellPadding() {
215: return getAttribute("cellpadding");
216: }
217:
218: public void setCellPadding(String cellPadding) {
219: setAttribute("cellpadding", cellPadding);
220: }
221:
222: public String getCellSpacing() {
223: return getAttribute("cellspacing");
224: }
225:
226: public void setCellSpacing(String cellSpacing) {
227: setAttribute("cellspacing", cellSpacing);
228: }
229:
230: public String getFrame() {
231: return capitalize(getAttribute("frame"));
232: }
233:
234: public void setFrame(String frame) {
235: setAttribute("frame", frame);
236: }
237:
238: public String getRules() {
239: return capitalize(getAttribute("rules"));
240: }
241:
242: public void setRules(String rules) {
243: setAttribute("rules", rules);
244: }
245:
246: public String getSummary() {
247: return getAttribute("summary");
248: }
249:
250: public void setSummary(String summary) {
251: setAttribute("summary", summary);
252: }
253:
254: public String getWidth() {
255: return getAttribute("width");
256: }
257:
258: public void setWidth(String width) {
259: setAttribute("width", width);
260: }
261:
262: public HTMLElement insertRow(int index) {
263: HTMLTableRowElementImpl newRow;
264:
265: newRow = new HTMLTableRowElementImpl(
266: (HTMLDocumentImpl) getOwnerDocument(), "TR");
267: newRow.insertCell(0);
268: insertRowX(index, newRow);
269: return newRow;
270: }
271:
272: void insertRowX(int index, HTMLTableRowElementImpl newRow) {
273: Node child;
274: Node lastSection = null;
275:
276: child = getFirstChild();
277: while (child != null) {
278: if (child instanceof HTMLTableRowElement) {
279: if (index == 0) {
280: insertBefore(newRow, child);
281: return;
282: }
283: } else {
284: if (child instanceof HTMLTableSectionElementImpl) {
285: lastSection = child;
286: index = ((HTMLTableSectionElementImpl) child)
287: .insertRowX(index, newRow);
288: if (index < 0) {
289: return;
290: }
291: }
292: }
293: child = child.getNextSibling();
294: }
295: if (lastSection != null) {
296: lastSection.appendChild(newRow);
297: } else {
298: appendChild(newRow);
299: }
300: }
301:
302: public synchronized void deleteRow(int index) {
303: Node child;
304:
305: child = getFirstChild();
306: while (child != null) {
307: if (child instanceof HTMLTableRowElement) {
308: if (index == 0) {
309: removeChild(child);
310: return;
311: }
312: } else {
313: if (child instanceof HTMLTableSectionElementImpl) {
314: index = ((HTMLTableSectionElementImpl) child)
315: .deleteRowX(index);
316: if (index < 0) {
317: return;
318: }
319: }
320: }
321: child = child.getNextSibling();
322: }
323: }
324:
325: /**
326: * Constructor requires owner document.
327: *
328: * @param owner The owner HTML document
329: */
330: public HTMLTableElementImpl(HTMLDocumentImpl owner, String name) {
331: super (owner, "TABLE");
332: }
333:
334: private HTMLCollectionImpl _rows;
335:
336: private HTMLCollectionImpl _bodies;
337:
338: }
|