1 21 24 package org.lobobrowser.html.domimpl; 25 26 import java.util.logging.*; 27 28 import org.lobobrowser.html.FormInput; 29 import org.w3c.dom.html2.*; 30 31 public class HTMLInputElementImpl extends HTMLBaseInputElement implements 32 HTMLInputElement { 33 public HTMLInputElementImpl(String name) { 34 super(name); 35 } 36 37 private boolean defaultChecked; 38 39 public boolean getDefaultChecked() { 40 return this.defaultChecked; 41 } 42 43 public void setDefaultChecked(boolean defaultChecked) { 44 this.defaultChecked = defaultChecked; 45 } 46 47 public boolean getChecked() { 48 InputContext ic = this.inputContext; 49 return ic == null ? false : ic.getChecked(); 50 } 51 52 public void setChecked(boolean checked) { 53 InputContext ic = this.inputContext; 54 if(ic != null) { 55 ic.setChecked(checked); 56 } 57 } 58 59 public int getMaxLength() { 60 InputContext ic = this.inputContext; 61 return ic == null ? 0 : ic.getMaxLength(); 62 } 63 64 public void setMaxLength(int maxLength) { 65 InputContext ic = this.inputContext; 66 if(ic != null) { 67 ic.setMaxLength(maxLength); 68 } 69 } 70 71 public int getSize() { 72 InputContext ic = this.inputContext; 73 return ic == null ? 0 : ic.getControlSize(); 74 } 75 76 public void setSize(int size) { 77 InputContext ic = this.inputContext; 78 if(ic != null) { 79 ic.setControlSize(size); 80 } 81 } 82 83 public String getSrc() { 84 return this.getAttribute("src"); 85 } 86 87 public void setSrc(String src) { 88 this.setAttribute("src", src); 89 } 90 91 94 public String getType() { 95 String type = this.getAttribute("type"); 96 return type == null ? null : type.toLowerCase(); 97 } 98 99 public void setType(String type) { 100 this.setAttribute("type", type); 101 } 102 103 public String getUseMap() { 104 return this.getAttribute("usemap"); 105 } 106 107 public void setUseMap(String useMap) { 108 this.setAttribute("usemap", useMap); 109 } 110 111 public void click() { 112 InputContext ic = this.inputContext; 113 if(ic != null) { 114 ic.click(); 115 } 116 } 117 118 public boolean isSubmittableWithEnterKey() { 119 String type = this.getType(); 120 return (type == null || "".equals(type) || "text".equals(type) || "password".equals(type)); 121 } 122 123 public boolean isSubmittableWithPress() { 124 String type = this.getType(); 125 return "submit".equals(type) || "image".equals(type); 126 } 127 128 public boolean isSubmitInput() { 129 String type = this.getType(); 130 return "submit".equals(type); 131 } 132 133 public boolean isImageInput() { 134 String type = this.getType(); 135 return "image".equals(type); 136 } 137 138 public boolean isResetInput() { 139 String type = this.getType(); 140 return "reset".equals(type); 141 } 142 143 void resetInput() { 144 InputContext ic = this.inputContext; 145 if(ic != null) { 146 ic.resetInput(); 147 } 148 } 149 150 protected FormInput[] getFormInputs() { 151 String type = this.getType(); 152 String name = this.getName(); 153 if(name == null) { 154 return null; 155 } 156 if(type == null) { 157 return new FormInput[] { new FormInput(name, this.getValue()) }; 158 } 159 else { 160 if("text".equals(type) || "password".equals(type) || "hidden".equals(type) || "".equals(type)) { 161 return new FormInput[] { new FormInput(name, this.getValue()) }; 162 } 163 else if("submit".equals(type)) { 164 return null; 166 } 167 else if("radio".equals(type) || "checkbox".equals(type)) { 168 if(this.getChecked()) { 169 String value = this.getValue(); 170 if(value == null || value.length() == 0) { 171 value = "on"; 172 } 173 return new FormInput[] { new FormInput(name, value) }; 174 } 175 else { 176 return null; 177 } 178 } 179 else if("image".equals(type)) { 180 return null; 182 } 183 else if("file".equals(type)) { 184 java.io.File file = this.getFileValue(); 185 if(file == null) { 186 if(logger.isLoggable(Level.INFO)) { 187 logger.info("getFormInputs(): File input named " + name + " has null file."); 188 } 189 return null; 190 } 191 else { 192 return new FormInput[] { new FormInput(name, file) }; 193 } 194 } 195 else { 196 return null; 197 } 198 } 199 } 200 } 201 | Popular Tags |