KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > html > domimpl > HTMLInputElementImpl


1 /*
2     GNU LESSER GENERAL PUBLIC LICENSE
3     Copyright (C) 2006 The Lobo Project
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19     Contact info: xamjadmin@users.sourceforge.net
20 */

21 /*
22  * Created on Jan 15, 2006
23  */

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 JavaDoc 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 JavaDoc getSrc() {
84         return this.getAttribute("src");
85     }
86
87     public void setSrc(String JavaDoc src) {
88         this.setAttribute("src", src);
89     }
90
91     /**
92      * Gets input type in lowercase.
93      */

94     public String JavaDoc getType() {
95         String JavaDoc type = this.getAttribute("type");
96         return type == null ? null : type.toLowerCase();
97     }
98
99     public void setType(String JavaDoc type) {
100         this.setAttribute("type", type);
101     }
102
103     public String JavaDoc getUseMap() {
104         return this.getAttribute("usemap");
105     }
106
107     public void setUseMap(String JavaDoc 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 JavaDoc type = this.getType();
120         return (type == null || "".equals(type) || "text".equals(type) || "password".equals(type));
121     }
122
123     public boolean isSubmittableWithPress() {
124         String JavaDoc type = this.getType();
125         return "submit".equals(type) || "image".equals(type);
126     }
127
128     public boolean isSubmitInput() {
129         String JavaDoc type = this.getType();
130         return "submit".equals(type);
131     }
132     
133     public boolean isImageInput() {
134         String JavaDoc type = this.getType();
135         return "image".equals(type);
136     }
137     
138     public boolean isResetInput() {
139         String JavaDoc 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 JavaDoc type = this.getType();
152             String JavaDoc 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                     // It's done as an "extra" form input
165
return null;
166                 }
167                 else if("radio".equals(type) || "checkbox".equals(type)) {
168                     if(this.getChecked()) {
169                         String JavaDoc 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                     // It's done as an "extra" form input
181
return null;
182                 }
183                 else if("file".equals(type)) {
184                     java.io.File JavaDoc 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