1 /* DomHTMLTableRowElement.java -- 2 Copyright (C) 2005 Free Software Foundation, Inc. 3 4 This file is part of GNU Classpath. 5 6 GNU Classpath is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Classpath is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Classpath; see the file COPYING. If not, write to the 18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301 USA. 20 21 Linking this library statically or dynamically with other modules is 22 making a combined work based on this library. Thus, the terms and 23 conditions of the GNU General Public License cover the whole 24 combination. 25 26 As a special exception, the copyright holders of this library give you 27 permission to link this library with independent modules to produce an 28 executable, regardless of the license terms of these independent 29 modules, and to copy and distribute the resulting executable under 30 terms of your choice, provided that you also meet, for each linked 31 independent module, the terms and conditions of the license of that 32 module. An independent module is a module which is not derived from 33 or based on this library. If you modify this library, you may extend 34 this exception to your version of the library, but you are not 35 obligated to do so. If you do not wish to do so, delete this 36 exception statement from your version. */ 37 38 package gnu.xml.dom.html2; 39 40 import gnu.xml.dom.DomDOMException; 41 import org.w3c.dom.DOMException; 42 import org.w3c.dom.Node; 43 import org.w3c.dom.html2.HTMLCollection; 44 import org.w3c.dom.html2.HTMLElement; 45 import org.w3c.dom.html2.HTMLTableRowElement; 46 47 /** 48 * An HTML 'TR' element node. 49 * 50 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> 51 */ 52 public class DomHTMLTableRowElement 53 extends DomHTMLElement 54 implements HTMLTableRowElement 55 { 56 DomHTMLTableRowElement(DomHTMLDocument owner, String namespaceURI, String name)57 protected DomHTMLTableRowElement(DomHTMLDocument owner, 58 String namespaceURI, 59 String name) 60 { 61 super(owner, namespaceURI, name); 62 } 63 getRowIndex()64 public int getRowIndex() 65 { 66 return getIndex(); 67 } 68 getSectionRowIndex()69 public int getSectionRowIndex() 70 { 71 int index = 0; 72 DomHTMLElement parent = (DomHTMLElement) getParentElement("table"); 73 if (parent != null) 74 { 75 Node thead = parent.getChildElement("thead"); 76 if (thead != null) 77 { 78 for (Node ctx = thead.getFirstChild(); ctx != null; 79 ctx = ctx.getNextSibling()) 80 { 81 if (ctx == this) 82 { 83 return index; 84 } 85 index++; 86 } 87 } 88 Node tbody = parent.getChildElement("tbody"); 89 if (tbody != null) 90 { 91 for (Node ctx = tbody.getFirstChild(); ctx != null; 92 ctx = ctx.getNextSibling()) 93 { 94 if (ctx == this) 95 { 96 return index; 97 } 98 index++; 99 } 100 } 101 Node tfoot = parent.getChildElement("tfoot"); 102 if (tfoot != null) 103 { 104 for (Node ctx = tfoot.getFirstChild(); ctx != null; 105 ctx = ctx.getNextSibling()) 106 { 107 if (ctx == this) 108 { 109 return index; 110 } 111 index++; 112 } 113 } 114 } 115 throw new DomDOMException(DOMException.NOT_FOUND_ERR); 116 } 117 getCells()118 public HTMLCollection getCells() 119 { 120 DomHTMLCollection ret = 121 new DomHTMLCollection((DomHTMLDocument) getOwnerDocument(), this); 122 ret.addNodeName("th"); 123 ret.addNodeName("td"); 124 ret.evaluate(); 125 return ret; 126 } 127 getAlign()128 public String getAlign() 129 { 130 return getHTMLAttribute("align"); 131 } 132 setAlign(String align)133 public void setAlign(String align) 134 { 135 setHTMLAttribute("align", align); 136 } 137 getBgColor()138 public String getBgColor() 139 { 140 return getHTMLAttribute("bgcolor"); 141 } 142 setBgColor(String bgColor)143 public void setBgColor(String bgColor) 144 { 145 setHTMLAttribute("bgcolor", bgColor); 146 } 147 getCh()148 public String getCh() 149 { 150 return getHTMLAttribute("char"); 151 } 152 setCh(String ch)153 public void setCh(String ch) 154 { 155 setHTMLAttribute("char", ch); 156 } 157 getChOff()158 public String getChOff() 159 { 160 return getHTMLAttribute("charoff"); 161 } 162 setChOff(String chOff)163 public void setChOff(String chOff) 164 { 165 setHTMLAttribute("charoff", chOff); 166 } 167 getVAlign()168 public String getVAlign() 169 { 170 return getHTMLAttribute("valign"); 171 } 172 setVAlign(String vAlign)173 public void setVAlign(String vAlign) 174 { 175 setHTMLAttribute("valign", vAlign); 176 } 177 insertCell(int index)178 public HTMLElement insertCell(int index) 179 { 180 Node ref = getCell(index); 181 Node cell = getOwnerDocument().createElement("td"); 182 if (ref == null) 183 { 184 appendChild(cell); 185 } 186 else 187 { 188 insertBefore(cell, ref); 189 } 190 return (HTMLElement) cell; 191 } 192 deleteCell(int index)193 public void deleteCell(int index) 194 { 195 Node ref = getCell(index); 196 if (ref == null) 197 { 198 throw new DomDOMException(DOMException.INDEX_SIZE_ERR); 199 } 200 removeChild(ref); 201 } 202 getCell(final int index)203 Node getCell(final int index) 204 { 205 int i = 0; 206 for (Node ctx = getFirstChild(); ctx != null; 207 ctx = ctx.getNextSibling()) 208 { 209 String name = ctx.getLocalName(); 210 if (name == null) 211 { 212 name = ctx.getNodeName(); 213 } 214 if (!"td".equalsIgnoreCase(name) && 215 !"th".equalsIgnoreCase(name)) 216 { 217 continue; 218 } 219 if (index == i) 220 { 221 return ctx; 222 } 223 i++; 224 } 225 return null; 226 } 227 228 } 229 230