1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import java.util.Map ; 41 import java.util.List ; 42 import java.util.ArrayList ; 43 import java.util.Collections ; 44 import java.util.Iterator ; 45 import java.util.NoSuchElementException ; 46 47 48 56 public class HtmlTableRow extends ClickableElement { 57 58 59 public static final String TAG_NAME = "tr"; 60 61 67 public HtmlTableRow( final HtmlPage page, final Map attributes ) { 68 super( page, attributes ); 69 } 70 71 74 public String getTagName() { 75 return TAG_NAME; 76 } 77 78 81 public CellIterator getCellIterator() { 82 return new CellIterator(); 83 } 84 85 89 public List getCells() { 90 final List result = new ArrayList (); 91 for(final CellIterator iterator = getCellIterator(); iterator.hasNext(); ) { 92 result.add(iterator.next()); 93 } 94 return Collections.unmodifiableList(result); 95 } 96 97 102 public HtmlTableCell getCell(final int index) throws IndexOutOfBoundsException { 103 int count = 0; 104 for(final CellIterator iterator = getCellIterator(); iterator.hasNext(); count++) { 105 final HtmlTableCell next = iterator.nextCell(); 106 if(count == index) { 107 return next; 108 } 109 } 110 throw new IndexOutOfBoundsException (); 111 } 112 113 114 115 123 public final String getAlignAttribute() { 124 return getAttributeValue("align"); 125 } 126 127 128 136 public final String getCharAttribute() { 137 return getAttributeValue("char"); 138 } 139 140 141 149 public final String getCharoffAttribute() { 150 return getAttributeValue("charoff"); 151 } 152 153 154 162 public final String getValignAttribute() { 163 return getAttributeValue("valign"); 164 } 165 166 170 public HtmlTable getEnclosingTable() { 171 return (HtmlTable) getEnclosingElement("table"); 172 } 173 174 175 183 public final String getBgcolorAttribute() { 184 return getAttributeValue("bgcolor"); 185 } 186 187 191 public class CellIterator implements Iterator { 192 193 private HtmlTableCell nextCell_; 194 private HtmlForm currentForm_; 195 196 197 public CellIterator() { 198 setNextCell(getFirstChild()); 199 } 200 201 202 public boolean hasNext() { 203 return nextCell_ != null; 204 } 205 206 210 public Object next() throws NoSuchElementException { 211 return nextCell(); 212 } 213 214 218 public void remove() throws IllegalStateException { 219 if(nextCell_ == null) { 220 throw new IllegalStateException (); 221 } 222 if(nextCell_.getPreviousSibling() != null) { 223 nextCell_.getPreviousSibling().remove(); 224 } 225 } 226 227 231 public HtmlTableCell nextCell() throws NoSuchElementException { 232 233 if(nextCell_ != null) { 234 final HtmlTableCell result = nextCell_; 235 setNextCell(nextCell_.getNextSibling()); 236 return result; 237 } 238 else { 239 throw new NoSuchElementException (); 240 } 241 } 242 243 248 private void setNextCell(final DomNode node) { 249 250 nextCell_ = null; 251 for(DomNode next = node; next != null; next = next.getNextSibling()) { 252 if(next instanceof HtmlTableCell) { 253 nextCell_ = (HtmlTableCell)next; 254 return; 255 } 256 else if(currentForm_ == null && next instanceof HtmlForm) { 257 currentForm_ = (HtmlForm)next; 259 setNextCell(next.getFirstChild()); 260 return; 261 } 262 } 263 if(currentForm_ != null) { 264 final DomNode form = currentForm_; 265 currentForm_ = null; 266 setNextCell(form.getNextSibling()); 267 } 268 } 269 } 270 } 271 | Popular Tags |