[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit Button.java,1.4,1.5 FormControl.java,1.35
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-02-17 23:55:16
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv28955/src/com/meterware/httpunit
Modified Files:
Button.java FormControl.java ResetButton.java
SubmitButton.java WebForm.java
Log Message:
#680695: Support form control ids and Button.click()
Index: Button.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/Button.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Button.java 26 Dec 2002 18:55:18 -0000 1.4
+++ Button.java 17 Feb 2003 23:54:40 -0000 1.5
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2002, Russell Gold
+ * Copyright (c) 2002-2003, 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
@@ -19,6 +19,8 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import com.meterware.httpunit.scripting.ScriptableDelegate;
+
import java.io.IOException;
import org.w3c.dom.Node;
@@ -27,7 +29,7 @@
/**
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class Button extends FormControl {
@@ -54,11 +56,11 @@
/**
- * Performs the action associated with clicking this button. For a submit button this typically
- * submits the form.
+ * Performs the action associated with clicking this button after running any 'onClick' script.
+ * For a submit button this typically submits the form.
*/
- public void click() throws IOException, SAXException {
- doOnClickEvent();
+ public void click() throws IOException, SAXException {
+ if (doOnClickEvent()) doButtonAction();
}
@@ -68,6 +70,12 @@
}
+ /**
+ * Perform the normal action of this button.
+ */
+ protected void doButtonAction() throws IOException, SAXException {}
+
+
//-------------------------------------------------- FormControl methods -----------------------------------------------
@@ -79,4 +87,16 @@
void addValues( ParameterProcessor processor, String characterSet ) throws IOException {
}
+
+ protected ScriptableDelegate newScriptable() {
+ return new Scriptable();
+ }
+
+
+ class Scriptable extends FormControl.Scriptable {
+
+ public void click() throws IOException, SAXException {
+ doButtonAction();
+ }
+ }
}
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- FormControl.java 6 Feb 2003 02:55:58 -0000 1.35
+++ FormControl.java 17 Feb 2003 23:54:40 -0000 1.36
@@ -25,6 +25,7 @@
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
import java.util.Hashtable;
import java.util.ArrayList;
@@ -315,6 +316,11 @@
}
+ public Scriptable() {
+ super( FormControl.this );
+ }
+
+
public Object get( String propertyName ) {
if (propertyName.equalsIgnoreCase( "name" )) {
return FormControl.this.getName();
@@ -333,8 +339,7 @@
}
- public Scriptable() {
- super( FormControl.this );
+ public void click() throws IOException, SAXException {
}
}
Index: ResetButton.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ResetButton.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ResetButton.java 26 Dec 2002 18:55:18 -0000 1.2
+++ ResetButton.java 17 Feb 2003 23:54:41 -0000 1.3
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2002, Russell Gold
+ * Copyright (c) 2002-2003, 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
@@ -19,10 +19,7 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import java.io.IOException;
-
import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
/**
@@ -38,11 +35,7 @@
}
- /**
- * Performs the action associated with clicking this button. For a submit button this typically
- * submits the form.
- */
- public void click() throws IOException, SAXException {
- if (doOnClickEvent()) getForm().reset();
+ protected void doButtonAction() {
+ getForm().reset();
}
}
Index: SubmitButton.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/SubmitButton.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- SubmitButton.java 17 Feb 2003 03:17:05 -0000 1.14
+++ SubmitButton.java 17 Feb 2003 23:54:41 -0000 1.15
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, 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
@@ -37,14 +37,13 @@
}
-//--------------------------------- FormButton methods ----------------------------------------------
+//--------------------------------- Button methods ----------------------------------------------
/**
- * Performs the action associated with clicking this button. For a submit button this typically
- * submits the form.
+ * Perform the normal action of this button.
*/
- public void click() throws IOException, SAXException {
+ protected void doButtonAction() throws IOException, SAXException {
getForm().submit( this );
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -r1.77 -r1.78
--- WebForm.java 17 Feb 2003 03:17:05 -0000 1.77
+++ WebForm.java 17 Feb 2003 23:54:41 -0000 1.78
@@ -56,14 +56,13 @@
/**
* Submits this form using the web client from which it was originally obtained.
- * Will usually return the result of that submission; however, if a scripted event is triggered which
- * inhibits the submission, will return the updated contents of the frame containing this form.
+ * Will usually return the result of that submission; however, if the 'onsubmit' event is triggered and
+ * inhibits the submission, will return the updated contents of the frame containing this form. Note that
+ * this will not run any event associated with the specified submit button. Use SubmitButton#click for that.
**/
public WebResponse submit( SubmitButton button ) throws IOException, SAXException {
- if (button.doOnClickEvent()) {
- String event = getAttribute( "onsubmit" );
- if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest( getRequest( button ) );
- }
+ String event = getAttribute( "onsubmit" );
+ if (event.length() == 0 || getScriptableObject().doEvent( event )) return submitRequest( getRequest( button ) );
return getBaseResponse().getWindow().getFrameContents( getTarget() );
}
@@ -546,7 +545,9 @@
return getTarget();
} else {
final FormParameter parameter = getParameter( propertyName );
- return parameter == UNKNOWN_PARAMETER ? super.get( propertyName ) : parameter.getScriptableObject();
+ if (parameter != UNKNOWN_PARAMETER) return parameter.getScriptableObject();
+ FormControl control = getControlWithID( propertyName );
+ return control == null ? super.get( propertyName ) : control.getScriptableDelegate();
}
}
@@ -599,6 +600,19 @@
WebForm( WebResponse response, URL baseURL, String frameName, Node node, String characterSet ) {
super( response, node, baseURL, NodeUtils.getNodeAttribute( node, "action" ), frameName );
_characterSet = characterSet;
+ }
+
+
+ /**
+ * Returns the form control which is part of this form with the specified ID.
+ */
+ FormControl getControlWithID( String id ) {
+ FormControl[] controls = getFormControls();
+ for (int i = 0; i < controls.length; i++) {
+ FormControl control = controls[i];
+ if (control.getID().equals(id)) return control;
+ }
+ return null;
}
|