[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit WebTable.java,1.19,1.20
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-11-25 17:02:24
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv20411/src/com/meterware/httpunit
Modified Files:
WebTable.java
Log Message:
Corrected handling of <th> tags
Index: WebTable.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- WebTable.java 4 Oct 2002 02:16:00 -0000 1.19
+++ WebTable.java 25 Nov 2002 17:02:21 -0000 1.20
@@ -356,10 +356,13 @@
private TableRow[] getRows() {
final Vector rows = new Vector();
- processChildren( _dom, "tr", "table", new ElementHandler() {
+ processChildren( _dom, "table", new ElementHandler() {
public void handleElement( Element element ) {
rows.addElement( new TableRow( element ) );
}
+ public boolean shouldHandleElement( String tagName ) {
+ return tagName.equalsIgnoreCase( "tr" );
+ }
} );
TableRow[] result = new TableRow[ rows.size() ];
@@ -374,22 +377,20 @@
}
TableCell[] getCells() {
- Vector cells = new Vector();
- collectChildren( "td", cells );
- collectChildren( "th", cells );
-
- TableCell[] result = new TableCell[ cells.size() ];
- cells.copyInto( result );
- return result;
- }
-
+ final Vector cells = new Vector();
- private void collectChildren( String childTag, final Vector children ) {
- processChildren( _element, childTag, "table", new ElementHandler() {
+ processChildren( _element, "table", new ElementHandler() {
public void handleElement( Element element ) {
- children.addElement( new TableCell( _response, element, _url, _parentTarget, _characterSet ) );
+ cells.addElement( new TableCell( _response, element, _url, _parentTarget, _characterSet ) );
+ }
+ public boolean shouldHandleElement( String tagName ) {
+ return tagName.equalsIgnoreCase( "th" ) || tagName.equalsIgnoreCase( "td" );
}
} );
+
+ TableCell[] result = new TableCell[ cells.size() ];
+ cells.copyInto( result );
+ return result;
}
@@ -400,21 +401,20 @@
}
-
-
interface ElementHandler {
public void handleElement( Element element );
+ public boolean shouldHandleElement( String tagName );
}
- static void processChildren( Element root, String childTag, String avoidingParentTag, ElementHandler handler ) {
+ static void processChildren( Element root, String avoidingParentTag, ElementHandler handler ) {
for (Node child = root.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child instanceof Element) {
Element element = (Element) child;
String name = child.getNodeName();
- if (name.equalsIgnoreCase( childTag )) handler.handleElement( element );
- if (!name.equalsIgnoreCase( avoidingParentTag )) processChildren( element, childTag, avoidingParentTag, handler );
+ if (handler.shouldHandleElement( name )) handler.handleElement( element );
+ if (!name.equalsIgnoreCase( avoidingParentTag )) processChildren( element, avoidingParentTag, handler );
}
}
}
|