[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit ClientProperties.java,1.3,1.4 HTMLPage.ja
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-02-04 05:32:06
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv6354/src/com/meterware/httpunit
Modified Files:
ClientProperties.java HTMLPage.java NodeUtils.java
ParsedHTML.java TableCell.java WebApplet.java WebFrame.java
WebResponse.java WebTable.java
Log Message:
Added IFRAME support
Index: ClientProperties.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ClientProperties.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ClientProperties.java 8 Oct 2002 14:36:00 -0000 1.3
+++ ClientProperties.java 4 Feb 2003 05:32:03 -0000 1.4
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2002, Russell Gold
+ * Copyright (c) 2002-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -23,7 +23,7 @@
/**
* A class which represents the properties of a web client.
*
- * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class ClientProperties {
@@ -129,6 +129,16 @@
}
+ public boolean isIframeSupported() {
+ return _iframeSupported;
+ }
+
+
+ public void setIframeSupported( boolean iframeSupported ) {
+ _iframeSupported = iframeSupported;
+ }
+
+
static ClientProperties cloneProperties() {
return new ClientProperties( getDefaultProperties() );
}
@@ -142,6 +152,8 @@
private int _availWidth = 800;
private int _availHeight = 600;
+ private boolean _iframeSupported = true;
+
private static ClientProperties _defaultProperties = new ClientProperties();
@@ -155,5 +167,6 @@
_applicationVersion = source._applicationVersion;
_userAgent = source._userAgent;
_platform = source._platform;
+ _iframeSupported = source._iframeSupported;
}
}
Index: HTMLPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- HTMLPage.java 10 Jan 2003 18:21:44 -0000 1.23
+++ HTMLPage.java 4 Feb 2003 05:32:03 -0000 1.24
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -46,8 +46,8 @@
private Scriptable _scriptable;
- HTMLPage( WebResponse response, URL baseURL, String baseTarget, String characterSet ) throws IOException, SAXException {
- super( response, baseURL, baseTarget, null, characterSet );
+ HTMLPage( WebResponse response, String frameName, URL baseURL, String baseTarget, String characterSet ) throws IOException, SAXException {
+ super( response, frameName, baseURL, baseTarget, null, characterSet );
}
Index: NodeUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- NodeUtils.java 26 Dec 2002 15:33:56 -0000 1.17
+++ NodeUtils.java 4 Feb 2003 05:32:03 -0000 1.18
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -19,7 +19,6 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -35,17 +34,6 @@
* Some common utilities for manipulating DOM nodes.
**/
class NodeUtils {
-
-
- public static NodeList getElementsByTagName( Node root, String tagName ) {
- if (root instanceof Document) {
- return ((Document) root).getElementsByTagName( tagName );
- } else if (root instanceof Element) {
- return ((Element) root).getElementsByTagName( tagName );
- } else {
- throw new RuntimeException( "root is neither an Element nor a Document" );
- }
- }
public static int getAttributeValue( Node node, String attributeName, int defaultValue ) {
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- ParsedHTML.java 30 Dec 2002 21:46:54 -0000 1.43
+++ ParsedHTML.java 4 Feb 2003 05:32:03 -0000 1.44
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -23,10 +23,7 @@
import org.w3c.dom.Node;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Arrays;
+import java.util.*;
import com.meterware.httpunit.scripting.ScriptableDelegate;
@@ -40,6 +37,8 @@
private URL _baseURL;
+ private String _frameName;
+
private String _baseTarget;
private String _characterSet;
@@ -70,9 +69,13 @@
private ArrayList _tableList = new ArrayList();
private WebTable[] _tables;
+ private ArrayList _frameList = new ArrayList();
+ private WebFrame[] _frames;
+
- ParsedHTML( WebResponse response, URL baseURL, String baseTarget, Node rootNode, String characterSet ) {
+ ParsedHTML( WebResponse response, String frameName, URL baseURL, String baseTarget, Node rootNode, String characterSet ) {
_response = response;
+ _frameName = frameName;
_baseURL = baseURL;
_baseTarget = baseTarget;
_rootNode = rootNode;
@@ -199,6 +202,7 @@
}
}
+ protected boolean isRecognized( ClientProperties properties ) { return true; }
protected boolean addToContext() { return false; }
protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
for (Iterator i = pot.getContexts(); i.hasNext();) {
@@ -267,6 +271,30 @@
}
+ static class WebFrameFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toWebFrame( element );
+ }
+ }
+
+
+ static class WebIFrameFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toWebFrame( element );
+ }
+
+
+ protected boolean isRecognized( ClientProperties properties ) {
+ return properties.isIframeSupported();
+ }
+
+
+ protected boolean addToContext() {
+ return true;
+ }
+ }
+
+
static class WebImageFactory extends HTMLElementFactory {
HTMLElement toHTMLElement( NodeUtils.PreOrderTraversal pot, ParsedHTML parsedHTML, Element element ) {
return parsedHTML.toWebImage( element );
@@ -353,6 +381,8 @@
_htmlFactoryClasses.put( "tr", new TableRowFactory() );
_htmlFactoryClasses.put( "td", new TableCellFactory() );
_htmlFactoryClasses.put( "th", new TableCellFactory() );
+ _htmlFactoryClasses.put( "frame", new WebFrameFactory() );
+ _htmlFactoryClasses.put( "iframe", new WebIFrameFactory() );
for (Iterator i = Arrays.asList( FormControl.getControlElementTags() ).iterator(); i.hasNext();) {
_htmlFactoryClasses.put( i.next(), new FormControlFactory() );
@@ -371,7 +401,8 @@
NodeUtils.NodeAction action = new NodeUtils.NodeAction() {
public boolean processElement( NodeUtils.PreOrderTraversal pot, Element element ) {
HTMLElementFactory factory = getHTMLElementFactory( element.getNodeName().toLowerCase() );
- if (factory == null) return true;
+ if (factory == null || !factory.isRecognized( getClientProperties() )) return true;
+ if (pot.getClosestContext( WebFrame.class ) != null) return true;
if (!_elements.containsKey( element )) factory.recordElement( pot, element, ParsedHTML.this );
if (factory.addToContext()) pot.pushContext( _elements.get( element ) );
@@ -389,11 +420,22 @@
}
+ private ClientProperties getClientProperties() {
+ WebWindow window = _response.getWindow();
+ return window == null ? ClientProperties.getDefaultProperties() : window.getClient().getClientProperties();
+ }
+
+
private WebForm toWebForm( Element element ) {
return new WebForm( _response, _baseURL, _baseTarget, element, _characterSet );
}
+ private WebFrame toWebFrame( Element element ) {
+ return new WebFrame( _baseURL, element, _frameName );
+ }
+
+
private WebLink toLinkAnchor( Element child ) {
return (!isWebLink( child )) ? null : new WebLink( _response, _baseURL, _baseTarget, child );
}
@@ -415,7 +457,7 @@
private WebTable toWebTable( Element element ) {
- return new WebTable( _response, element, _baseURL, _baseTarget, _characterSet );
+ return new WebTable( _response, _frameName, element, _baseURL, _baseTarget, _characterSet );
}
@@ -437,6 +479,7 @@
if (element instanceof WebImage) return _imagesList;
if (element instanceof WebApplet) return _appletList;
if (element instanceof WebTable) return _tableList;
+ if (element instanceof WebFrame) return _frameList;
return null;
}
@@ -608,6 +651,7 @@
_images = null;
_applets = null;
_tables = null;
+ _frames = null;
_updateElements = true;
}
@@ -630,6 +674,18 @@
**/
Node getOriginalDOM() {
return getRootNode();
+ }
+
+
+ /**
+ * Returns the frames found in the page in the order in which they appear.
+ **/
+ public WebFrame[] getFrames() {
+ if (_frames == null) {
+ loadElements();
+ _frames = (WebFrame[]) _frameList.toArray( new WebFrame[ _frameList.size() ] );
+ }
+ return _frames;
}
Index: TableCell.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/TableCell.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- TableCell.java 30 Dec 2002 21:46:54 -0000 1.10
+++ TableCell.java 4 Feb 2003 05:32:03 -0000 1.11
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -114,8 +114,8 @@
//---------------------------------------- package methods -----------------------------------------
- TableCell( WebResponse response, Element cellNode, URL url, String parentTarget, String characterSet ) {
- super( response, url, parentTarget, cellNode, characterSet );
+ TableCell( WebResponse response, String frameName, Element cellNode, URL url, String parentTarget, String characterSet ) {
+ super( response, frameName, url, parentTarget, cellNode, characterSet );
_element = cellNode;
_colSpan = getAttributeValue( cellNode, "colspan", 1 );
_rowSpan = getAttributeValue( cellNode, "rowspan", 1 );
Index: WebApplet.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebApplet.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- WebApplet.java 30 Dec 2002 21:46:54 -0000 1.5
+++ WebApplet.java 4 Feb 2003 05:32:03 -0000 1.6
@@ -40,7 +40,7 @@
/**
* This class represents the embedding of an applet in a web page.
*
- * @author <a href="Oli...@HV...">Oliver Imbusch</a>
+ * @author <a href="mailto:Oli...@HV...">Oliver Imbusch</a>
* @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
public class WebApplet extends HTMLElementBase {
Index: WebFrame.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebFrame.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- WebFrame.java 10 Oct 2002 21:10:19 -0000 1.10
+++ WebFrame.java 4 Feb 2003 05:32:03 -0000 1.11
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -19,6 +19,8 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import com.meterware.httpunit.scripting.ScriptableDelegate;
+
import java.net.URL;
import org.w3c.dom.Node;
@@ -26,26 +28,37 @@
/**
* A frame in a web page.
**/
-class WebFrame {
+class WebFrame extends HTMLElementBase {
+
+
+ protected ScriptableDelegate newScriptable() {
+ return null;
+ }
+
+
+ protected ScriptableDelegate getParentDelegate() {
+ return null;
+ }
//---------------------------------------- package methods -----------------------------------------
WebFrame( URL baseURL, Node frameNode, String parentFrameName ) {
+ super( frameNode );
_element = frameNode;
_baseURL = baseURL;
_name = getFrameName( parentFrameName );
}
- String getName() {
+ String getFrameName() {
return _name;
}
private String getFrameName( String parentFrameName ) {
- final String relativeName = NodeUtils.getNodeAttribute( _element, "name" );
+ final String relativeName = super.getName();
if (relativeName.length() == 0) return toString();
else return getNestedFrameName( parentFrameName, relativeName );
}
@@ -80,7 +93,7 @@
WebRequest getInitialRequest() {
return new GetMethodWebRequest( _baseURL,
NodeUtils.getNodeAttribute( _element, "src" ),
- getName() );
+ getFrameName() );
}
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -r1.105 -r1.106
--- WebResponse.java 26 Dec 2002 04:59:35 -0000 1.105
+++ WebResponse.java 4 Feb 2003 05:32:03 -0000 1.106
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -34,8 +34,6 @@
import java.util.zip.GZIPInputStream;
import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -266,7 +264,7 @@
WebFrame[] frames = getFrames();
String[] result = new String[ frames.length ];
for (int i = 0; i < result.length; i++) {
- result[i] = frames[i].getName();
+ result[i] = frames[i].getFrameName();
}
return result;
@@ -788,8 +786,6 @@
final private static int UNINITIALIZED_INT = -2;
- private WebFrame[] _frames;
-
private WebWindow _window;
private HTMLPage _page;
@@ -855,10 +851,11 @@
private void readTags( byte[] rawMessage ) throws UnsupportedEncodingException, MalformedURLException {
ByteTagParser parser = new ByteTagParser( rawMessage );
ByteTag tag = parser.getNextTag();
- while (tag != null && !tag.getName().equalsIgnoreCase( "body" )) {
+ while (tag != null) {
if (tag.getName().equalsIgnoreCase( "meta" )) processMetaTag( tag );
if (tag.getName().equalsIgnoreCase( "base" )) processBaseTag( tag );
if (tag.getName().equalsIgnoreCase( "frameset" )) _hasSubframes = true;
+ if (tag.getName().equalsIgnoreCase( "iframe" )) _hasSubframes = true;
tag = parser.getNextTag();
}
}
@@ -955,23 +952,8 @@
private WebFrame[] getFrames() throws SAXException {
- if (_frames == null) {
- Vector list = new Vector();
- addFrameTags( list, "frame" );
- _frames = new WebFrame[ list.size() ];
- list.copyInto( _frames );
- }
-
- return _frames;
- }
-
+ return getReceivedPage().getFrames();
- private void addFrameTags( Vector list, String frameTagName ) throws SAXException {
- NodeList nl = NodeUtils.getElementsByTagName( getReceivedPage().getOriginalDOM(), frameTagName );
- for (int i = 0; i < nl.getLength(); i++) {
- Node child = nl.item(i);
- list.addElement( new WebFrame( getReceivedPage().getBaseURL(), child, _frameName ) );
- }
}
@@ -979,7 +961,7 @@
if (_page == null) {
try {
if (!isHTML()) throw new NotHTMLException( getContentType() );
- _page = new HTMLPage( this, _baseURL, _baseTarget, getCharacterSet() );
+ _page = new HTMLPage( this, _frameName, _baseURL, _baseTarget, getCharacterSet() );
_page.parse( getText(), _pageURL );
} catch (IOException e) {
e.printStackTrace();
Index: WebTable.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- WebTable.java 30 Dec 2002 21:46:55 -0000 1.24
+++ WebTable.java 4 Feb 2003 05:32:03 -0000 1.25
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2002, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -241,7 +241,8 @@
private Element _dom;
private URL _url;
- private String _parentTarget;
+ private String _frameName;
+ private String _baseTarget;
private String _characterSet;
private WebResponse _response;
@@ -249,12 +250,13 @@
private TableCell[][] _cells;
- WebTable( WebResponse response, Node domTreeRoot, URL sourceURL, String parentTarget, String characterSet ) {
+ WebTable( WebResponse response, String frameName, Node domTreeRoot, URL sourceURL, String baseTarget, String characterSet ) {
super( domTreeRoot );
_response = response;
+ _frameName = frameName;
_dom = (Element) domTreeRoot;
_url = sourceURL;
- _parentTarget = parentTarget;
+ _baseTarget = baseTarget;
_characterSet = characterSet;
}
@@ -334,7 +336,7 @@
TableCell newTableCell( Element element ) {
- return new TableCell( _response, element, _url, _parentTarget, _characterSet );
+ return new TableCell( _response, _frameName, element, _url, _baseTarget, _characterSet );
}
|