org.jdesktop.dom
Class SimpleHtmlCollection

java.lang.Object
  extended by org.jdesktop.dom.SimpleHtmlCollection
All Implemented Interfaces:
Iterable<Node>, org.w3c.dom.html.HTMLCollection

public class SimpleHtmlCollection
extends Object
implements org.w3c.dom.html.HTMLCollection, Iterable<Node>

An implementation of HTMLCollection which also implements Iterable. This allows you to use a SimpleHtmlCollection in an enhanced for loop, such as:


  SimpleHtmlCollection nodes = ...;
  for (Node n : nodes) {
      System.out.println(n.getTextContent());
  }
 

SimpleHtmlCollection wraps a source HtmlCollection. So any normal HTMLCollection can be adapted for use with enhanced for loops by wrapping it in a SimpleHtmlCollection.


Constructor Summary
SimpleHtmlCollection(org.w3c.dom.html.HTMLCollection list)
          Creates a new instance of SimpleHtmlCollection.
 
Method Summary
 int getLength()
          This attribute specifies the length or size of the list.
 Node item(int index)
          This method retrieves a node specified by ordinal index.
 Iterator<Node> iterator()
          Returns an iterator over a set of elements of type T.
 Node namedItem(String name)
          This method retrieves a Node using a name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleHtmlCollection

public SimpleHtmlCollection(org.w3c.dom.html.HTMLCollection list)
Creates a new instance of SimpleHtmlCollection.

Parameters:
list - the HTMLCollection to wrap.
Method Detail

item

public Node item(int index)
Description copied from interface: org.w3c.dom.html.HTMLCollection
This method retrieves a node specified by ordinal index. Nodes are numbered in tree order (depth-first traversal order).

Specified by:
item in interface org.w3c.dom.html.HTMLCollection
Parameters:
index - The index of the node to be fetched. The index origin is 0.
Returns:
The Node at the corresponding position upon success. A value of null is returned if the index is out of range.

getLength

public int getLength()
Description copied from interface: org.w3c.dom.html.HTMLCollection
This attribute specifies the length or size of the list.

Specified by:
getLength in interface org.w3c.dom.html.HTMLCollection

iterator

public Iterator<Node> iterator()
Description copied from interface: java.lang.Iterable
Returns an iterator over a set of elements of type T.

Specified by:
iterator in interface Iterable<Node>
Returns:
an Iterator.

namedItem

public Node namedItem(String name)
Description copied from interface: org.w3c.dom.html.HTMLCollection
This method retrieves a Node using a name. It first searches for a Node with a matching id attribute. If it doesn't find one, it then searches for a Node with a matching name attribute, but only on those elements that are allowed a name attribute.

Specified by:
namedItem in interface org.w3c.dom.html.HTMLCollection
Parameters:
name - The name of the Node to be fetched.
Returns:
The Node with a name or id attribute whose value corresponds to the specified string. Upon failure (e.g., no node with this name exists), returns null .