[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit ScriptableObject.java,NONE,1.1 FormContro
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-04-08 18:40:30
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv5794/src/com/meterware/httpunit
Modified Files:
FormControl.java WebForm.java
Added Files:
ScriptableObject.java
Log Message:
Added hidden field scriptability
***** Error reading new file[Errno 2] No such file or directory: 'ScriptableObject.java'
Index: FormControl.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- FormControl.java 15 Mar 2002 17:23:25 -0000 1.9
+++ FormControl.java 8 Apr 2002 18:40:23 -0000 1.10
@@ -77,6 +77,14 @@
/**
+ * Returns a scriptable object which can act as a proxy for this control.
+ */
+ public ScriptableObject getScriptableObject() {
+ return new Scriptable();
+ }
+
+
+ /**
* Returns the values permitted in this control. Does not apply to text or file controls.
**/
public String[] getOptionValues() {
@@ -231,6 +239,19 @@
}
}
+
+ class Scriptable implements ScriptableObject {
+
+ public Object get( String propertyName ) {
+ throw new RuntimeException( "Unknown property: " + propertyName );
+ }
+
+
+ public void set( String propertyName, Object value ) {
+ throw new RuntimeException( "Unknown property: " + propertyName );
+ }
+ }
+
}
@@ -495,6 +516,11 @@
}
+ public ScriptableObject getScriptableObject() {
+ return new Scriptable();
+ }
+
+
void addValues( ParameterProcessor processor, String characterSet ) throws IOException {
if (getName().length() > 0) processor.addParameter( getName(), getValues()[0], characterSet );
}
@@ -523,6 +549,17 @@
protected void claimValueIsRequired( List values ) {
claimValueIsRequired( values, _defaultValue[0] );
+ }
+
+ class Scriptable extends FormControl.Scriptable {
+
+ public void set( String propertyName, Object value ) {
+ if (propertyName.equalsIgnoreCase( "value" )) {
+ _value[0] =_defaultValue[0] = value.toString();
+ } else {
+ super.set( propertyName, value );
+ }
+ }
}
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- WebForm.java 14 Mar 2002 22:18:26 -0000 1.48
+++ WebForm.java 8 Apr 2002 18:40:23 -0000 1.49
@@ -276,8 +276,8 @@
/**
* Returns an object which provides scripting access to this form.
**/
- public ScriptableObject getScriptableObject() {
- return new ScriptableObject();
+ public Scriptable getScriptableObject() {
+ return new Scriptable();
}
//---------------------------------- WebRequestSource methods --------------------------------
@@ -400,9 +400,17 @@
}
- public class ScriptableObject {
+ public class Scriptable implements ScriptableObject {
public String getAction() { return WebForm.this.getAction(); }
public void setAction( String newAction ) { _action = newAction; }
+
+ public void setParameterValue( String name, String value ) {
+ getParameter( name ).getScriptableObject().set( "value", value );
+ }
+
+
+ public void set( String propertyName, Object value ) {}
+ public Object get( String propertyName ) { return null; }
}
@@ -442,6 +450,11 @@
private String _action;
+ private Object getObject( String name ) {
+ return getParameter( name ).getScriptableObject();
+ }
+
+
private SubmitButton getDefaultButton() {
if (getSubmitButtons().length == 1) {
return getSubmitButtons()[0];
@@ -562,6 +575,11 @@
private FormControl[] getControls() {
if (_controls == null) _controls = (FormControl[]) _controlList.toArray( new FormControl[ _controlList.size() ] );
return _controls;
+ }
+
+
+ ScriptableObject getScriptableObject() {
+ return getControls()[0].getScriptableObject();
}
|