View Javadoc

1   /*
2       Jameleon HtmlUnit plug-in - A plug-in that uses HtmlUnit to drive web sites
3       Copyright (C) 2006 Christian W. Hargraves (engrean@hotmail.com)
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., 59 Temple Place, Suite 330, Boston, MA 02111AssertLevel.NO_FUNCTION07 USA
18  */
19  package net.sf.jameleon.plugin.htmlunit.tags;
20  
21  /***
22   * A tag which sets a file field to the provided value.
23   * <br/>
24   * To use XPath to set a file field named <b>testFileField</b> that exists in a form with the id <b>testform</b>:
25   * <pre><source>
26   *     &lt;htmlunit-set-file-field
27   *            functionId="Set the testFileField field to '/tmp/files/my_file.tar.gz'"
28   *            xpath="//form[@id='testform']/input[@name='testFileField']"
29   *            value="/tmp/files/my_file.tar.gz"/>
30   * </source></pre>
31   * To use XPath to set a file field named <b>testFileField</b> that doesn't exist in a form:
32   * <pre><source>
33   *     &lt;htmlunit-set-text-field
34   *            functionId="Set the testFileField field to 'some value' and set it against type just for grins."
35   *            xpath="//input[@name='testFileField' and @type='file']"
36   *            value="some value"/>
37   * </source></pre>
38   * @jameleon.function name="htmlunit-set-file-field" type="action"
39   */
40  public class HtmlUnitSetFileFieldTag extends AbstractHtmlUnitSetInputFieldTag{
41  
42      protected String getInputType(){
43          return "file";
44      }
45  
46      protected void setFieldValueInForm(){
47          if (value != null) {
48              setFileField(fieldName, value);
49          }
50      }
51  
52  }