jsimplebrowser-svn Mailing List for JSimpleBrowser
Status: Alpha
Brought to you by:
rdimarco
You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(16) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: <rdi...@us...> - 2007-08-14 01:49:48
|
Revision: 52 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=52&view=rev Author: rdimarco Date: 2007-08-13 18:49:46 -0700 (Mon, 13 Aug 2007) Log Message: ----------- Information about some related libraries that may interest some users. Added Paths: ----------- trunk/src/site/apt/relatedLibraries.apt Added: trunk/src/site/apt/relatedLibraries.apt =================================================================== --- trunk/src/site/apt/relatedLibraries.apt (rev 0) +++ trunk/src/site/apt/relatedLibraries.apt 2007-08-14 01:49:46 UTC (rev 52) @@ -0,0 +1,8 @@ +Related Libraries + + While we think JSimpleBrowser is pretty darn special, there are other libraries that may meet what you are looking for. Some of these are actually used under the covers of JSimpleBrowser + + * <a href="http://commons.apache.org/httpclient/">Apache HttpClient</a> is a great tool for actually executing the HTTP(s) requests that you may want to make. We are using it in JSimpleBrowser behind the scenes. + * <a href="http://sourceforge.net/projects/nekohtml">NekoHTML</a> is the best Java HTML parser around. If you have some not necessarily clean HTML and you want a parser to help turn it into a DOM tree, this is the library for you. + * <a href="http://www.mozilla.org/rhino/">Rhino</a> is a JavaScript engine that we use to execute JavaScript in the browser + * <a href="http://www.icesoft.com/products/icebrowser.html">ICE Browser</a> is a commercial product that you can embed in your Java applications. It has both headless and headful modes. \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-13 23:10:59
|
Revision: 51 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=51&view=rev Author: rdimarco Date: 2007-08-13 16:10:58 -0700 (Mon, 13 Aug 2007) Log Message: ----------- Some more minor updates to the XmlHttpRequest. Modified Paths: -------------- trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequest.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/XmlHttpRequestImpl.java Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequest.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequest.java 2007-08-13 23:04:26 UTC (rev 50) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequest.java 2007-08-13 23:10:58 UTC (rev 51) @@ -38,7 +38,7 @@ public String getAllResponseHeaders(); public String getResponseHeader(String header); public String getResponseText(); - public String getResponseXML(); + public Document getResponseXML(); public short getReadyState(); public short getStatus(); public String getStatusText(); Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/XmlHttpRequestImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/XmlHttpRequestImpl.java 2007-08-13 23:04:26 UTC (rev 50) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/XmlHttpRequestImpl.java 2007-08-13 23:10:58 UTC (rev 51) @@ -10,12 +10,16 @@ // package com.software416.jsimplebrowser.impl; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; @@ -23,6 +27,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.URI; import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.methods.EntityEnclosingMethod; @@ -35,6 +40,7 @@ import org.w3c.dom.events.EventException; import org.w3c.dom.events.EventListener; import org.w3c.dom.events.EventTarget; +import org.xml.sax.SAXException; import com.google.inject.Inject; import com.software416.jsimplebrowser.BrowserRuntimeException; @@ -55,9 +61,18 @@ private EntityEnclosingMethod _requestMethod; private boolean _sendFlag = false; private boolean _isAsync = true; - @Inject private Window _window = null; + private Window _window = null; @Inject private RequestService _requestService = null; - + + public XmlHttpRequestImpl() { + super(); + } + + public XmlHttpRequestImpl(Window w) { + this(); + _window = w; + } + /* (non-Javadoc) * @see com.software416.jsimplebrowser.XmlHttpRequest#abort() */ @@ -79,32 +94,51 @@ * @see com.software416.jsimplebrowser.XmlHttpRequest#getAllResponseHeaders() */ public String getAllResponseHeaders() { - // TODO Auto-generated method stub - return null; + if (_state != XmlHttpRequestReadyState.LOADING && _state != XmlHttpRequestReadyState.DONE) { + throw new IllegalStateException("Need to be loading or done to get header"); + } + Header[] headers = _requestMethod.getRequestHeaders(); + StringBuilder sb = new StringBuilder(); + for (Header header : headers) { + sb.append(header.getName() + ": " + header.getValue() + "\r\n"); + } + return sb.toString(); } /* (non-Javadoc) * @see com.software416.jsimplebrowser.XmlHttpRequest#getResponseHeader(java.lang.String) */ public String getResponseHeader(String header) { - // TODO Auto-generated method stub - return null; + if (_state != XmlHttpRequestReadyState.LOADING && _state != XmlHttpRequestReadyState.DONE) { + throw new IllegalStateException("Need to be loading or done to get header"); + } + return _requestMethod.getRequestHeader(header).getValue(); } /* (non-Javadoc) * @see com.software416.jsimplebrowser.XmlHttpRequest#getResponseText() */ public String getResponseText() { - // TODO Auto-generated method stub - return null; + try { + return _requestMethod.getResponseBodyAsString(); + } catch (IOException ex) { + throw new BrowserRuntimeException("Could not read response body", ex); + } } /* (non-Javadoc) * @see com.software416.jsimplebrowser.XmlHttpRequest#getResponseXML() */ - public String getResponseXML() { - // TODO Auto-generated method stub - return null; + public Document getResponseXML() { + try { + return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(getResponseText().getBytes())); + } catch (SAXException ex) { + throw new BrowserRuntimeException("Could not read response document", ex); + } catch (IOException ex) { + throw new BrowserRuntimeException("Could not read response document", ex); + } catch (ParserConfigurationException ex) { + throw new BrowserRuntimeException("Could not read response document", ex); + } } /* (non-Javadoc) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ebe...@us...> - 2007-08-13 23:07:04
|
Revision: 50 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=50&view=rev Author: ebernstein Date: 2007-08-13 16:04:26 -0700 (Mon, 13 Aug 2007) Log Message: ----------- fix mailing lists, point scm to trunk and add repositories for selenium and neko Modified Paths: -------------- trunk/core/pom.xml trunk/pom.xml Modified: trunk/core/pom.xml =================================================================== --- trunk/core/pom.xml 2007-08-13 22:51:16 UTC (rev 49) +++ trunk/core/pom.xml 2007-08-13 23:04:26 UTC (rev 50) @@ -1,57 +1,57 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>com.software416.jsimplebrowser</groupId> - <artifactId>jsimplebrowser</artifactId> - <version>1.0.0-SNAPSHOT</version> - </parent> - <name>JSimpleBrowser Core Classes</name> - <artifactId>jsimplebrowser-core</artifactId> - <version>1.0.0-SNAPSHOT</version> - <packaging>jar</packaging> - <dependencies> - <dependency> - <groupId>com.google.guice</groupId> - <artifactId>guice</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - </dependency> - <dependency> - <groupId>org.cyberneko</groupId> - <artifactId>html-core</artifactId> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - </dependency> - <dependency> - <groupId>commons-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - </dependency> - </dependencies> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.software416.jsimplebrowser</groupId> + <artifactId>jsimplebrowser</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + <name>JSimpleBrowser Core Classes</name> + <artifactId>jsimplebrowser-core</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>com.google.code.guice</groupId> + <artifactId>guice</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + </dependency> + <dependency> + <groupId>org.cyberneko</groupId> + <artifactId>html-core</artifactId> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> + <dependency> + <groupId>commons-httpclient</groupId> + <artifactId>commons-httpclient</artifactId> + </dependency> + </dependencies> </project> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2007-08-13 22:51:16 UTC (rev 49) +++ trunk/pom.xml 2007-08-13 23:04:26 UTC (rev 50) @@ -1,225 +1,237 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>com.software416.jsimplebrowser</groupId> - <artifactId>jsimplebrowser</artifactId> - <name>JSimpleBrowser</name> - <version>1.0.0-SNAPSHOT</version> - <packaging>pom</packaging> -<licenses> - <license> - <name>GPL</name> - <url>http://www.gnu.org/licenses/gpl-2.0.txt</url> - <distribution>repo</distribution> - </license> -</licenses> -<developers> - <developer> + <modelVersion>4.0.0</modelVersion> + <groupId>com.software416.jsimplebrowser</groupId> + <artifactId>jsimplebrowser</artifactId> + <name>JSimpleBrowser</name> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> + <licenses> + <license> + <name>GPL</name> + <url>http://www.gnu.org/licenses/gpl-2.0.txt</url> + <distribution>repo</distribution> + </license> + </licenses> + <developers> + <developer> <name>Rob Di Marco</name> <email>rob.dimarco (at) 416software.com</email> <url>http://www.416software.com</url> </developer> -</developers> + </developers> - <issueManagement> - <url>http://sourceforge.net/tracker/?group_id=202645</url> - </issueManagement> + <issueManagement> + <url>http://sourceforge.net/tracker/?group_id=202645</url> + </issueManagement> <mailingLists> <mailingList> <name>User List</name> - <subscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-users</subscribe> - <unsubscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-users</unsubscribe> + <subscribe>http://lists.sourceforge.net/lists/listinfo/jsimplebrowser-users</subscribe> + <unsubscribe>http://lists.sourceforge.net/lists/listinfo/jsimplebrowser-users</unsubscribe> <post>jsi...@li...</post> </mailingList> <mailingList> <name>Developer List</name> - <subscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-devel</subscribe> - <unsubscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-devel</unsubscribe> + <subscribe>http://lists.sourceforge.net/lists/listinfo/jsimplebrowser-devel</subscribe> + <unsubscribe>http://lists.sourceforge.net/lists/listinfo/jsimplebrowser-devel</unsubscribe> <post>jsi...@li...</post> </mailingList> <mailingList> <name>Subversion Commit List</name> - <subscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-svn</subscribe> - <unsubscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-svn</unsubscribe> + <subscribe>http://lists.sourceforge.net/lists/listinfo/jsimplebrowser-svn</subscribe> + <unsubscribe>http://lists.sourceforge.net/lists/listinfo/jsimplebrowser-svn</unsubscribe> <post>jsi...@li...</post> </mailingList> </mailingLists> <scm> - <connection>scm:svn:https://jsimplebrowser.svn.sourceforge.net/svnroot/jsimplebrowser</connection> - <developerConnection>scm:svn:https://jsimplebrowser.svn.sourceforge.net/svnroot/jsimplebrowser</developerConnection> + <connection>scm:svn:https://jsimplebrowser.svn.sourceforge.net/svnroot/jsimplebrowser/trunk/</connection> + <developerConnection>scm:svn:https://jsimplebrowser.svn.sourceforge.net/svnroot/jsimplebrowser/trunk/</developerConnection> <tag>HEAD</tag> <url>https://jsimplebrowser.svn.sourceforge.net/svnroot/jsimplebrowser</url> </scm> - <distributionManagement> - <snapshotRepository> - <id>snapshots</id> - <uniqueVersion>true</uniqueVersion> - <url>http://invincible.dynalias.com:8081/artifactory/libs-snapshots</url> - </snapshotRepository> - <repository> - <id>central</id> - <uniqueVersion>false</uniqueVersion> - <url>http://invincible.dynalias.com:8081/artifactory/libs-snapshots</url> - </repository> + <distributionManagement> + <snapshotRepository> + <id>snapshots</id> + <uniqueVersion>true</uniqueVersion> + <url>http://invincible.dynalias.com:8081/artifactory/libs-snapshots</url> + </snapshotRepository> + <repository> + <id>central</id> + <uniqueVersion>false</uniqueVersion> + <url>http://invincible.dynalias.com:8081/artifactory/libs-snapshots</url> + </repository> <site> <id>website</id> <url>scp://shell.sourceforge.net/home/groups/j/js/jsimplebrowser/htdocs</url> </site> - </distributionManagement> - <url>http://jsimplebrowser.sourceforge.net/</url> - <modules> - <module>core</module> - <module>client</module> - <module>selenium-client</module> - </modules> - <build> - <defaultGoal>install</defaultGoal> - <sourceDirectory>src/main/java</sourceDirectory> - <testSourceDirectory>src/test/java</testSourceDirectory> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.5</source> - <target>1.5</target> - </configuration> - </plugin> - <plugin> - <artifactId>maven-site-plugin</artifactId> - </plugin> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <includes> - <include>**/*Test.java</include> - </includes> - <argLine>-Xmx300m</argLine> - <printSummary>true</printSummary> - <reportFormat>plain</reportFormat> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>cobertura-maven-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>clean</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - <dependencyManagement> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3.1</version> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging-api</artifactId> - <version>1.0.4</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <version>1.0.4</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - <version>3.1</version> - </dependency> - <dependency> - <groupId>org.cyberneko</groupId> - <artifactId>html-core</artifactId> - <version>1.0.0-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.3</version> - </dependency> - <dependency> - <groupId>commons-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - <version>3.1-rc1</version> - </dependency> - <dependency> - <groupId>org.openqa.selenium.client-drivers</groupId> - <artifactId>selenium-java-client-driver</artifactId> - <version>0.9.2-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>com.google.guice</groupId> - <artifactId>guice</artifactId> - <version>1.0</version> - </dependency> - </dependencies> - </dependencyManagement> - <reporting> - <plugins> - <plugin> - <artifactId>maven-pmd-plugin</artifactId> - <configuration> - <linkXref>true</linkXref> - <sourceEncoding>utf-8</sourceEncoding> - <minimumTokens>80</minimumTokens> - <targetJdk>1.6</targetJdk> - </configuration> - <reportSets> - <reportSet> - <reports> - <report>cpd</report> - </reports> - </reportSet> - </reportSets> - </plugin> - <plugin> - <artifactId>maven-project-info-reports-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>cobertura-maven-plugin</artifactId> - </plugin> - <plugin> - <artifactId>maven-javadoc-plugin</artifactId> - <configuration> - <minmemory>128m</minmemory> - <maxmemory>512m</maxmemory> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>jxr-maven-plugin</artifactId> - </plugin> + </distributionManagement> + <url>http://jsimplebrowser.sourceforge.net/</url> + <modules> + <module>core</module> + <module>client</module> + <module>selenium-client</module> + </modules> + <build> + <defaultGoal>install</defaultGoal> + <sourceDirectory>src/main/java</sourceDirectory> + <testSourceDirectory>src/test/java</testSourceDirectory> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + <plugin> + <artifactId>maven-site-plugin</artifactId> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <includes> + <include>**/*Test.java</include> + </includes> + <argLine>-Xmx300m</argLine> + <printSummary>true</printSummary> + <reportFormat>plain</reportFormat> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>cobertura-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>clean</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3.1</version> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging-api</artifactId> + <version>1.0.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.0.4</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.1</version> + </dependency> + <dependency> + <groupId>org.cyberneko</groupId> + <artifactId>html-core</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> + <groupId>commons-httpclient</groupId> + <artifactId>commons-httpclient</artifactId> + <version>3.1-rc1</version> + </dependency> + <dependency> + <groupId>org.openqa.selenium.client-drivers</groupId> + <artifactId>selenium-java-client-driver</artifactId> + <version>0.9.2-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>com.google.code.guice</groupId> + <artifactId>guice</artifactId> + <version>1.0</version> + </dependency> + </dependencies> + </dependencyManagement> + <reporting> + <plugins> + <plugin> + <artifactId>maven-pmd-plugin</artifactId> + <configuration> + <linkXref>true</linkXref> + <sourceEncoding>utf-8</sourceEncoding> + <minimumTokens>80</minimumTokens> + <targetJdk>1.6</targetJdk> + </configuration> + <reportSets> + <reportSet> + <reports> + <report>cpd</report> + </reports> + </reportSet> + </reportSets> + </plugin> + <plugin> + <artifactId>maven-project-info-reports-plugin</artifactId> + </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>jdepend-maven-plugin</artifactId> - </plugin> - - <plugin> - <artifactId>maven-surefire-report-plugin</artifactId> - </plugin> - - </plugins> - </reporting> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>cobertura-maven-plugin</artifactId> + </plugin> + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <minmemory>128m</minmemory> + <maxmemory>512m</maxmemory> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>jxr-maven-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>jdepend-maven-plugin</artifactId> + </plugin> + + <plugin> + <artifactId>maven-surefire-report-plugin</artifactId> + </plugin> + + </plugins> + </reporting> + <repositories> + <repository> + <name>jsimplebrowser</name> + <id>jsimplebrowser</id> + <url>http://jsimplebrowser.sourceforge.net/maven2/</url> + </repository> + <repository> + <name>openqa</name> + <id>openqa</id> + <url>http://maven.openqa.org/</url> + </repository> + </repositories> </project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-13 22:51:19
|
Revision: 49 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=49&view=rev Author: rdimarco Date: 2007-08-13 15:51:16 -0700 (Mon, 13 Aug 2007) Log Message: ----------- Added an XmlHttpRequest object. Modified Paths: -------------- trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java Added Paths: ----------- trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequest.java trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequestReadyState.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/AbstractDOMEvent.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/ReadyStateChangedEvent.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/ReadyStateChangedEventListener.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/XmlHttpRequestImpl.java Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java 2007-08-13 21:08:29 UTC (rev 48) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java 2007-08-13 22:51:16 UTC (rev 49) @@ -21,22 +21,14 @@ */ @ImplementedBy(RequestServiceImpl.class) public interface RequestService { - /** - * Make a Http request with the specified message body. Ofent used to make - * AJAX calls. - * - * @param url The URL to connect to. Must be an absolute URL - * @param requestBody The text that will be passed as the body context to the server - * @return the response ID associated with the request - */ - public String makeXmlHttpRequest(String url, String requestBody); /** * Make a request with a specified request method. Intended for internal use * @param hm The HttpMethod that will be used to execute the request * @return the response id. */ - String makeRequest(HttpMethod hm); + String makeAsyncRequest(HttpMethod hm); + HttpResponse makeSynchronousRequest(HttpMethod hm); public void addRequestEventListener(RequestEventListener listener); public void removeRequestEventListener(RequestEventListener listener); Added: trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequest.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequest.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequest.java 2007-08-13 22:51:16 UTC (rev 49) @@ -0,0 +1,47 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser; + +import java.net.URISyntaxException; + +import org.w3c.dom.Document; +import org.w3c.dom.events.EventListener; + +import com.google.inject.ImplementedBy; +import com.software416.jsimplebrowser.impl.XmlHttpRequestImpl; + +/** + * Taken from the W3C XMLHTTPRequest description + * @link http://www.w3.org/TR/XMLHttpRequest/ + * @author Rob Di Marco + */ +@ImplementedBy(XmlHttpRequestImpl.class) +public interface XmlHttpRequest { + public void open(String method, String url) throws URISyntaxException; + public void open(String method, String url, boolean async) throws URISyntaxException; + public void open(String method, String url, boolean async, String user) throws URISyntaxException; + public void open(String method, String url, boolean async, String user, String password) throws URISyntaxException; + public void setRequestHeader(String header, String value); + public void send(); + public void send(String data); + public void send(Document data); + public void abort(); + + public String getAllResponseHeaders(); + public String getResponseHeader(String header); + public String getResponseText(); + public String getResponseXML(); + public short getReadyState(); + public short getStatus(); + public String getStatusText(); + + void onReadyStateChange(EventListener e); +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequestReadyState.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequestReadyState.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/XmlHttpRequestReadyState.java 2007-08-13 22:51:16 UTC (rev 49) @@ -0,0 +1,27 @@ +// +// Copyright (c) 2007, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser; + +/** + * @author Rob Di Marco + */ +public enum XmlHttpRequestReadyState{ + UNSENT((short)0), OPEN((short)1), SENT((short)2), LOADING((short)3), DONE((short)4); + + private short _value; + private XmlHttpRequestReadyState(short value) { + _value = value; + } + public short getValue() { + return _value; + } +} + Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/AbstractDOMEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/AbstractDOMEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/AbstractDOMEvent.java 2007-08-13 22:51:16 UTC (rev 49) @@ -0,0 +1,108 @@ +// +// Copyright (c) 2007, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +import org.w3c.dom.events.Event; +import org.w3c.dom.events.EventTarget; + +/** + * @author Rob Di Marco + */ +public class AbstractDOMEvent implements Event { + private boolean _bubbles = true; + private boolean _cancelable = false; + private EventTarget _currentTarget; + private short _eventPhase = AT_TARGET; + private EventTarget _target; + private long _timeStamp; + private String _type; + + + public void initEvent(String eventTypeArg, boolean canBubbleArg, boolean cancelableArg) { + _type = eventTypeArg; + _bubbles = canBubbleArg; + _cancelable = cancelableArg; + } + + /* (non-Javadoc) + * @see org.w3c.dom.events.Event#preventDefault() + */ + public void preventDefault() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.w3c.dom.events.Event#stopPropagation() + */ + public void stopPropagation() { + // TODO Auto-generated method stub + + } + + public boolean getBubbles() { + return _bubbles; + } + + public void setBubbles(boolean bubbles) { + _bubbles = bubbles; + } + + public boolean getCancelable() { + return _cancelable; + } + + public void setCancelable(boolean cancelable) { + _cancelable = cancelable; + } + + public EventTarget getCurrentTarget() { + return _currentTarget; + } + + public void setCurrentTarget(EventTarget currentTarget) { + _currentTarget = currentTarget; + } + + public short getEventPhase() { + return _eventPhase; + } + + public void setEventPhase(short eventPhase) { + _eventPhase = eventPhase; + } + + public EventTarget getTarget() { + return _target; + } + + public void setTarget(EventTarget target) { + _target = target; + } + + public long getTimeStamp() { + return _timeStamp; + } + + public void setTimeStamp(long timeStamp) { + _timeStamp = timeStamp; + } + + public String getType() { + return _type; + } + + public void setType(String type) { + _type = type; + } + + +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/ReadyStateChangedEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/ReadyStateChangedEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/ReadyStateChangedEvent.java 2007-08-13 22:51:16 UTC (rev 49) @@ -0,0 +1,36 @@ +// +// Copyright (c) 2007, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +import com.software416.jsimplebrowser.XmlHttpRequestReadyState; + +/** + * @author Rob Di Marco + */ +public class ReadyStateChangedEvent extends AbstractDOMEvent { + private XmlHttpRequestReadyState _oldState, _newState; + public ReadyStateChangedEvent() { + setCancelable(false); + setBubbles(false); + } + public XmlHttpRequestReadyState getNewState() { + return _newState; + } + public void setNewState(XmlHttpRequestReadyState newState) { + _newState = newState; + } + public XmlHttpRequestReadyState getOldState() { + return _oldState; + } + public void setOldState(XmlHttpRequestReadyState oldState) { + _oldState = oldState; + } +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/ReadyStateChangedEventListener.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/ReadyStateChangedEventListener.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/ReadyStateChangedEventListener.java 2007-08-13 22:51:16 UTC (rev 49) @@ -0,0 +1,18 @@ +// +// Copyright (c) 2007, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +/** + * @author Rob Di Marco + */ +public interface ReadyStateChangedEventListener { + public void onReadyStateChanged(ReadyStateChangedEvent e); +} Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java 2007-08-13 21:08:29 UTC (rev 48) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java 2007-08-13 22:51:16 UTC (rev 49) @@ -12,7 +12,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; @@ -24,12 +23,10 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.io.IOUtils; import com.google.inject.Singleton; -import com.software416.jsimplebrowser.BrowserRuntimeException; +import com.software416.jsimplebrowser.HttpResponse; import com.software416.jsimplebrowser.RequestService; import com.software416.jsimplebrowser.event.RequestEvent; import com.software416.jsimplebrowser.event.RequestEventListener; @@ -44,30 +41,43 @@ private List<RequestEventListener> _eventListeners = new ArrayList<RequestEventListener>(); private AtomicInteger _requestIdCounter = new AtomicInteger(1); private ExecutorService _requestPool = new ThreadPoolExecutor(1, REQUEST_POOL_THREAD_COUNT, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); - public String makeRequest(final HttpMethod m) { + public String makeAsyncRequest(final HttpMethod m) { final String requestId = String.valueOf(_requestIdCounter.addAndGet(1)); _requestPool.execute(new Runnable() { - public void run() { - HttpResponseImpl ri = new HttpResponseImpl(); - ri.setRequestMethod(m); - - try { - ri.setResponseCode(_client.executeMethod(m)); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - IOUtils.copy(m.getResponseBodyAsStream(), bos); - ri.setResponseBody(bos.toByteArray()); - notifyOfRequestSuccess(requestId, m, ri); - } catch (HttpException ex) { - notifyOfRequestFailure(requestId, m, ex); - } catch (IOException ex) { - notifyOfRequestFailure(requestId, m, ex); - } - } + makeRequest(m, requestId); + } }); return requestId; } + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.RequestService#makeSynchronousRequest(org.apache.commons.httpclient.HttpMethod) + */ + public HttpResponse makeSynchronousRequest(HttpMethod hm) { + final String requestId = String.valueOf(_requestIdCounter.addAndGet(1)); + return makeRequest(hm, requestId); + } + + protected HttpResponseImpl makeRequest(final HttpMethod m, final String requestId) { + + try { + HttpResponseImpl ri = new HttpResponseImpl(); + ri.setRequestMethod(m); + ri.setResponseCode(_client.executeMethod(m)); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + IOUtils.copy(m.getResponseBodyAsStream(), bos); + ri.setResponseBody(bos.toByteArray()); + notifyOfRequestSuccess(requestId, m, ri); + return ri; + } catch (HttpException ex) { + notifyOfRequestFailure(requestId, m, ex); + } catch (IOException ex) { + notifyOfRequestFailure(requestId, m, ex); + } + return null; + } + protected void notifyOfRequestSuccess(String requestId, HttpMethod request, HttpResponseImpl response) { RequestSuccessEvent e = new RequestSuccessEvent(); e.setRequestId(requestId); @@ -91,16 +101,6 @@ } } - public String makeXmlHttpRequest(String url, String requestBody) { - PostMethod m = new PostMethod(url); - try { - m.setRequestEntity(new StringRequestEntity(requestBody, "text/plain",null)); - } catch (UnsupportedEncodingException ex) { - throw new BrowserRuntimeException("Really weird encoding issue", ex); - } - return makeRequest(m); - } - public void addRequestEventListener(RequestEventListener listener) { _eventListeners.add(listener); } @@ -108,4 +108,5 @@ _eventListeners.remove(listener); } + } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-13 21:08:29 UTC (rev 48) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-13 22:51:16 UTC (rev 49) @@ -90,7 +90,7 @@ protected String makeRequest(HttpMethod hm) { _isWindowLoading = true; - return _requestService.makeRequest(hm); + return _requestService.makeAsyncRequest(hm); } public void handleResponse(HttpResponse requestInfo) { Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/XmlHttpRequestImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/XmlHttpRequestImpl.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/XmlHttpRequestImpl.java 2007-08-13 22:51:16 UTC (rev 49) @@ -0,0 +1,320 @@ +// +// Copyright (c) 2007, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.impl; + +import java.io.ByteArrayOutputStream; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.commons.httpclient.URI; +import org.apache.commons.httpclient.URIException; +import org.apache.commons.httpclient.methods.EntityEnclosingMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.commons.lang.StringUtils; +import org.w3c.dom.Document; +import org.w3c.dom.events.Event; +import org.w3c.dom.events.EventException; +import org.w3c.dom.events.EventListener; +import org.w3c.dom.events.EventTarget; + +import com.google.inject.Inject; +import com.software416.jsimplebrowser.BrowserRuntimeException; +import com.software416.jsimplebrowser.HttpResponse; +import com.software416.jsimplebrowser.RequestService; +import com.software416.jsimplebrowser.Window; +import com.software416.jsimplebrowser.XmlHttpRequest; +import com.software416.jsimplebrowser.XmlHttpRequestReadyState; +import com.software416.jsimplebrowser.event.ReadyStateChangedEvent; + +/** + * @author Rob Di Marco + */ +public class XmlHttpRequestImpl implements XmlHttpRequest, EventTarget{ + private List<EventListener> _eventListeners = new ArrayList<EventListener>(); + private XmlHttpRequestReadyState _state = XmlHttpRequestReadyState.UNSENT; + private EventListener _mandatoryListener = null; + private EntityEnclosingMethod _requestMethod; + private boolean _sendFlag = false; + private boolean _isAsync = true; + @Inject private Window _window = null; + @Inject private RequestService _requestService = null; + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#abort() + */ + public void abort() { + if (!_isAsync) { + throw new IllegalStateException("Request is not in the asynchronous request state"); + } + if (_requestMethod.isRequestSent()) { + _requestMethod.abort(); + } + if (!(_state == XmlHttpRequestReadyState.UNSENT || _state == XmlHttpRequestReadyState.DONE + ||(_state == XmlHttpRequestReadyState.OPEN && !_sendFlag))) { + changeReadyState(XmlHttpRequestReadyState.DONE); + } + changeReadyState(XmlHttpRequestReadyState.UNSENT); + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#getAllResponseHeaders() + */ + public String getAllResponseHeaders() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#getResponseHeader(java.lang.String) + */ + public String getResponseHeader(String header) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#getResponseText() + */ + public String getResponseText() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#getResponseXML() + */ + public String getResponseXML() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#getStatus() + */ + public short getStatus() { + return (short)_requestMethod.getStatusCode(); + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#getStatusText() + */ + public String getStatusText() { + return _requestMethod.getStatusText(); + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#open(java.lang.String, java.lang.String) + */ + public void open(String method, String url) throws URISyntaxException { + open(method, url, true, null, null); + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#open(java.lang.String, java.lang.String, boolean) + */ + public void open(String method, String url, boolean async) throws URISyntaxException { + open(method, url, async, null, null); + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#open(java.lang.String, java.lang.String, boolean, java.lang.String) + */ + public void open(String method, String url, boolean async, String user) throws URISyntaxException { + open(method, url, async, user, null); + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#open(java.lang.String, java.lang.String, boolean, java.lang.String, java.lang.String) + */ + public void open(String method, String url, boolean async, String user, String password) throws URISyntaxException { + _requestMethod = validateMethodDefinition(method); + configureUrl(url, user, password); + _isAsync = async; + changeReadyState(XmlHttpRequestReadyState.OPEN); + } + + protected void changeReadyState(XmlHttpRequestReadyState newState) { + XmlHttpRequestReadyState oldState = _state; + _state = newState;; + ReadyStateChangedEvent e = new ReadyStateChangedEvent(); + e.setTarget(this); + e.setCurrentTarget(this); + e.setOldState(oldState); + e.setNewState(newState); + dispatchEvent(e); + } + + /** + * Right now, we are ignoring the username and password. May want to revisit this. + */ + protected void configureUrl(String url, String username, String password) throws URISyntaxException{ + try { + URI uri; + if (_window != null && _window.getLocation() !=null) { + uri = new URI(new URI(_window.getLocation(), true), url, true); + } else { + uri = new URI(url, true); + } + _requestMethod.setURI(uri); + } catch (URIException ex) { + throw new URISyntaxException(url, ex.getMessage()); + } + } + + /** + * Validates that the method argument matches the Method production defined in section 5.1.1 of RFC 2616 + * @param method The method to validate agains + * @link http://ietf.org/rfc/rfc2616 + * @throws BrowserRuntimeException if the method definition is invalid + */ + protected EntityEnclosingMethod validateMethodDefinition(String method) { + if (method == null) { + throw new BrowserRuntimeException("Syntax Error: no method specified: " + method); + } else if (method.equalsIgnoreCase("POST")) { + return new PostMethod(); + } else if (method.equalsIgnoreCase("PUT")) { + return new PutMethod(); + } else if (method.equalsIgnoreCase("GET")||method.equalsIgnoreCase("HEAD") + ||method.equalsIgnoreCase("DELETE")||method.equalsIgnoreCase("OPTIONS")|| method.equalsIgnoreCase("TRACE") + || method.equalsIgnoreCase("CONNECT")) { + throw new BrowserRuntimeException("Unsupported Method for HTTP Requests: " + method); + } else { + throw new BrowserRuntimeException("Syntax Error: invalid method: " + method); + } + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#send() + */ + public void send() { + send((String)null); + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#send(java.lang.String) + */ + public void send(String data) { + if (data != null && StringUtils.isEmpty(_requestMethod.getRequestHeader("Content-Type").getValue())) { + throw new IllegalStateException("Trying to send a message with no content type"); + } + validateRequestIsOpen(); + if (_isAsync) { + _sendFlag = true; + } + //TODO Not supporting charsets or encoding. Probably should... + try { + _requestMethod.setRequestEntity(new StringRequestEntity(data, null, null)); + } catch (UnsupportedEncodingException ex) { + throw new BrowserRuntimeException("Unusual encoding problem.", ex); + } + if (_isAsync) { + _requestService.makeAsyncRequest(_requestMethod); + } else { + HttpResponse resp = _requestService.makeSynchronousRequest(_requestMethod); + changeReadyState(XmlHttpRequestReadyState.DONE); + if (resp == null) { + throw new BrowserRuntimeException("Request could not be processed."); + } + } + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#send(org.w3c.dom.Document) + */ + public void send(Document data) { + if (_requestMethod.getRequestHeader("Content-Type") == null) { + _requestMethod.setRequestHeader("Content-Type", "application/xml"); + } + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + TransformerFactory.newInstance().newTransformer().transform(new DOMSource(data), new StreamResult(out)); + send(out.toString("UTF-8")); + } catch (TransformerConfigurationException ex) { + throw new BrowserRuntimeException("Could not transform DOM to text", ex); + } catch (TransformerException ex) { + throw new BrowserRuntimeException("Could not transform DOM to text", ex); + } catch (TransformerFactoryConfigurationError ex) { + throw new BrowserRuntimeException("Could not transform DOM to text", ex); + } catch (UnsupportedEncodingException ex) { + throw new BrowserRuntimeException("Could not transform DOM to text", ex); + } + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#setRequestHeader(java.lang.String, java.lang.String) + */ + public void setRequestHeader(String header, String value) { + validateRequestIsOpen(); + _requestMethod.addRequestHeader(header, value); + } + + private void validateRequestIsOpen() { + if (_state != XmlHttpRequestReadyState.OPEN) { + throw new IllegalStateException("Request is not in the open state!!! Current state is " + _state); + } + if (_sendFlag) { + throw new IllegalStateException("Already sending message"); + } + } + + /* (non-Javadoc) + * @see com.software416.jsimplebrowser.XmlHttpRequest#getState() + */ + public short getReadyState() { + return _state.getValue(); + } + + + /* (non-Javadoc) + * @see org.w3c.dom.events.EventTarget#addEventListener(java.lang.String, org.w3c.dom.events.EventListener, boolean) + */ + public void addEventListener(String type, EventListener listener, boolean useCapture) { + if (type.equalsIgnoreCase("readystatechange") && !_eventListeners.contains(listener)) { + _eventListeners.add(listener); + } + } + + /* (non-Javadoc) + * @see org.w3c.dom.events.EventTarget#dispatchEvent(org.w3c.dom.events.Event) + */ + public boolean dispatchEvent(Event evt) throws EventException { + if (_mandatoryListener != null) { + _mandatoryListener.handleEvent(evt); + } + for (EventListener listener : _eventListeners) { + listener.handleEvent(evt); + } + return true; + } + + /* (non-Javadoc) + * @see org.w3c.dom.events.EventTarget#removeEventListener(java.lang.String, org.w3c.dom.events.EventListener, boolean) + */ + public void removeEventListener(String type, EventListener listener, boolean useCapture) { + _eventListeners.remove(listener); + } + + public void onReadyStateChange(EventListener listener) { + _mandatoryListener = listener; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-13 21:08:32
|
Revision: 48 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=48&view=rev Author: rdimarco Date: 2007-08-13 14:08:29 -0700 (Mon, 13 Aug 2007) Log Message: ----------- Refactored to support asynchronous events. Broke XmlHttpRequests but will fix shortly. Modified Paths: -------------- trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java Added Paths: ----------- trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/ trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEvent.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventListener.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventType.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEvent.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventListener.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventType.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEvent.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventListener.java trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventType.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestFailureEvent.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestSuccessEvent.java trunk/core/src/test/java/com/software416/jsimplebrowser/impl/WindowTest.java trunk/src/site/images/ trunk/src/site/images/Request_Flow_Diagram.png Modified: trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java =================================================================== --- trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,6 +10,7 @@ // package com.software416.jsimplebrowser.client; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; @@ -31,11 +32,19 @@ import com.google.inject.Guice; import com.google.inject.Inject; import com.software416.jsimplebrowser.Browser; -import com.software416.jsimplebrowser.BrowserException; +import com.software416.jsimplebrowser.BrowserRuntimeException; import com.software416.jsimplebrowser.Window; +import com.software416.jsimplebrowser.event.BrowserEvent; +import com.software416.jsimplebrowser.event.BrowserEventListener; +import com.software416.jsimplebrowser.event.BrowserEventType; +import com.software416.jsimplebrowser.event.WindowEvent; +import com.software416.jsimplebrowser.event.WindowEventListener; +import com.software416.jsimplebrowser.event.WindowEventType; import com.software416.jsimplebrowser.util.ElementLocator; -public class SimpleClient { +public class SimpleClient implements BrowserEventListener, WindowEventListener{ + public static final int DEFAULT_WAIT_TIME_IN_SECONDS = 15000; + @SuppressWarnings("unused") private static final Log LOG = LogFactory.getLog(SimpleClient.class); @@ -49,6 +58,10 @@ return sc; } + public void setCurrentWindow(String windowName) { + _currentWindowName = windowName; + } + public String getHtmlSource() { return getCurrentWindow().getSource(); } @@ -94,16 +107,16 @@ return windowNames.toArray(new String[windowNames.size()]); } - public void open(String url) throws BrowserException { + public void open(String url) throws URISyntaxException { getCurrentWindow().open(url); } - public void openWindow(String windowName, String url) throws BrowserException { + public void openWindow(String windowName, String url) throws URISyntaxException { _currentWindowName = windowName; getCurrentWindow().open(url); } - public void submitForm(String id) throws BrowserException { + public void submitForm(String id) throws URISyntaxException { getCurrentWindow().submitForm(id, new MultiHashMap()); } @@ -114,7 +127,7 @@ } } - public void click(String id) throws BrowserException { + public void click(String id) throws URISyntaxException { Element e = new ElementLocator(getDocument()).findElement(id); if (e != null) { if (e.getTagName().equalsIgnoreCase("a")) { @@ -146,6 +159,43 @@ } } + public void handleBrowserEvent(BrowserEvent e) { + if (e.getType().equals(BrowserEventType.WINDOW_OPENED)) { + ((Window)e.getTarget()).addWindowEventListener(this); + } + } + + public void handleWindowEvent(WindowEvent e) { + if (e.getType().equals(WindowEventType.LOAD)) { + // Nothing for now. + } else if (e.getType().equals(WindowEventType.REQUEST_FAILED)) { + // Nothing for now. + } + } + + public void waitForWindowToLoad(int timeOut) { + waitForWindowToLoad(getCurrentWindow().getWindowName(), timeOut); + } + + public void waitForWindowToLoad(String windowName) { + waitForWindowToLoad(windowName, DEFAULT_WAIT_TIME_IN_SECONDS); + } + + public void waitForWindowToLoad(String windowName, int timeoutInSeconds) { + Window w = _browser.getWindow(windowName); + long time = System.currentTimeMillis(); + while (w.isWindowLoading()) { + try { + Thread.sleep(50); + if ((System.currentTimeMillis() - time) > (timeoutInSeconds*1000)) { + throw new BrowserRuntimeException("Request has timed out."); + } + } catch (InterruptedException ex) { + return; + } + } + } + // public String[] getAllWindowTitles() { // throw new UnsupportedOperationException(); // } @@ -314,13 +364,6 @@ // // } // -// public void waitForFrameToLoad(String arg0, String arg1) { -// // noop -// } -// -// public void waitForPageToLoad(String arg0) { -// // noop -// } // public void check(String id) { // throw new UnsupportedOperationException(); // } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,21 +10,36 @@ // package com.software416.jsimplebrowser; +import java.net.URISyntaxException; import java.util.List; -import org.apache.commons.httpclient.HttpMethod; - import com.google.inject.ImplementedBy; +import com.software416.jsimplebrowser.event.BrowserEventListener; import com.software416.jsimplebrowser.impl.BrowserImpl; @ImplementedBy(BrowserImpl.class) public interface Browser { public static final String MAIN_BROWSER_WINDOW_NAME = "main"; - public void open(String url) throws BrowserException; - public void open(String url, String window) throws BrowserException; - public HttpResponse makeXmlHttpRequest(String url, String requestBody) throws BrowserException; public Window getWindow(String windowName); public void closeWindow(String windowName); public List<String> getWindowNames(); - HttpResponse makeRequest(HttpMethod hm) throws BrowserException; + + /** + * Open a URL in the current window + * @param url The location to connect to. May be relative URL if a previous request has been + * made in the current window. + * @throws BrowserException - Any problems are sent back to the user + */ + public void open(String url) throws URISyntaxException; + + /** + * Open a URL in the specified window. If the window exists, it will be used. Otherwise, it will be created. + * @param url The location to connect to. May be relative URL if a previous request has been + * made in the current window. + * @throws BrowserException - Any problems are sent back to the user + */ + public void open(String url, String window) throws URISyntaxException; + + public void addBrowserEventListener(BrowserEventListener listener); + public void removeBrowserEventListener(BrowserEventListener listener); } Added: trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/RequestService.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,43 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser; + +import org.apache.commons.httpclient.HttpMethod; + +import com.google.inject.ImplementedBy; +import com.software416.jsimplebrowser.event.RequestEventListener; +import com.software416.jsimplebrowser.impl.RequestServiceImpl; + +/** + * @author Rob Di Marco + */ +@ImplementedBy(RequestServiceImpl.class) +public interface RequestService { + /** + * Make a Http request with the specified message body. Ofent used to make + * AJAX calls. + * + * @param url The URL to connect to. Must be an absolute URL + * @param requestBody The text that will be passed as the body context to the server + * @return the response ID associated with the request + */ + public String makeXmlHttpRequest(String url, String requestBody); + + /** + * Make a request with a specified request method. Intended for internal use + * @param hm The HttpMethod that will be used to execute the request + * @return the response id. + */ + String makeRequest(HttpMethod hm); + + public void addRequestEventListener(RequestEventListener listener); + public void removeRequestEventListener(RequestEventListener listener); +} Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,19 +10,26 @@ // package com.software416.jsimplebrowser; +import java.net.URISyntaxException; + import org.apache.commons.collections.MultiMap; import org.w3c.dom.Document; import com.google.inject.ProvidedBy; +import com.software416.jsimplebrowser.event.WindowEventListener; import com.software416.jsimplebrowser.impl.WindowProvider; @ProvidedBy(WindowProvider.class) public interface Window { - public void open(String url) throws BrowserException; - public void submitForm(String formName, MultiMap parameters) throws BrowserException; + public String getWindowName(); + public String open(String url) throws URISyntaxException; + public String submitForm(String formName, MultiMap parameters) throws URISyntaxException; public HttpResponse getRequestInfo(); public Document getDocument(); public String getSource(); public History getHistory(); public String getLocation(); + public void addWindowEventListener(WindowEventListener listener); + public void removeWindowEventListener(WindowEventListener listener); + public boolean isWindowLoading(); } Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEvent.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,38 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +import java.util.Map; + +public class BrowserEvent { + private BrowserEventType _type; + private Object _target; + private Map<String, Object> _eventProperties; + public Map<String, Object> getEventProperties() { + return _eventProperties; + } + public void setEventProperties(Map<String, Object> eventProperties) { + _eventProperties = eventProperties; + } + public Object getTarget() { + return _target; + } + public void setTarget(Object target) { + _target = target; + } + public BrowserEventType getType() { + return _type; + } + public void setType(BrowserEventType type) { + _type = type; + } + +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventListener.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventListener.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventListener.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,15 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +public interface BrowserEventListener { + public void handleBrowserEvent(BrowserEvent e); +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventType.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventType.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/BrowserEventType.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,18 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +/** + * @author Rob Di Marco + */ +public enum BrowserEventType { + WINDOW_OPENED, WINDOW_CLOSED; +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEvent.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,30 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +public abstract class RequestEvent { + public String _requestId; + public RequestEventType _type; + public RequestEventType getType() { + return _type; + } + public void setType(RequestEventType type) { + _type = type; + } + public String getRequestId() { + return _requestId; + } + public void setRequestId(String requestId) { + _requestId = requestId; + } + + public abstract byte[] getResponseBytes(); +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventListener.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventListener.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventListener.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,15 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +public interface RequestEventListener { + public void handleRequestEvent(RequestEvent e); +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventType.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventType.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/RequestEventType.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,5 @@ +package com.software416.jsimplebrowser.event; + +public enum RequestEventType { + SUCCESS, FAILURE +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEvent.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,54 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import com.software416.jsimplebrowser.Window; + +public class WindowEvent { + private WindowEventType _type; + private Map<String, Object> _properties = new HashMap<String, Object>(); + private Window _eventWindow; + + public WindowEventType getType() { + return _type; + } + + public void setType(WindowEventType type) { + _type = type; + } + + public void addProperty(String key, Object value) { + _properties.put(key, value); + } + + public Object getProperty(String key) { + return _properties.get(key); + } + + /** + * @return A read only map representing the current properties. + */ + public Map<String, Object> getProperties() { + return Collections.unmodifiableMap(_properties); + } + + public Window getEventWindow() { + return _eventWindow; + } + + public void setEventWindow(Window eventWindow) { + _eventWindow = eventWindow; + } +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventListener.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventListener.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventListener.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,18 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.event; + +/** + * @author Rob Di Marco + */ +public interface WindowEventListener { + public void handleWindowEvent(WindowEvent e); +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventType.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventType.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/event/WindowEventType.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,5 @@ +package com.software416.jsimplebrowser.event; + +public enum WindowEventType { + LOAD, UNLOAD, REQUEST_FAILED +} Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,81 +10,76 @@ // package com.software416.jsimplebrowser.impl; -import java.io.ByteArrayOutputStream; -import java.io.IOException; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.apache.commons.io.IOUtils; - import com.google.inject.Inject; import com.google.inject.Provider; import com.software416.jsimplebrowser.Browser; -import com.software416.jsimplebrowser.BrowserException; import com.software416.jsimplebrowser.Window; +import com.software416.jsimplebrowser.event.BrowserEvent; +import com.software416.jsimplebrowser.event.BrowserEventListener; +import com.software416.jsimplebrowser.event.BrowserEventType; public class BrowserImpl implements Browser { @Inject private Provider<Window> _windowProvider; - private HttpClient _client = new HttpClient(); private Map<String, Window> _browserWindows = new HashMap<String, Window>(); + private List<BrowserEventListener> _eventListeners = new ArrayList<BrowserEventListener>(); - public synchronized HttpResponseImpl makeRequest(HttpMethod m) throws BrowserException { - HttpResponseImpl ri = new HttpResponseImpl(); - ri.setRequestMethod(m); - - try { - ri.setResponseCode(_client.executeMethod(m)); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - IOUtils.copy(m.getResponseBodyAsStream(), bos); - ri.setResponseBody(bos.toByteArray()); - } catch (HttpException ex) { - throw new BrowserException(ex); - } catch (IOException ex) { - throw new BrowserException(ex); - } - return ri; - } - - public HttpResponseImpl makeXmlHttpRequest(String url, String requestBody) throws BrowserException { - PostMethod m = new PostMethod(url); - try { - m.setRequestEntity(new StringRequestEntity(requestBody, "text/plain",null)); - return makeRequest(m); - } catch (IOException ex) { - throw new BrowserException(ex); - } - } - - public void open(String url) throws BrowserException { + public void open(String url) throws URISyntaxException { open(url, MAIN_BROWSER_WINDOW_NAME); } - public void open(String url, String window) throws BrowserException { + public void open(String url, String window) throws URISyntaxException { getWindow(window).open(url); } public synchronized Window getWindow(String windowName) { if (!_browserWindows.containsKey(windowName)) { - WindowProvider.CURRENT_BROWSER.set(this); + // Create window. + // We use the ThreadLocal current browser variable + // to pass this browser instance to the window that is + // created. + WindowProvider.NEXT_WINDOW_NAME.set(windowName); _browserWindows.put(windowName, _windowProvider.get()); - WindowProvider.CURRENT_BROWSER.remove(); + WindowProvider.NEXT_WINDOW_NAME.remove(); + + // Send the appropriate event + BrowserEvent e = new BrowserEvent(); + e.setType(BrowserEventType.WINDOW_OPENED); + e.setTarget(_browserWindows.get(windowName)); + notifyBrowserEventListeners(e); } return _browserWindows.get(windowName); } public void closeWindow(String windowName) { _browserWindows.remove(windowName); + BrowserEvent e = new BrowserEvent(); + e.setType(BrowserEventType.WINDOW_CLOSED); + e.setTarget(_browserWindows.get(windowName)); + notifyBrowserEventListeners(e); } public List<String> getWindowNames() { return new ArrayList<String>(_browserWindows.keySet()); } + + public void notifyBrowserEventListeners(BrowserEvent e) { + for (BrowserEventListener listener : _eventListeners) { + listener.handleBrowserEvent(e); + } + } + + public void addBrowserEventListener(BrowserEventListener listener) { + _eventListeners.add(listener); + } + + public void removeBrowserEventListener(BrowserEventListener listener) { + _eventListeners.remove(listener); + } } Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestFailureEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestFailureEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestFailureEvent.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,48 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.impl; + +import org.apache.commons.httpclient.HttpMethod; + +import com.software416.jsimplebrowser.event.RequestEvent; +import com.software416.jsimplebrowser.event.RequestEventType; + +/** + * @author Rob Di Marco + */ +public class RequestFailureEvent extends RequestEvent{ + private HttpMethod _request; + private Throwable _cause; + + public Throwable getCause() { + return _cause; + } + + public void setCause(Throwable cause) { + _cause = cause; + } + + public RequestFailureEvent() { + setType(RequestEventType.FAILURE); + } + + public HttpMethod getRequest() { + return _request; + } + + public void setRequest(HttpMethod request) { + _request = request; + } + @Override + public byte[] getResponseBytes() { + return null; + } +} \ No newline at end of file Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestServiceImpl.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,111 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.impl; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.commons.io.IOUtils; + +import com.google.inject.Singleton; +import com.software416.jsimplebrowser.BrowserRuntimeException; +import com.software416.jsimplebrowser.RequestService; +import com.software416.jsimplebrowser.event.RequestEvent; +import com.software416.jsimplebrowser.event.RequestEventListener; + +/** + * @author Rob Di Marco + */ +@Singleton +public class RequestServiceImpl implements RequestService { + private static final int REQUEST_POOL_THREAD_COUNT = 5; + HttpClient _client = new HttpClient(); + private List<RequestEventListener> _eventListeners = new ArrayList<RequestEventListener>(); + private AtomicInteger _requestIdCounter = new AtomicInteger(1); + private ExecutorService _requestPool = new ThreadPoolExecutor(1, REQUEST_POOL_THREAD_COUNT, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>()); + public String makeRequest(final HttpMethod m) { + final String requestId = String.valueOf(_requestIdCounter.addAndGet(1)); + _requestPool.execute(new Runnable() { + + public void run() { + HttpResponseImpl ri = new HttpResponseImpl(); + ri.setRequestMethod(m); + + try { + ri.setResponseCode(_client.executeMethod(m)); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + IOUtils.copy(m.getResponseBodyAsStream(), bos); + ri.setResponseBody(bos.toByteArray()); + notifyOfRequestSuccess(requestId, m, ri); + } catch (HttpException ex) { + notifyOfRequestFailure(requestId, m, ex); + } catch (IOException ex) { + notifyOfRequestFailure(requestId, m, ex); + } + } + }); + return requestId; + } + + protected void notifyOfRequestSuccess(String requestId, HttpMethod request, HttpResponseImpl response) { + RequestSuccessEvent e = new RequestSuccessEvent(); + e.setRequestId(requestId); + e.setRequest(request); + e.setResponse(response); + notifyListenersOfRequestEvent(e); + } + + protected void notifyOfRequestFailure(String requestId, HttpMethod method, Throwable t) { + RequestFailureEvent e = new RequestFailureEvent(); + e.setRequestId(requestId); + e.setRequest(method); + e.setCause(t); + notifyListenersOfRequestEvent(e); + + } + + protected void notifyListenersOfRequestEvent(RequestEvent e) { + for (RequestEventListener listener : _eventListeners) { + listener.handleRequestEvent(e); + } + } + + public String makeXmlHttpRequest(String url, String requestBody) { + PostMethod m = new PostMethod(url); + try { + m.setRequestEntity(new StringRequestEntity(requestBody, "text/plain",null)); + } catch (UnsupportedEncodingException ex) { + throw new BrowserRuntimeException("Really weird encoding issue", ex); + } + return makeRequest(m); + } + + public void addRequestEventListener(RequestEventListener listener) { + _eventListeners.add(listener); + } + public void removeRequestEventListener(RequestEventListener listener) { + _eventListeners.remove(listener); + } + +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestSuccessEvent.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestSuccessEvent.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestSuccessEvent.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,50 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// +package com.software416.jsimplebrowser.impl; + +import org.apache.commons.httpclient.HttpMethod; + +import com.software416.jsimplebrowser.event.RequestEvent; +import com.software416.jsimplebrowser.event.RequestEventType; + +/** + * @author Rob Di Marco + */ +public class RequestSuccessEvent extends RequestEvent { + private HttpMethod _request; + private HttpResponseImpl _response; + + public RequestSuccessEvent() { + setType(RequestEventType.SUCCESS); + } + + public HttpMethod getRequest() { + return _request; + } + + public void setRequest(HttpMethod request) { + _request = request; + } + + public HttpResponseImpl getResponse() { + return _response; + } + + public void setResponse(HttpResponseImpl response) { + _response = response; + } + + @Override + public byte[] getResponseBytes() { + return _response.getResponseBody(); + } + +} Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,9 +10,13 @@ // package com.software416.jsimplebrowser.impl; -import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -24,73 +28,98 @@ import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import com.google.inject.Inject; -import com.software416.jsimplebrowser.Browser; -import com.software416.jsimplebrowser.BrowserException; import com.software416.jsimplebrowser.BrowserRuntimeException; import com.software416.jsimplebrowser.History; import com.software416.jsimplebrowser.HtmlParseException; import com.software416.jsimplebrowser.HttpResponse; +import com.software416.jsimplebrowser.RequestService; import com.software416.jsimplebrowser.Window; +import com.software416.jsimplebrowser.event.RequestEvent; +import com.software416.jsimplebrowser.event.RequestEventListener; +import com.software416.jsimplebrowser.event.RequestEventType; +import com.software416.jsimplebrowser.event.WindowEvent; +import com.software416.jsimplebrowser.event.WindowEventListener; +import com.software416.jsimplebrowser.event.WindowEventType; import com.software416.jsimplebrowser.util.HtmlToDomConverter; -public class WindowImpl implements Window { +public class WindowImpl implements Window, RequestEventListener { + private static final Log LOG = LogFactory.getLog(WindowImpl.class); + @Inject private RequestService _requestService; + private String _windowName; private HttpResponse _requestInfo; private Document _responseDocument; - private Browser _browser; private HtmlToDomConverter _converter = new HtmlToDomConverter(); - private boolean _doFollowRedirects = true; + private boolean _doFollowRedirects = true; + protected List<WindowEventListener> _eventListeners = new ArrayList<WindowEventListener>(); + /** Controls how many threads will be used to emit events to event listeners. */ + private int _eventListenerThreadCount = 1; + private final ExecutorService _eventThreadService = Executors.newFixedThreadPool(_eventListenerThreadCount); + private boolean _isWindowLoading = false; - @Inject - public WindowImpl(Browser b) { - _browser = b; + public WindowImpl(String windowName) { + _windowName = windowName; } - public void open(String url) throws BrowserException { - try { - GetMethod gm; - if (_requestInfo != null) { - gm = new GetMethod(); + protected void setRequestService(RequestService requestService) { + _requestService = requestService; + _requestService.addRequestEventListener(this); + } + + public String open(String url) throws URISyntaxException { + GetMethod gm; + if (_requestInfo != null) { + gm = new GetMethod(); + try { gm.setURI(new URI(new URI(_requestInfo.getLocation(), true), url, true)); - } else { - gm = new GetMethod(url); - } - makeRequest(gm); - } catch (IOException ex) { - throw new BrowserException(ex); - } + } catch (URIException ex) { + LOG.info("Invalid URI Exception", ex); + throw new URISyntaxException(url, ex.getMessage()); + } + } else { + gm = new GetMethod(url); + } + return makeRequest(gm); } - protected void makeRequest(HttpMethod hm) throws BrowserException { - handleResponse(_browser.makeRequest(hm)); + protected String makeRequest(HttpMethod hm) { + _isWindowLoading = true; + return _requestService.makeRequest(hm); } - public void handleResponse(HttpResponse requestInfo) throws BrowserException { + public void handleResponse(HttpResponse requestInfo) { _requestInfo = requestInfo; _responseDocument = null; if (_doFollowRedirects) { String link = findRefreshLink(); if (link != null) { - open(link); + try { + open(link); + } catch (URISyntaxException ex) { + LOG.warn("Weird URI Syntax problem when trying to follow a redirect", ex); + } + } } + _isWindowLoading = false; + WindowEvent e = new WindowEvent(); + e.setType(WindowEventType.LOAD); + notifyOfWindowEvents(e); } - public void submitForm(String formName, MultiMap userSpecifiedParameterMap) throws BrowserException { - try { - HttpMethod m = buildMethodForForm(formName, userSpecifiedParameterMap); - if (m == null) { - throw new BrowserException("Could not submit form '" + formName + "' as it does not exist!!"); - } - makeRequest(m); - } catch (IOException ex) { - throw new BrowserException(ex); + public String submitForm(String formName, MultiMap userSpecifiedParameterMap) throws URISyntaxException { + HttpMethod m = buildMethodForForm(formName, userSpecifiedParameterMap); + if (m == null) { + throw new BrowserRuntimeException("Could not submit form '" + formName + "' as it does not exist!!"); } - } + return makeRequest(m); +} protected String findRefreshLink() { NodeList meta = getDocument().getElementsByTagName("meta"); @@ -110,7 +139,7 @@ } @SuppressWarnings("unchecked") - protected HttpMethod buildMethodForForm(String formName, MultiMap userParamMap) throws URIException { + protected HttpMethod buildMethodForForm(String formName, MultiMap userParamMap) throws URISyntaxException { Element formElement = findFormElementByFormNameOrId(formName); if (formElement == null) { return null; @@ -123,8 +152,12 @@ String formMethod = formElement.getAttribute("method"); boolean usePost = formMethod != null && formMethod.toUpperCase().equals("POST"); HttpMethod rv = usePost ? new PostMethod() : new GetMethod(); - - rv.setURI(new URI(new URI(_requestInfo.getLocation(), true), new URI(formElement.getAttribute("action"), true))); + String action = formElement.getAttribute("action"); + try { + rv.setURI(new URI(new URI(_requestInfo.getLocation(), true), new URI(action, true))); + } catch (URIException ex1) { + throw new URISyntaxException(action, ex1.getMessage()); + } Collection params = formParameters.values(); if (usePost) { @@ -132,8 +165,12 @@ } else { Iterator i = params.iterator(); StringBuilder sb = new StringBuilder(); - if (rv.getURI().getQuery() != null) { - sb.append(rv.getURI().getQuery()); + try { + if (rv.getURI().getQuery() != null) { + sb.append(rv.getURI().getQuery()); + } + } catch (URIException ex1) { + throw new BrowserRuntimeException("Unusual URI problem", ex1); } while (i.hasNext()) { if (sb.length() > 0) { @@ -148,7 +185,10 @@ rv.setURI(newUri); } catch (CloneNotSupportedException ex) { // Should never happen! - throw new RuntimeException(ex); + throw new BrowserRuntimeException(ex); + } catch (URIException ex) { + // Should never happen! + throw new BrowserRuntimeException("Unusual problem with URI", ex); } } @@ -228,7 +268,6 @@ return null; } - public String getSource() { return new String(_requestInfo.getResponseBody()); } @@ -243,10 +282,20 @@ } return _responseDocument; } + + protected void createWindowEvent() { + final WindowEvent e = new WindowEvent(); + _eventThreadService.execute(new Runnable() { + public void run() { + for (WindowEventListener listener : _eventListeners) { + listener.handleWindowEvent(e); + } + } + }); + } public History getHistory() { - // TODO Auto-generated method stub - return null; + throw new UnsupportedOperationException(); } public String getLocation() { @@ -268,7 +317,54 @@ public void setDoFollowRedirects(boolean doFollowRedirects) { _doFollowRedirects = doFollowRedirects; } + + protected void notifyOfWindowEvents(WindowEvent e) { + e.setEventWindow(this); + for (WindowEventListener listener : _eventListeners) { + listener.handleWindowEvent(e); + } + } + + public void addWindowEventListener(WindowEventListener listener) { + _eventListeners.add(listener); + } + public void removeWindowEventListener(WindowEventListener listener) { + _eventListeners.remove(listener); + } + + public void handleRequestEvent(RequestEvent e) { + if (e.getType().equals(RequestEventType.SUCCESS)) { + handleResponse(((RequestSuccessEvent)e).getResponse()); + } else if (e.getType().equals(RequestEventType.FAILURE)) { + WindowEvent we = new WindowEvent(); + we.setType(WindowEventType.REQUEST_FAILED); + we.addProperty("requestId", e.getRequestId()); + notifyOfWindowEvents(we); + } else { + LOG.warn("Unhandled request event: " + e); + } + } + + public boolean isWindowLoading() { + return _isWindowLoading; + } + + public void setWindowLoading(boolean isWindowLoading) { + _isWindowLoading = isWindowLoading; + } + + public String getWindowName() { + return _windowName; + } + + public void setWindowName(String windowName) { + _windowName = windowName; + } + + public RequestService getRequestService() { + return _requestService; + } } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,18 +10,24 @@ // package com.software416.jsimplebrowser.impl; +import com.google.inject.Inject; import com.google.inject.Provider; -import com.software416.jsimplebrowser.Browser; +import com.software416.jsimplebrowser.RequestService; import com.software416.jsimplebrowser.Window; public class WindowProvider implements Provider<Window> { - protected static final ThreadLocal<Browser> CURRENT_BROWSER = new ThreadLocal<Browser>(); + protected static final ThreadLocal<String> NEXT_WINDOW_NAME = new ThreadLocal<String>(); + + @Inject private RequestService _requestService; + public Window get() { - Browser b = CURRENT_BROWSER.get(); - if (b == null) { + String name = NEXT_WINDOW_NAME.get(); + if (name == null) { throw new IllegalStateException("Browser cannot be null"); } - return new WindowImpl(b); + WindowImpl wi = new WindowImpl(name); + wi.setRequestService(_requestService); + return wi; } } Modified: trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java 2007-08-13 21:08:29 UTC (rev 48) @@ -13,6 +13,7 @@ import static org.junit.Assert.*; import java.io.IOException; +import java.net.URISyntaxException; import org.apache.commons.collections.MultiHashMap; import org.apache.commons.collections.MultiMap; @@ -35,7 +36,7 @@ System.setProperty("org.apache.commons.logging.simplelog.log.com.software416", "debug"); } - @Test public void testParsingBadPages() throws BrowserException, IOException { + @Test public void testParsingBadPages() throws URISyntaxException, IOException { String baseForm = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("badlyFormattedPage.html")); HttpResponseImpl requestInfo = new HttpResponseImpl(); requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); @@ -44,7 +45,7 @@ wi.handleResponse(requestInfo); } - @Test public void testGetMetaRefresh() throws BrowserException { + @Test public void testGetMetaRefresh() throws URISyntaxException { WindowImpl w = new WindowImpl(null); w.setDoFollowRedirects(false); HttpResponseImpl ri = new HttpResponseImpl(); @@ -67,7 +68,7 @@ w.handleResponse(ri); assertNull(w.findRefreshLink()); } - @Test public void testDefaultFormValuesMethodGeneration() throws BrowserException, IOException { + @Test public void testDefaultFormValuesMethodGeneration() throws URISyntaxException, IOException, BrowserException { String baseForm = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("formTest1.html")); HttpResponseImpl requestInfo = new HttpResponseImpl(); requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); @@ -87,7 +88,7 @@ assertTrue(m.getURI().getQuery().contains("selectInput=youGotIt")); assertEquals(6, m.getURI().getQuery().split("&").length); } - @Test public void testFormMethodGeneration() throws BrowserException, URIException { + @Test public void testFormMethodGeneration() throws URISyntaxException, URIException { String baseForm = "<html><body><form name=\"%1$s\" method=\"%2$s\" action=\"%3$s\"></form></body></html>"; HttpResponseImpl requestInfo = new HttpResponseImpl(); requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); Added: trunk/core/src/test/java/com/software416/jsimplebrowser/impl/WindowTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/impl/WindowTest.java (rev 0) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/impl/WindowTest.java 2007-08-13 21:08:29 UTC (rev 48) @@ -0,0 +1,22 @@ +package com.software416.jsimplebrowser.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.google.inject.Guice; +import com.software416.jsimplebrowser.Window; + +public class WindowTest { + @Test public void testInjection() { + String windowName = "testWindow"; + WindowProvider.NEXT_WINDOW_NAME.set(windowName); + Window w = Guice.createInjector().getInstance(Window.class); + assertNotNull(w); + assertEquals(WindowImpl.class, w.getClass()); + assertEquals(windowName, w.getWindowName()); + WindowImpl wi = (WindowImpl)w; + assertNotNull("request service is null", wi.getRequestService()); + WindowProvider.NEXT_WINDOW_NAME.remove(); + } +} Modified: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-13 16:14:23 UTC (rev 47) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-13 21:08:29 UTC (rev 48) @@ -10,18 +10,19 @@ // package com.software416.jsimplebrowser.seleniumclient; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import com.software416.jsimplebrowser.BrowserException; import com.software416.jsimplebrowser.client.SimpleClient; import com.software416.jsimplebrowser.util.ElementLocator; import com.thoughtworks.selenium.Selenium; @@ -209,7 +210,7 @@ public void click(String id) { try { _simpleClient.click(id); - } catch (BrowserException ex) { + } catch (URISyntaxException ex) { LOG.warn("Problem clicking id: " + id, ex); } } @@ -284,7 +285,8 @@ try { url = buildUrl(url); _simpleClient.open(url); - } catch (BrowserException ex) { + waitForPageToLoad("15000"); + } catch (URISyntaxException ex) { LOG.warn("Problem loading page", ex); } } @@ -299,7 +301,7 @@ public void openWindow(String windowName, String url) { try { _simpleClient.openWindow(windowName, url); - } catch (BrowserException ex) { + } catch (URISyntaxException ex) { LOG.warn("Problem loading page", ex); } } @@ -323,14 +325,12 @@ } - public void selectFrame(String arg0) { - throw new UnsupportedOperationException(); - + public void selectFrame(String frameName) { + _simpleClient.setCurrentWindow(frameName); } - public void selectWindow(String arg0) { - throw new UnsupportedOperationException(); - + public void selectWindow(String windowName) { + _simpleClient.setCurrentWindow(windowName); } public void setBrowserLogLevel(String arg0) { @@ -353,7 +353,7 @@ public void submit(String id) { try { _simpleClient.submitForm(id); - } catch (BrowserException ex ) { + } catch (URISyntaxException ex ) { LOG.error("Problem submitting form: " + id, ex); } } @@ -366,7 +366,7 @@ throw new UnsupportedOperationException(); } - public void setTimeout(String arg0) { + public void setTimeout(String timeout) { throw new UnsupportedOperationException(); } @@ -375,17 +375,18 @@ } - public void waitForCondition(String arg0, String arg1) { + public void waitForCondition(String condition, String timeOut) { throw new UnsupportedOperationException(); } - public void waitForFrameToLoad(String arg0, String arg1) { - // noop right now until we make requests asynchronous... + public void waitForFrameToLoad(String windowName, String timeOut) { + _simpleClient.waitForWindowToLoad(windowName, Integer.parseInt(timeOut)); } - public void waitForPageToLoad(String arg0) { - // noop right now until we make requests asynchronous... + public void waitForPageToLoad(String timeOutStr) { + int timeOut = StringUtils.isEmpty(timeOutStr) ? SimpleClient.DEFAULT_WAIT_TIME_IN_SECONDS : Integer.parseInt(timeOutStr); + _simpleClient.waitForWindowToLoad(timeOut); } // Added: trunk/src/site/images/Request_Flow_Diagram.png =================================================================== (Binary files differ) Property changes on: trunk/src/site/images/Request_Flow_Diagram.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-13 16:21:00
|
Revision: 47 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=47&view=rev Author: rdimarco Date: 2007-08-13 09:14:23 -0700 (Mon, 13 Aug 2007) Log Message: ----------- Added license information to all files. Modified Paths: -------------- trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java trunk/client/src/test/java/com/software416/jsimplebrowser/client/SimpleClientTest.java trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserException.java trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserRuntimeException.java trunk/core/src/main/java/com/software416/jsimplebrowser/History.java trunk/core/src/main/java/com/software416/jsimplebrowser/HtmlParseException.java trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java trunk/core/src/main/java/com/software416/jsimplebrowser/util/BrowserHelper.java trunk/core/src/main/java/com/software416/jsimplebrowser/util/ElementLocator.java trunk/core/src/main/java/com/software416/jsimplebrowser/util/HtmlToDomConverter.java trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java trunk/core/src/test/java/com/software416/jsimplebrowser/util/ElementLocatorTest.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientException.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumCommand.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunner.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureEvent.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureListener.java trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunnerTest.java Modified: trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java =================================================================== --- trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.client; import java.util.ArrayList; Modified: trunk/client/src/test/java/com/software416/jsimplebrowser/client/SimpleClientTest.java =================================================================== --- trunk/client/src/test/java/com/software416/jsimplebrowser/client/SimpleClientTest.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/client/src/test/java/com/software416/jsimplebrowser/client/SimpleClientTest.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.client; import static org.junit.Assert.*; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser; import java.util.List; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserException.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserException.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserException.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser; public class BrowserException extends Exception { Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserRuntimeException.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserRuntimeException.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserRuntimeException.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser; public class BrowserRuntimeException extends RuntimeException { Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/History.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/History.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/History.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser; public interface History { Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/HtmlParseException.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/HtmlParseException.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/HtmlParseException.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser; public class HtmlParseException extends BrowserException { Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser; import org.apache.commons.collections.MultiMap; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser; import org.apache.commons.collections.MultiMap; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.impl; import java.io.ByteArrayOutputStream; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.impl; import java.util.Collection; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.impl; import java.io.IOException; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.impl; import com.google.inject.Provider; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/util/BrowserHelper.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/util/BrowserHelper.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/util/BrowserHelper.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.util; import java.util.ArrayList; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/util/ElementLocator.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/util/ElementLocator.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/util/ElementLocator.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.util; import javax.xml.xpath.XPath; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/util/HtmlToDomConverter.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/util/HtmlToDomConverter.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/util/HtmlToDomConverter.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.util; import java.io.ByteArrayInputStream; Modified: trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.impl; import static org.junit.Assert.*; Modified: trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.util; import static org.junit.Assert.assertEquals; Modified: trunk/core/src/test/java/com/software416/jsimplebrowser/util/ElementLocatorTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/util/ElementLocatorTest.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/util/ElementLocatorTest.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.util; import static org.junit.Assert.*; Modified: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.seleniumclient; import java.util.ArrayList; Modified: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientException.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientException.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientException.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.seleniumclient; public class SeleniumClientException extends Exception { Modified: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumCommand.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumCommand.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumCommand.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.seleniumclient; public class SeleniumCommand { Modified: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunner.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunner.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunner.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.seleniumclient; import java.io.File; Modified: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureEvent.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureEvent.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureEvent.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.seleniumclient; public class VerificationFailureEvent { Modified: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureListener.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureListener.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureListener.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.seleniumclient; public interface VerificationFailureListener { Modified: trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java =================================================================== --- trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.seleniumclient; import static org.junit.Assert.*; Modified: trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunnerTest.java =================================================================== --- trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunnerTest.java 2007-08-13 15:49:25 UTC (rev 46) +++ trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunnerTest.java 2007-08-13 16:14:23 UTC (rev 47) @@ -1,3 +1,13 @@ +// +// Copyright (c) 2008, 416 Software, LLC. +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the GNU General Public License v2.0 +// which accompanies this distribution, and is available at +// http://www.gnu.org/licenses/gpl-2.0.txt +// +// Any non-Open Source projects interested in using this program may purchase +// a commercial license by emailing sa...@41... +// package com.software416.jsimplebrowser.seleniumclient; import static org.junit.Assert.*; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-13 15:49:30
|
Revision: 46 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=46&view=rev Author: rdimarco Date: 2007-08-13 08:49:25 -0700 (Mon, 13 Aug 2007) Log Message: ----------- Added license information. Added Paths: ----------- trunk/LICENSE.txt Added: trunk/LICENSE.txt =================================================================== --- trunk/LICENSE.txt (rev 0) +++ trunk/LICENSE.txt 2007-08-13 15:49:25 UTC (rev 46) @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-11 20:44:16
|
Revision: 45 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=45&view=rev Author: rdimarco Date: 2007-08-11 13:44:05 -0700 (Sat, 11 Aug 2007) Log Message: ----------- Got a script generated Selenium IDE to actually work! Modified Paths: -------------- trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java Added Paths: ----------- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientException.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumCommand.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunner.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureEvent.java trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureListener.java trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunnerTest.java trunk/selenium-client/src/test/resources/testSeleniumHtmlScript.html Modified: trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java =================================================================== --- trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java 2007-08-11 17:36:52 UTC (rev 44) +++ trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java 2007-08-11 20:44:05 UTC (rev 45) @@ -9,10 +9,13 @@ import javax.xml.xpath.XPathFactory; import org.apache.commons.collections.MultiHashMap; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Attr; import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; import org.w3c.dom.NodeList; import com.google.inject.Guice; @@ -20,6 +23,7 @@ import com.software416.jsimplebrowser.Browser; import com.software416.jsimplebrowser.BrowserException; import com.software416.jsimplebrowser.Window; +import com.software416.jsimplebrowser.util.ElementLocator; public class SimpleClient { @SuppressWarnings("unused") @@ -93,7 +97,46 @@ getCurrentWindow().submitForm(id, new MultiHashMap()); } -// public String[] getAllWindowTitles() { + public void type(String id, String value) { + Element e = new ElementLocator(getDocument()).findElement(id); + if (e != null) { + e.setAttribute("value", value); + } + } + + public void click(String id) throws BrowserException { + Element e = new ElementLocator(getDocument()).findElement(id); + if (e != null) { + if (e.getTagName().equalsIgnoreCase("a")) { + // Logic should move to JavaScriptImpl layer to handle other events... + String href = e.getAttribute("href"); + String target = e.getAttribute("target"); + if (!StringUtils.isEmpty(href)) { + if (StringUtils.isEmpty(target)) { + open(href); + } else { + openWindow(target, href); + } + } + } else if (e.getTagName().equalsIgnoreCase("input") && "submit".equalsIgnoreCase(e.getAttribute("type"))) { + Node n = e.getParentNode(); + while (n != null) { + if (n.getNodeType() == Node.ELEMENT_NODE) { + Element parent = (Element)n; + if ("form".equalsIgnoreCase(parent.getTagName())) { + String formId = parent.getAttribute("id"); + String formName = parent.getAttribute("name"); + submitForm(StringUtils.isEmpty(formId) ? formName : formId); + break; + } + } + n = n.getParentNode(); + } + } + } + } + + // public String[] getAllWindowTitles() { // throw new UnsupportedOperationException(); // } // @@ -243,11 +286,6 @@ // // } // -// public void type(String arg0, String arg1) { -// throw new UnsupportedOperationException(); -// -// } -// // public void typeKeys(String arg0, String arg1) { // throw new UnsupportedOperationException(); // @@ -276,11 +314,8 @@ // public void check(String id) { // throw new UnsupportedOperationException(); // } -// public void click(String id) { -// throw new UnsupportedOperationException(); -// } // public void clickAt(String arg0, String arg1) { // throw new UnsupportedOperationException(); // } - +// } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-11 17:36:52 UTC (rev 44) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-11 20:44:05 UTC (rev 45) @@ -63,10 +63,9 @@ public synchronized Window getWindow(String windowName) { if (!_browserWindows.containsKey(windowName)) { - ThreadLocal<Browser> tl = new ThreadLocal<Browser>(); - tl.set(this); + WindowProvider.CURRENT_BROWSER.set(this); _browserWindows.put(windowName, _windowProvider.get()); - tl.remove(); + WindowProvider.CURRENT_BROWSER.remove(); } return _browserWindows.get(windowName); } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-11 17:36:52 UTC (rev 44) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-11 20:44:05 UTC (rev 45) @@ -74,7 +74,7 @@ try { HttpMethod m = buildMethodForForm(formName, userSpecifiedParameterMap); if (m == null) { - throw new BrowserException("Could not submit form as it does not exist!!"); + throw new BrowserException("Could not submit form '" + formName + "' as it does not exist!!"); } makeRequest(m); } catch (IOException ex) { @@ -101,7 +101,7 @@ @SuppressWarnings("unchecked") protected HttpMethod buildMethodForForm(String formName, MultiMap userParamMap) throws URIException { - Element formElement = findFormElementByFormName(formName); + Element formElement = findFormElementByFormNameOrId(formName); if (formElement == null) { return null; } @@ -205,12 +205,13 @@ } } - protected Element findFormElementByFormName(String name) { + protected Element findFormElementByFormNameOrId(String name) { NodeList formElements=getDocument().getElementsByTagName("form"); for (int i = 0; i < formElements.getLength(); i++) { Element formElement=(Element)formElements.item(i); String formName=formElement.getAttribute("name"); - if (name.equals(formName)) { + String formId =formElement.getAttribute("id"); + if (name.equals(formName) || name.equals(formId)) { return formElement; } } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java 2007-08-11 17:36:52 UTC (rev 44) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java 2007-08-11 20:44:05 UTC (rev 45) @@ -5,9 +5,13 @@ import com.software416.jsimplebrowser.Window; public class WindowProvider implements Provider<Window> { - + protected static final ThreadLocal<Browser> CURRENT_BROWSER = new ThreadLocal<Browser>(); public Window get() { - return new WindowImpl(new ThreadLocal<Browser>().get()); + Browser b = CURRENT_BROWSER.get(); + if (b == null) { + throw new IllegalStateException("Browser cannot be null"); + } + return new WindowImpl(b); } } Modified: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-11 17:36:52 UTC (rev 44) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-11 20:44:05 UTC (rev 45) @@ -1,5 +1,7 @@ package com.software416.jsimplebrowser.seleniumclient; +import java.util.ArrayList; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -17,7 +19,16 @@ public class SeleniumClient implements Selenium { private static final Log LOG = LogFactory.getLog(SeleniumClient.class); private SimpleClient _simpleClient = new SimpleClient(); + private String _baseUrl; + public String getBaseUrl() { + return _baseUrl; + } + + public void setBaseUrl(String baseUrl) { + _baseUrl = baseUrl; + } + public String getHtmlSource() { return _simpleClient.getHtmlSource(); } @@ -186,14 +197,23 @@ throw new UnsupportedOperationException(); } public void click(String id) { - throw new UnsupportedOperationException(); + try { + _simpleClient.click(id); + } catch (BrowserException ex) { + LOG.warn("Problem clicking id: " + id, ex); + } } public void clickAt(String arg0, String arg1) { throw new UnsupportedOperationException(); } + public void clickAndWait(String id, String time) { + click(id); + waitForPageToLoad(time); + } public String getText(String id) { - return _simpleClient.getDocument().getElementById(id).getTextContent(); + Element e = _simpleClient.getDocument().getElementById(id); + return e != null ? e.getTextContent() : null; } public String getTitle() { @@ -252,12 +272,20 @@ public void open(String url) { try { + url = buildUrl(url); _simpleClient.open(url); } catch (BrowserException ex) { LOG.warn("Problem loading page", ex); } } + protected String buildUrl(String url) { + if (!url.matches("^https?\\://.*")) { + url = _baseUrl + (!_baseUrl.endsWith("/") && !url.startsWith("/") ? "/" : "") + url; + } + return url; + } + public void openWindow(String windowName, String url) { try { _simpleClient.openWindow(windowName, url); @@ -320,9 +348,8 @@ } } - public void type(String arg0, String arg1) { - throw new UnsupportedOperationException(); - + public void type(String id, String value) { + _simpleClient.type(id, value); } public void typeKeys(String arg0, String arg1) { @@ -344,11 +371,11 @@ } public void waitForFrameToLoad(String arg0, String arg1) { - // noop + // noop right now until we make requests asynchronous... } public void waitForPageToLoad(String arg0) { - // noop + // noop right now until we make requests asynchronous... } // @@ -606,6 +633,30 @@ public void setSimpleClient(SimpleClient simpleClient) { _simpleClient = simpleClient; } + + private List<VerificationFailureListener> _verificationFailureListeners = new ArrayList<VerificationFailureListener>(); - + public void addVerificationFailureListener(VerificationFailureListener listener) { + _verificationFailureListeners.add(listener); + } + + public void removeVerificationFailureListener(VerificationFailureListener listener) { + _verificationFailureListeners.remove(listener); + } + + protected void createVerificationFailureEvent(String command, String... args) { + SeleniumCommand sc = new SeleniumCommand(); + sc.setCommand(command); + sc.setArguments(args); + VerificationFailureEvent e = new VerificationFailureEvent(sc, this); + for (VerificationFailureListener listener : _verificationFailureListeners) { + listener.handleVerificationFailureEvent(e); + } + } + + public void verifyTextPresent(String text) { + if (!getHtmlSource().contains(text)) { + createVerificationFailureEvent("verifyTextPresent", text); + } + } } Added: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientException.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientException.java (rev 0) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientException.java 2007-08-11 20:44:05 UTC (rev 45) @@ -0,0 +1,17 @@ +package com.software416.jsimplebrowser.seleniumclient; + +public class SeleniumClientException extends Exception { + private static final long serialVersionUID = 20070811L; + public SeleniumClientException() { + super(); + } + public SeleniumClientException(String msg) { + super(msg); + } + public SeleniumClientException(Throwable t) { + super(t); + } + public SeleniumClientException(String msg, Throwable t) { + super(msg, t); + } +} Added: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumCommand.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumCommand.java (rev 0) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumCommand.java 2007-08-11 20:44:05 UTC (rev 45) @@ -0,0 +1,28 @@ +package com.software416.jsimplebrowser.seleniumclient; + +public class SeleniumCommand { + private String _command; + private String[] _arguments; + + public SeleniumCommand() { + // no arg constructor + } + + public SeleniumCommand(String command, String... args) { + _command = command; + _arguments = args; + } + + public String[] getArguments() { + return _arguments; + } + public void setArguments(String[] arguments) { + _arguments = arguments; + } + public String getCommand() { + return _command; + } + public void setCommand(String command) { + _command = command; + } +} \ No newline at end of file Added: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunner.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunner.java (rev 0) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunner.java 2007-08-11 20:44:05 UTC (rev 45) @@ -0,0 +1,170 @@ +package com.software416.jsimplebrowser.seleniumclient; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import com.software416.jsimplebrowser.HtmlParseException; +import com.software416.jsimplebrowser.util.HtmlToDomConverter; + +public class SeleniumHtmlRunner { + private static final Log LOG = LogFactory.getLog(SeleniumHtmlRunner.class); + private static final Map<String, Method> CLIENT_METHOD_MAP = new HashMap<String, Method>(); + private SeleniumClient _client = new SeleniumClient(); + private List<SeleniumCommand> _commands = new ArrayList<SeleniumCommand>(); + private boolean _ignoreFailures; + + static { + Method[] methods = SeleniumClient.class.getMethods(); + for (Method method : methods) { + CLIENT_METHOD_MAP.put(method.getName(), method); + } + } + + public List<SeleniumCommand> getCommands() { + return _commands; + } + + public void setCommands(List<SeleniumCommand> commands) { + _commands = commands; + } + + public String getBaseUrl() { + return _client.getBaseUrl(); + } + + public void setBaseUrl(String baseUrl) { + _client.setBaseUrl(baseUrl); + } + + public void execute() throws SeleniumClientException { + _client.start(); + for (SeleniumCommand cmd : _commands) { + executeCommand(cmd); + } + _client.stop(); + } + + protected void executeCommand(SeleniumCommand cmd) throws SeleniumClientException { + Method m = CLIENT_METHOD_MAP.get(cmd.getCommand()); + if (m == null) { + LOG.warn("Command not allowed to be executed: " + cmd.getCommand()); + return; + } + Object[] args = new Object[m.getParameterTypes().length]; + for (int x = 0; x < args.length; x++) { + args[x] = x < cmd.getArguments().length ? cmd.getArguments()[x] : null; + } + try { + if (LOG.isDebugEnabled()) { + LOG.debug("Invoking command '" + cmd.getCommand() + "' with args '" + Arrays.toString(args) + "'"); + } + m.invoke(_client, args); + } catch (IllegalArgumentException ex) { + if (_ignoreFailures) { + LOG.warn("Problem executing command: " + cmd.getCommand(), ex); + } else { + throw new SeleniumClientException(ex.getCause()); + } + } catch (IllegalAccessException ex) { + if (_ignoreFailures) { + LOG.warn("Problem executing command: " + cmd.getCommand(), ex); + } else { + throw new SeleniumClientException(ex.getCause()); + } + } catch (InvocationTargetException ex) { + if (_ignoreFailures) { + LOG.warn("Problem executing command: " + cmd.getCommand(), ex); + } else { + throw new SeleniumClientException(ex.getCause()); + } + } + } + + public void loadTestHtmlFromFile(File f) throws SeleniumClientException { + InputStream in = null; + try { + in = new FileInputStream(f); + loadTestHtmlFromInputStream(in); + } catch (FileNotFoundException ex) { + throw new SeleniumClientException("Could not find file : " + f.getAbsolutePath(), ex); + } finally { + IOUtils.closeQuietly(in); + } + } + + public void loadTestHtmlFromInputStream(InputStream in) throws SeleniumClientException{ + Document doc; + try { + doc = new HtmlToDomConverter().getDocumentFromHtml(IOUtils.toByteArray(in)); + } catch (HtmlParseException ex) { + throw new SeleniumClientException(ex); + } catch (IOException ex) { + throw new SeleniumClientException(ex); + } + NodeList nl = doc.getElementsByTagName("table"); + if (nl.getLength() != 1) { + throw new SeleniumClientException("Invalid number of tables in HTML. Expected 1 but found :" + nl.getLength()); + } + Element table = (Element)nl.item(0); + nl = table.getElementsByTagName("tr"); + + // Start at second row as first row just has test name information + for (int x = 1 ; x < nl.getLength(); x++) { + NodeList cells = ((Element)nl.item(x)).getElementsByTagName("td"); + if (cells.getLength() == 0) { + LOG.warn("Unusual situation...No cells for row " + x); + continue; + } + SeleniumCommand cmd = new SeleniumCommand(); + _commands.add(cmd); + String[] args = new String[ cells.getLength() - 1]; + cmd.setArguments(args); + for (int y = 0; y < cells.getLength(); y++) { + if (y == 0) { + cmd.setCommand(cells.item(y).getTextContent()); + } else { + args[y - 1] = cells.item(y).getTextContent(); + } + } + } + } + + public static void main(String[] args) throws SeleniumClientException { + SeleniumHtmlRunner str = new SeleniumHtmlRunner(); + str.loadTestHtmlFromFile(new File(args[0])); + str.execute(); + } + + public boolean isIgnoreFailures() { + return _ignoreFailures; + } + + public void addVerificationFailureListener(VerificationFailureListener listener) { + _client.addVerificationFailureListener(listener); + } + + public void removeVerificationFailureListener(VerificationFailureListener listener) { + _client.removeVerificationFailureListener(listener); + } + + public void setIgnoreFailures(boolean ignoreFailures) { + _ignoreFailures = ignoreFailures; + } +} Added: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureEvent.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureEvent.java (rev 0) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureEvent.java 2007-08-11 20:44:05 UTC (rev 45) @@ -0,0 +1,31 @@ +package com.software416.jsimplebrowser.seleniumclient; + +public class VerificationFailureEvent { + private SeleniumCommand _command; + private SeleniumClient _client; + + public VerificationFailureEvent() { + // default constructor + } + + public VerificationFailureEvent(SeleniumCommand cmd, SeleniumClient client) { + _command=cmd; + _client=client; + } + + public SeleniumCommand getCommand() { + return _command; + } + + public void setCommand(SeleniumCommand command) { + _command = command; + } + + public SeleniumClient getClient() { + return _client; + } + + public void setClient(SeleniumClient client) { + _client = client; + } +} Added: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureListener.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureListener.java (rev 0) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/VerificationFailureListener.java 2007-08-11 20:44:05 UTC (rev 45) @@ -0,0 +1,5 @@ +package com.software416.jsimplebrowser.seleniumclient; + +public interface VerificationFailureListener { + public void handleVerificationFailureEvent(VerificationFailureEvent e); +} Modified: trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java =================================================================== --- trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java 2007-08-11 17:36:52 UTC (rev 44) +++ trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java 2007-08-11 20:44:05 UTC (rev 45) @@ -31,6 +31,22 @@ assertNull(sc.getTable("foo1.100")); } + @Test public void testBuildUrl() { + SeleniumClient sc = new SeleniumClient(); + sc.setBaseUrl("http://www.google.com"); + assertEquals("http://www.google.com/", sc.buildUrl("/")); + assertEquals("http://www.google.com/", sc.buildUrl("")); + assertEquals("http://www.google.com/foo", sc.buildUrl("/foo")); + assertEquals("http://www.google.com/foo", sc.buildUrl("foo")); + sc.setBaseUrl("http://www.google.com/"); + assertEquals("http://www.google.com//", sc.buildUrl("/")); + assertEquals("http://www.google.com/", sc.buildUrl("")); + assertEquals("http://www.google.com//foo", sc.buildUrl("/foo")); + assertEquals("http://www.google.com/foo", sc.buildUrl("foo")); + assertEquals("http://www.416software.com/foo", sc.buildUrl("http://www.416software.com/foo")); + assertEquals("https://www.416software.com/foo", sc.buildUrl("https://www.416software.com/foo")); + } + private static class TestSimpleClient extends SimpleClient { private Document _document; Added: trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunnerTest.java =================================================================== --- trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunnerTest.java (rev 0) +++ trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumHtmlRunnerTest.java 2007-08-11 20:44:05 UTC (rev 45) @@ -0,0 +1,53 @@ +package com.software416.jsimplebrowser.seleniumclient; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class SeleniumHtmlRunnerTest implements VerificationFailureListener { + @BeforeClass public static void setUpLog() { + System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); + System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.com.software416", "debug"); + // + // HTTP Client Debugging... +// System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug"); +// System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.content", "debug"); +// System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug"); + } + + @Test public void testLoadingScript() throws SeleniumClientException { + SeleniumHtmlRunner shr = new SeleniumHtmlRunner(); + shr.setBaseUrl("http://www.google.com"); + shr.loadTestHtmlFromInputStream(Thread.currentThread().getContextClassLoader().getResourceAsStream("testSeleniumHtmlScript.html")); + } + + @Test public void testRunningCommands() throws SeleniumClientException { + SeleniumHtmlRunner shr = new SeleniumHtmlRunner(); + shr.setBaseUrl("http://www.google.com"); + List<SeleniumCommand> cmds = new ArrayList<SeleniumCommand>(); + cmds.add(buildCommand("open", "/ig?hl=en", "")); + cmds.add(buildCommand("type", "q", "Java SDK")); + cmds.add(buildCommand("clickAndWait", "btnG", "")); + cmds.add(buildCommand("verifyTextPresent", "Java", "")); + shr.setCommands(cmds); + shr.addVerificationFailureListener(this); + shr.execute(); + } + + private SeleniumCommand buildCommand(String cmd, String... args) { + SeleniumCommand sc = new SeleniumCommand(); + sc.setCommand(cmd); + sc.setArguments(args); + return sc; + } + + public void handleVerificationFailureEvent(VerificationFailureEvent e) { + fail("Could not " + e.getCommand().getCommand() + " with args " + Arrays.toString(e.getCommand().getArguments())); + } +} Added: trunk/selenium-client/src/test/resources/testSeleniumHtmlScript.html =================================================================== --- trunk/selenium-client/src/test/resources/testSeleniumHtmlScript.html (rev 0) +++ trunk/selenium-client/src/test/resources/testSeleniumHtmlScript.html 2007-08-11 20:44:05 UTC (rev 45) @@ -0,0 +1,34 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<title>test</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">test</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/ig?hl=en</td> + <td></td> +</tr> +<tr> + <td>type</td> + <td>q</td> + <td>Java SDK</td> +</tr> +<tr> + <td>clickAndWait</td> + <td>btnG</td> + <td></td> +</tr> +<tr> + <td>verifyTextPresent</td> + <td>Download Java 2 Platform, Standard Edition, v 1.4.2 (J2SE)</td> + <td></td> +</tr> + +</tbody></table> +</body> +</html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-11 17:36:54
|
Revision: 44 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=44&view=rev Author: rdimarco Date: 2007-08-11 10:36:52 -0700 (Sat, 11 Aug 2007) Log Message: ----------- Refactored base client package out of selenium-client so that users do not have to use Selenium. Introduced Guice to better support testing and swapping out interface implementations. Modified Paths: -------------- trunk/core/pom.xml trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java trunk/pom.xml trunk/selenium-client/pom.xml trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java Added Paths: ----------- trunk/client/ trunk/client/pom.xml trunk/client/src/ trunk/client/src/main/ trunk/client/src/main/java/ trunk/client/src/main/java/com/ trunk/client/src/main/java/com/software416/ trunk/client/src/main/java/com/software416/jsimplebrowser/ trunk/client/src/main/java/com/software416/jsimplebrowser/client/ trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java trunk/client/src/test/ trunk/client/src/test/java/ trunk/client/src/test/java/com/ trunk/client/src/test/java/com/software416/ trunk/client/src/test/java/com/software416/jsimplebrowser/ trunk/client/src/test/java/com/software416/jsimplebrowser/client/ trunk/client/src/test/java/com/software416/jsimplebrowser/client/SimpleClientTest.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java Property changes on: trunk/client ___________________________________________________________________ Name: svn:ignore + .classpath .project .settings target Added: trunk/client/pom.xml =================================================================== --- trunk/client/pom.xml (rev 0) +++ trunk/client/pom.xml 2007-08-11 17:36:52 UTC (rev 44) @@ -0,0 +1,24 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.software416.jsimplebrowser</groupId> + <artifactId>jsimplebrowser</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + <name>JSimpleBrowser Selenium Client</name> + <artifactId>jsimplebrowser-client</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.software416.jsimplebrowser</groupId> + <artifactId>jsimplebrowser-core</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> +</project> Added: trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java =================================================================== --- trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java (rev 0) +++ trunk/client/src/main/java/com/software416/jsimplebrowser/client/SimpleClient.java 2007-08-11 17:36:52 UTC (rev 44) @@ -0,0 +1,286 @@ +package com.software416.jsimplebrowser.client; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.commons.collections.MultiHashMap; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.software416.jsimplebrowser.Browser; +import com.software416.jsimplebrowser.BrowserException; +import com.software416.jsimplebrowser.Window; + +public class SimpleClient { + @SuppressWarnings("unused") + private static final Log LOG = LogFactory.getLog(SimpleClient.class); + + @Inject + private Browser _browser; + private String _currentWindowName = Browser.MAIN_BROWSER_WINDOW_NAME; + + public static SimpleClient newInstance() { + SimpleClient sc = new SimpleClient(); + Guice.createInjector().injectMembers(sc); + return sc; + } + + public String getHtmlSource() { + return getCurrentWindow().getSource(); + } + + public String getLocation() { + return getCurrentWindow().getLocation(); + } + + public void close() { + _browser.closeWindow(_currentWindowName); + _currentWindowName = Browser.MAIN_BROWSER_WINDOW_NAME; + } + + public String[] getAllElements(String xpath) { + XPath xp = XPathFactory.newInstance().newXPath(); + NodeList nl; + try { + nl = (NodeList)xp.evaluate(xpath, getDocument(), XPathConstants.NODESET); + } catch (XPathExpressionException ex) { + throw new RuntimeException("Developer screwed up the xpath: " + xpath, ex); + } + List<String> links = new ArrayList<String>(); + for (int x = 0; x < nl.getLength(); x++) { + Attr a = (Attr)nl.item(x); + links.add(a.getValue()); + } + return links.toArray(new String[links.size()]); + } + + public String getText(String id) { + return getDocument().getElementById(id).getTextContent(); + } + + public Document getDocument() { + return getCurrentWindow().getDocument(); + } + public Window getCurrentWindow() { + return _browser.getWindow(_currentWindowName); + } + + public String[] getAllWindowNames() { + List<String> windowNames = _browser.getWindowNames(); + return windowNames.toArray(new String[windowNames.size()]); + } + + public void open(String url) throws BrowserException { + getCurrentWindow().open(url); + } + + public void openWindow(String windowName, String url) throws BrowserException { + _currentWindowName = windowName; + getCurrentWindow().open(url); + } + + public void submitForm(String id) throws BrowserException { + getCurrentWindow().submitForm(id, new MultiHashMap()); + } + +// public String[] getAllWindowTitles() { +// throw new UnsupportedOperationException(); +// } +// +// public String getAttribute(String arg0) { +// throw new UnsupportedOperationException(); +// } +// +// public String[] getAttributeFromAllWindows(String arg0) { +// throw new UnsupportedOperationException(); +// } +// +// public String getCookie() { +// throw new UnsupportedOperationException(); +// } +// +// +// public String[] getSelectOptions(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public String getSelectedId(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public String[] getSelectedIds(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public String getSelectedIndex(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public String[] getSelectedIndexes(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public String getSelectedLabel(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public String[] getSelectedLabels(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public String getSelectedValue(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public String[] getSelectedValues(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// public String getTitle() { +// throw new UnsupportedOperationException(); +// +// } +// +// public String getValue(String arg0) { +// throw new UnsupportedOperationException(); +// } +// +// public boolean getWhetherThisFrameMatchFrameExpression(String arg0, String arg1) { +// throw new UnsupportedOperationException(); +// } +// +// public boolean getWhetherThisWindowMatchWindowExpression(String arg0, String arg1) { +// throw new UnsupportedOperationException(); +// } +// +// public Number getXpathCount(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public void goBack() { +// throw new UnsupportedOperationException(); +// +// } +// +// public boolean isChecked(String id) { +// throw new UnsupportedOperationException(); +// } +// +// public boolean isEditable(String id) { +// throw new UnsupportedOperationException(); +// } +// +// public boolean isElementPresent(String id) { +// return getDocument().getElementById(id) != null; +// } +// +// public boolean isOrdered(String arg0, String arg1) { +// throw new UnsupportedOperationException(); +// } +// +// public boolean isSomethingSelected(String arg0) { +// throw new UnsupportedOperationException(); +// } +// +// public boolean isTextPresent(String text) { +// return getCurrentWindow().getSource().contains(text); +// } +// +// public boolean isVisible(String arg0) { +// throw new UnsupportedOperationException(); +// } +// +// public void refresh() { +// open(getCurrentWindow().getLocation()); +// } +// +// public void removeAllSelections(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public void removeSelection(String arg0, String arg1) { +// throw new UnsupportedOperationException(); +// +// } +// +// public void select(String arg0, String arg1) { +// throw new UnsupportedOperationException(); +// +// } +// +// public void selectFrame(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public void selectWindow(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public void setContext(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public void type(String arg0, String arg1) { +// throw new UnsupportedOperationException(); +// +// } +// +// public void typeKeys(String arg0, String arg1) { +// throw new UnsupportedOperationException(); +// +// } +// public void setTimeout(String arg0) { +// throw new UnsupportedOperationException(); +// } +// +// public void uncheck(String arg0) { +// throw new UnsupportedOperationException(); +// +// } +// +// public void waitForCondition(String arg0, String arg1) { +// throw new UnsupportedOperationException(); +// +// } +// +// public void waitForFrameToLoad(String arg0, String arg1) { +// // noop +// } +// +// public void waitForPageToLoad(String arg0) { +// // noop +// } +// public void check(String id) { +// throw new UnsupportedOperationException(); +// } +// public void click(String id) { +// throw new UnsupportedOperationException(); +// } +// public void clickAt(String arg0, String arg1) { +// throw new UnsupportedOperationException(); +// } + +} Added: trunk/client/src/test/java/com/software416/jsimplebrowser/client/SimpleClientTest.java =================================================================== --- trunk/client/src/test/java/com/software416/jsimplebrowser/client/SimpleClientTest.java (rev 0) +++ trunk/client/src/test/java/com/software416/jsimplebrowser/client/SimpleClientTest.java 2007-08-11 17:36:52 UTC (rev 44) @@ -0,0 +1,18 @@ +package com.software416.jsimplebrowser.client; + +import static org.junit.Assert.*; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class SimpleClientTest { + @BeforeClass public static void setUpLog() { + System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); + System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.com.software416", "debug"); + } + + @Test public void testNewInstance() { + assertNotNull(SimpleClient.newInstance()); + } +} Modified: trunk/core/pom.xml =================================================================== --- trunk/core/pom.xml 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/core/pom.xml 2007-08-11 17:36:52 UTC (rev 44) @@ -10,6 +10,10 @@ <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <dependencies> + <dependency> + <groupId>com.google.guice</groupId> + <artifactId>guice</artifactId> + </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-11 17:36:52 UTC (rev 44) @@ -2,6 +2,12 @@ import java.util.List; +import org.apache.commons.httpclient.HttpMethod; + +import com.google.inject.ImplementedBy; +import com.software416.jsimplebrowser.impl.BrowserImpl; + +@ImplementedBy(BrowserImpl.class) public interface Browser { public static final String MAIN_BROWSER_WINDOW_NAME = "main"; public void open(String url) throws BrowserException; @@ -10,4 +16,5 @@ public Window getWindow(String windowName); public void closeWindow(String windowName); public List<String> getWindowNames(); + HttpResponse makeRequest(HttpMethod hm) throws BrowserException; } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java 2007-08-11 17:36:52 UTC (rev 44) @@ -7,4 +7,5 @@ public MultiMap getCookies(); public String getCookieValue(String cookieName); public byte[] getResponseBody(); + public String getLocation(); } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-11 17:36:52 UTC (rev 44) @@ -3,6 +3,10 @@ import org.apache.commons.collections.MultiMap; import org.w3c.dom.Document; +import com.google.inject.ProvidedBy; +import com.software416.jsimplebrowser.impl.WindowProvider; + +@ProvidedBy(WindowProvider.class) public interface Window { public void open(String url) throws BrowserException; public void submitForm(String formName, MultiMap parameters) throws BrowserException; Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-11 17:36:52 UTC (rev 44) @@ -13,25 +13,20 @@ import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import com.google.inject.Inject; +import com.google.inject.Provider; import com.software416.jsimplebrowser.Browser; import com.software416.jsimplebrowser.BrowserException; import com.software416.jsimplebrowser.Window; public class BrowserImpl implements Browser { - @SuppressWarnings("unused") - private static final Log LOG = LogFactory.getLog(BrowserImpl.class); + @Inject private Provider<Window> _windowProvider; private HttpClient _client = new HttpClient(); - private Map<String, WindowImpl> _browserWindows = new HashMap<String, WindowImpl>(); + private Map<String, Window> _browserWindows = new HashMap<String, Window>(); - public BrowserImpl() { - _browserWindows.put(MAIN_BROWSER_WINDOW_NAME, new WindowImpl(this)); - } - - protected synchronized HttpResponseImpl makeRequest(HttpMethod m) throws BrowserException { + public synchronized HttpResponseImpl makeRequest(HttpMethod m) throws BrowserException { HttpResponseImpl ri = new HttpResponseImpl(); ri.setRequestMethod(m); @@ -68,11 +63,14 @@ public synchronized Window getWindow(String windowName) { if (!_browserWindows.containsKey(windowName)) { - _browserWindows.put(windowName, new WindowImpl(this)); + ThreadLocal<Browser> tl = new ThreadLocal<Browser>(); + tl.set(this); + _browserWindows.put(windowName, _windowProvider.get()); + tl.remove(); } return _browserWindows.get(windowName); } - + public void closeWindow(String windowName) { _browserWindows.remove(windowName); } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java 2007-08-11 17:36:52 UTC (rev 44) @@ -6,7 +6,9 @@ import org.apache.commons.collections.MultiMap; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.URIException; +import com.software416.jsimplebrowser.BrowserRuntimeException; import com.software416.jsimplebrowser.HttpResponse; public class HttpResponseImpl implements HttpResponse{ @@ -14,6 +16,13 @@ private int _responseCode; private byte[] _responseBody; + public String getLocation() { + try { + return _requestMethod.getURI().toString(); + } catch (URIException ex) { + throw new BrowserRuntimeException(ex); + } + } public MultiMap getCookies() { MultiHashMap rv = new MultiHashMap(); Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-11 17:36:52 UTC (rev 44) @@ -18,6 +18,8 @@ import org.w3c.dom.Element; import org.w3c.dom.NodeList; +import com.google.inject.Inject; +import com.software416.jsimplebrowser.Browser; import com.software416.jsimplebrowser.BrowserException; import com.software416.jsimplebrowser.BrowserRuntimeException; import com.software416.jsimplebrowser.History; @@ -27,22 +29,23 @@ import com.software416.jsimplebrowser.util.HtmlToDomConverter; public class WindowImpl implements Window { - private HttpResponseImpl _requestInfo; + private HttpResponse _requestInfo; private Document _responseDocument; - private BrowserImpl _browser; + private Browser _browser; private HtmlToDomConverter _converter = new HtmlToDomConverter(); private boolean _doFollowRedirects = true; - public WindowImpl(BrowserImpl b) { + @Inject + public WindowImpl(Browser b) { _browser = b; } - + public void open(String url) throws BrowserException { try { GetMethod gm; if (_requestInfo != null) { gm = new GetMethod(); - gm.setURI(new URI(_requestInfo.getRequestMethod().getURI(), url, true)); + gm.setURI(new URI(new URI(_requestInfo.getLocation(), true), url, true)); } else { gm = new GetMethod(url); } @@ -56,7 +59,7 @@ handleResponse(_browser.makeRequest(hm)); } - public void handleResponse(HttpResponseImpl requestInfo) throws BrowserException { + public void handleResponse(HttpResponse requestInfo) throws BrowserException { _requestInfo = requestInfo; _responseDocument = null; if (_doFollowRedirects) { @@ -111,7 +114,7 @@ boolean usePost = formMethod != null && formMethod.toUpperCase().equals("POST"); HttpMethod rv = usePost ? new PostMethod() : new GetMethod(); - rv.setURI(new URI(_requestInfo.getRequestMethod().getURI(), new URI(formElement.getAttribute("action"), true))); + rv.setURI(new URI(new URI(_requestInfo.getLocation(), true), new URI(formElement.getAttribute("action"), true))); Collection params = formParameters.values(); if (usePost) { @@ -236,11 +239,7 @@ } public String getLocation() { - try { - return _requestInfo.getRequestMethod().getURI().toString(); - } catch (URIException ex) { - throw new BrowserRuntimeException(ex); - } + return _requestInfo.getLocation(); } public HttpResponse getRequestInfo() { Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowProvider.java 2007-08-11 17:36:52 UTC (rev 44) @@ -0,0 +1,13 @@ +package com.software416.jsimplebrowser.impl; + +import com.google.inject.Provider; +import com.software416.jsimplebrowser.Browser; +import com.software416.jsimplebrowser.Window; + +public class WindowProvider implements Provider<Window> { + + public Window get() { + return new WindowImpl(new ThreadLocal<Browser>().get()); + } + +} Modified: trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java 2007-08-11 17:36:52 UTC (rev 44) @@ -8,15 +8,15 @@ import org.apache.commons.io.IOUtils; import org.junit.Test; +import com.google.inject.Guice; import com.software416.jsimplebrowser.Browser; import com.software416.jsimplebrowser.BrowserException; -import com.software416.jsimplebrowser.impl.BrowserImpl; import com.software416.jsimplebrowser.impl.HttpResponseImpl; import com.software416.jsimplebrowser.impl.WindowImpl; public class BrowserHelperTest { @Test public void testLinkParsing() throws BrowserException, IOException { - BrowserImpl b = new BrowserImpl(); + Browser b = Guice.createInjector().getInstance(Browser.class); BrowserHelper bh = new BrowserHelper(b); WindowImpl wi = (WindowImpl)b.getWindow(Browser.MAIN_BROWSER_WINDOW_NAME); HttpResponseImpl ri = new HttpResponseImpl(); Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/pom.xml 2007-08-11 17:36:52 UTC (rev 44) @@ -69,6 +69,7 @@ <url>http://jsimplebrowser.sourceforge.net/</url> <modules> <module>core</module> + <module>client</module> <module>selenium-client</module> </modules> <build> @@ -165,6 +166,11 @@ <artifactId>selenium-java-client-driver</artifactId> <version>0.9.2-SNAPSHOT</version> </dependency> + <dependency> + <groupId>com.google.guice</groupId> + <artifactId>guice</artifactId> + <version>1.0</version> + </dependency> </dependencies> </dependencyManagement> <reporting> Modified: trunk/selenium-client/pom.xml =================================================================== --- trunk/selenium-client/pom.xml 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/selenium-client/pom.xml 2007-08-11 17:36:52 UTC (rev 44) @@ -28,5 +28,10 @@ <artifactId>jsimplebrowser-core</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>com.software416.jsimplebrowser</groupId> + <artifactId>jsimplebrowser-client</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> </project> Modified: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-11 17:36:52 UTC (rev 44) @@ -1,57 +1,33 @@ package com.software416.jsimplebrowser.seleniumclient; -import java.util.ArrayList; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - -import org.apache.commons.collections.MultiHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import com.software416.jsimplebrowser.Browser; import com.software416.jsimplebrowser.BrowserException; -import com.software416.jsimplebrowser.Window; -import com.software416.jsimplebrowser.impl.BrowserImpl; +import com.software416.jsimplebrowser.client.SimpleClient; import com.software416.jsimplebrowser.util.ElementLocator; import com.thoughtworks.selenium.Selenium; public class SeleniumClient implements Selenium { private static final Log LOG = LogFactory.getLog(SeleniumClient.class); - private BrowserImpl _browser; - private String _currentWindowName = Browser.MAIN_BROWSER_WINDOW_NAME; - - public void check(String id) { - throw new UnsupportedOperationException(); - } - public void click(String id) { - throw new UnsupportedOperationException(); - } - public void clickAt(String arg0, String arg1) { - throw new UnsupportedOperationException(); - } + private SimpleClient _simpleClient = new SimpleClient(); public String getHtmlSource() { - return getCurrentWindow().getSource(); + return _simpleClient.getHtmlSource(); } public String getLocation() { - return getCurrentWindow().getLocation(); + return _simpleClient.getLocation(); } public void close() { - _browser.closeWindow(_currentWindowName); - _currentWindowName = Browser.MAIN_BROWSER_WINDOW_NAME; + _simpleClient.close(); } public void windowFocus() { // noop (although, I would think a window id/name would come in here. @@ -62,40 +38,17 @@ } public String[] getAllButtons() { - return getAllElements("//input[@type='button' or @type='submit' or @type = 'reset']/@id"); + return _simpleClient.getAllElements("//input[@type='button' or @type='submit' or @type = 'reset']/@id"); } public String[] getAllFields() { - return getAllElements("//input[@type='text']/@id"); + return _simpleClient.getAllElements("//input[@type='text']/@id"); } public String[] getAllLinks() { - return getAllElements("//a/@id"); + return _simpleClient.getAllElements("//a/@id"); } - - protected String[] getAllElements(String xpath) { - XPath xp = XPathFactory.newInstance().newXPath(); - NodeList nl; - try { - nl = (NodeList)xp.evaluate(xpath, getDocument(), XPathConstants.NODESET); - } catch (XPathExpressionException ex) { - throw new RuntimeException("Developer screwed up the xpath: " + xpath, ex); - } - List<String> links = new ArrayList<String>(); - for (int x = 0; x < nl.getLength(); x++) { - Attr a = (Attr)nl.item(x); - links.add(a.getValue()); - } - return links.toArray(new String[links.size()]); - } - - protected Document getDocument() { - return getCurrentWindow().getDocument(); - } - private Window getCurrentWindow() { - return _browser.getWindow(_currentWindowName); - } - + public void createCookie(String arg0, String arg1) { throw new UnsupportedOperationException(); } @@ -105,14 +58,17 @@ } public String[] getAllWindowIds() { - return getAllWindowNames(); + return _simpleClient.getAllWindowNames(); } public String[] getAllWindowNames() { - List<String> windowNames = _browser.getWindowNames(); - return windowNames.toArray(new String[windowNames.size()]); + return _simpleClient.getAllWindowNames(); } + public String getBodyText() { + return _simpleClient.getDocument().getElementsByTagName("body").item(0).getTextContent(); + } + public String[] getAllWindowTitles() { throw new UnsupportedOperationException(); } @@ -125,10 +81,6 @@ throw new UnsupportedOperationException(); } - public String getBodyText() { - return getDocument().getElementsByTagName("body").item(0).getTextContent(); - } - public String getCookie() { throw new UnsupportedOperationException(); } @@ -202,7 +154,7 @@ return null; } - Element table = new ElementLocator(getDocument()).findElement(m.group(1)); + Element table = new ElementLocator(_simpleClient.getDocument()).findElement(m.group(1)); if (table != null) { NodeList rows = table.getElementsByTagName("tr"); if (row < rows.getLength()) { @@ -230,13 +182,22 @@ return null; } + public void check(String id) { + throw new UnsupportedOperationException(); + } + public void click(String id) { + throw new UnsupportedOperationException(); + } + public void clickAt(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + public String getText(String id) { - return getDocument().getElementById(id).getTextContent(); + return _simpleClient.getDocument().getElementById(id).getTextContent(); } public String getTitle() { throw new UnsupportedOperationException(); - } public String getValue(String arg0) { @@ -270,7 +231,7 @@ } public boolean isElementPresent(String id) { - return getDocument().getElementById(id) != null; + return _simpleClient.getDocument().getElementById(id) != null; } public boolean isOrdered(String arg0, String arg1) { @@ -282,7 +243,7 @@ } public boolean isTextPresent(String text) { - return getCurrentWindow().getSource().contains(text); + return _simpleClient.getHtmlSource().contains(text); } public boolean isVisible(String arg0) { @@ -291,7 +252,7 @@ public void open(String url) { try { - getCurrentWindow().open(url); + _simpleClient.open(url); } catch (BrowserException ex) { LOG.warn("Problem loading page", ex); } @@ -299,15 +260,14 @@ public void openWindow(String windowName, String url) { try { - _currentWindowName = windowName; - getCurrentWindow().open(url); + _simpleClient.openWindow(windowName, url); } catch (BrowserException ex) { LOG.warn("Problem loading page", ex); } } public void refresh() { - open(getCurrentWindow().getLocation()); + open(_simpleClient.getLocation()); } public void removeAllSelections(String arg0) { @@ -345,19 +305,19 @@ } public void start() { - _browser = new BrowserImpl(); + _simpleClient = SimpleClient.newInstance(); } public void stop() { - _browser = null; + _simpleClient = null; } public void submit(String id) { try { - getCurrentWindow().submitForm(id, new MultiHashMap()); - } catch (BrowserException ex) { - LOG.warn("Problem loading page", ex); - } + _simpleClient.submitForm(id); + } catch (BrowserException ex ) { + LOG.error("Problem submitting form: " + id, ex); + } } public void type(String arg0, String arg1) { @@ -639,5 +599,13 @@ } + public SimpleClient getSimpleClient() { + return _simpleClient; + } + public void setSimpleClient(SimpleClient simpleClient) { + _simpleClient = simpleClient; + } + + } Modified: trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java =================================================================== --- trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java 2007-08-11 15:32:47 UTC (rev 43) +++ trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java 2007-08-11 17:36:52 UTC (rev 44) @@ -10,6 +10,7 @@ import org.w3c.dom.Document; import com.software416.jsimplebrowser.BrowserException; +import com.software416.jsimplebrowser.client.SimpleClient; import com.software416.jsimplebrowser.util.HtmlToDomConverter; public class SeleniumClientTest { @@ -20,7 +21,8 @@ } @Test public void testElementSearch() throws IOException, BrowserException { - SeleniumClient sc = new TestSeleniumClient("tableTest.html"); + SeleniumClient sc = new SeleniumClient(); + sc.setSimpleClient(new TestSimpleClient("tableTest.html")); assertEquals("/ig?hl=en", sc.getTable("//table[1].2.1")); assertEquals("/ig?hl=en", sc.getTable("foo.2.1")); assertEquals("Command", sc.getTable("foo.1.0")); @@ -28,11 +30,11 @@ assertNull(sc.getTable("foo1.100.100")); assertNull(sc.getTable("foo1.100")); } - - private static class TestSeleniumClient extends SeleniumClient { + + private static class TestSimpleClient extends SimpleClient { private Document _document; - TestSeleniumClient (String resourceLocation) throws IOException, BrowserException { + TestSimpleClient (String resourceLocation) throws IOException, BrowserException { _document = new HtmlToDomConverter().getDocumentFromHtml(IOUtils.toByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceLocation))); } @@ -41,4 +43,5 @@ return _document; } } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-11 15:32:51
|
Revision: 43 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=43&view=rev Author: rdimarco Date: 2007-08-11 08:32:47 -0700 (Sat, 11 Aug 2007) Log Message: ----------- Updated unit tests to actually read the HTML file. Modified Paths: -------------- trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java Added Paths: ----------- trunk/selenium-client/pom.xml Added: trunk/selenium-client/pom.xml =================================================================== --- trunk/selenium-client/pom.xml (rev 0) +++ trunk/selenium-client/pom.xml 2007-08-11 15:32:47 UTC (rev 43) @@ -0,0 +1,32 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.software416.jsimplebrowser</groupId> + <artifactId>jsimplebrowser</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + <name>JSimpleBrowser Selenium Client</name> + <artifactId>jsimplebrowser-selenium-client</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-httpclient</groupId> + <artifactId>commons-httpclient</artifactId> + </dependency> + <dependency> + <groupId>org.openqa.selenium.client-drivers</groupId> + <artifactId>selenium-java-client-driver</artifactId> + </dependency> + <dependency> + <groupId>com.software416.jsimplebrowser</groupId> + <artifactId>jsimplebrowser-core</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> +</project> Modified: trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java =================================================================== --- trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java 2007-08-11 03:21:37 UTC (rev 42) +++ trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java 2007-08-11 15:32:47 UTC (rev 43) @@ -20,10 +20,10 @@ } @Test public void testElementSearch() throws IOException, BrowserException { - SeleniumClient sc = new TestSeleniumClient(""); - //assertEquals("/ig?hl=en", sc.getTable("//table[1].1.1")); - //assertEquals("/ig?hl=en", sc.getTable("foo.1.1")); - //assertEquals("Command", sc.getTable("foo.0.0")); + SeleniumClient sc = new TestSeleniumClient("tableTest.html"); + assertEquals("/ig?hl=en", sc.getTable("//table[1].2.1")); + assertEquals("/ig?hl=en", sc.getTable("foo.2.1")); + assertEquals("Command", sc.getTable("foo.1.0")); assertNull(sc.getTable("foo1.0.0")); assertNull(sc.getTable("foo1.100.100")); assertNull(sc.getTable("foo1.100")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-11 03:21:39
|
Revision: 42 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=42&view=rev Author: rdimarco Date: 2007-08-10 20:21:37 -0700 (Fri, 10 Aug 2007) Log Message: ----------- First version of selenium client. Not all tests passing yet. Modified Paths: -------------- trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java trunk/pom.xml Added Paths: ----------- trunk/core/src/main/java/com/software416/jsimplebrowser/util/ElementLocator.java trunk/core/src/test/java/com/software416/jsimplebrowser/util/ElementLocatorTest.java trunk/core/src/test/resources/elementLocatorTest.html trunk/selenium-client/ trunk/selenium-client/src/ trunk/selenium-client/src/main/ trunk/selenium-client/src/main/java/ trunk/selenium-client/src/main/java/com/ trunk/selenium-client/src/main/java/com/software416/ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java trunk/selenium-client/src/main/resources/ trunk/selenium-client/src/test/ trunk/selenium-client/src/test/java/ trunk/selenium-client/src/test/java/com/ trunk/selenium-client/src/test/java/com/software416/ trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/ trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/ trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java trunk/selenium-client/src/test/resources/ trunk/selenium-client/src/test/resources/tableTest.html Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-10 19:04:30 UTC (rev 41) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-11 03:21:37 UTC (rev 42) @@ -1,9 +1,13 @@ package com.software416.jsimplebrowser; +import java.util.List; + public interface Browser { public static final String MAIN_BROWSER_WINDOW_NAME = "main"; public void open(String url) throws BrowserException; public void open(String url, String window) throws BrowserException; public HttpResponse makeXmlHttpRequest(String url, String requestBody) throws BrowserException; public Window getWindow(String windowName); + public void closeWindow(String windowName); + public List<String> getWindowNames(); } Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-10 19:04:30 UTC (rev 41) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-11 03:21:37 UTC (rev 42) @@ -2,7 +2,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.commons.httpclient.HttpClient; @@ -70,4 +72,12 @@ } return _browserWindows.get(windowName); } + + public void closeWindow(String windowName) { + _browserWindows.remove(windowName); + } + + public List<String> getWindowNames() { + return new ArrayList<String>(_browserWindows.keySet()); + } } Added: trunk/core/src/main/java/com/software416/jsimplebrowser/util/ElementLocator.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/util/ElementLocator.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/util/ElementLocator.java 2007-08-11 03:21:37 UTC (rev 42) @@ -0,0 +1,58 @@ +package com.software416.jsimplebrowser.util; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +public class ElementLocator { + private Log LOG = LogFactory.getLog(ElementLocator.class); + private Document _document; + public ElementLocator(Document doc) { + _document = doc; + } + + public Element findElement(String locator) { + if (locator.startsWith("//")) { + if (LOG.isDebugEnabled()) { + LOG.debug("locator is an XPATH expression"); + } + return locateElementByXPath(locator); + } + if (locator.startsWith("document.")) { + if (LOG.isDebugEnabled()) { + LOG.debug("locator is an javascript expression"); + } + return this.locateElementByDomTraversal(locator); + } + if (LOG.isDebugEnabled()) { + LOG.debug("locator is an idenitfier"); + } + return this.locateElementByIdentifier(locator); + } + + protected Element locateElementByXPath(String locator) { + XPath xp = XPathFactory.newInstance().newXPath(); + try { + NodeList nl = (NodeList)xp.evaluate(locator.toUpperCase(), _document.getDocumentElement(), XPathConstants.NODESET); + return nl.getLength() > 0 ? (Element)nl.item(0) : null; + } catch (XPathExpressionException ex) { + LOG.warn("Problem handling XPath : " + locator, ex); + return null; + } + } + + protected Element locateElementByDomTraversal(String locator) { + throw new UnsupportedOperationException(); + } + + protected Element locateElementByIdentifier(String locator) { + return _document.getElementById(locator); + } +} Added: trunk/core/src/test/java/com/software416/jsimplebrowser/util/ElementLocatorTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/util/ElementLocatorTest.java (rev 0) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/util/ElementLocatorTest.java 2007-08-11 03:21:37 UTC (rev 42) @@ -0,0 +1,36 @@ +package com.software416.jsimplebrowser.util; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.apache.commons.io.IOUtils; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.software416.jsimplebrowser.BrowserException; +import com.software416.jsimplebrowser.impl.HttpResponseImpl; +import com.software416.jsimplebrowser.impl.WindowImpl; + +public class ElementLocatorTest { + @BeforeClass public static void setUpLog() { + System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); + System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.com.software416", "debug"); + } + + @Test public void testElementLocator() throws BrowserException, IOException { + WindowImpl w = new WindowImpl(null); + HttpResponseImpl ri = new HttpResponseImpl(); + ri.setResponseBody(IOUtils.toByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream("elementLocatorTest.html"))); + w.handleResponse(ri); + + ElementLocator lc = new ElementLocator(w.getDocument()); + + assertNotNull(w.getDocument().getElementsByTagName("form")); + + assertNotNull(lc.findElement("//form[1]")); + assertNotNull(lc.findElement("//FORM[1]")); + assertNotNull(lc.findElement("foo")); + } +} Added: trunk/core/src/test/resources/elementLocatorTest.html =================================================================== --- trunk/core/src/test/resources/elementLocatorTest.html (rev 0) +++ trunk/core/src/test/resources/elementLocatorTest.html 2007-08-11 03:21:37 UTC (rev 42) @@ -0,0 +1,7 @@ +<html> + <body> + <form id="foo"> + <input type="text" id="bar"> + </form> + </body> +</html> \ No newline at end of file Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2007-08-10 19:04:30 UTC (rev 41) +++ trunk/pom.xml 2007-08-11 03:21:37 UTC (rev 42) @@ -69,6 +69,7 @@ <url>http://jsimplebrowser.sourceforge.net/</url> <modules> <module>core</module> + <module>selenium-client</module> </modules> <build> <defaultGoal>install</defaultGoal> @@ -159,6 +160,11 @@ <artifactId>commons-httpclient</artifactId> <version>3.1-rc1</version> </dependency> + <dependency> + <groupId>org.openqa.selenium.client-drivers</groupId> + <artifactId>selenium-java-client-driver</artifactId> + <version>0.9.2-SNAPSHOT</version> + </dependency> </dependencies> </dependencyManagement> <reporting> Property changes on: trunk/selenium-client ___________________________________________________________________ Name: svn:ignore + .settings target .classpath .project Added: trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java =================================================================== --- trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java (rev 0) +++ trunk/selenium-client/src/main/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClient.java 2007-08-11 03:21:37 UTC (rev 42) @@ -0,0 +1,643 @@ +package com.software416.jsimplebrowser.seleniumclient; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.commons.collections.MultiHashMap; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import com.software416.jsimplebrowser.Browser; +import com.software416.jsimplebrowser.BrowserException; +import com.software416.jsimplebrowser.Window; +import com.software416.jsimplebrowser.impl.BrowserImpl; +import com.software416.jsimplebrowser.util.ElementLocator; +import com.thoughtworks.selenium.Selenium; + +public class SeleniumClient implements Selenium { + private static final Log LOG = LogFactory.getLog(SeleniumClient.class); + private BrowserImpl _browser; + private String _currentWindowName = Browser.MAIN_BROWSER_WINDOW_NAME; + + public void check(String id) { + throw new UnsupportedOperationException(); + } + public void click(String id) { + throw new UnsupportedOperationException(); + } + public void clickAt(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + + public String getHtmlSource() { + return getCurrentWindow().getSource(); + } + + public String getLocation() { + return getCurrentWindow().getLocation(); + } + + public void close() { + _browser.closeWindow(_currentWindowName); + _currentWindowName = Browser.MAIN_BROWSER_WINDOW_NAME; + } + public void windowFocus() { + // noop (although, I would think a window id/name would come in here. + } + + public void windowMaximize() { + // noop + } + + public String[] getAllButtons() { + return getAllElements("//input[@type='button' or @type='submit' or @type = 'reset']/@id"); + } + + public String[] getAllFields() { + return getAllElements("//input[@type='text']/@id"); + } + + public String[] getAllLinks() { + return getAllElements("//a/@id"); + } + + protected String[] getAllElements(String xpath) { + XPath xp = XPathFactory.newInstance().newXPath(); + NodeList nl; + try { + nl = (NodeList)xp.evaluate(xpath, getDocument(), XPathConstants.NODESET); + } catch (XPathExpressionException ex) { + throw new RuntimeException("Developer screwed up the xpath: " + xpath, ex); + } + List<String> links = new ArrayList<String>(); + for (int x = 0; x < nl.getLength(); x++) { + Attr a = (Attr)nl.item(x); + links.add(a.getValue()); + } + return links.toArray(new String[links.size()]); + } + + protected Document getDocument() { + return getCurrentWindow().getDocument(); + } + private Window getCurrentWindow() { + return _browser.getWindow(_currentWindowName); + } + + public void createCookie(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + + public void deleteCookie(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + + public String[] getAllWindowIds() { + return getAllWindowNames(); + } + + public String[] getAllWindowNames() { + List<String> windowNames = _browser.getWindowNames(); + return windowNames.toArray(new String[windowNames.size()]); + } + + public String[] getAllWindowTitles() { + throw new UnsupportedOperationException(); + } + + public String getAttribute(String arg0) { + throw new UnsupportedOperationException(); + } + + public String[] getAttributeFromAllWindows(String arg0) { + throw new UnsupportedOperationException(); + } + + public String getBodyText() { + return getDocument().getElementsByTagName("body").item(0).getTextContent(); + } + + public String getCookie() { + throw new UnsupportedOperationException(); + } + + + public String[] getSelectOptions(String arg0) { + throw new UnsupportedOperationException(); + + } + + public String getSelectedId(String arg0) { + throw new UnsupportedOperationException(); + + } + + public String[] getSelectedIds(String arg0) { + throw new UnsupportedOperationException(); + + } + + public String getSelectedIndex(String arg0) { + throw new UnsupportedOperationException(); + + } + + public String[] getSelectedIndexes(String arg0) { + throw new UnsupportedOperationException(); + + } + + public String getSelectedLabel(String arg0) { + throw new UnsupportedOperationException(); + + } + + public String[] getSelectedLabels(String arg0) { + throw new UnsupportedOperationException(); + + } + + public String getSelectedValue(String arg0) { + throw new UnsupportedOperationException(); + + } + + public String[] getSelectedValues(String arg0) { + throw new UnsupportedOperationException(); + + } + /** + * Gets the text from a cell of a table. The cellAddress syntax + * tableLocator.row.column, where row and column start at 0. + * + * @param tableCellAddress a cell address, e.g. "foo.1.4" + * @return string the text from the specified cell + */ + public String getTable(String tableCellAddress) { + Pattern p = Pattern.compile("(.*)\\.(\\d+)\\.(\\d+)"); + Matcher m = p.matcher(tableCellAddress); + if (!m.matches()) { + LOG.warn("Invalid table cell address: " + tableCellAddress); + return null; + } + + int row,col; + try { + row = Integer.parseInt(m.group(2)); + col = Integer.parseInt(m.group(3)); + } catch (NumberFormatException ex) { + LOG.warn("Invalid table cell address: " + tableCellAddress); + return null; + } + + Element table = new ElementLocator(getDocument()).findElement(m.group(1)); + if (table != null) { + NodeList rows = table.getElementsByTagName("tr"); + if (row < rows.getLength()) { + NodeList cells = ((Element)rows.item(row)).getChildNodes(); + int cellCount = 0; + for (int x = 0; x < cells.getLength(); x++) { + if (cells.item(x).getNodeType() == Node.ELEMENT_NODE) { + Element cell = (Element)cells.item(x); + if (cell.getTagName().equalsIgnoreCase("td") || cell.getTagName().equalsIgnoreCase("th")) { + if (cellCount == col) { + return cell.getTextContent(); + } else { + cellCount++; + } + } + } + } + + } else { + LOG.warn("Invalid table cell address: " + tableCellAddress + " table only has " + rows.getLength() + " rows "); + } + } else { + LOG.warn("Could not find table : " + m.group(1)); + } + return null; + } + + public String getText(String id) { + return getDocument().getElementById(id).getTextContent(); + } + + public String getTitle() { + throw new UnsupportedOperationException(); + + } + + public String getValue(String arg0) { + throw new UnsupportedOperationException(); + } + + public boolean getWhetherThisFrameMatchFrameExpression(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + + public boolean getWhetherThisWindowMatchWindowExpression(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + + public Number getXpathCount(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void goBack() { + throw new UnsupportedOperationException(); + + } + + public boolean isChecked(String id) { + throw new UnsupportedOperationException(); + } + + public boolean isEditable(String id) { + throw new UnsupportedOperationException(); + } + + public boolean isElementPresent(String id) { + return getDocument().getElementById(id) != null; + } + + public boolean isOrdered(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + + public boolean isSomethingSelected(String arg0) { + throw new UnsupportedOperationException(); + } + + public boolean isTextPresent(String text) { + return getCurrentWindow().getSource().contains(text); + } + + public boolean isVisible(String arg0) { + throw new UnsupportedOperationException(); + } + + public void open(String url) { + try { + getCurrentWindow().open(url); + } catch (BrowserException ex) { + LOG.warn("Problem loading page", ex); + } + } + + public void openWindow(String windowName, String url) { + try { + _currentWindowName = windowName; + getCurrentWindow().open(url); + } catch (BrowserException ex) { + LOG.warn("Problem loading page", ex); + } + } + + public void refresh() { + open(getCurrentWindow().getLocation()); + } + + public void removeAllSelections(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void removeSelection(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void select(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void selectFrame(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void selectWindow(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void setBrowserLogLevel(String arg0) { + throw new UnsupportedOperationException(); + } + + public void setContext(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void start() { + _browser = new BrowserImpl(); + } + + public void stop() { + _browser = null; + } + + public void submit(String id) { + try { + getCurrentWindow().submitForm(id, new MultiHashMap()); + } catch (BrowserException ex) { + LOG.warn("Problem loading page", ex); + } + } + + public void type(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void typeKeys(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + public void setTimeout(String arg0) { + throw new UnsupportedOperationException(); + } + + public void uncheck(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void waitForCondition(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void waitForFrameToLoad(String arg0, String arg1) { + // noop + } + + public void waitForPageToLoad(String arg0) { + // noop + } + + // + // Currently Unsupported Operations + // + public void addSelection(String arg0, String arg1) { + throw new UnsupportedOperationException(); + } + + public void altKeyDown() { + throw new UnsupportedOperationException(); + } + + public void altKeyUp() { + throw new UnsupportedOperationException(); + } + + public void answerOnNextPrompt(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void captureScreenshot(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void chooseCancelOnNextConfirmation() { + throw new UnsupportedOperationException(); + + } + + public void chooseOkOnNextConfirmation() { + throw new UnsupportedOperationException(); + + } + + public void controlKeyDown() { + throw new UnsupportedOperationException(); + + } + + public void controlKeyUp() { + throw new UnsupportedOperationException(); + + } + + public void doubleClick(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void doubleClickAt(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void dragAndDrop(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void dragAndDropToObject(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void dragdrop(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void fireEvent(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public String getAlert() { + throw new UnsupportedOperationException(); + } + + public String getConfirmation() { + throw new UnsupportedOperationException(); + } + + public Number getCursorPosition(String arg0) { + throw new UnsupportedOperationException(); + } + + public Number getElementHeight(String arg0) { + throw new UnsupportedOperationException(); + + } + + public Number getElementIndex(String arg0) { + throw new UnsupportedOperationException(); + + } + + public Number getElementPositionLeft(String arg0) { + throw new UnsupportedOperationException(); + + } + + public Number getElementPositionTop(String arg0) { + throw new UnsupportedOperationException(); + + } + + public Number getElementWidth(String arg0) { + throw new UnsupportedOperationException(); + + } + + public String getEval(String arg0) { + throw new UnsupportedOperationException(); + + } + + public String getExpression(String arg0) { + throw new UnsupportedOperationException(); + + } + + public Number getMouseSpeed() { + throw new UnsupportedOperationException(); + + } + + public String getPrompt() { + throw new UnsupportedOperationException(); + + } + public void getSpeed() { + throw new UnsupportedOperationException(); + + } + + public void highlight(String arg0) { + throw new UnsupportedOperationException(); + + } + + public boolean isAlertPresent() { + throw new UnsupportedOperationException(); + } + + public boolean isConfirmationPresent() { + throw new UnsupportedOperationException(); + } + + public boolean isPromptPresent() { + throw new UnsupportedOperationException(); + } + + public void keyDown(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void keyPress(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void keyUp(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void metaKeyDown() { + throw new UnsupportedOperationException(); + + } + + public void metaKeyUp() { + throw new UnsupportedOperationException(); + + } + + public void mouseDown(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void mouseDownAt(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void mouseMove(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void mouseMoveAt(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void mouseOut(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void mouseOver(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void mouseUp(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void mouseUpAt(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void setCursorPosition(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + public void setMouseSpeed(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void setSpeed(String arg0) { + throw new UnsupportedOperationException(); + + } + + public void shiftKeyDown() { + throw new UnsupportedOperationException(); + + } + + public void shiftKeyUp() { + throw new UnsupportedOperationException(); + + } + + public void waitForPopUp(String arg0, String arg1) { + throw new UnsupportedOperationException(); + + } + + +} Added: trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java =================================================================== --- trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java (rev 0) +++ trunk/selenium-client/src/test/java/com/software416/jsimplebrowser/seleniumclient/SeleniumClientTest.java 2007-08-11 03:21:37 UTC (rev 42) @@ -0,0 +1,44 @@ +package com.software416.jsimplebrowser.seleniumclient; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.apache.commons.io.IOUtils; +import org.junit.BeforeClass; +import org.junit.Test; +import org.w3c.dom.Document; + +import com.software416.jsimplebrowser.BrowserException; +import com.software416.jsimplebrowser.util.HtmlToDomConverter; + +public class SeleniumClientTest { + @BeforeClass public static void setUpLog() { + System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); + System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.com.software416", "debug"); + } + + @Test public void testElementSearch() throws IOException, BrowserException { + SeleniumClient sc = new TestSeleniumClient(""); + //assertEquals("/ig?hl=en", sc.getTable("//table[1].1.1")); + //assertEquals("/ig?hl=en", sc.getTable("foo.1.1")); + //assertEquals("Command", sc.getTable("foo.0.0")); + assertNull(sc.getTable("foo1.0.0")); + assertNull(sc.getTable("foo1.100.100")); + assertNull(sc.getTable("foo1.100")); + } + + private static class TestSeleniumClient extends SeleniumClient { + private Document _document; + + TestSeleniumClient (String resourceLocation) throws IOException, BrowserException { + _document = new HtmlToDomConverter().getDocumentFromHtml(IOUtils.toByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceLocation))); + } + + @Override + public Document getDocument() { + return _document; + } + } +} Added: trunk/selenium-client/src/test/resources/tableTest.html =================================================================== --- trunk/selenium-client/src/test/resources/tableTest.html (rev 0) +++ trunk/selenium-client/src/test/resources/tableTest.html 2007-08-11 03:21:37 UTC (rev 42) @@ -0,0 +1,42 @@ +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<title>test</title> +</head> +<body> +<table id="foo" cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">test</td></tr> +</thead><tbody> +<tr> + <th>Command</th> + <th>Data</th> + + <th>Optional</th> +</tr> +<tr> + <td>open</td> + <td>/ig?hl=en</td> + + <td></td> +</tr> +<tr> + <td>type</td> + <td>q</td> + <td>Java SDK</td> +</tr> +<tr> + <td>clickAndWait</td> + + <td>btnG</td> + <td></td> +</tr> +<tr> + <td>verifyTextPresent</td> + <td>Download Java 2 Platform, Standard Edition, v 1.4.2 (J2SE)</td> + <td></td> +</tr> + +</tbody></table> +</body> +</html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-10 19:04:37
|
Revision: 41 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=41&view=rev Author: rdimarco Date: 2007-08-10 12:04:30 -0700 (Fri, 10 Aug 2007) Log Message: ----------- Getting apt right Modified Paths: -------------- trunk/src/site/apt/index.apt Modified: trunk/src/site/apt/index.apt =================================================================== --- trunk/src/site/apt/index.apt 2007-08-10 18:54:41 UTC (rev 40) +++ trunk/src/site/apt/index.apt 2007-08-10 19:04:30 UTC (rev 41) @@ -7,5 +7,5 @@ Big ToDos... * Selenium Client - * JavaScript Execution Environment + * JavaScript Execution Engine This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-10 18:54:44
|
Revision: 40 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=40&view=rev Author: rdimarco Date: 2007-08-10 11:54:41 -0700 (Fri, 10 Aug 2007) Log Message: ----------- Renamed RequestInfo to HttpResponse added some documentation. Modified Paths: -------------- trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java Added Paths: ----------- trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java trunk/src/site/apt/index.apt Removed Paths: ------------- trunk/core/src/main/java/com/software416/jsimplebrowser/RequestInfo.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestInfoImpl.java Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-10 16:12:54 UTC (rev 39) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-10 18:54:41 UTC (rev 40) @@ -4,6 +4,6 @@ public static final String MAIN_BROWSER_WINDOW_NAME = "main"; public void open(String url) throws BrowserException; public void open(String url, String window) throws BrowserException; - public void makeXmlHttpRequest(String url, String requestBody) throws BrowserException; + public HttpResponse makeXmlHttpRequest(String url, String requestBody) throws BrowserException; public Window getWindow(String windowName); } Copied: trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java (from rev 37, trunk/core/src/main/java/com/software416/jsimplebrowser/RequestInfo.java) =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/HttpResponse.java 2007-08-10 18:54:41 UTC (rev 40) @@ -0,0 +1,10 @@ +package com.software416.jsimplebrowser; + +import org.apache.commons.collections.MultiMap; + +public interface HttpResponse { + public int getResponseCode(); + public MultiMap getCookies(); + public String getCookieValue(String cookieName); + public byte[] getResponseBody(); +} Deleted: trunk/core/src/main/java/com/software416/jsimplebrowser/RequestInfo.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/RequestInfo.java 2007-08-10 16:12:54 UTC (rev 39) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/RequestInfo.java 2007-08-10 18:54:41 UTC (rev 40) @@ -1,8 +0,0 @@ -package com.software416.jsimplebrowser; - -import org.apache.commons.collections.MultiMap; - -public interface RequestInfo { - public int getResponseCode(); - public MultiMap getCookies(); -} Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-10 16:12:54 UTC (rev 39) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-10 18:54:41 UTC (rev 40) @@ -6,7 +6,7 @@ public interface Window { public void open(String url) throws BrowserException; public void submitForm(String formName, MultiMap parameters) throws BrowserException; - public RequestInfo getRequestInfo(); + public HttpResponse getRequestInfo(); public Document getDocument(); public String getSource(); public History getHistory(); Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-10 16:12:54 UTC (rev 39) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-10 18:54:41 UTC (rev 40) @@ -29,8 +29,8 @@ _browserWindows.put(MAIN_BROWSER_WINDOW_NAME, new WindowImpl(this)); } - protected synchronized RequestInfoImpl makeRequest(HttpMethod m) throws BrowserException { - RequestInfoImpl ri = new RequestInfoImpl(); + protected synchronized HttpResponseImpl makeRequest(HttpMethod m) throws BrowserException { + HttpResponseImpl ri = new HttpResponseImpl(); ri.setRequestMethod(m); try { @@ -46,11 +46,11 @@ return ri; } - public void makeXmlHttpRequest(String url, String requestBody) throws BrowserException { + public HttpResponseImpl makeXmlHttpRequest(String url, String requestBody) throws BrowserException { PostMethod m = new PostMethod(url); try { m.setRequestEntity(new StringRequestEntity(requestBody, "text/plain",null)); - makeRequest(m); + return makeRequest(m); } catch (IOException ex) { throw new BrowserException(ex); } Copied: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java (from rev 37, trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestInfoImpl.java) =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/HttpResponseImpl.java 2007-08-10 18:54:41 UTC (rev 40) @@ -0,0 +1,57 @@ +package com.software416.jsimplebrowser.impl; + +import java.util.Collection; + +import org.apache.commons.collections.MultiHashMap; +import org.apache.commons.collections.MultiMap; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpMethod; + +import com.software416.jsimplebrowser.HttpResponse; + +public class HttpResponseImpl implements HttpResponse{ + private HttpMethod _requestMethod; + private int _responseCode; + private byte[] _responseBody; + + + public MultiMap getCookies() { + MultiHashMap rv = new MultiHashMap(); + Header[] headers = _requestMethod.getRequestHeaders("Cookie"); + for (Header header : headers) { + String[] vals = header.getValue().split("\\s*;\\s*"); + for (String cookie : vals) { + int idx = cookie.indexOf("="); + if (idx > 0 && idx < cookie.length() - 2) { + rv.put(cookie.substring(0, idx), cookie.substring(idx + 1)); + } + } + } + return rv; + } + + public String getCookieValue(String cookieName) { + Object rv = getCookies().get(cookieName); + return rv == null ? null : rv instanceof String ? rv.toString() : ((Collection)rv).iterator().next().toString(); + } + + public byte[] getResponseBody() { + return _responseBody; + } + public void setResponseBody(byte[] responseBody) { + _responseBody = responseBody; + } + public HttpMethod getRequestMethod() { + return _requestMethod; + } + public void setRequestMethod(HttpMethod requestMethod) { + _requestMethod = requestMethod; + } + public int getResponseCode() { + return _responseCode; + } + public void setResponseCode(int responseCode) { + _responseCode = responseCode; + } + +} Deleted: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestInfoImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestInfoImpl.java 2007-08-10 16:12:54 UTC (rev 39) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestInfoImpl.java 2007-08-10 18:54:41 UTC (rev 40) @@ -1,57 +0,0 @@ -package com.software416.jsimplebrowser.impl; - -import java.util.Collection; - -import org.apache.commons.collections.MultiHashMap; -import org.apache.commons.collections.MultiMap; -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpMethod; - -import com.software416.jsimplebrowser.RequestInfo; - -public class RequestInfoImpl implements RequestInfo{ - private HttpMethod _requestMethod; - private int _responseCode; - private byte[] _responseBody; - - - public MultiMap getCookies() { - MultiHashMap rv = new MultiHashMap(); - Header[] headers = _requestMethod.getRequestHeaders("Cookie"); - for (Header header : headers) { - String[] vals = header.getValue().split("\\s*;\\s*"); - for (String cookie : vals) { - int idx = cookie.indexOf("="); - if (idx > 0 && idx < cookie.length() - 2) { - rv.put(cookie.substring(0, idx), cookie.substring(idx + 1)); - } - } - } - return rv; - } - - public String getCookieValue(String cookieName) { - Object rv = getCookies().get(cookieName); - return rv == null ? "" : rv instanceof String ? rv.toString() : ((Collection)rv).iterator().next().toString(); - } - - public byte[] getResponseBody() { - return _responseBody; - } - public void setResponseBody(byte[] responseBody) { - _responseBody = responseBody; - } - public HttpMethod getRequestMethod() { - return _requestMethod; - } - public void setRequestMethod(HttpMethod requestMethod) { - _requestMethod = requestMethod; - } - public int getResponseCode() { - return _responseCode; - } - public void setResponseCode(int responseCode) { - _responseCode = responseCode; - } - -} Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-10 16:12:54 UTC (rev 39) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-10 18:54:41 UTC (rev 40) @@ -22,12 +22,12 @@ import com.software416.jsimplebrowser.BrowserRuntimeException; import com.software416.jsimplebrowser.History; import com.software416.jsimplebrowser.HtmlParseException; -import com.software416.jsimplebrowser.RequestInfo; +import com.software416.jsimplebrowser.HttpResponse; import com.software416.jsimplebrowser.Window; import com.software416.jsimplebrowser.util.HtmlToDomConverter; public class WindowImpl implements Window { - private RequestInfoImpl _requestInfo; + private HttpResponseImpl _requestInfo; private Document _responseDocument; private BrowserImpl _browser; private HtmlToDomConverter _converter = new HtmlToDomConverter(); @@ -56,7 +56,7 @@ handleResponse(_browser.makeRequest(hm)); } - public void handleResponse(RequestInfoImpl requestInfo) throws BrowserException { + public void handleResponse(HttpResponseImpl requestInfo) throws BrowserException { _requestInfo = requestInfo; _responseDocument = null; if (_doFollowRedirects) { @@ -243,7 +243,7 @@ } } - public RequestInfo getRequestInfo() { + public HttpResponse getRequestInfo() { return _requestInfo; } Modified: trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java 2007-08-10 16:12:54 UTC (rev 39) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java 2007-08-10 18:54:41 UTC (rev 40) @@ -27,7 +27,7 @@ @Test public void testParsingBadPages() throws BrowserException, IOException { String baseForm = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("badlyFormattedPage.html")); - RequestInfoImpl requestInfo = new RequestInfoImpl(); + HttpResponseImpl requestInfo = new HttpResponseImpl(); requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); requestInfo.setResponseBody(baseForm.getBytes()); WindowImpl wi = new WindowImpl(null); @@ -37,7 +37,7 @@ @Test public void testGetMetaRefresh() throws BrowserException { WindowImpl w = new WindowImpl(null); w.setDoFollowRedirects(false); - RequestInfoImpl ri = new RequestInfoImpl(); + HttpResponseImpl ri = new HttpResponseImpl(); ri.setResponseBody("<html><body><meta http-equiv=\"Refresh\" content=\"0;URL=http://www.linkedin.com/home\"></body></html>".getBytes()); w.handleResponse(ri); assertEquals("http://www.linkedin.com/home", w.findRefreshLink()); @@ -59,7 +59,7 @@ } @Test public void testDefaultFormValuesMethodGeneration() throws BrowserException, IOException { String baseForm = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("formTest1.html")); - RequestInfoImpl requestInfo = new RequestInfoImpl(); + HttpResponseImpl requestInfo = new HttpResponseImpl(); requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); requestInfo.setResponseBody(baseForm.getBytes()); WindowImpl wi = new WindowImpl(null); @@ -79,7 +79,7 @@ } @Test public void testFormMethodGeneration() throws BrowserException, URIException { String baseForm = "<html><body><form name=\"%1$s\" method=\"%2$s\" action=\"%3$s\"></form></body></html>"; - RequestInfoImpl requestInfo = new RequestInfoImpl(); + HttpResponseImpl requestInfo = new HttpResponseImpl(); requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); requestInfo.setResponseBody(String.format(baseForm, "login", "GET", "http://foo.com/login").getBytes()); WindowImpl wi = new WindowImpl(null); Modified: trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java 2007-08-10 16:12:54 UTC (rev 39) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java 2007-08-10 18:54:41 UTC (rev 40) @@ -11,7 +11,7 @@ import com.software416.jsimplebrowser.Browser; import com.software416.jsimplebrowser.BrowserException; import com.software416.jsimplebrowser.impl.BrowserImpl; -import com.software416.jsimplebrowser.impl.RequestInfoImpl; +import com.software416.jsimplebrowser.impl.HttpResponseImpl; import com.software416.jsimplebrowser.impl.WindowImpl; public class BrowserHelperTest { @@ -19,7 +19,7 @@ BrowserImpl b = new BrowserImpl(); BrowserHelper bh = new BrowserHelper(b); WindowImpl wi = (WindowImpl)b.getWindow(Browser.MAIN_BROWSER_WINDOW_NAME); - RequestInfoImpl ri = new RequestInfoImpl(); + HttpResponseImpl ri = new HttpResponseImpl(); ri.setResponseBody("<html><body><a href=\"foo.html\">Sign In</a></body></html>".getBytes()); wi.handleResponse(ri); assertEquals("foo.html", bh.getFirstLinkForTextRegex("Sign In")); Added: trunk/src/site/apt/index.apt =================================================================== --- trunk/src/site/apt/index.apt (rev 0) +++ trunk/src/site/apt/index.apt 2007-08-10 18:54:41 UTC (rev 40) @@ -0,0 +1,11 @@ +About + + The JSimpleBrowser project is intended to be an all-Java headless web browser. + + When trying to write automated tests of a website (especially with JavaScript modifying the DOM), it is nice to have a headless browser. In addition, it would make web scraping tools easier. + +Big ToDos... + + * Selenium Client + * JavaScript Execution Environment + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-10 16:12:56
|
Revision: 39 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=39&view=rev Author: rdimarco Date: 2007-08-10 09:12:54 -0700 (Fri, 10 Aug 2007) Log Message: ----------- Added website information to the pom.xml Modified Paths: -------------- trunk/core/pom.xml trunk/pom.xml Added Paths: ----------- trunk/src/ trunk/src/site/ trunk/src/site/apt/ trunk/src/site/site.xml Modified: trunk/core/pom.xml =================================================================== --- trunk/core/pom.xml 2007-08-10 15:47:57 UTC (rev 38) +++ trunk/core/pom.xml 2007-08-10 16:12:54 UTC (rev 39) @@ -5,6 +5,7 @@ <artifactId>jsimplebrowser</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> + <name>JSimpleBrowser Core Classes</name> <artifactId>jsimplebrowser-core</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> @@ -40,21 +41,11 @@ <groupId>org.cyberneko</groupId> <artifactId>html-core</artifactId> </dependency> -<!-- <dependency> - <groupId>jtidy</groupId> - <artifactId>jtidy</artifactId> - </dependency> ---> - <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </dependency> <dependency> - <groupId>net.htmlparser.jericho-html</groupId> - <artifactId>jericho-html</artifactId> - </dependency> - <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> </dependency> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2007-08-10 15:47:57 UTC (rev 38) +++ trunk/pom.xml 2007-08-10 16:12:54 UTC (rev 39) @@ -5,6 +5,51 @@ <name>JSimpleBrowser</name> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> +<licenses> + <license> + <name>GPL</name> + <url>http://www.gnu.org/licenses/gpl-2.0.txt</url> + <distribution>repo</distribution> + </license> +</licenses> +<developers> + <developer> + <name>Rob Di Marco</name> + <email>rob.dimarco (at) 416software.com</email> + <url>http://www.416software.com</url> + </developer> +</developers> + + <issueManagement> + <url>http://sourceforge.net/tracker/?group_id=202645</url> + </issueManagement> + <mailingLists> + <mailingList> + <name>User List</name> + <subscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-users</subscribe> + <unsubscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-users</unsubscribe> + <post>jsi...@li...</post> + </mailingList> + <mailingList> + <name>Developer List</name> + <subscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-devel</subscribe> + <unsubscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-devel</unsubscribe> + <post>jsi...@li...</post> + </mailingList> + <mailingList> + <name>Subversion Commit List</name> + <subscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-svn</subscribe> + <unsubscribe>http://lists.sourceforge.net/lists/listsinfo/jsimplebrowser-svn</unsubscribe> + <post>jsi...@li...</post> + </mailingList> + </mailingLists> + <scm> + <connection>scm:svn:https://jsimplebrowser.svn.sourceforge.net/svnroot/jsimplebrowser</connection> + <developerConnection>scm:svn:https://jsimplebrowser.svn.sourceforge.net/svnroot/jsimplebrowser</developerConnection> + <tag>HEAD</tag> + <url>https://jsimplebrowser.svn.sourceforge.net/svnroot/jsimplebrowser</url> + </scm> + <distributionManagement> <snapshotRepository> <id>snapshots</id> @@ -16,6 +61,10 @@ <uniqueVersion>false</uniqueVersion> <url>http://invincible.dynalias.com:8081/artifactory/libs-snapshots</url> </repository> + <site> + <id>website</id> + <url>scp://shell.sourceforge.net/home/groups/j/js/jsimplebrowser/htdocs</url> + </site> </distributionManagement> <url>http://jsimplebrowser.sourceforge.net/</url> <modules> @@ -29,12 +78,8 @@ <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> - <source>1.6</source> - <target>1.6</target> - <compilerArguments> - <verbose /> - <bootclasspath>${java.home}/lib/rt.jar</bootclasspath> - </compilerArguments> + <source>1.5</source> + <target>1.5</target> </configuration> </plugin> <plugin> @@ -104,22 +149,12 @@ <artifactId>html-core</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> - <!--<dependency> - <groupId>jtidy</groupId> - <artifactId>jtidy</artifactId> - <version>8.0-SNAPSHOT</version> - </dependency>--> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.3</version> </dependency> <dependency> - <groupId>net.htmlparser.jericho-html</groupId> - <artifactId>jericho-html</artifactId> - <version>2.4</version> - </dependency> - <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1-rc1</version> Added: trunk/src/site/site.xml =================================================================== --- trunk/src/site/site.xml (rev 0) +++ trunk/src/site/site.xml 2007-08-10 16:12:54 UTC (rev 39) @@ -0,0 +1,19 @@ +<project name="JSimpleBrowser"> + <publishDate position="left" format="MM-dd-yyyy hh:mm" /> + <bannerLeft> + <name>Sourceforge</name> + <src>http://sflogo.sourceforge.net/sflogo.php?group_id=202645&amp;type=2</src> + <href>http://sourceforge.net/projects/jsimplebrowser</href> + </bannerLeft> + <body> + <links> + <item name="JSimpleBrowser SourceForge project page" href="http://sourceforge.net/projects/jsimplebrowser" /> + </links> + <menu name="Subprojects"> + <item name="Core Classes" href="/multiproject/core/index.html" /> + </menu> + + ${reports} + + </body> +</project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-10 15:47:58
|
Revision: 38 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=38&view=rev Author: rdimarco Date: 2007-08-10 08:47:57 -0700 (Fri, 10 Aug 2007) Log Message: ----------- Added more ignores. Property Changed: ---------------- trunk/core/ Property changes on: trunk/core ___________________________________________________________________ Name: svn:ignore - .settings target + .settings target .classpath .project This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rdi...@us...> - 2007-08-10 15:46:44
|
Revision: 37 http://jsimplebrowser.svn.sourceforge.net/jsimplebrowser/?rev=37&view=rev Author: rdimarco Date: 2007-08-10 08:46:42 -0700 (Fri, 10 Aug 2007) Log Message: ----------- Moved from JTidy to CyberNeko for better parsing. Modified Paths: -------------- trunk/core/pom.xml trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java trunk/pom.xml Added Paths: ----------- trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserRuntimeException.java trunk/core/src/main/java/com/software416/jsimplebrowser/History.java trunk/core/src/main/java/com/software416/jsimplebrowser/RequestInfo.java trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestInfoImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java trunk/core/src/main/java/com/software416/jsimplebrowser/util/ trunk/core/src/main/java/com/software416/jsimplebrowser/util/BrowserHelper.java trunk/core/src/main/java/com/software416/jsimplebrowser/util/HtmlToDomConverter.java trunk/core/src/test/java/com/software416/jsimplebrowser/impl/ trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java trunk/core/src/test/java/com/software416/jsimplebrowser/util/ trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java trunk/core/src/test/resources/badlyFormattedPage.html trunk/core/src/test/resources/formTest1.html trunk/core/src/test/resources/linkTest1.html Removed Paths: ------------- trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserHelper.java trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserWindow.java trunk/core/src/main/java/com/software416/jsimplebrowser/HtmlToDomConverter.java trunk/core/src/main/java/com/software416/jsimplebrowser/SimpleBrowser.java trunk/core/src/test/java/com/software416/jsimplebrowser/BrowserTest.java Property Changed: ---------------- trunk/core/ Property changes on: trunk/core ___________________________________________________________________ Name: svn:ignore - .settings + .settings target Modified: trunk/core/pom.xml =================================================================== --- trunk/core/pom.xml 2007-08-07 21:56:12 UTC (rev 36) +++ trunk/core/pom.xml 2007-08-10 15:46:42 UTC (rev 37) @@ -19,6 +19,10 @@ <artifactId>commons-io</artifactId> </dependency> <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + </dependency> + <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging-api</artifactId> <scope>provided</scope> @@ -33,9 +37,15 @@ <artifactId>commons-collections</artifactId> </dependency> <dependency> - <groupId>org.hibernate</groupId> + <groupId>org.cyberneko</groupId> + <artifactId>html-core</artifactId> + </dependency> +<!-- + <dependency> + <groupId>jtidy</groupId> <artifactId>jtidy</artifactId> </dependency> +--> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> Modified: trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-07 21:56:12 UTC (rev 36) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Browser.java 2007-08-10 15:46:42 UTC (rev 37) @@ -1,27 +1,9 @@ package com.software416.jsimplebrowser; -import java.util.Map; - -import org.apache.commons.collections.MultiMap; -import org.w3c.dom.Document; - public interface Browser { - - public void go(String url) throws BrowserException; - - public void submitForm(String formName, - Map<String, String> userSpecifiedParameterMap) throws BrowserException; - - public void makeRequestWithBody(String link, String body) throws BrowserException; - - public MultiMap getCookies(); - - public String getCookieValue(String cookieName); - - public String getResponseHtml(); - - public Document getResponseDocument(); - - public int getResponseCode(); - + public static final String MAIN_BROWSER_WINDOW_NAME = "main"; + public void open(String url) throws BrowserException; + public void open(String url, String window) throws BrowserException; + public void makeXmlHttpRequest(String url, String requestBody) throws BrowserException; + public Window getWindow(String windowName); } Deleted: trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserHelper.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserHelper.java 2007-08-07 21:56:12 UTC (rev 36) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserHelper.java 2007-08-10 15:46:42 UTC (rev 37) @@ -1,46 +0,0 @@ -package com.software416.jsimplebrowser; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -public class BrowserHelper { - private static final Log LOG = LogFactory.getLog(BrowserHelper.class); - private Browser _browser; - public BrowserHelper(Browser browser) { - _browser = browser; - } - - public String getFirstLinkForTextRegex(String regex) { - List<String> links = getLinksForTextRegex(regex, 1); - return links.size() == 0 ? null : links.get(0); - } - - public List<String> getLinksForTextRegex(String regex) { - return getLinksForTextRegex(regex, Integer.MAX_VALUE); - } - - public List<String> getLinksForTextRegex(String regex, int maxResults) { - List<String> rv = new ArrayList<String>(); - NodeList nl = _browser.getResponseDocument().getElementsByTagName("a"); - Pattern p = Pattern.compile(".*" + regex + ".*", Pattern.CASE_INSENSITIVE); - for (int x = 0; x < nl.getLength() && rv.size() < maxResults; x++) { - Element element = (Element)nl.item(x); - String href = element.getAttribute("href"); - if (LOG.isDebugEnabled()) { - LOG.debug("matching " + regex + " against content " + element.getTextContent()); - } - if (href != null && element.getTextContent() != null && p.matcher(element.getTextContent()).matches()) { - rv.add(href); - } - } - return rv; - } - - -} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserRuntimeException.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserRuntimeException.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserRuntimeException.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,21 @@ +package com.software416.jsimplebrowser; + +public class BrowserRuntimeException extends RuntimeException { + private static final long serialVersionUID = 20070808L; + public BrowserRuntimeException() { + // Support no arg call + } + + public BrowserRuntimeException(String message) { + super(message); + } + + public BrowserRuntimeException(Throwable cause) { + super(cause); + } + + public BrowserRuntimeException(String message, Throwable cause) { + super(message, cause); + } + +} Deleted: trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserWindow.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserWindow.java 2007-08-07 21:56:12 UTC (rev 36) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/BrowserWindow.java 2007-08-10 15:46:42 UTC (rev 37) @@ -1,5 +0,0 @@ -package com.software416.jsimplebrowser; - -public class BrowserWindow { - -} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/History.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/History.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/History.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,5 @@ +package com.software416.jsimplebrowser; + +public interface History { + // Empty for now... +} Deleted: trunk/core/src/main/java/com/software416/jsimplebrowser/HtmlToDomConverter.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/HtmlToDomConverter.java 2007-08-07 21:56:12 UTC (rev 36) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/HtmlToDomConverter.java 2007-08-10 15:46:42 UTC (rev 37) @@ -1,51 +0,0 @@ -package com.software416.jsimplebrowser; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.w3c.dom.Document; -import org.w3c.tidy.Tidy; -import org.xml.sax.SAXException; - -public class HtmlToDomConverter { - private static final Log LOG = LogFactory.getLog(HtmlToDomConverter.class); - private DocumentBuilder _builder; - public HtmlToDomConverter() { - try { - _builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - } catch (ParserConfigurationException ex) { - throw new RuntimeException("Weird problem creating a document builder", ex); - } - } - - public Document getDocumentFromHtml(byte[] docBytes) throws HtmlParseException { - Tidy t = new Tidy(); - t.setXHTML(true); - t.setXmlOut(true); - t.setXmlPi(true); - t.setXmlPIs(true); - t.setQuiet(true); - t.setShowErrors(0); - t.setShowWarnings(false); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { - LOG.debug("Tidying input"); - t.parse(new ByteArrayInputStream(docBytes), out); - LOG.debug("Parsing tidied file"); - Document rv = _builder.parse(new ByteArrayInputStream(out.toByteArray())); - LOG.debug("Done with parsing"); - return rv; - } catch (SAXException ex) { - throw new HtmlParseException(ex); - } catch (IOException ex) { - throw new HtmlParseException(ex); - } - } -} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/RequestInfo.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/RequestInfo.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/RequestInfo.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,8 @@ +package com.software416.jsimplebrowser; + +import org.apache.commons.collections.MultiMap; + +public interface RequestInfo { + public int getResponseCode(); + public MultiMap getCookies(); +} Deleted: trunk/core/src/main/java/com/software416/jsimplebrowser/SimpleBrowser.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/SimpleBrowser.java 2007-08-07 21:56:12 UTC (rev 36) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/SimpleBrowser.java 2007-08-10 15:46:42 UTC (rev 37) @@ -1,221 +0,0 @@ -package com.software416.jsimplebrowser; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Collection; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.collections.MultiHashMap; -import org.apache.commons.collections.MultiMap; -import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.NameValuePair; -import org.apache.commons.httpclient.URI; -import org.apache.commons.httpclient.URIException; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -public class SimpleBrowser implements Browser { - @SuppressWarnings("unused") - private static final Log LOG = LogFactory.getLog(SimpleBrowser.class); - private HttpClient _client = new HttpClient(); - private HttpMethod _requestMethod; - private Document _responseDocument; - private byte[] _responseBody; - private int _responseCode; - private HtmlToDomConverter _converter = new HtmlToDomConverter(); - - public void go(String url) throws BrowserException{ - try { - GetMethod gm; - if (_requestMethod != null) { - gm = new GetMethod(); - gm.setURI(new URI(_requestMethod.getURI(), url, true)); - } else { - gm = new GetMethod(url); - } - makeRequest(gm); - } catch (IOException ex) { - throw new BrowserException(ex); - } - } - - public void submitForm(String formName, Map<String, String> userSpecifiedParameterMap) throws BrowserException { - try { - HttpMethod m = buildMethodForForm(formName, userSpecifiedParameterMap); - if (m == null) { - throw new BrowserException("Could not submit form as it does not exist!!"); - } - makeRequest(m); - } catch (IOException ex) { - throw new BrowserException(ex); - } - } - - public void makeRequestWithBody(String link, String body) throws BrowserException{ - PostMethod m = new PostMethod(link); - try { - m.setRequestEntity(new StringRequestEntity(body, "text/plain",null)); - makeRequest(m); - } catch (IOException ex) { - throw new BrowserException(ex); - } - } - - public MultiMap getCookies() { - MultiHashMap rv = new MultiHashMap(); - Header[] headers = _requestMethod.getRequestHeaders("Cookie"); - for (Header header : headers) { - String[] vals = header.getValue().split("\\s*;\\s*"); - for (String cookie : vals) { - int idx = cookie.indexOf("="); - if (idx > 0 && idx < cookie.length() - 2) { - rv.put(cookie.substring(0, idx), cookie.substring(idx + 1)); - } - } - } - return rv; - } - - public String getCookieValue(String cookieName) { - Object rv = getCookies().get(cookieName); - return rv == null ? "" : rv instanceof String ? rv.toString() : ((Collection)rv).iterator().next().toString(); - } - - protected synchronized void makeRequest(HttpMethod m) throws HttpException, IOException, BrowserException { - _requestMethod = m; - _responseCode = _client.executeMethod(_requestMethod); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - IOUtils.copy(_requestMethod.getResponseBodyAsStream(), bos); - setResponseBody(bos.toByteArray()); - String link = findRefreshLink(); - if (link != null) { - go(link); - } - } - - protected String findRefreshLink() { - NodeList meta = _responseDocument.getElementsByTagName("meta"); - for (int x = 0; x < meta.getLength(); x++) { - Element e = (Element)meta.item(x); - if (e.getAttribute("http-equiv") != null && e.getAttribute("http-equiv") != null && e.getAttribute("http-equiv").equalsIgnoreCase("refresh")) { - String content = e.getAttribute("content"); - if (content != null) { - Matcher m = Pattern.compile(".*URL=([^;]+).*").matcher(content); - if (m.matches()) { - return m.group(1); - } - } - } - } - return null; - } - - @SuppressWarnings("unchecked") - protected HttpMethod buildMethodForForm(String formName, Map<String, String> userParamMap) throws URIException { - Element formElement = findFormElementByFormName(formName); - if (formElement == null) { - return null; - } - - String formMethod = formElement.getAttribute("method"); - boolean usePost = formMethod != null && formMethod.toUpperCase().equals("POST"); - HttpMethod rv = usePost ? new PostMethod() : new GetMethod(); -// Iterator formFieldIterator = formElement.findFormFields().iterator(); - Map paramsToUse = new MultiHashMap(); -// while (formFieldIterator.hasNext()) { -// FormField f = (FormField)formFieldIterator.next(); -// Collection c = f.getValues(); -// Iterator formFieldValueIterator = c.iterator(); -// while (formFieldValueIterator.hasNext()) { -// paramsToUse.put(f.getName(), new NameValuePair(f.getName(), formFieldValueIterator.next().toString())); -// } -// } - - for (Entry<String, String> e : userParamMap.entrySet()) { - paramsToUse.remove(e.getKey()); - paramsToUse.put(e.getKey(), new NameValuePair(e.getKey(), e.getValue())); - } - - rv.setURI(new URI(_requestMethod.getURI(), new URI(formElement.getAttribute("action"), true))); - - Collection params = paramsToUse.values(); - if (usePost) { - ((PostMethod)rv).setRequestBody((NameValuePair[])params.toArray(new NameValuePair[params.size()])); - } else { - Iterator i = params.iterator(); - StringBuilder sb = new StringBuilder(); - if (rv.getURI().getQuery() != null) { - sb.append(rv.getURI().getQuery()); - } - while (i.hasNext()) { - if (sb.length() > 0) { - sb.append("&"); - } - NameValuePair pair = (NameValuePair)i.next(); - sb.append(pair.getName() + "=" + pair.getValue()); - } - try { - URI newUri = (URI)rv.getURI().clone(); - newUri.setQuery(sb.toString()); - rv.setURI(newUri); - } catch (CloneNotSupportedException ex) { - // Should never happen! - throw new RuntimeException(ex); - } - } - - return rv; - } - - protected Element findFormElementByFormName(String name) { - NodeList formElements=_responseDocument.getElementsByTagName("form"); - for (int i = 0; i < formElements.getLength(); i++) { - Element formElement=(Element)formElements.item(i); - String formName=formElement.getAttribute("name"); - if (name.equals(formName)) { - return formElement; - } - } - return null; - } - - - public String getResponseHtml() { - return new String(_responseBody); - } - - public int getResponseCode() { - return _responseCode; - } - - protected void setRequestMethod(HttpMethod m) { - _requestMethod = m; - } - protected void setResponseBody(String responseBody) throws HtmlParseException { - setResponseBody(responseBody.getBytes()); - } - - protected void setResponseBody(byte[] responseBody) throws HtmlParseException { - _responseBody = responseBody; - _responseDocument = _converter.getDocumentFromHtml(responseBody); - } - public Document getResponseDocument() { - return _responseDocument; - } - - -} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/Window.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,14 @@ +package com.software416.jsimplebrowser; + +import org.apache.commons.collections.MultiMap; +import org.w3c.dom.Document; + +public interface Window { + public void open(String url) throws BrowserException; + public void submitForm(String formName, MultiMap parameters) throws BrowserException; + public RequestInfo getRequestInfo(); + public Document getDocument(); + public String getSource(); + public History getHistory(); + public String getLocation(); +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/BrowserImpl.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,73 @@ +package com.software416.jsimplebrowser.impl; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.software416.jsimplebrowser.Browser; +import com.software416.jsimplebrowser.BrowserException; +import com.software416.jsimplebrowser.Window; + +public class BrowserImpl implements Browser { + @SuppressWarnings("unused") + private static final Log LOG = LogFactory.getLog(BrowserImpl.class); + + private HttpClient _client = new HttpClient(); + private Map<String, WindowImpl> _browserWindows = new HashMap<String, WindowImpl>(); + + public BrowserImpl() { + _browserWindows.put(MAIN_BROWSER_WINDOW_NAME, new WindowImpl(this)); + } + + protected synchronized RequestInfoImpl makeRequest(HttpMethod m) throws BrowserException { + RequestInfoImpl ri = new RequestInfoImpl(); + ri.setRequestMethod(m); + + try { + ri.setResponseCode(_client.executeMethod(m)); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + IOUtils.copy(m.getResponseBodyAsStream(), bos); + ri.setResponseBody(bos.toByteArray()); + } catch (HttpException ex) { + throw new BrowserException(ex); + } catch (IOException ex) { + throw new BrowserException(ex); + } + return ri; + } + + public void makeXmlHttpRequest(String url, String requestBody) throws BrowserException { + PostMethod m = new PostMethod(url); + try { + m.setRequestEntity(new StringRequestEntity(requestBody, "text/plain",null)); + makeRequest(m); + } catch (IOException ex) { + throw new BrowserException(ex); + } + } + + public void open(String url) throws BrowserException { + open(url, MAIN_BROWSER_WINDOW_NAME); + } + + public void open(String url, String window) throws BrowserException { + getWindow(window).open(url); + } + + public synchronized Window getWindow(String windowName) { + if (!_browserWindows.containsKey(windowName)) { + _browserWindows.put(windowName, new WindowImpl(this)); + } + return _browserWindows.get(windowName); + } +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestInfoImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestInfoImpl.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/RequestInfoImpl.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,57 @@ +package com.software416.jsimplebrowser.impl; + +import java.util.Collection; + +import org.apache.commons.collections.MultiHashMap; +import org.apache.commons.collections.MultiMap; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpMethod; + +import com.software416.jsimplebrowser.RequestInfo; + +public class RequestInfoImpl implements RequestInfo{ + private HttpMethod _requestMethod; + private int _responseCode; + private byte[] _responseBody; + + + public MultiMap getCookies() { + MultiHashMap rv = new MultiHashMap(); + Header[] headers = _requestMethod.getRequestHeaders("Cookie"); + for (Header header : headers) { + String[] vals = header.getValue().split("\\s*;\\s*"); + for (String cookie : vals) { + int idx = cookie.indexOf("="); + if (idx > 0 && idx < cookie.length() - 2) { + rv.put(cookie.substring(0, idx), cookie.substring(idx + 1)); + } + } + } + return rv; + } + + public String getCookieValue(String cookieName) { + Object rv = getCookies().get(cookieName); + return rv == null ? "" : rv instanceof String ? rv.toString() : ((Collection)rv).iterator().next().toString(); + } + + public byte[] getResponseBody() { + return _responseBody; + } + public void setResponseBody(byte[] responseBody) { + _responseBody = responseBody; + } + public HttpMethod getRequestMethod() { + return _requestMethod; + } + public void setRequestMethod(HttpMethod requestMethod) { + _requestMethod = requestMethod; + } + public int getResponseCode() { + return _responseCode; + } + public void setResponseCode(int responseCode) { + _responseCode = responseCode; + } + +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/impl/WindowImpl.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,264 @@ +package com.software416.jsimplebrowser.impl; + +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.collections.MultiHashMap; +import org.apache.commons.collections.MultiMap; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.httpclient.URI; +import org.apache.commons.httpclient.URIException; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import com.software416.jsimplebrowser.BrowserException; +import com.software416.jsimplebrowser.BrowserRuntimeException; +import com.software416.jsimplebrowser.History; +import com.software416.jsimplebrowser.HtmlParseException; +import com.software416.jsimplebrowser.RequestInfo; +import com.software416.jsimplebrowser.Window; +import com.software416.jsimplebrowser.util.HtmlToDomConverter; + +public class WindowImpl implements Window { + private RequestInfoImpl _requestInfo; + private Document _responseDocument; + private BrowserImpl _browser; + private HtmlToDomConverter _converter = new HtmlToDomConverter(); + private boolean _doFollowRedirects = true; + + public WindowImpl(BrowserImpl b) { + _browser = b; + } + + public void open(String url) throws BrowserException { + try { + GetMethod gm; + if (_requestInfo != null) { + gm = new GetMethod(); + gm.setURI(new URI(_requestInfo.getRequestMethod().getURI(), url, true)); + } else { + gm = new GetMethod(url); + } + makeRequest(gm); + } catch (IOException ex) { + throw new BrowserException(ex); + } + } + + protected void makeRequest(HttpMethod hm) throws BrowserException { + handleResponse(_browser.makeRequest(hm)); + } + + public void handleResponse(RequestInfoImpl requestInfo) throws BrowserException { + _requestInfo = requestInfo; + _responseDocument = null; + if (_doFollowRedirects) { + String link = findRefreshLink(); + if (link != null) { + open(link); + } + } + } + + public void submitForm(String formName, MultiMap userSpecifiedParameterMap) throws BrowserException { + try { + HttpMethod m = buildMethodForForm(formName, userSpecifiedParameterMap); + if (m == null) { + throw new BrowserException("Could not submit form as it does not exist!!"); + } + makeRequest(m); + } catch (IOException ex) { + throw new BrowserException(ex); + } + } + + protected String findRefreshLink() { + NodeList meta = getDocument().getElementsByTagName("meta"); + for (int x = 0; x < meta.getLength(); x++) { + Element e = (Element)meta.item(x); + if (e.getAttribute("http-equiv") != null && e.getAttribute("http-equiv") != null && e.getAttribute("http-equiv").equalsIgnoreCase("refresh")) { + String content = e.getAttribute("content"); + if (content != null) { + Matcher m = Pattern.compile(".*URL=([^;]+).*").matcher(content); + if (m.matches()) { + return m.group(1); + } + } + } + } + return null; + } + + @SuppressWarnings("unchecked") + protected HttpMethod buildMethodForForm(String formName, MultiMap userParamMap) throws URIException { + Element formElement = findFormElementByFormName(formName); + if (formElement == null) { + return null; + } + + MultiMap formParameters = populateMapWithDefaultValuesFromForm(formElement); + + mergeFormParameters(userParamMap, formParameters); + + String formMethod = formElement.getAttribute("method"); + boolean usePost = formMethod != null && formMethod.toUpperCase().equals("POST"); + HttpMethod rv = usePost ? new PostMethod() : new GetMethod(); + + rv.setURI(new URI(_requestInfo.getRequestMethod().getURI(), new URI(formElement.getAttribute("action"), true))); + + Collection params = formParameters.values(); + if (usePost) { + ((PostMethod)rv).setRequestBody((NameValuePair[])params.toArray(new NameValuePair[params.size()])); + } else { + Iterator i = params.iterator(); + StringBuilder sb = new StringBuilder(); + if (rv.getURI().getQuery() != null) { + sb.append(rv.getURI().getQuery()); + } + while (i.hasNext()) { + if (sb.length() > 0) { + sb.append("&"); + } + NameValuePair pair = (NameValuePair)i.next(); + sb.append(pair.getName() + "=" + pair.getValue()); + } + try { + URI newUri = (URI)rv.getURI().clone(); + newUri.setQuery(sb.toString()); + rv.setURI(newUri); + } catch (CloneNotSupportedException ex) { + // Should never happen! + throw new RuntimeException(ex); + } + } + + return rv; + } + + private MultiMap populateMapWithDefaultValuesFromForm(Element formElement) { + MultiMap formParameters = new MultiHashMap(); + populateFormParametersFromInputTags(formElement, formParameters); + populateFormParametersFromSelectLists(formElement, formParameters); + return formParameters; + } + + private void populateFormParametersFromSelectLists(Element formElement, MultiMap formParameters) { + NodeList nodes; + nodes = formElement.getElementsByTagName("select"); + for (int x = 0; x < nodes.getLength(); x++) { + Element e = (Element)nodes.item(x); + String name = e.getAttribute("name"); + if (name != null) { + NodeList options = e.getElementsByTagName("option"); + for (int y = 0; y < options.getLength(); y++) { + Element option = (Element)options.item(y); + if (option.hasAttribute("selected") && !option.getAttribute("selected").equalsIgnoreCase("false")) { + String value = option.getAttribute("value"); + if (value == null||value.equals("")) { + value = option.getTextContent(); + } + formParameters.put(name, new NameValuePair(name,value)); + } + } + } + } + } + + private void populateFormParametersFromInputTags(Element formElement, MultiMap formParameters) { + NodeList nodes = formElement.getElementsByTagName("input"); + for (int x = 0; x < nodes.getLength(); x++) { + Element e = (Element)nodes.item(x); + String name = e.getAttribute("name"); + String type = e.getAttribute("type"); + if (name != null) { + if (type == null || type.equalsIgnoreCase("text") || type.equalsIgnoreCase("password") || type.equalsIgnoreCase("hidden")) { + formParameters.put(name, new NameValuePair(name,e.getAttribute("value"))); + } else if (type.equalsIgnoreCase("checkbox") || type.equalsIgnoreCase("radio")) { + if (e.hasAttribute("checked") && !e.getAttribute("checked").equalsIgnoreCase("false")) { + formParameters.put(name, new NameValuePair(name, e.getAttribute("value"))); + } + } + } + } + } + + private void mergeFormParameters(MultiMap userParamMap, MultiMap formParameters) { + Iterator userParamIterator = userParamMap.keySet().iterator(); + while (userParamIterator.hasNext()) { + String key = userParamIterator.next().toString(); + formParameters.remove(key); + Collection c = (Collection)userParamMap.get(key); + Iterator i2 = c.iterator(); + while (i2.hasNext()) { + formParameters.put(key, new NameValuePair(key, i2.next().toString())); + } + } + } + + protected Element findFormElementByFormName(String name) { + NodeList formElements=getDocument().getElementsByTagName("form"); + for (int i = 0; i < formElements.getLength(); i++) { + Element formElement=(Element)formElements.item(i); + String formName=formElement.getAttribute("name"); + if (name.equals(formName)) { + return formElement; + } + } + return null; + } + + + public String getSource() { + return new String(_requestInfo.getResponseBody()); + } + + public Document getDocument() { + if (_responseDocument == null) { + try { + _responseDocument = _converter.getDocumentFromHtml(_requestInfo.getResponseBody()); + } catch (HtmlParseException ex) { + throw new BrowserRuntimeException(ex); + } + } + return _responseDocument; + } + + public History getHistory() { + // TODO Auto-generated method stub + return null; + } + + public String getLocation() { + try { + return _requestInfo.getRequestMethod().getURI().toString(); + } catch (URIException ex) { + throw new BrowserRuntimeException(ex); + } + } + + public RequestInfo getRequestInfo() { + return _requestInfo; + } + + protected int getResponseCode() { + return _requestInfo.getResponseCode(); + } + + public boolean isDoFollowRedirects() { + return _doFollowRedirects; + } + + public void setDoFollowRedirects(boolean doFollowRedirects) { + _doFollowRedirects = doFollowRedirects; + } + +} + + Added: trunk/core/src/main/java/com/software416/jsimplebrowser/util/BrowserHelper.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/util/BrowserHelper.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/util/BrowserHelper.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,51 @@ +package com.software416.jsimplebrowser.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import com.software416.jsimplebrowser.Browser; + +public class BrowserHelper { + private static final Log LOG = LogFactory.getLog(BrowserHelper.class); + private Browser _browser; + public BrowserHelper(Browser browser) { + _browser = browser; + } + + public String getFirstLinkForTextRegex(String regex) { + List<String> links = getLinksForTextRegex(regex, 1); + return links.size() == 0 ? null : links.get(0); + } + + public List<String> getLinksForTextRegex(String regex) { + return getLinksForTextRegex(regex, Integer.MAX_VALUE); + } + + public List<String> getLinksForTextRegex(String regex, int maxResults) { + return getLinksForTextRegex(regex, maxResults, Browser.MAIN_BROWSER_WINDOW_NAME); + } + public List<String> getLinksForTextRegex(String regex, int maxResults, String windowName) { + List<String> rv = new ArrayList<String>(); + NodeList nl = _browser.getWindow(windowName).getDocument().getElementsByTagName("a"); + Pattern p = Pattern.compile(".*" + regex + ".*", Pattern.CASE_INSENSITIVE); + for (int x = 0; x < nl.getLength() && rv.size() < maxResults; x++) { + Element element = (Element)nl.item(x); + String href = element.getAttribute("href"); + if (LOG.isDebugEnabled()) { + LOG.debug("matching " + regex + " against content " + element.getTextContent() + " with href " + href); + } + if (href != null && element.getTextContent() != null && p.matcher(element.getTextContent()).matches()) { + rv.add(href); + } + } + return rv; + } + + +} Added: trunk/core/src/main/java/com/software416/jsimplebrowser/util/HtmlToDomConverter.java =================================================================== --- trunk/core/src/main/java/com/software416/jsimplebrowser/util/HtmlToDomConverter.java (rev 0) +++ trunk/core/src/main/java/com/software416/jsimplebrowser/util/HtmlToDomConverter.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,29 @@ +package com.software416.jsimplebrowser.util; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.cyberneko.html.parsers.DOMParser; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import com.software416.jsimplebrowser.HtmlParseException; + +public class HtmlToDomConverter { + private static final Log LOG = LogFactory.getLog(HtmlToDomConverter.class); + public Document getDocumentFromHtml(byte[] docBytes) throws HtmlParseException { + try { + LOG.debug("Tidying input"); + DOMParser p = new DOMParser(); + p.parse(new InputSource(new ByteArrayInputStream(docBytes))); + return p.getDocument(); + } catch (SAXException ex) { + throw new HtmlParseException(ex); + } catch (IOException ex) { + throw new HtmlParseException(ex); + } + } +} Deleted: trunk/core/src/test/java/com/software416/jsimplebrowser/BrowserTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/BrowserTest.java 2007-08-07 21:56:12 UTC (rev 36) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/BrowserTest.java 2007-08-10 15:46:42 UTC (rev 37) @@ -1,91 +0,0 @@ -package com.software416.jsimplebrowser; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.URI; -import org.apache.commons.httpclient.URIException; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.junit.BeforeClass; -import org.junit.Test; - -public class BrowserTest { - @BeforeClass public static void setUpLog() { - System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); - System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); - System.setProperty("org.apache.commons.logging.simplelog.log.com.software416", "debug"); - } - @Test public void testLinkParsing() throws HtmlParseException { - SimpleBrowser b = new SimpleBrowser(); - BrowserHelper bh = new BrowserHelper(b); - b.setResponseBody("<html><body><a href=\"foo.html\">Sign In</a></body></html>"); - assertEquals("foo.html", bh.getFirstLinkForTextRegex("Sign In")); - // check case insensitive of link - assertEquals("foo.html", bh.getFirstLinkForTextRegex("Sign in")); - // check case insensitive of tag - b.setResponseBody("<html><body><A href=\"foo.html\">Sign In</A></body></html>"); - assertEquals("foo.html", bh.getFirstLinkForTextRegex("Sign In")); - assertNull(bh.getFirstLinkForTextRegex("Foo")); - } - - @Test public void testGetMetaRefresh() throws HtmlParseException { - SimpleBrowser b = new SimpleBrowser(); - b.setResponseBody("<html><body><meta http-equiv=\"Refresh\" content=\"0;URL=http://www.linkedin.com/home\"></body></html>"); - assertEquals("http://www.linkedin.com/home", b.findRefreshLink()); - b.setResponseBody("<html><body></body></html>"); - assertNull(b.findRefreshLink()); - b.setResponseBody("<html><body><meta></meta></body></html>"); - assertNull(b.findRefreshLink()); - b.setResponseBody("<html><body><meta http-equiv=\"Foo\"></meta></body></html>"); - assertNull(b.findRefreshLink()); - b.setResponseBody("<html><body><meta http-equiv=\"Refreshment\"></meta></body></html>"); - assertNull(b.findRefreshLink()); - b.setResponseBody("<html><body><meta http-equiv=\"Refreshment\" content=\"blah\"></meta></body></html>"); - assertNull(b.findRefreshLink()); - } - - @Test public void testFormMethodGeneration() throws URIException, HtmlParseException { - String baseForm = "<html><body><form name=\"%1$s\" method=\"%2$s\" action=\"%3$s\"></form></body></html>"; - SimpleBrowser b = new SimpleBrowser(); - b.setRequestMethod(new GetMethod("http://www.foo.com")); - - b.setResponseBody(String.format(baseForm, "login", "GET", "http://foo.com/login")); - HttpMethod m = b.buildMethodForForm("login", new HashMap<String, String>()); - assertNotNull(m); - assertEquals(GetMethod.class, m.getClass()); - assertEquals(m.getURI(), new URI("http://foo.com/login", true)); - - b.setResponseBody(String.format(baseForm, "login", "GET", "/login")); - m = b.buildMethodForForm("login", new HashMap<String, String>()); - assertNotNull(m); - assertEquals(GetMethod.class, m.getClass()); - assertEquals(m.getURI(), new URI("http://www.foo.com/login", true)); - - b.setResponseBody(String.format(baseForm, "login", "GET", "/login")); - Map<String,String> params = new HashMap<String, String>(); - params.put("test_key", "test_value"); - params.put("test2", "foo"); - m = b.buildMethodForForm("login", params); - assertNotNull(m); - assertEquals(GetMethod.class, m.getClass()); - assertEquals(new URI("http://www.foo.com/login?test_key=test_value&test2=foo", true), m.getURI()); - - b.setResponseBody(String.format(baseForm, "login", "POST", "https://bar.com/login")); - m = b.buildMethodForForm("login", new HashMap<String, String>()); - assertNotNull(m); - assertEquals(PostMethod.class, m.getClass()); - assertEquals(m.getURI(), new URI("https://bar.com/login", true)); - - b.setResponseBody(String.format(baseForm, "login", "POST", "login")); - m = b.buildMethodForForm("login", new HashMap<String, String>()); - assertNotNull(m); - assertEquals(PostMethod.class, m.getClass()); - assertEquals(m.getURI(), new URI("http://www.foo.com/login", true)); - - assertNull(b.buildMethodForForm("noform", new HashMap<String, String>())); - } -} Added: trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java (rev 0) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/impl/BrowserTest.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,124 @@ +package com.software416.jsimplebrowser.impl; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import org.apache.commons.collections.MultiHashMap; +import org.apache.commons.collections.MultiMap; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.URI; +import org.apache.commons.httpclient.URIException; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.LogFactory; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.software416.jsimplebrowser.BrowserException; + +public class BrowserTest { + @BeforeClass public static void setUpLog() { + System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); + System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.com.software416", "debug"); + } + + @Test public void testParsingBadPages() throws BrowserException, IOException { + String baseForm = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("badlyFormattedPage.html")); + RequestInfoImpl requestInfo = new RequestInfoImpl(); + requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); + requestInfo.setResponseBody(baseForm.getBytes()); + WindowImpl wi = new WindowImpl(null); + wi.handleResponse(requestInfo); + } + + @Test public void testGetMetaRefresh() throws BrowserException { + WindowImpl w = new WindowImpl(null); + w.setDoFollowRedirects(false); + RequestInfoImpl ri = new RequestInfoImpl(); + ri.setResponseBody("<html><body><meta http-equiv=\"Refresh\" content=\"0;URL=http://www.linkedin.com/home\"></body></html>".getBytes()); + w.handleResponse(ri); + assertEquals("http://www.linkedin.com/home", w.findRefreshLink()); + ri.setResponseBody("<html><body></body></html>".getBytes()); + w.handleResponse(ri); + assertNull(w.findRefreshLink()); + ri.setResponseBody("<html><body><meta></meta></body></html>".getBytes()); + w.handleResponse(ri); + assertNull(w.findRefreshLink()); + ri.setResponseBody("<html><body><meta http-equiv=\"Foo\"></meta></body></html>".getBytes()); + w.handleResponse(ri); + assertNull(w.findRefreshLink()); + ri.setResponseBody("<html><body><meta http-equiv=\"Refreshment\"></meta></body></html>".getBytes()); + w.handleResponse(ri); + assertNull(w.findRefreshLink()); + ri.setResponseBody("<html><body><meta http-equiv=\"Refreshment\" content=\"blah\"></meta></body></html>".getBytes()); + w.handleResponse(ri); + assertNull(w.findRefreshLink()); + } + @Test public void testDefaultFormValuesMethodGeneration() throws BrowserException, IOException { + String baseForm = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("formTest1.html")); + RequestInfoImpl requestInfo = new RequestInfoImpl(); + requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); + requestInfo.setResponseBody(baseForm.getBytes()); + WindowImpl wi = new WindowImpl(null); + wi.handleResponse(requestInfo); + HttpMethod m = wi.buildMethodForForm("login", new MultiHashMap()); + assertNotNull(m); + assertEquals(GetMethod.class, m.getClass()); + assertEquals(m.getURI().getPath(), "/foo.action"); + LogFactory.getLog(getClass()).debug(m.getURI().getQuery()); + assertTrue(m.getURI().getQuery().contains("foo=baz")); + assertTrue(m.getURI().getQuery().contains("password=secret")); + assertTrue(m.getURI().getQuery().contains("checkedBox=yep")); + assertTrue(m.getURI().getQuery().contains("radioB=yep")); + assertTrue(m.getURI().getQuery().contains("selectInput=IsSelected")); + assertTrue(m.getURI().getQuery().contains("selectInput=youGotIt")); + assertEquals(6, m.getURI().getQuery().split("&").length); + } + @Test public void testFormMethodGeneration() throws BrowserException, URIException { + String baseForm = "<html><body><form name=\"%1$s\" method=\"%2$s\" action=\"%3$s\"></form></body></html>"; + RequestInfoImpl requestInfo = new RequestInfoImpl(); + requestInfo.setRequestMethod(new GetMethod("http://www.foo.com")); + requestInfo.setResponseBody(String.format(baseForm, "login", "GET", "http://foo.com/login").getBytes()); + WindowImpl wi = new WindowImpl(null); + wi.handleResponse(requestInfo); + HttpMethod m = wi.buildMethodForForm("login", new MultiHashMap()); + assertNotNull(m); + assertEquals(GetMethod.class, m.getClass()); + assertEquals(m.getURI(), new URI("http://foo.com/login", true)); + + requestInfo.setResponseBody(String.format(baseForm, "login", "GET", "/login").getBytes()); + wi.handleResponse(requestInfo); + m = wi.buildMethodForForm("login", new MultiHashMap()); + assertNotNull(m); + assertEquals(GetMethod.class, m.getClass()); + assertEquals(m.getURI(), new URI("http://www.foo.com/login", true)); + + requestInfo.setResponseBody(String.format(baseForm, "login", "GET", "/login").getBytes()); + MultiMap params = new MultiHashMap(); + params.put("test_key", "test_value"); + params.put("test2", "foo"); + m = wi.buildMethodForForm("login", params); + assertNotNull(m); + assertEquals(GetMethod.class, m.getClass()); + assertEquals(new URI("http://www.foo.com/login?test_key=test_value&test2=foo", true), m.getURI()); + + requestInfo.setResponseBody(String.format(baseForm, "login", "POST", "https://bar.com/login").getBytes()); + wi.handleResponse(requestInfo); + m = wi.buildMethodForForm("login", new MultiHashMap()); + assertNotNull(m); + assertEquals(PostMethod.class, m.getClass()); + assertEquals(m.getURI(), new URI("https://bar.com/login", true)); + + requestInfo.setResponseBody(String.format(baseForm, "login", "POST", "login").getBytes()); + wi.handleResponse(requestInfo); + m = wi.buildMethodForForm("login", new MultiHashMap()); + assertNotNull(m); + assertEquals(PostMethod.class, m.getClass()); + assertEquals(m.getURI(), new URI("http://www.foo.com/login", true)); + + assertNull(wi.buildMethodForForm("noform", new MultiHashMap())); + } +} Added: trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java =================================================================== --- trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java (rev 0) +++ trunk/core/src/test/java/com/software416/jsimplebrowser/util/BrowserHelperTest.java 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,39 @@ +package com.software416.jsimplebrowser.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.IOException; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; + +import com.software416.jsimplebrowser.Browser; +import com.software416.jsimplebrowser.BrowserException; +import com.software416.jsimplebrowser.impl.BrowserImpl; +import com.software416.jsimplebrowser.impl.RequestInfoImpl; +import com.software416.jsimplebrowser.impl.WindowImpl; + +public class BrowserHelperTest { + @Test public void testLinkParsing() throws BrowserException, IOException { + BrowserImpl b = new BrowserImpl(); + BrowserHelper bh = new BrowserHelper(b); + WindowImpl wi = (WindowImpl)b.getWindow(Browser.MAIN_BROWSER_WINDOW_NAME); + RequestInfoImpl ri = new RequestInfoImpl(); + ri.setResponseBody("<html><body><a href=\"foo.html\">Sign In</a></body></html>".getBytes()); + wi.handleResponse(ri); + assertEquals("foo.html", bh.getFirstLinkForTextRegex("Sign In")); + // check case insensitive of link + assertEquals("foo.html", bh.getFirstLinkForTextRegex("Sign in")); + // check case insensitive of tag + ri.setResponseBody("<html><body><A href=\"foo.html\">Sign In</A></body></html>".getBytes()); + wi.handleResponse(ri); + assertEquals("foo.html", bh.getFirstLinkForTextRegex("Sign\\s+In")); + assertNull(bh.getFirstLinkForTextRegex("Foo")); + ri.setResponseBody(IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream("linkTest1.html")).getBytes()); + wi.handleResponse(ri); + assertEquals("https://www.linkedin.com/secure/login?trk=ghdr_signin", bh.getFirstLinkForTextRegex("Sign\\s+In")); + } + + +} Added: trunk/core/src/test/resources/badlyFormattedPage.html =================================================================== --- trunk/core/src/test/resources/badlyFormattedPage.html (rev 0) +++ trunk/core/src/test/resources/badlyFormattedPage.html 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,66 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html lang="en-US"> +<head name="connections_browser"> + <title>LinkedIn: My Contacts: Connections</title> + <meta http-equiv="content-type" content="text/html; charset=UTF-8"> + + <link rel="shortcut icon" type="image/ico" href="/favicon.ico"> + <link rel="stylesheet" type="text/css" href="/css/style.css?v=build-399_3_1424"> + <link rel="stylesheet" type="text/css" href="/css/cobrand/no_cobrand.css?v=build-399_3_1424"> + <script type="text/javascript" src="/js/scripts.js?v=build-399_3_1424"></script> + <script type="text/javascript" src="/js/searchbar.js?v=build-399_3_1424"></script> + + + <link rel="stylesheet" type="text/css" href="/css/connection-browser.css?v=build-399_3_1424"> + + <script type="text/javascript" src="/js/dwr/util.js?v=build-399_3_1424"></script> + <script type="text/javascript" src="/js/dwr/engine.js?v=build-399_3_1424"></script> + <script type="text/javascript" src="/js/dwr/engine_fix.js?v=build-399_3_1424"></script> + <script type="text/javascript" src="/js/yui/yahoo-dom-event.js?v=build-399_3_1424"></script> + <script type="text/javascript" src="/js/lui/log4javascript.js?v=build-399_3_1424"></script> + <script type="text/javascript" src="/js/lui/linkedin.js?v=build-399_3_1424"></script> + <script type="text/javascript"> + DWREngine.setErrorHandler(function(message, ex) { + alert('We are sorry. It looks like there is a problem with your request.'); + }); + DWREngine.setTextHtmlHandler(function(message, ex) { + alert('We are sorry. It looks like there is a problem with your request.'); + }); + </script> + <script type="text/javascript" src="/js/lui/linkedin_goback.js?v=build-399_3_1424"></script> + <script type="text/javascript" src="/js/ajax/connections_browser_service.js?v=build-399_3_1424"></script> + <script type="text/javascript" src="/dwr/interface/ConnectionsBrowserService.js"></script> + + <script type="text/javascript" src="/js/lui/linkedin_json.js?v=build-399_3_1424"></script> + <script type="text/javascript" src="/js/lui/linkedin_ui.js?v=build-399_3_1424"></script> +</head> + +<script type="text/javascript"> +connectionsBrowser.setThreshold(500); +connectionsBrowser.setErrorMessage("There was a problem loading your connections. Try to refresh the page."); +connectionsBrowser.setMessageNoCon('<a href="/findContacts?displayFindContact=&membersOnly=membersOnly&context=2&sortAction=lastname&trk=cnx_noconx" >Start building your network.</a> Discover which friends and colleagues are already LinkedIn.'); +connectionsBrowser.setMessageFilterNoCon("None of your connections meet the filtering criteria specified above. Reset the filters to see all of your connections."); +</script> + +<body class="my-contacts"> +<div id="main"> + <noscript> + <h1> + <span>My Contacts:</span> Connections + <div class="hdrlink"> + + + <p class="dc88x31"> + <script type="text/javascript"> + var dbl_page = 'connections_browser'; + var dbl_tile = '5'; + var dbl_sz = '88x31'; + </script> + <script type="text/javascript" src="/js/doubleclick.js?v=build-399_3_1424"></script> + </p> +</div> + </h1> + <p>You currently have JavaScript disabled or are using a browser that doesn't support it. Either enable JavaScript and refresh this page or proceed to the <a href="/connectionsnojs?trk=cnx_nojslink" >basic connection browser</a>.</p> + </noscript> +</body> +</html> \ No newline at end of file Added: trunk/core/src/test/resources/formTest1.html =================================================================== --- trunk/core/src/test/resources/formTest1.html (rev 0) +++ trunk/core/src/test/resources/formTest1.html 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,20 @@ +<html> + <body> + <form name="login" method="GET" action="/foo.action"> + <input type="text" name="foo" value="baz" /> + <input type="invalid" name="foo1" value="baz" /> + <input type="password" name="password" value="secret" /> + <input type="checkbox" name="uncheckedBox" value="secret" /> + <input type="checkbox" checked name="checkedBox" value="yep" /> + <input type="radio" name="radioB" value="secret" /> + <input type="radio" checked name="radioB" value="yep" /> + <input type="button" name="Foo" value="Bad Button" /> + <select name="selectInput"> + <option></option> + <option value="false">False</option> + <option selected>IsSelected</option> + <option selected="true" value="youGotIt">Use Value</option> + </select> + </form> + </body> +</html> \ No newline at end of file Added: trunk/core/src/test/resources/linkTest1.html =================================================================== --- trunk/core/src/test/resources/linkTest1.html (rev 0) +++ trunk/core/src/test/resources/linkTest1.html 2007-08-10 15:46:42 UTC (rev 37) @@ -0,0 +1,11 @@ +<html><body><div id="hdr"> + <h1><a href="/home?trk=ghdr_logo" >LinkedIn</a></h1> + <ul> + <li><a href="/static?key=what_is_linkedin&trk=ghdr_whatis" ><strong>What is LinkedIn?</strong></a></li> + <li><a href="https://www.linkedin.com/secure/register?trk=ghdr_join" ><strong>Join now</strong></a></li> + + <li class="signin">Already a user? <a href="https://www.linkedin.com/secure/login?trk=ghdr_signin" >Sign in</a></li> + </ul> +</div> +</body> +</html> \ No newline at end of file Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2007-08-07 21:56:12 UTC (rev 36) +++ trunk/pom.xml 2007-08-10 15:46:42 UTC (rev 37) @@ -5,6 +5,18 @@ <name>JSimpleBrowser</name> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> + <distributionManagement> + <snapshotRepository> + <id>snapshots</id> + <uniqueVersion>true</uniqueVersion> + <url>http://invincible.dynalias.com:8081/artifactory/libs-snapshots</url> + </snapshotRepository> + <repository> + <id>central</id> + <uniqueVersion>false</uniqueVersion> + <url>http://invincible.dynalias.com:8081/artifactory/libs-snapshots</url> + </repository> + </distributionManagement> <url>http://jsimplebrowser.sourceforge.net/</url> <modules> <module>core</module> @@ -78,15 +90,25 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + </dependency> + <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.1</version> </dependency> <dependency> - <groupId>org.hibernate</groupId> + <groupId>org.cyberneko</groupId> + <artifactId>html-core</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <!--<dependency> + <groupId>jtidy</groupId> <artifactId>jtidy</artifactId> - <version>r8-21122004</version> - </dependency> + <version>8.0-SNAPSHOT</version> + </dependency>--> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |