[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit SubmitButton.java,1.9,1.10 WebForm.java,1
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-08-13 17:57:50
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv25269/src/com/meterware/httpunit
Modified Files:
SubmitButton.java WebForm.java WebRequestSource.java
Log Message:
Added Button.submit to submit a form from a button
Index: SubmitButton.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SubmitButton.java 25 Mar 2002 05:07:29 -0000 1.9
+++ SubmitButton.java 13 Aug 2002 17:57:47 -0000 1.10
@@ -22,6 +22,7 @@
import java.io.IOException;
import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
/**
* This class represents a submit button in an HTML form.
@@ -29,7 +30,7 @@
public class SubmitButton extends FormControl {
- public static SubmitButton UNNAMED_BUTTON = new SubmitButton();
+// public static SubmitButton UNNAMED_BUTTON = new SubmitButton();
/**
@@ -50,6 +51,15 @@
/**
+ * Performs the action associated with clicking this button. For a submit button this typically
+ * submits the form.
+ */
+ public void click() throws IOException, SAXException {
+ _form.submit( this );
+ }
+
+
+ /**
* Returns true if this submit button is an image map.
**/
public boolean isImageButton() {
@@ -102,17 +112,25 @@
SubmitButton( WebForm form, Node node ) {
super( node );
+ _form = form;
_isImageButton = NodeUtils.getNodeAttribute( node, "type" ).equalsIgnoreCase( "image" );
_id = NodeUtils.getNodeAttribute( node, "id" );
}
- public void setPressed( boolean pressed ) {
+ SubmitButton( WebForm form ) {
+ _form = form;
+ _id = "";
+ _isImageButton = false;
+ }
+
+
+ void setPressed( boolean pressed ) {
_pressed = pressed;
}
- public void setLocation( int x, int y ) {
+ void setLocation( int x, int y ) {
_x = x;
_y = y;
}
@@ -120,19 +138,13 @@
//------------------------------------------ private members ----------------------------------
-
+ private final WebForm _form;
private final String _id;
private final boolean _isImageButton;
private boolean _pressed;
private int _x;
private int _y;
private String[] _value = new String[1];
-
-
- private SubmitButton() {
- _id = "";
- _isImageButton = false;
- }
private String[] toArray( String value ) {
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- WebForm.java 8 Aug 2002 20:47:21 -0000 1.55
+++ WebForm.java 13 Aug 2002 17:57:47 -0000 1.56
@@ -49,8 +49,16 @@
* Submits this form using the web client from which it was originally obtained.
**/
public WebResponse submit() throws IOException, SAXException {
+ return submit( getDefaultButton() );
+ }
+
+
+ /**
+ * Submits this form using the web client from which it was originally obtained.
+ **/
+ WebResponse submit( SubmitButton button ) throws IOException, SAXException {
String event = NodeUtils.getNodeAttribute( getNode(), "onsubmit" );
- if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest();
+ if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest( getRequest( button ) );
return getBaseResponse();
}
@@ -475,10 +483,8 @@
private SubmitButton getDefaultButton() {
if (getSubmitButtons().length == 1) {
return getSubmitButtons()[0];
- } else if (getSubmitButtonVector().contains( SubmitButton.UNNAMED_BUTTON )) {
- return getSubmitButton( "" );
} else {
- return null;
+ return getSubmitButton( "" );
}
}
@@ -492,7 +498,7 @@
if (control instanceof SubmitButton) _buttonVector.add( control );
}
- if (_buttonVector.isEmpty()) _buttonVector.addElement( SubmitButton.UNNAMED_BUTTON );
+ if (_buttonVector.isEmpty()) _buttonVector.addElement( new SubmitButton( this ) );
}
return _buttonVector;
}
Index: WebRequestSource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- WebRequestSource.java 6 Aug 2002 19:14:56 -0000 1.11
+++ WebRequestSource.java 13 Aug 2002 17:57:47 -0000 1.12
@@ -174,9 +174,18 @@
**/
final
protected WebResponse submitRequest() throws IOException, SAXException {
+ return submitRequest( getRequest() );
+ }
+
+
+ /**
+ * Submits a request to the web client from which this request source was originally obtained.
+ **/
+ final
+ protected WebResponse submitRequest( WebRequest request ) throws IOException, SAXException {
return getDestination().equals( "#" )
? _baseResponse
- : _baseResponse.getClient().sendRequest( getRequest() );
+ : _baseResponse.getClient().sendRequest( request );
}
|