KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > gargoylesoftware > htmlunit > html > HtmlTextArea


1 /*
2  * Copyright (c) 2002, 2005 Gargoyle Software Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * 3. The end-user documentation included with the redistribution, if any, must
13  * include the following acknowledgment:
14  *
15  * "This product includes software developed by Gargoyle Software Inc.
16  * (http://www.GargoyleSoftware.com/)."
17  *
18  * Alternately, this acknowledgment may appear in the software itself, if
19  * and wherever such third-party acknowledgments normally appear.
20  * 4. The name "Gargoyle Software" must not be used to endorse or promote
21  * products derived from this software without prior written permission.
22  * For written permission, please contact info@GargoyleSoftware.com.
23  * 5. Products derived from this software may not be called "HtmlUnit", nor may
24  * "HtmlUnit" appear in their name, without prior written permission of
25  * Gargoyle Software Inc.
26  *
27  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
28  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
30  * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
33  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */

38 package com.gargoylesoftware.htmlunit.html;
39
40 import com.gargoylesoftware.htmlunit.KeyValuePair;
41
42 import java.util.Map JavaDoc;
43
44 /**
45  * Wrapper for the html element "textarea"
46  *
47  * @version $Revision: 100 $
48  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
49  * @author <a HREF="mailto:BarnabyCourt@users.sourceforge.net">Barnaby Court</a>
50  * @author David K. Taylor
51  * @author <a HREF="mailto:cse@dynabean.de">Christian Sell</a>
52  * @author David D. Kilzer
53  * @author Marc Guillemot
54  */

