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  import com.gargoylesoftware.htmlunit.html.SubmittableElement;
22  import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
23  
24  /***
25   * A tag which sets a text area to the provided value.
26   * <br/>
27   * To use XPath to set a text field named <b>testTextArea</b> that exists in a form with the name <b>testform</b>:
28   * <pre><source>
29   *     &lt;htmlunit-set-text-area
30   *            functionId="Set the testTextArea field to 'some value'"
31   *            xpath="//form[@name='testform']/textarea[@name='testTextArea']"
32   *            value="some value"/>
33   * </source></pre>
34   * To use XPath to set a text area named <b>testTextArea</b> that doesn't exist in a form:
35   * <pre><source>
36   *     &lt;htmlunit-set-text-area
37   *            functionId="Set the testTextArea field to 'some value'"
38   *            xpath="//input[@name='testTextArea']"
39   *            value="some value"/>
40   * </source></pre>
41   * To to set a text area named <b>testTextArea</b> that exists in a form with id or name of <b>form_test</b> w/o using XPath:
42   * <pre><source>
43   *     &lt;htmlunit-set-text-area
44   *            functionId="Set the testTextArea field to 'some value'"
45   *            form="form_test"
46   *            fieldName="testTextArea"
47   *            value="some value"/>
48   * </source></pre>
49   * To to set a text area named <b>testTextArea</b> that exists in the 2nd form <b>form_test</b> w/o using XPath:
50   * <pre><source>
51   *     &lt;htmlunit-set-text-area
52   *            functionId="Set the testTextArea field to 'some value'"
53   *            form="2"
54   *            fieldName="testTextArea"
55   *            value="some value"/>
56   * </source></pre>
57   * To to set a text field named <b>testTextArea</b> that exists in form define by <b>//table/tr[3]/td/form</b> XPath:
58   * <pre><source>
59   *     &lt;htmlunit-set-text-area
60   *            functionId="Set the testTextArea field to 'some value'"
61   *            form="//table/tr[3]/td/form"
62   *            fieldName="testTextArea"
63   *            value="some value"/>
64   * </source></pre>
65   * @jameleon.function name="htmlunit-set-text-area" type="action"
66   */
67  public class HtmlUnitSetTextAreaTag extends AbstractHtmlUnitSetFormFieldTag{
68  
69      protected void setFieldValueInForm(){
70          setTextArea(fieldName, value);
71      }
72  
73      protected void setFieldValueFoundByXPath(SubmittableElement formField){
74          assertTrue(fieldName+" is not a textarea", formField instanceof HtmlTextArea);
75          HtmlTextArea textArea = (HtmlTextArea)formField;
76          textArea.setText(value);
77      }
78  }