[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit/javascript JavaScript.java,1.6,1.7
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-08-07 20:36:27
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript In directory usw-pr-cvs1:/tmp/cvs-serv31870/src/com/meterware/httpunit/javascript Modified Files: JavaScript.java Log Message: Added JavaScript support for Select and Option Index: JavaScript.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- JavaScript.java 6 Aug 2002 19:14:59 -0000 1.6 +++ JavaScript.java 7 Aug 2002 20:36:24 -0000 1.7 @@ -25,6 +25,8 @@ import com.meterware.httpunit.WebResponse; import com.meterware.httpunit.WebLink; import com.meterware.httpunit.WebImage; +import com.meterware.httpunit.scripting.SelectionOptions; +import com.meterware.httpunit.scripting.SelectionOption; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; @@ -66,6 +68,8 @@ ScriptableObject.defineClass( scope, Control.class ); ScriptableObject.defineClass( scope, Link.class ); ScriptableObject.defineClass( scope, Image.class ); + ScriptableObject.defineClass( scope, Options.class ); + ScriptableObject.defineClass( scope, Option.class ); } @@ -115,7 +119,21 @@ if (result != NOT_FOUND) return result; if (_scriptable == null) return NOT_FOUND; - final Object property = _scriptable.get( propertyName ); + return convertIfNeeded( _scriptable.get( propertyName ) ); + + } + + + public Object get( int i, Scriptable scriptable ) { + Object result = super.get( i, scriptable ); + if (result != NOT_FOUND) return result; + if (_scriptable == null) return NOT_FOUND; + + return convertIfNeeded( _scriptable.get( i ) ); + } + + + private Object convertIfNeeded( final Object property ) { if (property == null) return NOT_FOUND; if (!(property instanceof com.meterware.httpunit.ScriptableObject)) return property; @@ -358,6 +376,22 @@ return control; } + + public String jsGet_action() { + return getDelegate().getAction(); + } + + + public void jsSet_action( String action ) { + getDelegate().setAction( action ); + } + + + + private WebForm.Scriptable getDelegate() { + return (WebForm.Scriptable) _scriptable; + } + } @@ -366,6 +400,98 @@ public String getClassName() { return "Control"; } + + + Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { + JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( delegate ) ); + element.initialize( this, delegate ); + return element; + } + + + private String getScriptableClassName( com.meterware.httpunit.ScriptableObject delegate ) { + if (delegate instanceof SelectionOptions) { + return "Options"; + } else { + throw new IllegalArgumentException( "Unknown ScriptableObject class: " + delegate.getClass() ); + } + } + } + + static public class Options extends JavaScriptEngine { + + public String getClassName() { + return "Options"; + } + + + public int jsGet_length() { + return getDelegate().getLength(); + } + + + private SelectionOptions getDelegate() { + return (SelectionOptions) _scriptable; + } + + + Scriptable toScriptable( com.meterware.httpunit.ScriptableObject delegate ) + throws PropertyException, JavaScriptException, NotAFunctionException, SAXException { + JavaScriptEngine element = (JavaScriptEngine) Context.getCurrentContext().newObject( this, "Option" ); + element.initialize( this, delegate ); + return element; + } + + } + + + static public class Option extends JavaScriptEngine { + + public String getClassName() { + return "Option"; + } + + + public int jsGet_index() { + return getDelegate().getIndex(); + } + + + public String jsGet_text() { + return getDelegate().getText(); + } + + + public String jsGet_value() { + return getDelegate().getValue(); + } + + + public void jsSet_value( String value ) { + getDelegate().setValue( value ); + } + + + public boolean jsGet_selected() { + return getDelegate().isSelected(); + } + + + public void jsSet_selected( boolean selected ) { + getDelegate().setSelected( selected ); + } + + + public boolean jsGet_defaultSelected() { + return getDelegate().isDefaultSelected(); + } + + + private SelectionOption getDelegate() { + return (SelectionOption) _scriptable; + } + } } |