[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HTMLPage.java,1.3,1.4 ParsedHTML.java,1.2
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-08-05 17:34:28
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv19892/src/com/meterware/httpunit Modified Files: HTMLPage.java ParsedHTML.java WebImage.java WebResponse.java Log Message: Added support for Javascript image object Index: HTMLPage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- HTMLPage.java 2 Aug 2002 16:26:15 -0000 1.3 +++ HTMLPage.java 5 Aug 2002 17:34:25 -0000 1.4 @@ -137,6 +137,9 @@ WebLink wl = getLinkWithName( propertyName ); if (wl != null) return wl.getScriptableObject(); + WebImage wi = getImageWithName( propertyName ); + if (wi != null) return wi.getScriptableObject(); + return super.get( propertyName ); } @@ -161,6 +164,16 @@ WebForm.Scriptable[] result = new WebForm.Scriptable[ forms.length ]; for (int i = 0; i < forms.length; i++) { result[i] = forms[i].getScriptableObject(); + } + return result; + } + + + public WebImage.Scriptable[] getImages() { + WebImage[] images = HTMLPage.this.getImages(); + WebImage.Scriptable[] result = new WebImage.Scriptable[ images.length ]; + for (int i = 0; i < images.length; i++) { + result[i] = images[i].getScriptableObject(); } return result; } Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- ParsedHTML.java 5 Aug 2002 15:21:19 -0000 1.23 +++ ParsedHTML.java 5 Aug 2002 17:34:25 -0000 1.24 @@ -197,6 +197,19 @@ /** + * Returns the image found in the page with the specified name. + **/ + public WebImage getImageWithName( String name ) { + WebImage[] images = getImages(); + for (int i = 0; i < images.length; i++) { + if (images[i].getName().equals( name )) return images[i]; + else if (HttpUnitOptions.getMatchesIgnoreCase() && images[i].getName().equalsIgnoreCase( name )) return images[i]; + } + return null; + } + + + /** * Returns the image found in the page with the specified src attribute. **/ public WebImage getImageWithSource( String source ) { Index: WebImage.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebImage.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- WebImage.java 15 Jul 2002 14:30:32 -0000 1.1 +++ WebImage.java 5 Aug 2002 17:34:25 -0000 1.2 @@ -33,17 +33,25 @@ private URL _baseURL; private Node _node; private ParsedHTML _parsedHTML; + private Scriptable _scriptable; + private String _src; WebImage( ParsedHTML parsedHTML, URL baseURL, Node node ) { _baseURL = baseURL; _node = node; _parsedHTML = parsedHTML; + _src = NodeUtils.getNodeAttribute( _node, "src" ); + } + + + public String getName() { + return NodeUtils.getNodeAttribute( _node, "name" ); } public String getSource() { - return NodeUtils.getNodeAttribute( _node, "src" ); + return _src; } @@ -58,4 +66,36 @@ } } ); } + + + /** + * Returns an object which provides scripting access to this link. + **/ + public Scriptable getScriptableObject() { + if (_scriptable == null) _scriptable = new Scriptable(); + return _scriptable; + } + + + public class Scriptable extends ScriptableObject { + + public Object get( String propertyName ) { + if (propertyName.equalsIgnoreCase( "src" )) { + return getSource(); + } else { + return super.get( propertyName ); + } + } + + + public void set( String propertyName, Object value ) { + if (propertyName.equalsIgnoreCase( "src" )) { + if (value != null) _src = value.toString(); + } else { + super.set( propertyName, value ); + } + } + } + + } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.70 retrieving revision 1.71 diff -u -r1.70 -r1.71 --- WebResponse.java 1 Aug 2002 14:58:59 -0000 1.70 +++ WebResponse.java 5 Aug 2002 17:34:25 -0000 1.71 @@ -370,6 +370,15 @@ /** + * Returns the image found in the page with the specified name attribute. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebImage getImageWithName( String source ) throws SAXException { + return getReceivedPage().getImageWithName( source ); + } + + + /** * Returns the image found in the page with the specified src attribute. * @exception SAXException thrown if there is an error parsing the response. **/ |