Class NodeList

  • All Implemented Interfaces:
    java.io.Serializable

    public class NodeList
    extends java.lang.Object
    implements java.io.Serializable
    See Also:
    Serialized Form
    • Constructor Detail

      • NodeList

        public NodeList()
      • NodeList

        public NodeList​(Node node)
        Create a one element node list.
        Parameters:
        node - The initial node to add.
    • Method Detail

      • add

        public void add​(Node node)
      • add

        public void add​(NodeList list)
        Add another node list to this one.
        Parameters:
        list - The list to add.
      • prepend

        public void prepend​(Node node)
        Insert the given node at the head of the list.
        Parameters:
        node - The new first element.
      • size

        public int size()
      • elementAt

        public Node elementAt​(int i)
      • toNodeArray

        public Node[] toNodeArray()
      • copyToNodeArray

        public void copyToNodeArray​(Node[] array)
      • asString

        public java.lang.String asString()
      • toHtml

        public java.lang.String toHtml​(boolean verbatim)
        Convert this nodelist into the equivalent HTML.
        Parameters:
        verbatim - If true return as close to the original page text as possible.
        Returns:
        The contents of the list as HTML text.
      • toHtml

        public java.lang.String toHtml()
        Convert this nodelist into the equivalent HTML.
        Returns:
        The contents of the list as HTML text.
      • remove

        public Node remove​(int index)
        Remove the node at index.
        Parameters:
        index - The index of the node to remove.
        Returns:
        The node that was removed.
      • removeAll

        public void removeAll()
      • contains

        public boolean contains​(Node node)
        Check to see if the NodeList contains the supplied Node.
        Parameters:
        node - The node to look for.
        Returns:
        True is the Node is in this NodeList.
      • indexOf

        public int indexOf​(Node node)
        Finds the index of the supplied Node.
        Parameters:
        node - The node to look for.
        Returns:
        The index of the node in the list or -1 if it isn't found.
      • remove

        public boolean remove​(Node node)
        Remove the supplied Node from the list.
        Parameters:
        node - The node to remove.
        Returns:
        True if the node was found and removed from the list.
      • toString

        public java.lang.String toString()
        Return the contents of the list as a string. Suitable for debugging.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of the list.
      • extractAllNodesThatMatch

        public NodeList extractAllNodesThatMatch​(NodeFilter filter)
        Filter the list with the given filter non-recursively.
        Parameters:
        filter - The filter to use.
        Returns:
        A new node array containing the nodes accepted by the filter. This is a linear list and preserves the nested structure of the returned nodes only.
      • extractAllNodesThatMatch

        public NodeList extractAllNodesThatMatch​(NodeFilter filter,
                                                 boolean recursive)
        Filter the list with the given filter.
        Parameters:
        filter - The filter to use.
        recursive - If true digs into the children recursively.
        Returns:
        A new node array containing the nodes accepted by the filter. This is a linear list and preserves the nested structure of the returned nodes only.
      • keepAllNodesThatMatch

        public void keepAllNodesThatMatch​(NodeFilter filter)
        Remove nodes not matching the given filter non-recursively.
        Parameters:
        filter - The filter to use.
      • keepAllNodesThatMatch

        public void keepAllNodesThatMatch​(NodeFilter filter,
                                          boolean recursive)
        Remove nodes not matching the given filter.
        Parameters:
        filter - The filter to use.
        recursive - If true digs into the children recursively.
      • visitAllNodesWith

        public void visitAllNodesWith​(NodeVisitor visitor)
                               throws ParserException
        Utility to apply a visitor to a node list. Provides for a visitor to modify the contents of a page and get the modified HTML as a string with code like this:
         Parser parser = new Parser ("http://whatever");
         NodeList list = parser.parse (null); // no filter
         list.visitAllNodesWith (visitor);
         System.out.println (list.toHtml ());
         
        Throws:
        ParserException