Additional top-level class in compilation unit: CollectionIndex.
org.w3c.dom.html.HTMLCollection to traverse any named
elements on a org.w3c.dom.html.HTMLDocument . The elements type to
look for is identified in the constructor by code. This collection is not
optimized for traversing large trees.
The collection has to meet two requirements: it has to be live, and it has
to traverse depth first and always return results in that order. As such,
using an object container (such as java.) is expensive on
insert/remove operations. Instead, the collection has been implemented using
three traversing functions. As a result, operations on large documents will
result in traversal of the entire document tree and consume a considerable
amount of time.
Note that synchronization on the traversed document cannot be achieved. The document itself cannot be locked, and locking each traversed node is likely to lead to a dead lock condition. Therefore, there is a chance of the document being changed as results are fetched; in all likelihood, the results might be out dated, but not erroneous.
org.w3c.dom.html.HTMLCollection
| Modifier and Type | Field and Description |
|---|---|
| private short | _lookingFor
Indicates what this collection is looking for. |
| private Element | _topLevel
This is the top level element underneath which the collection exists. |
| pack-priv static final short | ANCHOR
Request collection of all anchors in document: <A> elements that
have a |
| pack-priv static final short | APPLET
Request collection of all Applets in document: <APPLET> and <OBJECT> elements (<OBJECT> must contain an Applet). |
| pack-priv static final short | AREA
Request collection of all areas in map: <AREA> element in <MAP> (non recursive). |
| pack-priv static final short | CELL
Request collection of all cells in row: <TD> and <TH> elements in <TR> (non recursive). |
| pack-priv static final short | ELEMENT
Request collection of all form elements: <INPUT>, <BUTTON>, <SELECT>, and <TEXTAREA> elements inside form <FORM>. |
| pack-priv static final short | FORM
Request collection of all forms in document: <FORM> elements. |
| pack-priv static final short | IMAGE
Request collection of all images in document: <IMG> elements. |
| pack-priv static final short | LINK
Request collection of all links in document: <A> and <AREA>
elements (must have a |
| pack-priv static final short | OPTION
Request collection of all options in selection: <OPTION> elements in <SELECT> or <OPTGROUP>. |
| pack-priv static final short | ROW
Request collection of all rows in table: <TR> elements in table or table section. |
| private static final long | |
| pack-priv static final short | TBODY
Request collection of all table bodies in table: <TBODY> element in table <TABLE> (non recursive). |
| Access | Constructor and Description |
|---|---|
| pack-priv | HTMLCollectionImpl(HTMLElement
The element underneath which the collection exists topLevel, short Code indicating what elements to look for lookingFor)Construct a new collection that retrieves element of the specific type
( |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | Returns: The element matches what we're looking forThe current element elem, String The identifier name or null name)Determines if current element matches based on what we're looking for. |
| public final int | Returns: Length of the collectionImplements org. |
| private int | |
| public final Node | Returns: The specified node or null if no such node foundThe index of the node to return index)Implements org. |
| private Node | Returns: Number of elementsTop level element from which to scan topLevel, CollectionIndex The index of the item to retreive index)Recursive function returns the numbered element of a particular type that exist under the top level element. |
| public final Node | Returns: The specified node or null if no such node foundThe name of the node to return name)Implements org. |
| private Node | |
| protected boolean | Returns: True if methods should recurse to traverse entire treeReturns true if scanning methods should iterate through the collection. |
| _lookingFor | back to summary |
|---|---|
| private short _lookingFor Indicates what this collection is looking for. Holds one of the enumerated
values and used by | |
| _topLevel | back to summary |
|---|---|
| private Element _topLevel This is the top level element underneath which the collection exists. | |
| ANCHOR | back to summary |
|---|---|
| pack-priv static final short ANCHOR Request collection of all anchors in document: <A> elements that
have a | |
| APPLET | back to summary |
|---|---|
| pack-priv static final short APPLET Request collection of all Applets in document: <APPLET> and <OBJECT> elements (<OBJECT> must contain an Applet). | |
| AREA | back to summary |
|---|---|
| pack-priv static final short AREA Request collection of all areas in map: <AREA> element in <MAP> (non recursive). | |
| CELL | back to summary |
|---|---|
| pack-priv static final short CELL Request collection of all cells in row: <TD> and <TH> elements in <TR> (non recursive). | |
| ELEMENT | back to summary |
|---|---|
| pack-priv static final short ELEMENT Request collection of all form elements: <INPUT>, <BUTTON>, <SELECT>, and <TEXTAREA> elements inside form <FORM>. | |
| FORM | back to summary |
|---|---|
| pack-priv static final short FORM Request collection of all forms in document: <FORM> elements. | |
| IMAGE | back to summary |
|---|---|
| pack-priv static final short IMAGE Request collection of all images in document: <IMG> elements. | |
| LINK | back to summary |
|---|---|
| pack-priv static final short LINK Request collection of all links in document: <A> and <AREA>
elements (must have a | |
| OPTION | back to summary |
|---|---|
| pack-priv static final short OPTION Request collection of all options in selection: <OPTION> elements in <SELECT> or <OPTGROUP>. | |
| ROW | back to summary |
|---|---|
| pack-priv static final short ROW Request collection of all rows in table: <TR> elements in table or table section. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| TBODY | back to summary |
|---|---|
| pack-priv static final short TBODY Request collection of all table bodies in table: <TBODY> element in table <TABLE> (non recursive). | |
| HTMLCollectionImpl | back to summary |
|---|---|
| pack-priv HTMLCollectionImpl(HTMLElement topLevel, short lookingFor) Construct a new collection that retrieves element of the specific type
(
| |
| collectionMatch | back to summary |
|---|---|
| protected boolean collectionMatch(Element elem, String name) Determines if current element matches based on what we're looking for.
The element is passed along with an optional identifier name. If the
element is the one we're looking for, return true. If the name is also
specified, the name must match the | |
| getLength | back to summary |
|---|---|
| public final int getLength() Implements org. Returns the length of the collection. This method might traverse the entire document tree.
| |
| getLength | back to summary |
|---|---|
| private int getLength(Element topLevel) Recursive function returns the number of elements of a particular type that exist under the top level element. This is a recursive function and the top level element is passed along.
| |
| item | back to summary |
|---|---|
| public final Node item(int index) Implements org. Retrieves the indexed node from the collection. Nodes are numbered in tree order - depth-first traversal order. This method might traverse the entire document tree.
| |
| item | back to summary |
|---|---|
| private Node item(Element topLevel, CollectionIndex index) Recursive function returns the numbered element of a particular type that exist under the top level element. This is a recursive function and the top level element is passed along.
Note that this function must call itself with an index and get back both
the element (if one was found) and the new index which is decremeneted
for any like element found. Since integers are only passed by value,
this function makes use of a separate class (
| |
| namedItem | back to summary |
|---|---|
| public final Node namedItem(String name) Implements org. Retrieves the named node from the collection. The name is matched case sensitive against the id attribute of each element in the collection, returning the first match. The tree is traversed in depth-first order. This method might traverse the entire document tree. | |
| namedItem | back to summary |
|---|---|
| private Node namedItem(Element topLevel, String name) Recursive function returns an element of a particular type with the specified name (id attribute). | |
| recurse | back to summary |
|---|---|
| protected boolean recurse() Returns true if scanning methods should iterate through the collection. When looking for elements in the document, recursing is needed to traverse the full document tree. When looking inside a specific element (e.g. for a cell inside a row), recursing can lead to erroneous results.
| |