55 public class HtmlTextArea extends FocusableElement implements DisabledElement, SubmittableElement {
56
57     /** the HTML tag represented by this element */
58     public static final String JavaDoc TAG_NAME = "textarea";
59
60     private DomText oldText_;
61
62     /**
63      * Create an instance
64      *
65      * @param page The page that contains this element
66      * @param attributes the initial attributes
67      */

68     public HtmlTextArea( final HtmlPage page, final Map JavaDoc attributes ) {
69         super( page, attributes );
70     }
71
72     /**
73      * @return the HTML tag name
74      */

75     public String JavaDoc getTagName() {
76         return TAG_NAME;
77     }
78
79     /**
80      * Return the value that would be displayed in the text area
81      *
82      * @return The text
83      * @deprecated Use {@link #getText()} instead
84      */

85     public final String JavaDoc getValue() {
86         return getText();
87     }
88
89
90     /**
91      * Return the value that would be displayed in the text area
92      *
93      * @return The text
94      */

95     public final String JavaDoc getText() {
96         return getChildrenAsText();
97     }
98
99
100     /**
101      * Set the new value of this text area.
102      *
103      * @param newValue The new value or null if the original value returned
104      * from the server should be used
105      * @deprecated Use {@link #setText(String)} instead
106      */

107     public final void setValue( final String JavaDoc newValue ) {
108         if( newValue == null ) {
109             reset();
110         }
111         else {
112             setText(newValue);
113         }
114     }
115
116
117     /**
118      * Set the new value of this text area.
119      *
120      * @param newValue The new value.
121      */

122     public final void setText( final String JavaDoc newValue ) {
123         oldText_ = (DomText)getFirstChild();
124         final DomText newText = new DomText(getPage(), newValue);
125         if (oldText_ == null) {
126             appendChild(newText);
127         }
128         else {
129             oldText_.replace(newText);
130         }
131
132         getPage().executeOnChangeHandlerIfAppropriate(this);
133     }
134
135
136     /**
137      * Return an array of KeyValuePairs that are the values that will be sent
138      * back to the server whenever the current form is submitted.<p>
139      *
140      * THIS METHOD IS INTENDED FOR THE USE OF THE FRAMEWORK ONLY AND SHOULD NOT
141      * BE USED BY CONSUMERS OF HTMLUNIT. USE AT YOUR OWN RISK.
142      *
143      * @return See above
144      */

145     public KeyValuePair[] getSubmitKeyValuePairs() {
146         return new KeyValuePair[]{new KeyValuePair( getNameAttribute(), getText() )};
147     }
148
149
150     /**
151      * Return the value of this element to what it was at the time the page was loaded.
152      */

153     public void reset() {
154         if(oldText_ != null) {
155             getFirstChild().replace(oldText_);
156         }
157     }
158
159
160     /**
161      * Return the value of the attribute "name". Refer to the
162      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
163      * documentation for details on the use of this attribute.
164      *
165      * @return The value of the attribute "name"
166      * or an empty string if that attribute isn't defined.
167      */

168     public final String JavaDoc getNameAttribute() {
169         return getAttributeValue("name");
170     }
171
172
173     /**
174      * Return the value of the attribute "rows". Refer to the
175      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
176      * documentation for details on the use of this attribute.
177      *
178      * @return The value of the attribute "rows"
179      * or an empty string if that attribute isn't defined.
180      */

181     public final String JavaDoc getRowsAttribute() {
182         return getAttributeValue("rows");
183     }
184
185
186     /**
187      * Return the value of the attribute "cols". Refer to the
188      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
189      * documentation for details on the use of this attribute.
190      *
191      * @return The value of the attribute "cols"
192      * or an empty string if that attribute isn't defined.
193      */

194     public final String JavaDoc getColumnsAttribute() {
195         return getAttributeValue("cols");
196     }
197
198
199     /**
200      * Return true if the disabled attribute is set for this element.
201      *
202      * @return Return true if this element is disabled.
203      */

204     public final boolean isDisabled() {
205         return isAttributeDefined("disabled");
206     }
207
208
209     /**
210      * Return the value of the attribute "disabled". Refer to the
211      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
212      * documentation for details on the use of this attribute.
213      *
214      * @return The value of the attribute "disabled"
215      * or an empty string if that attribute isn't defined.
216      */

217     public final String JavaDoc getDisabledAttribute() {
218         return getAttributeValue("disabled");
219     }
220
221
222     /**
223      * Return the value of the attribute "readonly". Refer to the
224      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
225      * documentation for details on the use of this attribute.
226      *
227      * @return The value of the attribute "readonly"
228      * or an empty string if that attribute isn't defined.
229      */

230     public final String JavaDoc getReadOnlyAttribute() {
231         return getAttributeValue("readonly");
232     }
233
234
235     /**
236      * Return the value of the attribute "tabindex". Refer to the
237      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
238      * documentation for details on the use of this attribute.
239      *
240      * @return The value of the attribute "tabindex"
241      * or an empty string if that attribute isn't defined.
242      */

243     public final String JavaDoc getTabIndexAttribute() {
244         return getAttributeValue("tabindex");
245     }
246
247
248     /**
249      * Return the value of the attribute "accesskey". Refer to the
250      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
251      * documentation for details on the use of this attribute.
252      *
253      * @return The value of the attribute "accesskey"
254      * or an empty string if that attribute isn't defined.
255      */

256     public final String JavaDoc getAccessKeyAttribute() {
257         return getAttributeValue("accesskey");
258     }
259
260
261     /**
262      * Return the value of the attribute "onfocus". Refer to the
263      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
264      * documentation for details on the use of this attribute.
265      *
266      * @return The value of the attribute "onfocus"
267      * or an empty string if that attribute isn't defined.
268      */

269     public final String JavaDoc getOnFocusAttribute() {
270         return getAttributeValue("onfocus");
271     }
272
273
274     /**
275      * Return the value of the attribute "onblur". Refer to the
276      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
277      * documentation for details on the use of this attribute.
278      *
279      * @return The value of the attribute "onblur"
280      * or an empty string if that attribute isn't defined.
281      */

282     public final String JavaDoc getOnBlurAttribute() {
283         return getAttributeValue("onblur");
284     }
285
286
287     /**
288      * Return the value of the attribute "onselect". Refer to the
289      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
290      * documentation for details on the use of this attribute.
291      *
292      * @return The value of the attribute "onselect"
293      * or an empty string if that attribute isn't defined.
294      */

295     public final String JavaDoc getOnSelectAttribute() {
296         return getAttributeValue("onselect");
297     }
298
299
300     /**
301      * Return the value of the attribute "onchange". Refer to the
302      * <a HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a>
303      * documentation for details on the use of this attribute.
304      *
305      * @return The value of the attribute "onchange"
306      * or an empty string if that attribute isn't defined.
307      */

308     public final String JavaDoc getOnChangeAttribute() {
309         return getAttributeValue("onchange");
310     }
311 }
312
Popular Tags