1 38 package com.gargoylesoftware.htmlunit.javascript.host; 39 40 import com.gargoylesoftware.htmlunit.html.HtmlElement; 41 import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; 42 43 52 public class Attribute extends SimpleScriptable { 53 54 private static final long serialVersionUID = 3256441425892750900L; 55 56 60 public static final String JS_OBJECT_NAME = "Attribute"; 61 62 65 private String name_; 66 67 71 private String value_; 72 73 79 private HtmlElement parent_; 80 81 84 public Attribute() {} 85 86 91 public void init(final String name, final HtmlElement parent) { 92 name_ = name; 93 parent_ = parent; 94 if(parent_ == null) { 95 value_ = ""; 96 } 97 } 98 99 102 public void detachFromParent() { 103 if(parent_ != null) { 104 value_ = parent_.getAttributeValue(name_); 105 } 106 parent_ = null; 107 } 108 109 113 public boolean jsxGet_expando() { 114 return true; 115 } 116 117 121 public Object jsxGet_firstChild() { 122 return null; 123 } 124 125 129 public Object jsxGet_lastChild() { 130 return null; 131 } 132 133 137 public String jsxGet_name() { 138 return name_; 139 } 140 141 145 public Object jsxGet_nextSibling() { 146 return null; 147 } 148 149 153 public String jsxGet_nodeName() { 154 return jsxGet_name(); 155 } 156 157 161 public int jsxGet_nodeType() { 162 return 2; 163 } 164 165 169 public String jsxGet_nodeValue() { 170 return jsxGet_value(); 171 } 172 173 177 public Object jsxGet_ownerDocument() { 178 if(parent_ != null) { 179 final SimpleScriptable documentScriptable = getScriptableFor(parent_.getPage()); 180 return documentScriptable; 181 } 182 else { 183 return null; 184 } 185 } 186 187 191 public Object jsxGet_parentNode() { 192 return null; 193 } 194 195 199 public Object jsxGet_previousSibling() { 200 return null; 201 } 202 203 207 public boolean jsxGet_specified() { 208 return true; 209 } 210 211 215 public String jsxGet_value() { 216 if(parent_ != null) { 217 return parent_.getAttributeValue(name_); 218 } 219 else { 220 return value_; 221 } 222 } 223 224 228 public void jsxSet_value(final String value) { 229 if(parent_ != null) { 230 parent_.setAttributeValue(name_, value); 231 } 232 else { 233 value_ = value; 234 } 235 } 236 } 237 | Popular Tags |