[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit FormControl.java,1.15,1.16 HTMLPage.java,
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-08-08 20:47:26
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv16831/src/com/meterware/httpunit Modified Files: FormControl.java HTMLPage.java HttpUnitOptions.java WebForm.java WebImage.java WebLink.java WebResponse.java Removed Files: ScriptEngine.java ScriptableObject.java ScriptingEngineFactory.java Log Message: Class renaming, added support for Option constructor and options property writing Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- FormControl.java 7 Aug 2002 20:36:23 -0000 1.15 +++ FormControl.java 8 Aug 2002 20:47:21 -0000 1.16 @@ -21,6 +21,7 @@ *******************************************************************************************************************/ import com.meterware.httpunit.scripting.SelectionOptions; import com.meterware.httpunit.scripting.SelectionOption; +import com.meterware.httpunit.scripting.ScriptableDelegate; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -82,7 +83,7 @@ /** * Returns a scriptable object which can act as a proxy for this control. */ - public ScriptableObject getScriptableObject() { + public ScriptableDelegate getScriptableObject() { return new Scriptable(); } @@ -243,7 +244,7 @@ } - class Scriptable extends ScriptableObject { + class Scriptable extends ScriptableDelegate { } } @@ -452,7 +453,7 @@ } - public ScriptableObject getScriptableObject() { + public ScriptableDelegate getScriptableObject() { return new Scriptable(); } @@ -536,7 +537,7 @@ } - public ScriptableObject getScriptableObject() { + public ScriptableDelegate getScriptableObject() { return new Scriptable(); } @@ -750,7 +751,7 @@ } - public ScriptableObject getScriptableObject() { + public ScriptableDelegate getScriptableObject() { if (_scriptable == null) _scriptable = new Scriptable(); return _scriptable; } @@ -778,7 +779,7 @@ } - class Option extends ScriptableObject implements SelectionOption { + static class Option extends ScriptableDelegate implements SelectionOption { private String _text; private String _value; @@ -787,6 +788,10 @@ private int _index; + Option() { + } + + Option( String text, String value, boolean selected ) { _text = text; _value = value; @@ -812,6 +817,14 @@ //------------------------- SelectionOption methods ------------------------------ + public void initialize( String text, String value, boolean defaultSelected, boolean selected ) { + _text = text; + _value = value; + _defaultSelected = defaultSelected; + _selected = selected; + } + + public int getIndex() { return _index; } @@ -822,6 +835,11 @@ } + public void setText( String text ) { + _text = text; + } + + public String getValue() { return _value; } @@ -848,13 +866,10 @@ } - class Options extends ScriptableObject implements SelectionOptions { + class Options extends ScriptableDelegate implements SelectionOptions { private Option[] _options; - private String[] _text; - private String[] _value; - Options( Node selectionNode ) { NodeList nl = ((Element) selectionNode).getElementsByTagName( "option" ); @@ -905,20 +920,16 @@ String[] getDisplayedText() { - if (_text == null) { - _text = new String[ _options.length ]; - for (int i = 0; i < _text.length; i++) _text[i] = _options[i].getText(); - } - return _text; + String[] displayedText = new String[ _options.length ]; + for (int i = 0; i < displayedText.length; i++) displayedText[i] = _options[i].getText(); + return displayedText; } String[] getValues() { - if (_value == null) { - _value = new String[ _options.length ]; - for (int i = 0; i < _value.length; i++) _value[i] = _options[i].getValue(); - } - return _value; + String[] values = new String[ _options.length ]; + for (int i = 0; i < values.length; i++) values[i] = _options[i].getValue(); + return values; } @@ -935,6 +946,46 @@ public int getLength() { return _options.length; + } + + + public void setLength( int length ) { + if (length < 0 || length >= _options.length) return; + Option[] newArray = new Option[ length ]; + System.arraycopy( _options, 0, newArray, 0, length ); + _options = newArray; + } + + + public void put( int i, SelectionOption option ) { + if (i < 0) return; + + if (option == null) { + if (i >= _options.length) return; + deleteOptionsEntry( i ); + } else { + if (i >= _options.length) { + i = _options.length; + expandOptionsArray(); + } + _options[i] = (Option) option; + _options[i].setIndex(i); + } + } + + + private void deleteOptionsEntry( int i ) { + Option[] newArray = new Option[ _options.length-1 ]; + System.arraycopy( _options, 0, newArray, 0, i ); + System.arraycopy( _options, i+1, newArray, i, newArray.length - i ); + _options = newArray; + } + + + private void expandOptionsArray() { + Option[] newArray = new Option[ _options.length+1 ]; + System.arraycopy( _options, 0, newArray, 0, _options.length ); + _options = newArray; } Index: HTMLPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- HTMLPage.java 6 Aug 2002 21:42:08 -0000 1.5 +++ HTMLPage.java 8 Aug 2002 20:47:21 -0000 1.6 @@ -19,6 +19,8 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptableDelegate; + import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; @@ -127,7 +129,7 @@ } - public class Scriptable extends ScriptableObject { + public class Scriptable extends ScriptableDelegate { public Object get( String propertyName ) { WebForm wf = getFormWithName( propertyName ); Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- HttpUnitOptions.java 5 Aug 2002 18:58:43 -0000 1.22 +++ HttpUnitOptions.java 8 Aug 2002 20:47:21 -0000 1.23 @@ -20,6 +20,8 @@ * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptingEngineFactory; + import java.util.Vector; /** Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- WebForm.java 6 Aug 2002 19:14:55 -0000 1.54 +++ WebForm.java 8 Aug 2002 20:47:21 -0000 1.55 @@ -19,6 +19,8 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptableDelegate; + import java.io.IOException; import java.net.URL; @@ -411,7 +413,7 @@ } - public class Scriptable extends ScriptableObject { + public class Scriptable extends ScriptableDelegate { public String getAction() { return WebForm.this.getAction(); } public void setAction( String newAction ) { setDestination( newAction ); } @@ -593,7 +595,7 @@ } - ScriptableObject getScriptableObject() { + ScriptableDelegate getScriptableObject() { return getControls()[0].getScriptableObject(); } Index: WebImage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebImage.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- WebImage.java 5 Aug 2002 17:34:25 -0000 1.2 +++ WebImage.java 8 Aug 2002 20:47:21 -0000 1.3 @@ -19,6 +19,8 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptableDelegate; + import java.net.URL; import org.w3c.dom.Node; @@ -77,7 +79,7 @@ } - public class Scriptable extends ScriptableObject { + public class Scriptable extends ScriptableDelegate { public Object get( String propertyName ) { if (propertyName.equalsIgnoreCase( "src" )) { Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- WebLink.java 6 Aug 2002 19:14:56 -0000 1.23 +++ WebLink.java 8 Aug 2002 20:47:21 -0000 1.24 @@ -19,6 +19,8 @@ * DEALINGS IN THE SOFTWARE. * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptableDelegate; + import java.net.URL; import java.net.MalformedURLException; @@ -230,7 +232,7 @@ } - public class Scriptable extends ScriptableObject { + public class Scriptable extends ScriptableDelegate { public Object get( String propertyName ) { if (propertyName.equalsIgnoreCase( "href" )) { Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.72 retrieving revision 1.73 diff -u -r1.72 -r1.73 --- WebResponse.java 6 Aug 2002 19:14:57 -0000 1.72 +++ WebResponse.java 8 Aug 2002 20:47:21 -0000 1.73 @@ -20,6 +20,8 @@ * *******************************************************************************************************************/ +import com.meterware.httpunit.scripting.ScriptableDelegate; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -488,7 +490,16 @@ } - public class Scriptable extends ScriptableObject { + public static ScriptableDelegate newDelegate( String delegateClassName ) { + if (delegateClassName.equalsIgnoreCase( "Option" )) { + return new SelectionFormControl.Option(); + } else { + throw new IllegalArgumentException( "No such scripting class supported: " + delegateClassName ); + } + } + + + public class Scriptable extends ScriptableDelegate { public void alert( String message ) { _alerts.addLast( message ); |