001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.html.dom;
018:
019: import org.w3c.dom.Node;
020: import org.w3c.dom.html.HTMLCollection;
021: import org.w3c.dom.html.HTMLElement;
022: import org.w3c.dom.html.HTMLTableRowElement;
023: import org.w3c.dom.html.HTMLTableSectionElement;
024:
025: /**
026: * @xerces.internal
027: * @version $Revision: 447255 $ $Date: 2006-09-18 01:36:42 -0400 (Mon, 18 Sep 2006) $
028: * @author <a href="mailto:arkin@exoffice.com">Assaf Arkin</a>
029: * @see org.w3c.dom.html.HTMLTableSectionElement
030: * @see org.apache.xerces.dom.ElementImpl
031: */
032: public class HTMLTableSectionElementImpl extends HTMLElementImpl
033: implements HTMLTableSectionElement {
034:
035: private static final long serialVersionUID = 1016412997716618027L;
036:
037: public String getAlign() {
038: return capitalize(getAttribute("align"));
039: }
040:
041: public void setAlign(String align) {
042: setAttribute("align", align);
043: }
044:
045: public String getCh() {
046: String ch;
047:
048: // Make sure that the access key is a single character.
049: ch = getAttribute("char");
050: if (ch != null && ch.length() > 1)
051: ch = ch.substring(0, 1);
052: return ch;
053: }
054:
055: public void setCh(String ch) {
056: // Make sure that the access key is a single character.
057: if (ch != null && ch.length() > 1)
058: ch = ch.substring(0, 1);
059: setAttribute("char", ch);
060: }
061:
062: public String getChOff() {
063: return getAttribute("charoff");
064: }
065:
066: public void setChOff(String chOff) {
067: setAttribute("charoff", chOff);
068: }
069:
070: public String getVAlign() {
071: return capitalize(getAttribute("valign"));
072: }
073:
074: public void setVAlign(String vAlign) {
075: setAttribute("valign", vAlign);
076: }
077:
078: public HTMLCollection getRows() {
079: if (_rows == null)
080: _rows = new HTMLCollectionImpl(this , HTMLCollectionImpl.ROW);
081: return _rows;
082: }
083:
084: public HTMLElement insertRow(int index) {
085: HTMLTableRowElementImpl newRow;
086:
087: newRow = new HTMLTableRowElementImpl(
088: (HTMLDocumentImpl) getOwnerDocument(), "TR");
089: newRow.insertCell(0);
090: if (insertRowX(index, newRow) >= 0)
091: appendChild(newRow);
092: return newRow;
093: }
094:
095: int insertRowX(int index, HTMLTableRowElementImpl newRow) {
096: Node child;
097:
098: child = getFirstChild();
099: while (child != null) {
100: if (child instanceof HTMLTableRowElement) {
101: if (index == 0) {
102: insertBefore(newRow, child);
103: return -1;
104: }
105: --index;
106: }
107: child = child.getNextSibling();
108: }
109: return index;
110: }
111:
112: public void deleteRow(int index) {
113: deleteRowX(index);
114: }
115:
116: int deleteRowX(int index) {
117: Node child;
118:
119: child = getFirstChild();
120: while (child != null) {
121: if (child instanceof HTMLTableRowElement) {
122: if (index == 0) {
123: removeChild(child);
124: return -1;
125: }
126: --index;
127: }
128: child = child.getNextSibling();
129: }
130: return index;
131: }
132:
133: /**
134: * Explicit implementation of cloneNode() to ensure that cache used
135: * for getRows() gets cleared.
136: */
137: public Node cloneNode(boolean deep) {
138: HTMLTableSectionElementImpl clonedNode = (HTMLTableSectionElementImpl) super
139: .cloneNode(deep);
140: clonedNode._rows = null;
141: return clonedNode;
142: }
143:
144: /**
145: * Constructor requires owner document.
146: *
147: * @param owner The owner HTML document
148: */
149: public HTMLTableSectionElementImpl(HTMLDocumentImpl owner,
150: String name) {
151: super (owner, name);
152: }
153:
154: private HTMLCollectionImpl _rows;
155:
156: }
|