1 38 package com.gargoylesoftware.htmlunit.javascript.host; 39 40 import java.util.List ; 41 42 import org.jaxen.JaxenException; 43 import org.mozilla.javascript.Context; 44 45 import com.gargoylesoftware.htmlunit.html.xpath.HtmlUnitXPath; 46 import com.gargoylesoftware.htmlunit.javascript.ElementArray; 47 48 57 public class Table extends RowContainer { 58 59 private static final long serialVersionUID = 2779888994049521608L; 60 private ElementArray tBodies_; 62 65 public Table() { 66 } 67 68 72 public void jsConstructor() { 73 } 74 75 80 public Object jsxGet_caption() { 81 final List captions = getHtmlElementOrDie().getHtmlElementsByTagName("caption"); 82 if(captions.isEmpty()) { 83 return null; 84 } 85 else { 86 return getScriptableFor(captions.get(0)); 87 } 88 } 89 90 95 public Object jsxGet_tFoot() { 96 final List tfoots = getHtmlElementOrDie().getHtmlElementsByTagName("tfoot"); 97 if(tfoots.isEmpty()) { 98 return null; 99 } 100 else { 101 return getScriptableFor(tfoots.get(0)); 102 } 103 } 104 105 110 public Object jsxGet_tHead() { 111 final List theads = getHtmlElementOrDie().getHtmlElementsByTagName("thead"); 112 if(theads.isEmpty()) { 113 return null; 114 } 115 else { 116 return getScriptableFor(theads.get(0)); 117 } 118 } 119 120 124 public Object jsxGet_tBodies() { 125 if (tBodies_ == null) { 126 tBodies_ = (ElementArray) makeJavaScriptObject(ElementArray.JS_OBJECT_NAME); 127 try { 128 tBodies_.init(getDomNodeOrDie(), new HtmlUnitXPath("//tbody")); 129 } 130 catch (final JaxenException e) { 131 throw Context.reportRuntimeError("Failed to initialize collection table.tBodies: " + e.getMessage()); 132 } 133 } 134 return tBodies_; 135 } 136 137 145 public Object jsxFunction_createCaption() { 146 return getScriptableFor( getHtmlElementOrDie().appendChildIfNoneExists("caption") ); 147 } 148 149 157 public Object jsxFunction_createTFoot() { 158 return getScriptableFor( getHtmlElementOrDie().appendChildIfNoneExists("tfoot") ); 159 } 160 161 169 public Object jsxFunction_createTHead() { 170 return getScriptableFor( getHtmlElementOrDie().appendChildIfNoneExists("thead") ); 171 } 172 173 180 public void jsxFunction_deleteCaption() { 181 getHtmlElementOrDie().removeChild("caption", 0); 182 } 183 184 191 public void jsxFunction_deleteTFoot() { 192 getHtmlElementOrDie().removeChild("tfoot", 0); 193 } 194 195 202 public void jsxFunction_deleteTHead() { 203 getHtmlElementOrDie().removeChild("thead", 0); 204 } 205 206 } 207 | Popular Tags |