[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit FormControl.java,1.3,1.4 SubmitButton.jav
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-01-09 12:57:51
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv22896/src/com/meterware/httpunit
Modified Files:
FormControl.java SubmitButton.java WebForm.java
Log Message:
Made SubmitButton subclass of FormControl
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FormControl.java 2002/01/08 23:21:53 1.3
+++ FormControl.java 2002/01/09 12:57:48 1.4
@@ -36,15 +36,25 @@
final static String[] NO_VALUE = new String[0];
- private String _name;
- private boolean _readOnly;
- private boolean _disabled;
+ private final String _name;
+ private final String _valueAttribute;
+ private final boolean _readOnly;
+ private final boolean _disabled;
+
+
+ FormControl() {
+ _name = "";
+ _valueAttribute = "";
+ _readOnly = false;
+ _disabled = false;
+ }
FormControl( Node node ) {
- _name = NodeUtils.getNodeAttribute( node, "name" );
- _readOnly = NodeUtils.isNodeAttributePresent( node, "readonly" );
- _disabled = NodeUtils.isNodeAttributePresent( node, "disabled" );
+ _name = NodeUtils.getNodeAttribute( node, "name" );
+ _valueAttribute = NodeUtils.getNodeAttribute( node, "value" );
+ _readOnly = NodeUtils.isNodeAttributePresent( node, "readonly" );
+ _disabled = NodeUtils.isNodeAttributePresent( node, "disabled" );
}
@@ -131,24 +141,11 @@
}
- protected void addValue( Hashtable valueMap, String name, String value ) {
- String[] currentValues = (String[]) valueMap.get( name );
- if (currentValues == null) {
- valueMap.put( name, new String[] { value } );
- } else {
- valueMap.put( name, withNewValue( currentValues, value ) );
- }
- }
-
-
/**
- * Adds a string to an array of strings and returns the result.
+ * Returns the default value of this control in the form. If no value is specified, defaults to the empty string.
**/
- private String[] withNewValue( String[] group, String value ) {
- String[] result = new String[ group.length+1 ];
- System.arraycopy( group, 0, result, 0, group.length );
- result[ group.length ] = value;
- return result;
+ protected String getValueAttribute() {
+ return _valueAttribute;
}
@@ -169,6 +166,8 @@
return new RadioButtonFormControl( node );
} else if (type.equalsIgnoreCase( "checkbox" )) {
return new CheckboxFormControl( node );
+// } else if (type.equalsIgnoreCase( "submit" ) || type.equalsIgnoreCase( "image" )) {
+// return new SubmitButton( node );
} else if (type.equalsIgnoreCase( "file" )) {
return new FileSubmitFormControl( node );
} else {
@@ -187,14 +186,12 @@
private String[] _value = new String[1];
private final boolean _isCheckedDefault;
- private final String _valueAttribute;
public BooleanFormControl( Node node ) {
super( node );
_isChecked = _isCheckedDefault = NodeUtils.isNodeAttributePresent( node, "checked" );
- _valueAttribute = NodeUtils.getNodeAttribute( node, "value" );
}
@@ -220,14 +217,6 @@
}
- /**
- * Returns the default value of this control in the form. If no value is specified, defaults to the empty string.
- **/
- String getValueAttribute() {
- return _valueAttribute;
- }
-
-
abstract String getQueryValue();
@@ -284,6 +273,28 @@
final String value = getValueAttribute();
return value.length() == 0 ? "on" : value;
}
+
+
+ private void addValue( Hashtable valueMap, String name, String value ) {
+ String[] currentValues = (String[]) valueMap.get( name );
+ if (currentValues == null) {
+ valueMap.put( name, new String[] { value } );
+ } else {
+ valueMap.put( name, withNewValue( currentValues, value ) );
+ }
+ }
+
+
+ /**
+ * Adds a string to an array of strings and returns the result.
+ **/
+ private String[] withNewValue( String[] group, String value ) {
+ String[] result = new String[ group.length+1 ];
+ System.arraycopy( group, 0, result, 0, group.length );
+ result[ group.length ] = value;
+ return result;
+ }
+
}
Index: SubmitButton.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SubmitButton.java 2001/12/03 15:39:31 1.5
+++ SubmitButton.java 2002/01/09 12:57:48 1.6
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -22,26 +22,19 @@
import org.w3c.dom.Node;
/**
- * This class represents a suubmit button in an HTML form.
+ * This class represents a submit button in an HTML form.
**/
-public class SubmitButton {
+public class SubmitButton extends FormControl {
- public static SubmitButton UNNAMED_BUTTON = new SubmitButton();
-
- /**
- * Returns the name of this submit button.
- **/
- public String getName() {
- return _name;
- }
+ public static SubmitButton UNNAMED_BUTTON = new SubmitButton();
/**
* Returns the value associated with this submit button.
**/
public String getValue() {
- return _value;
+ return getValueAttribute();
}
@@ -50,7 +43,7 @@
* @return the button ID, or an empty string if no ID is defined.
**/
public String getID() {
- return NodeUtils.getNodeAttribute( _node, "id" );
+ return _id;
}
@@ -63,10 +56,11 @@
/**
- * Returns true if this submit button is disabled. Requests cannot be made for disabled buttons.
+ * Returns the current value(s) associated with this control. These values will be transmitted to the server
+ * if the control is 'successful'.
**/
- public boolean isDisabled() {
- return _isDisabled;
+ public String[] getValues() {
+ return isDisabled() ? NO_VALUE : toArray( getValueAttribute() );
}
@@ -92,26 +86,29 @@
SubmitButton( Node node ) {
- _node = node;
- _name = NodeUtils.getNodeAttribute( node, "name" );
- _value = NodeUtils.getNodeAttribute( _node, "value" );
- _isImageButton = NodeUtils.getNodeAttribute( _node, "type" ).equalsIgnoreCase( "image" );
- _isDisabled = _node.getAttributes().getNamedItem( "disabled" ) != null;
+ super( node );
+ _isImageButton = NodeUtils.getNodeAttribute( node, "type" ).equalsIgnoreCase( "image" );
+ _id = NodeUtils.getNodeAttribute( node, "id" );
}
//------------------------------------------ private members ----------------------------------
+
- private Node _node;
- private String _name;
- private String _value;
- private boolean _isImageButton;
- private boolean _isDisabled;
+ private final String _id;
+ private final boolean _isImageButton;
+ private String[] _value = new String[1];
private SubmitButton() {
- _name = "";
- _value = "";
+ _id = "";
+ _isImageButton = false;
+ }
+
+
+ private String[] toArray( String value ) {
+ _value[0] = value;
+ return _value;
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- WebForm.java 2002/01/08 23:21:53 1.38
+++ WebForm.java 2002/01/09 12:57:48 1.39
@@ -153,8 +153,7 @@
nl = ((Element) getNode()).getElementsByTagName( "button" );
for (int i = 0; i < nl.getLength(); i++) {
- if ((hasMatchingAttribute( nl.item(i), "type", "submit" ) || hasMatchingAttribute( nl.item(i), "type", "" ))
- && nl.item(i).getAttributes().getNamedItem( "disabled" ) == null) {
+ if (hasMatchingAttribute( nl.item(i), "type", "submit" ) || hasMatchingAttribute( nl.item(i), "type", "" )) {
_buttonVector.addElement( new SubmitButton( nl.item(i) ) );
}
}
|