[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit WebApplet.java,1.1,1.2
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-11-15 06:44:51
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv27410/src/com/meterware/httpunit
Modified Files:
WebApplet.java
Log Message:
support applet load, find, show-document
Index: WebApplet.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebApplet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebApplet.java 12 Nov 2002 13:41:54 -0000 1.1
+++ WebApplet.java 15 Nov 2002 00:07:33 -0000 1.2
@@ -1,10 +1,4 @@
package com.meterware.httpunit;
-
-import java.net.URL;
-import java.net.MalformedURLException;
-
-import org.w3c.dom.Node;
-
/********************************************************************************************************************
* $Id$
*
@@ -25,6 +19,15 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.net.URLClassLoader;
+import java.applet.Applet;
+import java.io.IOException;
+
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
/**
* This class represents the embedding of an applet in a web page.
@@ -39,6 +42,7 @@
private String _baseTarget;
private URL _codeBase;
private String _className;
+ private Applet _applet;
final private String CLASS_EXTENSION = ".class";
@@ -108,4 +112,50 @@
public int getHeight() {
return Integer.parseInt( getAttribute( "height" ) );
}
+
+
+ public Applet getApplet() throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+ if (_applet == null) {
+ ClassLoader cl = new URLClassLoader( getClassPath() );
+ Object o = cl.loadClass( getMainClassName() ).newInstance();
+ if (!(o instanceof Applet)) throw new RuntimeException( getMainClassName() + " is not an Applet" );
+ _applet = (Applet) o;
+ _applet.setStub( new AppletStubImpl( this ) );
+ }
+ return _applet;
+ }
+
+
+ private URL[] getClassPath() throws MalformedURLException {
+ return new URL[] { getCodeBase() };
+ }
+
+
+ String getBaseTarget() {
+ return _baseTarget;
+ }
+
+
+ WebApplet[] getAppletsInPage() {
+ try {
+ return _response.getApplets();
+ } catch (SAXException e) {
+ e.printStackTrace(); // should never happen.
+ return null;
+ }
+ }
+
+
+ void sendRequest( URL url, String target ) {
+ WebRequest wr = new GetMethodWebRequest( null, url.toExternalForm(), target );
+ try {
+ _response.getWindow().getResponse( wr );
+ } catch (IOException e) {
+ e.printStackTrace(); //To change body of catch statement use Options | File Templates.
+ throw new RuntimeException( e.toString() );
+ } catch (SAXException e) {
+ }
+ }
+
+
}
|