[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HTMLPage.java,1.28,1.29 ParsedHTML.java,1
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-04-02 15:31:45
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv5947/src/com/meterware/httpunit
Modified Files:
HTMLPage.java ParsedHTML.java WebForm.java
WebRequestSource.java WebResponse.java
Log Message:
Added getElementsByTagName support
Index: HTMLPage.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLPage.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- HTMLPage.java 28 Mar 2003 03:22:33 -0000 1.28
+++ HTMLPage.java 2 Apr 2003 15:31:04 -0000 1.29
@@ -221,12 +221,12 @@
public ScriptableDelegate[] getElementsByName( String name ) {
- final HTMLElement[] elements = HTMLPage.this.getElementsByName( name );
- ScriptableDelegate[] result = new ScriptableDelegate[ elements.length ];
- for (int i = 0; i < elements.length; i++) {
- result[i] = elements[i].getScriptableDelegate();
- }
- return result;
+ return getDelegates( HTMLPage.this.getElementsByName( name ) );
+ }
+
+
+ public ScriptableDelegate[] getElementsByTagName( String name ) {
+ return getDelegates( HTMLPage.this.getElementsByTagName( HTMLPage.this.getRootNode(), name ) );
}
}
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- ParsedHTML.java 28 Mar 2003 03:22:33 -0000 1.46
+++ ParsedHTML.java 2 Apr 2003 15:31:04 -0000 1.47
@@ -21,6 +21,8 @@
*******************************************************************************************************************/
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Document;
import java.net.URL;
import java.util.*;
@@ -167,6 +169,30 @@
}
+ HTMLElement[] getElementsByTagName( Node dom, String name ) {
+ loadElements();
+ if (dom instanceof Element) {
+ return getElementsFromList( ((Element) dom).getElementsByTagName( name ) );
+ } else {
+ return getElementsFromList( ((Document) dom).getElementsByTagName( name ) );
+ }
+ }
+
+
+ private HTMLElement[] getElementsFromList( NodeList nl ) {
+ HTMLElement[] elements = new HTMLElement[ nl.getLength() ];
+ for (int i = 0; i < elements.length; i++) {
+ Node node = nl.item(i);
+ elements[i] = (HTMLElement) _elements.get( node );
+ if (elements[i] == null) {
+ elements[i] = toDefaultElement( (Element) node );
+ _elements.put( node, elements[i] );
+ }
+ }
+ return elements;
+ }
+
+
/**
* Returns the form found in the page with the specified ID.
**/
@@ -796,7 +822,7 @@
//---------------------------------- private members --------------------------------
- private Node getRootNode() {
+ Node getRootNode() {
if (_rootNode == null) throw new IllegalStateException( "The root node has not been specified" );
return _rootNode;
}
Index: WebForm.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- WebForm.java 14 Mar 2003 17:41:27 -0000 1.82
+++ WebForm.java 2 Apr 2003 15:31:05 -0000 1.83
@@ -588,6 +588,11 @@
}
+ public ScriptableDelegate[] getElementsByTagName( String name ) throws SAXException {
+ return getDelegates( getHTMLPage().getElementsByTagName( getNode(), name ) );
+ }
+
+
Scriptable() {
super( WebForm.this );
}
Index: WebRequestSource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- WebRequestSource.java 27 Mar 2003 03:36:37 -0000 1.27
+++ WebRequestSource.java 2 Apr 2003 15:31:05 -0000 1.28
@@ -192,6 +192,14 @@
/**
+ * Returns the HTMLPage associated with this request source.
+ */
+ protected HTMLPage getHTMLPage() throws SAXException {
+ return _baseResponse.getReceivedPage();
+ }
+
+
+ /**
* Extracts any parameters specified as part of the destination URL, calling addPresetParameter for each one
* in the order in which they are found.
*/
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -r1.115 -r1.116
--- WebResponse.java 1 Apr 2003 12:55:24 -0000 1.115
+++ WebResponse.java 2 Apr 2003 15:31:06 -0000 1.116
@@ -954,7 +954,7 @@
}
- private HTMLPage getReceivedPage() throws SAXException {
+ HTMLPage getReceivedPage() throws SAXException {
if (_page == null) {
try {
_parsingPage = true;
|