[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HTMLSegment.java,1.8,1.9 ParsedHTML.java,
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-04-04 14:51:37
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv3493/src/com/meterware/httpunit
Modified Files:
HTMLSegment.java ParsedHTML.java WebResponse.java
Log Message:
George Murnock: added getMatchingTables
Index: HTMLSegment.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HTMLSegment.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- HTMLSegment.java 26 Dec 2002 15:33:56 -0000 1.8
+++ HTMLSegment.java 4 Apr 2003 14:51:27 -0000 1.9
@@ -144,6 +144,13 @@
/**
+ * Returns all tables found in the page matching the specified criteria.
+ * @exception SAXException thrown if there is an error parsing the response.
+ **/
+ public WebTable[] getMatchingTables( HTMLElementPredicate predicate, Object criteria ) throws SAXException;
+
+
+ /**
* Returns the first table in this HTML segment which has the specified text as the full text of
* its first non-blank row and non-blank column. Will recurse into any nested tables, as needed.
* @return the selected table, or null if none is found
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- ParsedHTML.java 2 Apr 2003 15:31:04 -0000 1.47
+++ ParsedHTML.java 4 Apr 2003 14:51:27 -0000 1.48
@@ -709,6 +709,15 @@
return getTableSatisfyingPredicate( getTables(), predicate, criteria );
}
+ /**
+ * Returns the tables in the response which match the specified predicate and value.
+ * Will recurse into any nested tables, as needed.
+ * @return the selected tables, or null if none are found
+ **/
+ public WebTable[] getMatchingTables( HTMLElementPredicate predicate, Object criteria ) {
+ return getTablesSatisfyingPredicate( getTables(), predicate, criteria );
+ }
+
/**
* Returns the first table in the response which has the specified text as the full text of
@@ -853,6 +862,39 @@
return null;
}
+
+ /**
+ * Returns the tables which match the specified criteria.
+ **/
+ private WebTable[] getTablesSatisfyingPredicate(WebTable[] tables, HTMLElementPredicate predicate, Object value) {
+ ArrayList matches = new ArrayList();
+ for (int i = 0; i < tables.length; i++) {
+ if (predicate.matchesCriteria(tables[i], value)) {
+ matches.add(tables[i]);
+ }
+ for (int j = 0; j < tables[i].getRowCount(); j++) {
+ for (int k = 0; k < tables[i].getColumnCount(); k++) {
+ TableCell cell = tables[i].getTableCell(j, k);
+ if (cell != null) {
+ WebTable[] innerTables = cell.getTables();
+ if (innerTables.length != 0) {
+ WebTable[] result = getTablesSatisfyingPredicate(innerTables, predicate, value);
+ if (result != null && result.length > 0) {
+ for (int l = 0; l < result.length; l++) {
+ matches.add(result[l]);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if(matches.size() > 0) {
+ return (WebTable[]) matches.toArray( new WebTable[ matches.size() ] );
+ } else {
+ return null;
+ }
+ }
class WebIFrame extends WebFrame implements ContentConcealer {
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -r1.117 -r1.118
--- WebResponse.java 2 Apr 2003 16:47:56 -0000 1.117
+++ WebResponse.java 4 Apr 2003 14:51:28 -0000 1.118
@@ -455,6 +455,15 @@
}
+ /**
+ * Returns all tables found in the page matching the specified criteria.
+ * @exception SAXException thrown if there is an error parsing the response.
+ **/
+ public WebTable[] getMatchingTables( HTMLElementPredicate predicate, Object criteria ) throws SAXException {
+ return getReceivedPage().getMatchingTables( predicate, criteria );
+ }
+
+
/**
* Returns the first table in the response which has the specified text as the full text of
* its first non-blank row and non-blank column. Will recurse into any nested tables, as needed.
|