KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
41 import java.net.MalformedURLException JavaDoc;
42 import java.net.URL JavaDoc;
43 import java.util.ArrayList JavaDoc;
44 import java.util.Arrays JavaDoc;
45 import java.util.Collection JavaDoc;
46 import java.util.Iterator JavaDoc;
47 import java.util.List JavaDoc;
48 import java.util.Map JavaDoc;
49
50 import org.org.apache.commons.httpclient.NameValuePair;
51 import org.org.apache.commons.httpclient.util.EncodingUtil;
52 import org.apache.commons.lang.StringUtils;
53 import org.mozilla.javascript.Function;
54 import org.mozilla.javascript.Scriptable;
55
56
57 import com.gargoylesoftware.htmlunit.Assert;
58 import com.gargoylesoftware.htmlunit.ElementNotFoundException;
59 import com.gargoylesoftware.htmlunit.FormEncodingType;
60 import com.gargoylesoftware.htmlunit.KeyValuePair;
61 import com.gargoylesoftware.htmlunit.Page;
62 import com.gargoylesoftware.htmlunit.ScriptResult;
63 import com.gargoylesoftware.htmlunit.SubmitMethod;
64 import com.gargoylesoftware.htmlunit.TextUtil;
65 import com.gargoylesoftware.htmlunit.WebRequestSettings;
66 import com.gargoylesoftware.htmlunit.WebWindow;
67
68 /**
69  * Wrapper for the html element "form"
70  *
71  * @version $Revision: 100 $
72  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
73  * @author David K. Taylor
74  * @author Brad Clarke
75  * @author <a HREF="mailto:cse@dynabean.de">Christian Sell</a>
76  * @author Marc Guillemot
77  * @author George Murnock
78  * @author Kent Tong
79  */

