[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit FormControl.java,1.38,1.39
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-05-04 12:45:14
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv23915/src/com/meterware/httpunit
Modified Files:
FormControl.java
Log Message:
Support getOptions for radio buttons and checkboxes
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- FormControl.java 1 Apr 2003 13:42:09 -0000 1.38
+++ FormControl.java 4 May 2003 12:45:10 -0000 1.39
@@ -353,6 +353,8 @@
private String[] _value = new String[1];
private final boolean _isCheckedDefault;
+ private String[] _displayedValue;
+
protected ScriptableDelegate newScriptable() {
return new Scriptable();
@@ -385,10 +387,19 @@
public BooleanFormControl( WebForm form, Node node ) {
super( form, node );
+ _displayedValue = new String[] { readDisplayedValue( node ) };
_isChecked = _isCheckedDefault = NodeUtils.isNodeAttributePresent( node, "checked" );
}
+ private String readDisplayedValue( Node node ) {
+ Node nextSibling = node.getNextSibling();
+ while (nextSibling != null && nextSibling.getNodeType() != Node.TEXT_NODE && nextSibling.getNodeType() != Node.ELEMENT_NODE) nextSibling = nextSibling.getNextSibling();
+ if (nextSibling == null || nextSibling.getNodeType() != Node.TEXT_NODE) return "";
+ return nextSibling.getNodeValue();
+ }
+
+
boolean isChecked() {
return _isChecked;
}
@@ -421,6 +432,11 @@
}
+ String[] getDisplayedOptions() {
+ return _displayedValue;
+ }
+
+
void addValues( ParameterProcessor processor, String characterSet ) throws IOException {
if (isChecked() && !isDisabled()) processor.addParameter( getName(), getQueryValue(), characterSet );
}
@@ -506,6 +522,19 @@
FormControl[] buttons = getButtons();
for (int i = 0; i < buttons.length; i++) {
valueList.addAll( Arrays.asList( buttons[i].getOptionValues() ) );
+ }
+ return (String[]) valueList.toArray( new String[ valueList.size() ] );
+ }
+
+
+ /**
+ * Returns the options displayed for this radio button group.
+ */
+ String[] getDisplayedOptions() {
+ ArrayList valueList = new ArrayList();
+ FormControl[] buttons = getButtons();
+ for (int i = 0; i < buttons.length; i++) {
+ valueList.addAll( Arrays.asList( buttons[i].getDisplayedOptions() ) );
}
return (String[]) valueList.toArray( new String[ valueList.size() ] );
}
|