[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit WebFrame.java,1.2,1.3 HttpUnitOptions.jav
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2000-10-11 19:15:17
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv2316/src/com/meterware/httpunit Modified Files: HttpUnitOptions.java WebConversation.java WebRequest.java WebResponse.java Added Files: WebFrame.java Log Message: Support unnamed frames, controlled logging of headers Index: HttpUnitOptions.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HttpUnitOptions.java 2000/10/02 16:32:10 1.2 +++ HttpUnitOptions.java 2000/10/11 19:15:11 1.3 @@ -80,6 +80,22 @@ } + /** + * Returns true if HTTP headers are to be dumped to system output. + **/ + public static boolean isLoggingHttpHeaders() { + return _loggingHttpHeaders; + } + + + /** + * If true, tells HttpUnit to log HTTP headers to system output. The default is false. + **/ + public static void setLoggingHttpHeaders( boolean enabled ) { + _loggingHttpHeaders = enabled; + } + + //--------------------------------- private members -------------------------------------- @@ -88,6 +104,8 @@ private static boolean _parameterValuesValidated = true; private static boolean _imagesTreatedAsAltText; + + private static boolean _loggingHttpHeaders; } Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- WebConversation.java 2000/10/06 18:38:54 1.14 +++ WebConversation.java 2000/10/11 19:15:11 1.15 @@ -245,6 +245,9 @@ for (int i = 1; true; i++) { String key = connection.getHeaderFieldKey( i ); if (key == null) break; + if (HttpUnitOptions.isLoggingHttpHeaders()) { + System.out.println( "Header:: " + connection.getHeaderFieldKey( i ) + ": " + connection.getHeaderField(i) ); + } if (!key.equalsIgnoreCase( "Set-Cookie" )) continue; StringTokenizer st = new StringTokenizer( connection.getHeaderField( i ), "=;" ); String name = st.nextToken(); Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebRequest.java 2000/10/02 16:31:36 1.7 +++ WebRequest.java 2000/10/11 19:15:11 1.8 @@ -246,10 +246,12 @@ private void validateProtocol( String urlString ) { - String protocol = urlString.substring( 0, urlString.indexOf( ':' ) ); - if (protocol.length() == 0) { + if (urlString.indexOf(':') <= 0) { throw new RuntimeException( "No protocol specified in URL '" + urlString + "'" ); - } else if (protocol.equalsIgnoreCase( "http" )) { + } + + String protocol = urlString.substring( 0, urlString.indexOf( ':' ) ); + if (protocol.equalsIgnoreCase( "http" )) { return; } else if (protocol.equalsIgnoreCase( "https" )) { validateHttpsProtocolSupport(); Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- WebResponse.java 2000/10/06 18:38:54 1.18 +++ WebResponse.java 2000/10/11 19:15:11 1.19 @@ -84,10 +84,10 @@ * Returns the names of the frames found in the page in the order in which they appear. **/ public String[] getFrameNames() throws SAXException { - NodeList frames = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); - String[] result = new String[ frames.getLength() ]; + WebFrame[] frames = getFrames(); + String[] result = new String[ frames.length ]; for (int i = 0; i < result.length; i++) { - result[i] = NodeUtils.getNodeAttribute( frames.item(i), "name" ); + result[i] = frames[i].getName(); } return result; @@ -95,26 +95,6 @@ /** - * Returns the frames found in the page in the order in which they appear. - **/ - public WebRequest[] getFrameRequests() throws SAXException { - NodeList frames = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); - Vector requests = new Vector(); - for (int i = 0; i < frames.getLength(); i++) { - if (NodeUtils.getNodeAttribute( frames.item(i), "src" ).length() > 0) { - requests.addElement( new GetMethodWebRequest( getReceivedPage().getBaseURL(), - NodeUtils.getNodeAttribute( frames.item(i), "src" ), - NodeUtils.getNodeAttribute( frames.item(i), "name" ) ) ); - } - } - - WebRequest[] result = new WebRequest[ requests.size() ]; - requests.copyInto( result ); - return result; - } - - - /** * Returns the forms found in the page in the order in which they appear. * @exception SAXException thrown if there is an error parsing the response. **/ @@ -232,6 +212,24 @@ } + /** + * Returns the frames found in the page in the order in which they appear. + **/ + WebRequest[] getFrameRequests() throws SAXException { + WebFrame[] frames = getFrames(); + Vector requests = new Vector(); + for (int i = 0; i < frames.length; i++) { + if (frames[i].hasInitialRequest()) { + requests.addElement( frames[i].getInitialRequest() ); + } + } + + WebRequest[] result = new WebRequest[ requests.size() ]; + requests.copyInto( result ); + return result; + } + + //--------------------------------- private members -------------------------------------- @@ -241,6 +239,8 @@ final private static String HTML_CONTENT = "text/html"; + private WebFrame[] _frames; + private ReceivedPage _page; private String _responseText; @@ -293,6 +293,22 @@ } catch (IOException e) { throw new RuntimeException( "Unable to retrieve data from URL: " + url.toExternalForm() + " (" + e + ")" ); } + } + + + private WebFrame[] getFrames() throws SAXException { + if (_frames == null) { + NodeList nl = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); + Vector list = new Vector(); + for (int i = 0; i < nl.getLength(); i++) { + Node child = nl.item(i); + list.addElement( new WebFrame( getReceivedPage().getBaseURL(), child ) ); + } + _frames = new WebFrame[ list.size() ]; + list.copyInto( _frames ); + } + + return _frames; } |