80 public class HtmlForm extends ClickableElement {
81
82     /** the HTML tag represented by this element */
83     public static final String JavaDoc TAG_NAME = "form";
84
85     private static final Collection JavaDoc SUBMITTABLE_ELEMENT_NAMES =
86         Arrays.asList( new String JavaDoc[]{"input", "button", "select", "textarea", "isindex"} );
87
88     private KeyValuePair fakeSelectedRadioButton_ = null;
89
90     /**
91      * Create an instance
92      *
93      * @param htmlPage The page that contains this element
94      * @param attributes the initial attributes
95      */

96     public HtmlForm( final HtmlPage htmlPage, final Map JavaDoc attributes) {
97         super(htmlPage, attributes);
98     }
99
100     /**
101      * @return the HTML tag name
102      */

103     public String JavaDoc getTagName() {
104         return TAG_NAME;
105     }
106
107     /**
108      * Submit this form to the appropriate server as if a submit button had
109      * been pressed
110      *
111      * @param buttonName The name of a submit input element or a button element
112      * which will be sent back up with the response
113      * @return A new Page that reflects the results of this submission
114      * @throws IOException If an IO error occurs
115      * @throws ElementNotFoundException If a button with the specified name cannot be found.
116      */

117     public Page submit( final String JavaDoc buttonName ) throws IOException JavaDoc, ElementNotFoundException {
118
119         final List JavaDoc inputList = getHtmlElementsByAttribute("input", "name", buttonName);
120         final Iterator JavaDoc iterator = inputList.iterator();
121         while( iterator.hasNext() ) {
122             final HtmlInput input = (HtmlInput)iterator.next();
123             if( input.getTypeAttribute().equals("submit")) {
124                 return submit( input );
125             }
126         }
127
128         final HtmlButton button = (HtmlButton)getOneHtmlElementByAttribute( "button", "name", buttonName );
129         return submit( button );
130     }
131
132
133     /**
134      * Submit this form to the appropriate server as if it had been submitted
135      * by javascript - ie no submit buttons were pressed. Note that because we
136      * are simulating a javascript submit, the onsubmit handler will not get
137      * executed.
138      *
139      * @return A new Page that reflects the results of this submission
140      * @exception IOException If an IO error occurs
141      */

142     public Page submit() throws IOException JavaDoc {
143         return submit( ( SubmittableElement )null );
144     }
145
146
147     /**
148      * Submit this form to the appropriate server. If submitElement is null then
149      * treat this as if it was called by javascript. In this case, the onsubmit
150      * handler will not get executed.
151      *
152      * @param submitElement The element that caused the submit to occur
153      * @return A new Page that reflects the results of this submission
154      * @exception IOException If an IO error occurs
155      */

156     Page submit( final SubmittableElement submitElement ) throws IOException JavaDoc {
157
158         final String JavaDoc action = getActionAttribute();
159         final HtmlPage htmlPage = getPage();
160         if( htmlPage.getWebClient().isJavaScriptEnabled() ) {
161             if( submitElement != null ) {
162                 final Function onsubmit = getEventHandler("onsubmit");
163                 if (onsubmit != null
164                         && htmlPage.getWebClient().isJavaScriptEnabled()) {
165                     final ScriptResult scriptResult = htmlPage
166                             .executeJavaScriptFunctionIfPossible(onsubmit,
167                                     (Scriptable) getScriptObject(),
168                                     new Object JavaDoc[0], this);
169                     if (scriptResult.getJavaScriptResult()
170                             .equals(Boolean.FALSE)) {
171                         return scriptResult.getNewPage();
172                     }
173                 }
174             }
175
176             if( TextUtil.startsWithIgnoreCase(action, "javascript:") ) {
177                  return htmlPage.executeJavaScriptIfPossible( action, "Form action", false, this ).getNewPage();
178             }
179         }
180         else {
181             if( TextUtil.startsWithIgnoreCase(action, "javascript:") ) {
182                 // The action is javascript but javascript isn't enabled. Return
183
// the current page.
184
return htmlPage;
185             }
186         }
187
188         final List JavaDoc parameters = getParameterListForSubmit(submitElement);
189         final SubmitMethod method = SubmitMethod.getInstance( getAttributeValue("method"));
190
191         String JavaDoc actionUrl = action;
192         if (SubmitMethod.GET.equals(method)) {
193             // discard anchor (not fully correct, but quick fix)
194
actionUrl = StringUtils.substringBefore(actionUrl, "#");
195
196             final NameValuePair[] pairs = new NameValuePair[parameters.size()];
197             parameters.toArray( pairs );
198             final String JavaDoc queryFromFields = EncodingUtil.formUrlEncode(pairs, getPage().getPageEncoding());
199             // action may already contain some query parameters: they have to be removed
200
actionUrl = StringUtils.substringBefore(actionUrl, "?") + "?" + queryFromFields;
201             parameters.clear(); // parameters have been added to query
202
}
203         final URL JavaDoc url;
204         try {
205             url = htmlPage.getFullyQualifiedUrl( actionUrl );
206         }
207         catch( final MalformedURLException JavaDoc e ) {
208             throw new IllegalArgumentException JavaDoc( "Not a valid url: " + actionUrl );
209         }
210
211         final WebRequestSettings settings = new WebRequestSettings(url, method);
212         settings.setRequestParameters(parameters);
213         settings.setEncodingType(FormEncodingType.getInstance( getEnctypeAttribute() ));
214
215         final WebWindow webWindow = htmlPage.getEnclosingWindow();
216         return htmlPage.getWebClient().getPage(
217                 webWindow,
218                 htmlPage.getResolvedTarget(getTargetAttribute()),
219                 settings);
220     }
221
222
223     /**
224      * Return a list of {@link KeyValuePair}s that represent the data that will be
225      * sent to the server on a form submit. This is primarily intended to aid
226      * debugging.
227      *
228      * @param submitElement The element that would have been pressed to submit the
229      * form or null if the form was submitted by javascript.
230      * @return The list of {@link KeyValuePair}s.
231      */

232     public final List JavaDoc getParameterListForSubmit( final SubmittableElement submitElement ) {
233         final Collection JavaDoc submittableElements = getAllSubmittableElements(submitElement);
234
235         final List JavaDoc parameterList = new ArrayList JavaDoc( submittableElements.size() );
236         final Iterator JavaDoc iterator = submittableElements.iterator();
237         while( iterator.hasNext() ) {
238             final SubmittableElement element = ( SubmittableElement )iterator.next();
239             final KeyValuePair[] pairs = element.getSubmitKeyValuePairs();
240
241             for( int i = 0; i < pairs.length; i++ ) {
242                 parameterList.add( pairs[i] );
243             }
244         }
245
246         if( fakeSelectedRadioButton_ != null ) {
247             adjustParameterListToAccountForFakeSelectedRadioButton( parameterList );
248         }
249         return parameterList;
250     }
251
252
253     /**
254      * Reset this form to its initial values.
255      * @return The page that is loaded at the end of calling this method. Typically this
256      * will be the same page that had been loaded previously but since javascript might
257      * have run, this isn't guarenteed.
258      */

259     public Page reset() {
260         final HtmlPage htmlPage = getPage();
261         if( htmlPage.getWebClient().isJavaScriptEnabled() ) {
262             final String JavaDoc onReset = getOnResetAttribute();
263             if( onReset.length() != 0 ) {
264                 final ScriptResult scriptResult
265                     = htmlPage.executeJavaScriptIfPossible( onReset, "onReset", true, this );
266                 if( scriptResult.getJavaScriptResult().equals(Boolean.FALSE) ) {
267                     return scriptResult.getNewPage();
268                 }
269             }
270         }
271
272         final Iterator JavaDoc elementIterator = getAllHtmlChildElements();
273         while( elementIterator.hasNext() ) {
274             final Object JavaDoc next = elementIterator.next();
275             if( next instanceof SubmittableElement ) {
276                 ((SubmittableElement)next).reset();
277             }
278         }
279
280         return htmlPage;
281     }
282
283     /**
284      * Return a collection of elements that represent all the "submittable"
285      * elements in this form
286      *
287      * @param submitElement The element that would have been pressed to submit the
288      * form or null if the form was submitted by javascript.
289      * @return See above
290      * @deprecated Use {@link #getSubmittableElements} instead.
291      */

292     public Collection JavaDoc getAllSubmittableElements(final SubmittableElement submitElement) {
293         return getSubmittableElements(submitElement);
294     }
295
296     /**
297      * Return a collection of elements that represent all the "submittable"
298      * elements in this form
299      *
300      * @param submitElement The element that would have been pressed to submit the
301      * form or null if the form was submitted by javascript.
302      * @return See above
303      */

304     public Collection JavaDoc getSubmittableElements(final SubmittableElement submitElement) {
305
306         final List JavaDoc submittableElements = new ArrayList JavaDoc();
307
308         final DescendantElementsIterator iterator = getAllHtmlChildElements();
309         while( iterator.hasNext() ) {
310             final HtmlElement element = ( HtmlElement )iterator.next();
311             if( isSubmittable(element, submitElement) ) {
312                 submittableElements.add(element);
313             }
314         }
315
316         return submittableElements;
317     }
318
319     private boolean isValidForSubmission(final HtmlElement element, final SubmittableElement submitElement){
320         final String JavaDoc tagName = element.getTagName();
321         if (!SUBMITTABLE_ELEMENT_NAMES.contains(tagName.toLowerCase())) {
322             return false;
323         }
324         if(element.isAttributeDefined("disabled")) {
325             return false;
326         }
327         // clicked input type="image" is submittted even if it hasn't a name
328
if (element == submitElement && element instanceof HtmlImageInput) {
329             return true;
330         }
331
332         if (!tagName.equals("isindex") && !element.isAttributeDefined("name")){
333             return false;
334         }
335
336         if( ! tagName.equals( "isindex" ) && element.getAttributeValue("name").equals("") ) {
337             return false;
338         }
339
340         if( tagName.equals( "input" ) ) {
341             final String JavaDoc type = element.getAttributeValue("type").toLowerCase();
342             if( type.equals( "radio" ) || type.equals( "checkbox" ) ) {
343                 return element.isAttributeDefined("checked");
344             }
345         }
346         if ( tagName.equals("select") ) {
347             //an empty select list has no value, and is therefore not submittable
348
if (((HtmlSelect) element).getOptionSize() < 1) {
349                 return false;
350             }
351         }
352         return true;
353     }
354
355     /**
356      * @param element The element that we are checking for isSubmittable
357      * @param submitElement The element that would have been pressed to submit the
358      * form or null if the form was submitted by javascript.
359      * @return true if element is submittable
360      */

361     private boolean isSubmittable(final HtmlElement element, final SubmittableElement submitElement) {
362         final String JavaDoc tagName = element.getTagName();
363         if (!isValidForSubmission(element, submitElement)){
364             return false;
365         }
366
367         // The one submit button that was clicked can be submitted but no other ones
368
if (element == submitElement) {
369             return true;
370         }
371         if( tagName.equals( "input" ) ) {
372             final HtmlInput input = (HtmlInput)element;
373             final String JavaDoc type = input.getTypeAttribute().toLowerCase();
374             if( type.equals("submit") || type.equals("image") ){
375                 return false;
376             }
377         }
378         if ( tagName.equals("button") ) {
379             final HtmlButton button = (HtmlButton)element;
380             final String JavaDoc type = button.getTypeAttribute().toLowerCase();
381             if( type.equals("submit") ){
382                 return false;
383             }
384         }
385
386         return true;
387     }
388
389     /**
390      * Return the input tags that have the specified name
391      *
392      * @param name The name of the input
393      * @return A list of HtmlInputs
394      * @see #getInputsByName(String)
395      * @deprecated Use {@link #getInputsByName} instead.
396      */

397     public List JavaDoc getAllInputsByName( final String JavaDoc name ) {
398         return getInputsByName(name);
399     }
400
401     /**
402      * Return the input tags that have the specified name
403      *
404      * @param name The name of the input
405      * @return A list of HtmlInputs
406      */

407     public List JavaDoc getInputsByName( final String JavaDoc name ) {
408         return getHtmlElementsByAttribute( "input", "name", name );
409     }
410
411     /**
412      * Return the first input with the specified name
413      *
414      * @param name The name of the input
415      * @return The input
416      * @throws ElementNotFoundException If no inputs could be found with the specified name.
417      */

418     public final HtmlInput getInputByName( final String JavaDoc name ) throws ElementNotFoundException {
419         final List JavaDoc inputs = getHtmlElementsByAttribute( "input", "name", name );
420         if( inputs.size() == 0 ) {
421             throw new ElementNotFoundException( "input", "name", name );
422         }
423         else {
424             return ( HtmlInput )inputs.get( 0 );
425         }
426     }
427
428
429     /**
430      * Return the "radio" type input field that matches the specified name and value
431      *
432      * @param name The name of the HtmlInput
433      * @param value The value of the HtmlInput
434      * @return See above
435      * @exception ElementNotFoundException If the field could not be found
436      */

437     public HtmlRadioButtonInput getRadioButtonInput( final String JavaDoc name, final String JavaDoc value )
438         throws
439             ElementNotFoundException {
440
441         final DescendantElementsIterator iterator = getAllHtmlChildElements();
442         while( iterator.hasNext() ) {
443             final HtmlElement element = iterator.nextElement();
444
445             if( element instanceof HtmlRadioButtonInput
446                     && element.getAttributeValue("name").equals( name ) ) {
447
448                 final HtmlRadioButtonInput input = (HtmlRadioButtonInput)element;
449                 if( input.getValueAttribute().equals( value ) ) {
450                     return input;
451                 }
452             }
453         }
454         throw new ElementNotFoundException( "input", "value", value );
455     }
456
457
458     /**
459      * Return all the HtmlSelect that match the specified name
460      *
461      * @param name The name
462      * @return See above
463      */

464     public List JavaDoc getSelectsByName( final String JavaDoc name ) {
465         return getHtmlElementsByAttribute( "select", "name", name );
466     }
467
468
469     /**
470      * Find the first select element with the specified name
471      * @param name The name of the select element
472      * @return The first select.
473      * @throws ElementNotFoundException If the select cannot be found.
474      */

475     public HtmlSelect getSelectByName( final String JavaDoc name ) throws ElementNotFoundException {
476         final List JavaDoc list = getSelectsByName( name );
477         if( list.isEmpty() ) {
478             throw new ElementNotFoundException( "select", "name", name );
479         }
480         else {
481             return ( HtmlSelect )list.get( 0 );
482         }
483     }
484
485
486     /**
487      * Return all the HtmlButtons that match the specified name
488      *
489      * @param name The name
490      * @return See above
491      * @exception ElementNotFoundException If no matching buttons were found
492      */

493     public List JavaDoc getButtonsByName( final String JavaDoc name )
494         throws ElementNotFoundException {
495         return getHtmlElementsByAttribute( "button", "name", name );
496     }
497
498
499     /**
500      * Return all the HtmlTextAreas that match the specified name
501      *
502      * @param name The name
503      * @return See above
504      */

505     public List JavaDoc getTextAreasByName( final String JavaDoc name ) {
506         return getHtmlElementsByAttribute( "textarea", "name", name );
507     }
508
509
510     /**
511      * Return a list of HtmlInputs that are of type radio and match the
512      * specified name
513      *
514      * @param name The name
515      * @return See above
516      */

517     public List JavaDoc getRadioButtonsByName( final String JavaDoc name ) {
518
519         Assert.notNull( "name", name );
520
521         final List JavaDoc results = new ArrayList JavaDoc();
522
523         final DescendantElementsIterator iterator = getAllHtmlChildElements();
524         while( iterator.hasNext() ) {
525             final HtmlElement element = ( HtmlElement )iterator.next();
526             if( element instanceof HtmlRadioButtonInput
527                      && element.getAttributeValue("name").equals( name ) ) {
528                 results.add(element);
529             }
530         }
531
532         return results;
533     }
534
535
536     /**
537      * Select the specified radio button in the form. <p />
538      *
539      * Only a radio button that is actually contained in the form can be
540      * selected. If you need to be able to select a button that really isn't
541      * there (ie during testing of error cases) then use {@link
542      * #fakeCheckedRadioButton(String,String)} instead
543      *
544      * @param name The name of the radio buttons
545      * @param value The value to match
546      * @exception ElementNotFoundException If the specified element could not be found
547      */

548     public void setCheckedRadioButton(
549             final String JavaDoc name,
550             final String JavaDoc value )
551         throws
552             ElementNotFoundException {
553
554         //we could do this with one iterator, but that would set the state of the other
555
//radios also in the case where the specified one is not found
556
final HtmlInput inputToSelect = getRadioButtonInput( name, value );
557
558         final DescendantElementsIterator iterator = getAllHtmlChildElements();
559         while( iterator.hasNext() ) {
560             final HtmlElement element = iterator.nextElement();
561             if( element instanceof HtmlRadioButtonInput
562                      && element.getAttributeValue("name").equals( name ) ) {
563
564                 final HtmlRadioButtonInput input = (HtmlRadioButtonInput)element;
565                 if( input == inputToSelect ) {
566                     input.setAttributeValue("checked", "checked");
567                 }
568                 else {
569                     input.removeAttribute("checked");
570                 }
571             }
572         }
573     }
574
575     /**
576      * Set the "selected radio buttion" to a value that doesn't actually exist
577      * in the page. This is useful primarily for testing error cases.
578      *
579      * @param name The name of the radio buttons
580      * @param value The value to match
581      * @exception ElementNotFoundException If a particular xml element could
582      * not be found in the dom model
583      */

584     public final void fakeCheckedRadioButton(
585             final String JavaDoc name,
586             final String JavaDoc value )
587         throws
588             ElementNotFoundException {
589
590         fakeSelectedRadioButton_ = new KeyValuePair( name, value );
591     }
592
593
594     private void adjustParameterListToAccountForFakeSelectedRadioButton( final List JavaDoc list ) {
595         final String JavaDoc fakeRadioButtonName = fakeSelectedRadioButton_.getKey();
596
597         // Remove any pairs that match the name of the radio button
598
final Iterator JavaDoc iterator = list.iterator();
599         while( iterator.hasNext() ) {
600             final KeyValuePair pair = ( KeyValuePair )iterator.next();
601             if( pair.getKey().equals( fakeRadioButtonName ) ) {
602                 iterator.remove();
603             }
604         }
605
606         // Now add this one back in
607
list.add( fakeSelectedRadioButton_ );
608     }
609
610
611     /**
612      * Return the first checked radio button with the specified name. If none of
613      * the radio buttons by that name are checked then return null.
614      *
615      * @param name The name of the radio button
616      * @return The first checked radio button.
617      */

618     public HtmlRadioButtonInput getCheckedRadioButton( final String JavaDoc name ) {
619
620         Assert.notNull("name", name);
621
622         final DescendantElementsIterator iterator = getAllHtmlChildElements();
623         while( iterator.hasNext() ) {
624             final HtmlElement element = iterator.nextElement();
625             if( element instanceof HtmlRadioButtonInput
626                      && element.getAttributeValue("name").equals( name ) ) {
627
628                 final HtmlRadioButtonInput input = (HtmlRadioButtonInput)element;
629                 if( input.isChecked() ) {
630                     return input;
631                 }
632             }
633         }
634         return null;
635     }
636
637
638     /**
639      * Return the value of the attribute "action". Refer to the <a
640      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
641      * details on the use of this attribute.
642      *
643      * @return The value of the attribute "action" or an empty string if that
644      * attribute isn't defined.
645      */

646     public final String JavaDoc getActionAttribute() {
647         return getAttributeValue( "action" );
648     }
649
650
651     /**
652      * Set the value of the attribute "action". Refer to the <a
653      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
654      * details on the use of this attribute.
655      *
656      * @param action The value of the attribute "action"
657      */

658     public final void setActionAttribute( final String JavaDoc action ) {
659         setAttributeValue( "action", action );
660     }
661
662
663     /**
664      * Return the value of the attribute "method". Refer to the <a
665      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
666      * details on the use of this attribute.
667      *
668      * @return The value of the attribute "method" or an empty string if that
669      * attribute isn't defined.
670      */

671     public final String JavaDoc getMethodAttribute() {
672         return getAttributeValue( "method" );
673     }
674
675
676     /**
677      * Set the value of the attribute "method". Refer to the <a
678      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
679      * details on the use of this attribute.
680      *
681      * @param method The value of the attribute "method" or an empty string if that
682      * attribute isn't defined.
683      */

684     public final void setMethodAttribute( final String JavaDoc method ) {
685         setAttributeValue( "method", method );
686     }
687
688
689     /**
690      * Return the value of the attribute "name". Refer to the <a
691      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
692      * details on the use of this attribute.
693      *
694      * @return The value of the attribute "name" or an empty string if that
695      * attribute isn't defined.
696      */

697     public final String JavaDoc getNameAttribute() {
698         return getAttributeValue( "name" );
699     }
700
701
702     /**
703      * Return the value of the attribute "enctype". Refer to the <a
704      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
705      * details on the use of this attribute.<p>
706      *
707      * Enctype is the encoding type used when submitting a form back to the server
708      *
709      * @return The value of the attribute "enctype" or an empty string if that
710      * attribute isn't defined.
711      */

712     public final String JavaDoc getEnctypeAttribute() {
713         return getAttributeValue( "enctype" );
714     }
715
716
717     /**
718      * Set the value of the attribute "enctype". Refer to the <a
719      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
720      * details on the use of this attribute.<p>
721      *
722      * Enctype is the encoding type used when submitting a form back to the server
723      *
724      * @param encoding The value of the attribute "enctype" or an empty string if that
725      * attribute isn't defined.
726      */

727     public final void setEnctypeAttribute( final String JavaDoc encoding ) {
728         setAttributeValue( "enctype", encoding );
729     }
730
731
732     /**
733      * Return the value of the attribute "onsubmit". Refer to the <a
734      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
735      * details on the use of this attribute.
736      *
737      * @return The value of the attribute "onsubmit" or an empty string if that
738      * attribute isn't defined.
739      */

740     public final String JavaDoc getOnSubmitAttribute() {
741         return getAttributeValue( "onsubmit" );
742     }
743
744
745     /**
746      * Return the value of the attribute "onreset". Refer to the <a
747      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
748      * details on the use of this attribute.
749      *
750      * @return The value of the attribute "onreset" or an empty string if that
751      * attribute isn't defined.
752      */

753     public final String JavaDoc getOnResetAttribute() {
754         return getAttributeValue( "onreset" );
755     }
756
757
758     /**
759      * Return the value of the attribute "accept". Refer to the <a
760      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
761      * details on the use of this attribute.
762      *
763      * @return The value of the attribute "accept" or an empty string if that
764      * attribute isn't defined.
765      */

766     public final String JavaDoc getAcceptAttribute() {
767         return getAttributeValue( "accept" );
768     }
769
770
771     /**
772      * Return the value of the attribute "accept-charset". Refer to the <a
773      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
774      * details on the use of this attribute.
775      *
776      * @return The value of the attribute "accept-charset" or an empty string
777      * if that attribute isn't defined.
778      */

779     public final String JavaDoc getAcceptCharsetAttribute() {
780         return getAttributeValue( "accept-charset" );
781     }
782
783
784     /**
785      * Return the value of the attribute "target". Refer to the <a
786      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
787      * details on the use of this attribute.
788      *
789      * @return The value of the attribute "target" or an empty string if that
790      * attribute isn't defined.
791      */

792     public final String JavaDoc getTargetAttribute() {
793         return getAttributeValue( "target" );
794     }
795
796
797     /**
798      * Set the value of the attribute "target". Refer to the <a
799      * HREF='http://www.w3.org/TR/html401/'>HTML 4.01</a> documentation for
800      * details on the use of this attribute.
801      *
802      * @param target The value of the attribute "target" or an empty string if that
803      * attribute isn't defined.
804      */

805     public final void setTargetAttribute( final String JavaDoc target ) {
806         setAttributeValue( "target", target );
807     }
808
809     /**
810      * Return the first input with the specified value.
811      * @param value The value
812      * @return The first input with the specified value.
813      * @throws ElementNotFoundException If no elements can be found with the specified value.
814      */

815     public HtmlInput getInputByValue( final String JavaDoc value ) throws ElementNotFoundException {
816         return (HtmlInput)getOneHtmlElementByAttribute("input", "value", value);
817     }
818
819     /**
820      * Return all the inputs with the specified value.
821      * @param value The value
822      * @return all the inputs with the specified value.
823      */

824     public List JavaDoc getInputsByValue( final String JavaDoc value ) {
825         return getHtmlElementsByAttribute("input", "value", value);
826     }
827 }
828
Popular Tags