[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit WebImage.java,NONE,1.1 ParsedHTML.java,1.
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-07-15 14:30:36
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv4133/src/com/meterware/httpunit Modified Files: ParsedHTML.java WebResponse.java Added Files: WebImage.java Log Message: Added web image support ***** Error reading new file[Errno 2] No such file or directory: 'WebImage.java' Index: ParsedHTML.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- ParsedHTML.java 14 May 2002 19:31:04 -0000 1.20 +++ ParsedHTML.java 15 Jul 2002 14:30:32 -0000 1.21 @@ -32,6 +32,7 @@ class ParsedHTML { private WebForm[] _forms; + private WebImage[] _images; ParsedHTML( URL baseURL, String baseTarget, Node rootNode, String characterSet ) { @@ -174,6 +175,35 @@ /** + * Returns the images found in the page in the order in which they appear. + **/ + public WebImage[] getImages() { + if (_images == null) { + NodeList images = NodeUtils.getElementsByTagName( _rootNode, "img" ); + + _images = new WebImage[ images.getLength() ]; + for (int i = 0; i < _images.length; i++) { + _images[i] = new WebImage( this, _baseURL, images.item( i ) ); + } + } + return _images; + } + + + /** + * Returns the image found in the page with the specified src attribute. + **/ + public WebImage getImageWithSource( String source ) { + WebImage[] images = getImages(); + for (int i = 0; i < images.length; i++) { + if (images[i].getSource().equals( source )) return images[i]; + else if (HttpUnitOptions.getMatchesIgnoreCase() && images[i].getSource().equalsIgnoreCase( source )) return images[i]; + } + return null; + } + + + /** * Returns the top-level tables found in this page in the order in which * they appear. **/ @@ -299,6 +329,20 @@ interface TablePredicate { public boolean isTrue( WebTable table ); + } + + + interface LinkPredicate { + public boolean isTrue( WebLink link ); + } + + + WebLink getLinkSatisfyingPredicate( LinkPredicate predicate ) { + WebLink[] links = getLinks(); + for (int i = 0; i < links.length; i++) { + if (predicate.isTrue( links[ i ] )) return links[ i ]; + } + return null; } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.66 retrieving revision 1.67 diff -u -r1.66 -r1.67 --- WebResponse.java 17 Jun 2002 21:22:05 -0000 1.66 +++ WebResponse.java 15 Jul 2002 14:30:32 -0000 1.67 @@ -360,6 +360,24 @@ /** + * Returns the images found in the page in the order in which they appear. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebImage[] getImages() throws SAXException { + return getReceivedPage().getImages(); + } + + + /** + * Returns the image found in the page with the specified src attribute. + * @exception SAXException thrown if there is an error parsing the response. + **/ + public WebImage getImageWithSource( String source ) throws SAXException { + return getReceivedPage().getImageWithSource( source ); + } + + + /** * Returns the top-level tables found in this page in the order in which * they appear. * @exception SAXException thrown if there is an error parsing the response. |