[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit WebForm.java,1.26,1.27 WebRequest.java,1.
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2001-10-19 19:17:00
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv17965/src/com/meterware/httpunit
Modified Files:
WebForm.java WebRequest.java
Log Message:
Allow multi-values text parameters
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- WebForm.java 2001/08/21 19:56:22 1.26
+++ WebForm.java 2001/10/19 19:16:57 1.27
@@ -337,6 +337,22 @@
/**
+ * Returns the number of text parameters in this form with the specified name.
+ **/
+ public int getNumTextParameters( String name ) {
+ Object count = getTextParameterCounts().get( name );
+ if (count == null) return 0;
+ return ((Number) count ).intValue();
+ }
+
+
+ private Hashtable getTextParameterCounts() {
+ getParameterTypes();
+ return _textParameterCounts;
+ }
+
+
+ /**
* Returns true if the named parameter accepts files for upload.
**/
public boolean isFileParameter( String name ) {
@@ -378,7 +394,10 @@
/** The type of a parameter which accepts files for upload. **/
private final static Integer TYPE_FILE = new Integer(4);
+ /** A constant set to indicate one parameter. **/
+ private final static Integer ONE_PARAMETER = new Integer(1);
+
/** The attributes of the form parameters. **/
private NamedNodeMap[] _parameters;
@@ -394,6 +413,9 @@
/** The parameters mapped to the type of data which they accept. **/
private Hashtable _dataTypes;
+ /** The parameters mapped to their number of occurrences as text parameters. **/
+ private Hashtable _textParameterCounts;
+
/** The submit buttons in this form. **/
private SubmitButton[] _submitButtons;
@@ -513,19 +535,26 @@
if (_dataTypes == null) {
NamedNodeMap[] parameters = getParameters();
Hashtable types = new Hashtable();
+ _textParameterCounts = new Hashtable();
for (int i = 0; i < parameters.length; i++) {
String name = getValue( parameters[i].getNamedItem( "name" ) );
String type = getValue( parameters[i].getNamedItem( "type" ) ).toUpperCase();
if (type == null || type.length() == 0) type = "TEXT";
- if (type.equals( "TEXT" ) || type.equals( "HIDDEN" ) || type.equals( "PASSWORD" )) {
- types.put( name, TYPE_TEXT );
- } else if (type.equals( "RADIO" )) {
+ if (type.equals( "RADIO" )) {
types.put( name, TYPE_SCALAR );
} else if (type.equals( "CHECKBOX" )) {
types.put( name, TYPE_MULTI_VALUED );
} else if (type.equals( "FILE" )) {
types.put( name, TYPE_FILE );
+ } else if (type.equals( "TEXT" ) || type.equals( "HIDDEN" ) || type.equals( "PASSWORD" )) {
+ types.put( name, TYPE_TEXT );
+ Integer oldCount = (Integer) _textParameterCounts.get( name );
+ if (oldCount == null) {
+ _textParameterCounts.put( name, ONE_PARAMETER );
+ } else {
+ _textParameterCounts.put( name, new Integer( oldCount.intValue() + 1 ) );
+ }
}
}
HTMLSelectElement[] selections = getSelections();
Index: WebRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- WebRequest.java 2001/10/19 18:26:29 1.25
+++ WebRequest.java 2001/10/19 19:16:57 1.26
@@ -497,7 +497,11 @@
private void validateParameterValues( String name, String[] values ) {
if (_sourceForm == null) return;
if (values.length > 1 && !_sourceForm.isMultiValuedParameter( name )) {
- throw new SingleValuedParameterException( name );
+ if (!_sourceForm.isTextParameter( name ) || _sourceForm.getNumTextParameters( name ) == 1) {
+ throw new SingleValuedParameterException( name );
+ } else if (values.length > _sourceForm.getNumTextParameters( name )) {
+ throw new TextParameterCountException( name, _sourceForm.getNumTextParameters( name ) );
+ }
}
for (int i = 0; i < values.length; i++) validateParameterValue( name, values[i] );
@@ -661,6 +665,29 @@
private String _parameterName;
+
+}
+
+
+/**
+ * This exception is thrown on an attempt to set a text parameter to more values than are allowed.
+ **/
+class TextParameterCountException extends IllegalRequestParameterException {
+
+
+ TextParameterCountException( String parameterName, int numAllowed ) {
+ _parameterName = parameterName;
+ _numAllowed = numAllowed;
+ }
+
+
+ public String getMessage() {
+ return "Parameter '" + _parameterName + "' may have no more than " + _numAllowed + " values.";
+ }
+
+
+ private String _parameterName;
+ private int _numAllowed;
}
|