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.HtmlCheckBoxInput;
22  import com.gargoylesoftware.htmlunit.html.HtmlInput;
23  
24  /***
25   * This tag is used to set or unset checkboxes defined by a given XPath expression.
26   * 
27   * <p>
28   * To use XPath to check a checkbox named <b>cb_1</b> that exists in a form with the name <b>testform</b>:<br/>
29   * <pre><source>
30   *     &lt;htmlunit-set-checkbox
31   *            functionId="Check the checkbox named cb_1 field"
32   *            xpath="//form[@name='testform']/input[@name='cb_1']"
33   *            checked="true"/>
34   * </source></pre>
35   * </p>
36   * <p>
37   * To use XPath to uncheck a checkbox named <b>cb_1</b> that exists in a form with the name <b>testform</b>:
38   * <pre><source>
39   *     &lt;htmlunit-set-checkbox
40   *            functionId="Uncheck the checkbox named cb_1 field"
41   *            xpath="//form[@name='testform']/input[@name='cb_1']"
42   *            checked="false"/>
43   * </source></pre>
44   * </p>
45   * <p>
46   * To use the form and the field name to check a checkbox named <b>cb_1</b> that exists in a form with the name <b>testform</b>:
47   * <pre><source>
48   *     &lt;htmlunit-set-checkbox
49   *            functionId="Check the checkbox named cb_1 field"
50   *            form="testform"
51   *            fieldName="cb_1"
52   *            checked="true"/>
53   * </source></pre>
54   * </p>
55   * @jameleon.function name="htmlunit-set-checkbox" type="action"
56   */
57  public class HtmlUnitSetCheckBoxTag extends AbstractHtmlUnitCheckFieldTag{
58  
59  
60      protected void checkFieldWithValue(String fieldName, String value, boolean check){
61          setCheckBox(fieldName, value, check);
62      }
63  
64      protected void checkField(HtmlInput inputField, boolean check){
65          ((HtmlCheckBoxInput)inputField).setChecked(check);
66      }
67  
68      protected void checkFieldWithNoValue(String fieldName, boolean check){
69          setCheckBox(fieldName, checked.booleanValue());
70      }
71  
72      protected String getInputType(){
73          return "checkbox";
74      }
75  
76  }