1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import java.io.IOException ; 41 import java.util.Map ; 42 43 import com.gargoylesoftware.htmlunit.BrowserVersion; 44 import com.gargoylesoftware.htmlunit.ElementNotFoundException; 45 import com.gargoylesoftware.htmlunit.KeyValuePair; 46 import com.gargoylesoftware.htmlunit.Page; 47 48 57 public class HtmlButton extends FocusableElement implements DisabledElement, SubmittableElement { 58 59 60 public static final String TAG_NAME = "button"; 61 62 68 public HtmlButton( final HtmlPage page, final Map attributes) { 69 super(page, attributes); 70 } 71 72 75 public String getTagName() { 76 return TAG_NAME; 77 } 78 79 84 public void setValueAttribute( final String newValue ) { 85 setAttributeValue( "value", newValue ); 86 } 87 88 97 public Page submit() throws IOException , ElementNotFoundException { 98 99 return click(); 100 } 101 102 114 protected Page doClickAction(final Page defaultPage) throws IOException { 115 final String type = getTypeAttribute().toLowerCase(); 116 if (type.equals("submit")) { 117 return getEnclosingFormOrDie().submit(this); 118 } 119 else if (type.equals("reset")){ 120 return getEnclosingFormOrDie().reset(); 121 } 122 else { 123 return defaultPage; 124 } 125 } 126 127 128 132 public final boolean isDisabled() { 133 return isAttributeDefined("disabled"); 134 } 135 136 137 146 public KeyValuePair[] getSubmitKeyValuePairs() { 147 return new KeyValuePair[]{new KeyValuePair( getNameAttribute(), getValueAttribute() )}; 148 } 149 150 151 154 public void reset() { 155 getLog().debug("reset() not implemented for this element"); 156 } 157 158 159 167 public final String getNameAttribute() { 168 return getAttributeValue("name"); 169 } 170 171 172 180 public final String getValueAttribute() { 181 return getAttributeValue("value"); 182 } 183 184 185 195 public final String getTypeAttribute() { 196 String type = getAttributeValue("type"); 197 if( type == HtmlElement.ATTRIBUTE_NOT_DEFINED ) { 198 final BrowserVersion browser = getPage().getWebClient().getBrowserVersion(); 199 if( browser.getApplicationName().equals(BrowserVersion.INTERNET_EXPLORER) ) { 200 type = "button"; 201 } 202 else { 203 type = "submit"; 204 } 205 } 206 return type; 207 } 208 209 210 218 public final String getDisabledAttribute() { 219 return getAttributeValue("disabled"); 220 } 221 222 223 231 public final String getTabIndexAttribute() { 232 return getAttributeValue("tabindex"); 233 } 234 235 236 244 public final String getAccessKeyAttribute() { 245 return getAttributeValue("accesskey"); 246 } 247 248 249 257 public final String getOnFocusAttribute() { 258 return getAttributeValue("onfocus"); 259 } 260 261 262 270 public final String getOnBlurAttribute() { 271 return getAttributeValue("onblur"); 272 } 273 } 274 | Popular Tags |