[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HTMLElement.java,NONE,1.1 HTMLElementBase
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-12-26 04:59:38
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv4153/src/com/meterware/httpunit
Modified Files:
NodeUtils.java ParsedHTML.java WebApplet.java
WebRequestSource.java WebResponse.java WebTable.java
Added Files:
HTMLElement.java HTMLElementBase.java
Log Message:
Adding support for getElementWithID
***** Error reading new file[Errno 2] No such file or directory: 'HTMLElement.java'
***** Error reading new file[Errno 2] No such file or directory: 'HTMLElementBase.java'
Index: NodeUtils.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/NodeUtils.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- NodeUtils.java 24 Dec 2002 17:17:02 -0000 1.15
+++ NodeUtils.java 26 Dec 2002 04:59:35 -0000 1.16
@@ -26,6 +26,7 @@
import org.w3c.dom.NodeList;
import java.util.Stack;
+import java.util.Iterator;
import com.meterware.httpunit.parsing.HTMLParserFactory;
@@ -81,7 +82,7 @@
* Does appropriate processing on specified element. Will return false if the subtree below the element
* should be skipped.
*/
- public boolean processElement( Element element );
+ public boolean processElement( PreOrderTraversal traversal, Element element );
/**
* Processes a text node.
@@ -95,8 +96,8 @@
**/
public static String asText( NodeList rootNodes ) {
final StringBuffer sb = new StringBuffer(HttpUnitUtils.DEFAULT_TEXT_BUFFER_SIZE);
- processNodes( rootNodes, new NodeAction() {
- public boolean processElement( Element node ) {
+ NodeAction action = new NodeAction() {
+ public boolean processElement( PreOrderTraversal traversal, Element node ) {
if (node.getNodeName().equalsIgnoreCase( "p" )) {
sb.append( "\n" );
} else if (node.getNodeName().equalsIgnoreCase( "tr" )) {
@@ -113,41 +114,76 @@
public void processTextNodeValue( String value ) {
sb.append( HTMLParserFactory.getHTMLParser().getCleanedText( value ) );
}
- } );
+ };
+ new PreOrderTraversal( rootNodes ).perform( action );
return sb.toString();
}
- /**
- * Converts the DOM trees rooted at the specified nodes to text, ignoring
- * any HTML tags.
- **/
- public static void processNodes( NodeList rootNodes, NodeAction action ) {
- Stack pendingNodes = new Stack();
- pushNodeList( rootNodes, pendingNodes );
+ static class PreOrderTraversal {
- while (!pendingNodes.empty()) {
- Node node = (Node) pendingNodes.pop();
+ private Stack _pendingNodes = new Stack();
+ private Stack _traversalContext = new Stack();
+ private static final Object POP_CONTEXT = new Object();
- if (node.getNodeType() == Node.TEXT_NODE) {
- action.processTextNodeValue( node.getNodeValue() );
- } else if (node.getNodeType() != Node.ELEMENT_NODE) {
- continue;
- } else
- action.processElement( (Element) node );
- pushNodeList( node.getChildNodes(), pendingNodes );
+ public PreOrderTraversal( NodeList rootNodes ) {
+ pushNodeList( rootNodes );
+ }
+
+
+ public PreOrderTraversal( Node rootNode ) {
+ pushNodeList( rootNode.getLastChild() );
+ }
+
+
+ public void pushBaseContext( Object context ) {
+ _traversalContext.push( context );
+ }
+
+
+ public void pushContext( Object context ) {
+ _traversalContext.push( context );
+ _pendingNodes.push( POP_CONTEXT );
}
- }
- private static void pushNodeList( NodeList nl, Stack stack ) {
- if (nl != null) {
- for (int i = nl.getLength()-1; i >= 0; i--) {
- stack.push( nl.item(i) );
+ public Iterator getContexts() {
+ return _traversalContext.iterator();
+ }
+
+
+ public void perform( NodeAction action ) {
+ while (!_pendingNodes.empty()) {
+ final Object object = _pendingNodes.pop();
+ if (object == POP_CONTEXT) {
+ _traversalContext.pop();
+ } else {
+ Node node = (Node) object;
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ action.processTextNodeValue( node.getNodeValue() );
+ } else if (node.getNodeType() != Node.ELEMENT_NODE) {
+ continue;
+ } else
+ action.processElement( this, (Element) node );
+ pushNodeList( node.getLastChild() );
+ }
}
}
- }
+
+ private void pushNodeList( NodeList nl ) {
+ if (nl != null) {
+ for (int i = nl.getLength()-1; i >= 0; i--) {
+ _pendingNodes.push( nl.item(i) );
+ }
+ }
+ }
+
+
+ private void pushNodeList( Node lastChild ) {
+ for (Node node = lastChild; node != null; node = node.getPreviousSibling()) { _pendingNodes.push( node ); }
+ }
+ }
}
Index: ParsedHTML.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ParsedHTML.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- ParsedHTML.java 24 Dec 2002 17:17:02 -0000 1.38
+++ ParsedHTML.java 26 Dec 2002 04:59:35 -0000 1.39
@@ -21,10 +21,11 @@
*******************************************************************************************************************/
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
/**
* @author <a href="mailto:rus...@ht...">Russell Gold</a>
@@ -42,18 +43,29 @@
private WebResponse _response;
- private boolean _updateForms;
+ private boolean _updateElements = true;
+
+ /** map of element IDs to elements. **/
+ private HashMap _elementsByID = new HashMap();
+
+ /** map of DOM elements to HTML elements **/
+ private HashMap _elements = new HashMap();
+
+ private ArrayList _formsList = new ArrayList();
private WebForm[] _forms;
- private boolean _updateImages;
+ private ArrayList _imagesList = new ArrayList();
private WebImage[] _images;
- private boolean _updateLinks;
+ private ArrayList _linkList = new ArrayList();
private WebLink[] _links;
- private boolean _updateApplets;
+ private ArrayList _appletList = new ArrayList();
private WebApplet[] _applets;
+ private ArrayList _tableList = new ArrayList();
+ private WebTable[] _tables;
+
ParsedHTML( WebResponse response, URL baseURL, String baseTarget, Node rootNode, String characterSet ) {
_response = response;
@@ -68,30 +80,95 @@
* Returns the forms found in the page in the order in which they appear.
**/
public WebForm[] getForms() {
- if (_forms == null || _updateForms) {
- NodeList forms = NodeUtils.getElementsByTagName( getRootNode(), "form" );
- WebForm[] oldForms = _forms;
- _forms = new WebForm[ forms.getLength() ];
-
- if (oldForms != null) System.arraycopy( oldForms, 0, _forms, 0, oldForms.length );
- for (int i = (oldForms == null ? 0 : oldForms.length); i < _forms.length; i++) {
- _forms[i] = new WebForm( _response, _baseURL, _baseTarget, forms.item( i ), _characterSet );
- _updateForms = false;
- }
+ if (_forms == null) {
+ loadElements();
+ _forms = (WebForm[]) _formsList.toArray( new WebForm[ _formsList.size() ] );
}
return _forms;
}
/**
- * Returns the form found in the page with the specified ID.
+ * Returns the links found in the page in the order in which they appear.
**/
- public WebForm getFormWithID( String ID ) {
- WebForm[] forms = getForms();
- for (int i = 0; i < forms.length; i++) {
- if (HttpUnitUtils.matches( ID, forms[i].getID() )) return forms[i];
+ public WebLink[] getLinks() {
+ if (_links == null) {
+ loadElements();
+ _links = (WebLink[]) _linkList.toArray( new WebLink[ _linkList.size() ] );
}
- return null;
+ return _links;
+ }
+
+
+ /**
+ * Returns a proxy for each applet found embedded in this page.
+ */
+ public WebApplet[] getApplets() {
+ if (_applets == null) {
+ loadElements();
+ _applets = (WebApplet[]) _appletList.toArray( new WebApplet[ _appletList.size() ] );
+ }
+ return _applets;
+ }
+
+
+ /**
+ * Returns the images found in the page in the order in which they appear.
+ **/
+ public WebImage[] getImages() {
+ if (_images == null) {
+ loadElements();
+ _images = (WebImage[]) _imagesList.toArray( new WebImage[ _imagesList.size() ] );
+ }
+ return _images;
+ }
+
+
+ /**
+ * Returns the top-level tables found in the page in the order in which they appear.
+ **/
+ public WebTable[] getTables() {
+ if (_tables == null) {
+ loadElements();
+ _tables = (WebTable[]) _tableList.toArray( new WebTable[ _tableList.size() ] );
+ }
+ return _tables;
+ }
+
+
+ /**
+ * Returns the HTMLElement with the specified ID.
+ */
+ public HTMLElement getElementWithID( String id ) {
+ return (HTMLElement) getElementWithID( id, HTMLElement.class );
+ }
+
+
+ /**
+ * Returns the form found in the page with the specified ID.
+ **/
+ public WebForm getFormWithID( String id ) {
+ return (WebForm) getElementWithID( id, WebForm.class );
+ }
+
+
+ /**
+ * Returns the link found in the page with the specified ID.
+ **/
+ public WebLink getLinkWithID( String id ) {
+ return (WebLink) getElementWithID( id, WebLink.class );
+
+ }
+
+
+ private Object getElementWithID( String id, final Class klass ) {
+ loadElements();
+ return whenCast( _elementsByID.get( id ), klass );
+ }
+
+
+ private Object whenCast( Object o, Class klass ) {
+ return klass.isInstance( o ) ? o : null;
}
@@ -107,37 +184,162 @@
}
- /**
- * Returns the links found in the page in the order in which they appear.
- **/
- public WebLink[] getLinks() {
- if (_links == null || _updateLinks) {
- final ArrayList list = new ArrayList();
- NodeUtils.processNodes( getRootNode().getChildNodes(), new NodeUtils.NodeAction() {
- public boolean processElement( Element element ) {
- if (element.getNodeName().equalsIgnoreCase( "a" )) addLinkAnchor( list, element );
- else if (element.getNodeName().equalsIgnoreCase( "area" )) addLinkAnchor( list, element );
- return true;
- }
- public void processTextNodeValue( String value ) {
- }
- } );
- if (_links != null) for (int i = 0; i < _links.length; i++) list.set( i, _links[i] );
- _links = (WebLink[]) list.toArray( new WebLink[ list.size() ] );
- _updateLinks = false;
+ abstract static class HTMLElementFactory {
+ abstract HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element );
+ void recordElement( NodeUtils.PreOrderTraversal pot, Element element, HTMLElement htmlElement ) {
+ if (htmlElement != null) {
+ addToMaps( pot, element, htmlElement );
+ addToLists( pot, htmlElement );
+ }
+ }
+ protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
+ for (Iterator i = pot.getContexts(); i.hasNext();) {
+ Object o = i.next();
+ if (o instanceof ParsedHTML) ((ParsedHTML) o).addToList( htmlElement );
+ }
+ }
+ protected void addToMaps( NodeUtils.PreOrderTraversal pot, Element element, HTMLElement htmlElement ) {
+ for (Iterator i = pot.getContexts(); i.hasNext();) {
+ Object o = i.next();
+ if (o instanceof ParsedHTML) ((ParsedHTML) o).addToMaps( element, htmlElement );
+ }
+ }
+ }
+
+
+ static class WebFormFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toWebForm( element );
}
+ }
- return _links;
+
+ static class WebLinkFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toLinkAnchor( element );
+ }
}
- private void addLinkAnchor( ArrayList list, Node child ) {
- if (isLinkAnchor( child )) {
- list.add( new WebLink( _response, _baseURL, _baseTarget, child ) );
+ static class WebImageFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toWebImage( element );
}
}
+ static class WebAppletFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toWebApplet( element );
+ }
+ }
+
+
+ static class WebTableFactory extends HTMLElementFactory {
+ HTMLElement toHTMLElement( ParsedHTML parsedHTML, Element element ) {
+ return parsedHTML.toWebTable( element );
+ }
+
+
+// protected void addToLists( NodeUtils.PreOrderTraversal pot, HTMLElement htmlElement ) {
+// for (Iterator i = pot.getContexts(); i.hasNext();) {
+// Object o = i.next();
+// if (o instanceof ParsedHTML) {
+// ((ParsedHTML) o).addToList( htmlElement );
+// return;
+// }
+// }
+// }
+ }
+
+
+ private static HashMap _htmlFactoryClasses = new HashMap();
+
+ static {
+ _htmlFactoryClasses.put( "a", new WebLinkFactory() );
+ _htmlFactoryClasses.put( "area", new WebLinkFactory() );
+ _htmlFactoryClasses.put( "form", new WebFormFactory() );
+ _htmlFactoryClasses.put( "img", new WebImageFactory() );
+ _htmlFactoryClasses.put( "applet", new WebAppletFactory() );
+ _htmlFactoryClasses.put( "table", new WebTableFactory() );
+ }
+
+ private static HTMLElementFactory getHTMLElementFactory( String tagName ) {
+ return (HTMLElementFactory) _htmlFactoryClasses.get( tagName );
+ }
+
+
+ private void loadElements() {
+ if (!_updateElements) return;
+
+ NodeUtils.NodeAction action = new NodeUtils.NodeAction() {
+ public boolean processElement( NodeUtils.PreOrderTraversal pot, Element element ) {
+ if (_elements.containsKey( element )) return true;
+
+ HTMLElementFactory factory = getHTMLElementFactory( element.getNodeName().toLowerCase() );
+ if (factory != null) factory.recordElement( pot, element, factory.toHTMLElement( ParsedHTML.this, element ) );
+
+ return true;
+ }
+ public void processTextNodeValue( String value ) {
+ }
+ };
+ NodeUtils.PreOrderTraversal nt = new NodeUtils.PreOrderTraversal( getRootNode() );
+ nt.pushBaseContext( this );
+ nt.perform( action );
+
+ _updateElements = false;
+ }
+
+
+ private WebForm toWebForm( Element element ) {
+ return new WebForm( _response, _baseURL, _baseTarget, element, _characterSet );
+ }
+
+
+ private WebLink toLinkAnchor( Element child ) {
+ return (!isLinkAnchor( child )) ? null : new WebLink( _response, _baseURL, _baseTarget, child );
+ }
+
+
+ private WebImage toWebImage( Element child ) {
+ return new WebImage( _response, this, _baseURL, child, _baseTarget );
+ }
+
+
+ private WebApplet toWebApplet( Element element ) {
+ return new WebApplet( _response, element, _baseTarget );
+ }
+
+
+ private WebTable toWebTable( Element element ) {
+ if (!WebTable.isTopLevelTable( element, getRootNode() )) return null;
+ return new WebTable( _response, element, _baseURL, _baseTarget, _characterSet );
+ }
+
+
+ private void addToMaps( Element element, HTMLElement htmlElement ) {
+ _elements.put( element, htmlElement );
+ if (htmlElement.getID() != null) _elementsByID.put( htmlElement.getID(), htmlElement );
+ }
+
+
+ private void addToList( HTMLElement htmlElement ) {
+ ArrayList list = getListForElement( htmlElement );
+ if (list != null) list.add( htmlElement );
+ }
+
+
+ private ArrayList getListForElement( HTMLElement element ) {
+ if (element instanceof WebLink) return _linkList;
+ if (element instanceof WebForm) return _formsList;
+ if (element instanceof WebImage) return _imagesList;
+ if (element instanceof WebApplet) return _appletList;
+ if (element instanceof WebTable) return _tableList;
+ return null;
+ }
+
+
/**
* Returns the first link which contains the specified text.
**/
@@ -156,14 +358,6 @@
/**
- * Returns the link found in the page with the specified ID.
- **/
- public WebLink getLinkWithID( String ID ) {
- return getFirstMatchingLink( WebLink.MATCH_ID, ID );
- }
-
-
- /**
* Returns the link found in the page with the specified name.
**/
public WebLink getLinkWithName( String name ) {
@@ -197,25 +391,6 @@
/**
- * Returns the images found in the page in the order in which they appear.
- **/
- public WebImage[] getImages() {
- if (_images == null || _updateImages) {
- NodeList images = NodeUtils.getElementsByTagName( getRootNode(), "img" );
- WebImage[] oldImages = _images;
-
- _images = new WebImage[ images.getLength() ];
- if (oldImages != null) System.arraycopy( oldImages, 0, _images, 0, oldImages.length );
- for (int i = (oldImages == null ? 0 : oldImages.length); i < _images.length; i++) {
- _images[i] = new WebImage( _response, this, _baseURL, images.item( i ), _baseTarget );
- }
- _updateImages = false;
- }
- return _images;
- }
-
-
- /**
* Returns the image found in the page with the specified name.
**/
public WebImage getImageWithName( String name ) {
@@ -252,34 +427,6 @@
/**
- * Returns a proxy for each applet found embedded in this page.
- */
- public WebApplet[] getApplets() {
- if (_applets == null || _updateApplets) {
- NodeList applets = NodeUtils.getElementsByTagName( getRootNode(), "applet" );
- WebApplet[] oldApplets = _applets;
-
- _applets = new WebApplet[ applets.getLength() ];
- if (oldApplets != null) System.arraycopy( oldApplets, 0, _applets, 0, oldApplets.length );
- for (int i = (oldApplets == null ? 0 : oldApplets.length); i < _applets.length; i++) {
- _applets[i] = new WebApplet( _response, applets.item( i ), _baseTarget );
- }
- _updateApplets = false;
- }
- return _applets;
- }
-
-
- /**
- * Returns the top-level tables found in this page in the order in which
- * they appear.
- **/
- public WebTable[] getTables() {
- return WebTable.getTables( _response, getOriginalDOM(), _baseURL, _baseTarget, _characterSet );
- }
-
-
- /**
* Returns the first table in the response which matches the specified predicate and value.
* Will recurse into any nested tables, as needed.
* @return the selected table, or null if none is found
@@ -355,8 +502,12 @@
if (_rootNode != null && rootNode != _rootNode )
throw new IllegalStateException( "The root node has already been defined as " + _rootNode + " and cannot be redefined as " + rootNode );
_rootNode = rootNode;
-
- _updateLinks = _updateForms = _updateImages = _updateApplets = true;
+ _links = null;
+ _forms = null;
+ _images = null;
+ _applets = null;
+ _tables = null;
+ _updateElements = true;
}
@@ -394,7 +545,7 @@
/**
* Returns true if the node is a link anchor node.
**/
- private boolean isLinkAnchor( Node node ) {
+ private boolean isLinkAnchor( Node node ) { // XXX do we really need all these tests any more?
if (node.getNodeType() != Node.ELEMENT_NODE) {
return false;
} else if (!node.getNodeName().equalsIgnoreCase( "a" ) && !node.getNodeName().equalsIgnoreCase( "area" )) {
Index: WebApplet.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebApplet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebApplet.java 22 Nov 2002 17:19:35 -0000 1.3
+++ WebApplet.java 26 Dec 2002 04:59:35 -0000 1.4
@@ -42,10 +42,9 @@
* @author <a href="Oli...@HV...">Oliver Imbusch</a>
* @author <a href="mailto:rus...@ht...">Russell Gold</a>
**/
-public class WebApplet {
+public class WebApplet extends HTMLElementBase {
private WebResponse _response;
- private Node _node;
private String _baseTarget;
private URL _codeBase;
@@ -58,8 +57,8 @@
public WebApplet( WebResponse response, Node rootNode, String baseTarget ) {
+ super( rootNode );
_response = response;
- _node = rootNode;
_baseTarget = baseTarget;
}
@@ -96,24 +95,6 @@
}
- String getAttribute( final String name ) {
- return NodeUtils.getNodeAttribute( _node, name );
- }
-
-
- String getAttribute( final String name, String defaultValue ) {
- return NodeUtils.getNodeAttribute( _node, name, defaultValue );
- }
-
-
- /**
- * Returns the name of the applet.
- */
- public String getName() {
- return getAttribute( "name" );
- }
-
-
/**
* Returns the width of the panel in which the applet will be drawn.
*/
@@ -171,7 +152,7 @@
private Map getParameterMap() {
if (_parameters == null) {
_parameters = new HashMap();
- NodeList nl = ((Element) _node).getElementsByTagName( "param" );
+ NodeList nl = ((Element) getNode()).getElementsByTagName( "param" );
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i);
_parameters.put( NodeUtils.getNodeAttribute( n, "name", "" ), NodeUtils.getNodeAttribute( n, "value", "" ) );
Index: WebRequestSource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequestSource.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- WebRequestSource.java 20 Nov 2002 13:04:16 -0000 1.20
+++ WebRequestSource.java 26 Dec 2002 04:59:35 -0000 1.21
@@ -31,7 +31,7 @@
abstract
-public class WebRequestSource extends ParameterHolder {
+public class WebRequestSource extends ParameterHolder implements HTMLElement {
/**
* Returns the ID associated with this request source.
@@ -97,13 +97,6 @@
**/
abstract
public String[] getParameterValues( String name );
-
-
- /**
- * Returns the scriptable delegate.
- */
- abstract
- ScriptableDelegate getScriptableDelegate();
/**
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- WebResponse.java 13 Dec 2002 12:57:11 -0000 1.104
+++ WebResponse.java 26 Dec 2002 04:59:35 -0000 1.105
@@ -286,6 +286,16 @@
//---------------------- HTMLSegment methods -----------------------------
+
+ /**
+ * Returns the HTMLElement with the specified ID.
+ * @throws SAXException thrown if there is an error parsing the response.
+ */
+ public HTMLElement getElementWithID( String id ) throws SAXException {
+ return getReceivedPage().getElementWithID( id );
+ }
+
+
/**
* Returns the forms found in the page in the order in which they appear.
* @exception SAXException thrown if there is an error parsing the response.
Index: WebTable.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebTable.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- WebTable.java 18 Dec 2002 23:58:10 -0000 1.21
+++ WebTable.java 26 Dec 2002 04:59:35 -0000 1.22
@@ -31,7 +31,7 @@
* @author <a href="mailto:rus...@ac...">Russell Gold</a>
* @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
-public class WebTable {
+public class WebTable extends HTMLElementBase {
/** Predicate to match the complete text of a table's first non-blank cell. **/
@@ -207,14 +207,6 @@
}
- /**
- * Returns the unique ID attribute associated with this table.
- **/
- public String getID() {
- return NodeUtils.getNodeAttribute( _dom, "id" );
- }
-
-
public String toString() {
String eol = System.getProperty( "line.separator" );
if (_cells == null) readTable();
@@ -235,29 +227,6 @@
}
-//----------------------------------- package members -----------------------------------
-
-
- /**
- * Returns the top-level tables found in the specified DOM.
- **/
- static WebTable[] getTables( WebResponse response, Node domRoot, URL baseURL, String parentTarget, String characterSet ) {
- NodeList nl = NodeUtils.getElementsByTagName( domRoot, "table" );
- Vector topLevelTables = new Vector();
-
- for (int i = 0; i < nl.getLength(); i++) {
- if (isTopLevelTable( nl.item(i), domRoot )) {
- topLevelTables.addElement( new WebTable( response, nl.item(i), baseURL, parentTarget, characterSet ) );
- }
- }
-
- WebTable[] result = new WebTable[ topLevelTables.size() ];
- topLevelTables.copyInto( result );
- return result;
- }
-
-
-
//----------------------------------- private members -----------------------------------
private Element _dom;
@@ -270,7 +239,8 @@
private TableCell[][] _cells;
- private WebTable( WebResponse response, Node domTreeRoot, URL sourceURL, String parentTarget, String characterSet ) {
+ WebTable( WebResponse response, Node domTreeRoot, URL sourceURL, String parentTarget, String characterSet ) {
+ super( domTreeRoot );
_response = response;
_dom = (Element) domTreeRoot;
_url = sourceURL;
@@ -324,7 +294,7 @@
/**
* Returns true if the specified table node is not nested within another one.
**/
- private static boolean isTopLevelTable( Node tableNode, Node root ) {
+ static boolean isTopLevelTable( Node tableNode, Node root ) {
return isMoreCloselyNested( tableNode, root, "table" );
}
@@ -416,7 +386,7 @@
}
static {
- MATCH_FIRST_NONBLANK_CELL = new HTMLElementPredicate() {
+ MATCH_FIRST_NONBLANK_CELL = new HTMLElementPredicate() { // XXX find a way to do this w/o purging the table cells
public boolean matchesCriteria( Object htmlElement, Object criteria ) {
WebTable table = ((WebTable) htmlElement);
table.purgeEmptyCells();
@@ -426,7 +396,7 @@
};
- MATCH_FIRST_NONBLANK_CELL_PREFIX = new HTMLElementPredicate() {
+ MATCH_FIRST_NONBLANK_CELL_PREFIX = new HTMLElementPredicate() { // XXX find a way to do this w/o purging the table cells
public boolean matchesCriteria( Object htmlElement, Object criteria ) {
WebTable table = ((WebTable) htmlElement);
table.purgeEmptyCells();
|