it.sauronsoftware.grab4j.html
Class HTMLDocument

java.lang.Object
  extended by it.sauronsoftware.grab4j.html.HTMLDocument

public class HTMLDocument
extends java.lang.Object

A HTML document representation.

Author:
Carlo Pelliccia

Method Summary
 HTMLElement getElement(int index)
          This method returns the element at the given index.
 HTMLElement getElementById(java.lang.String id)
          This method explores recursively the document elements, searching the first occurrence of an element with the given value in its "id" attribute.
 int getElementCount()
          This method returns the number of the first-level elements in the document.
 HTMLElement[] getElements()
          This method returns an array with all the document first-level elements.
 HTMLElement[] getElementsByAttribute(java.lang.String attributeName, java.lang.String attributeValue)
          This method searches recursively inside the document elements, selecting the ones whose have a given attribute with a given value.
 HTMLElement[] getElementsByTag(java.lang.String tagName)
          This method searches recursively inside the document elements, selecting the ones whose name is equal to the given tag name.
 java.net.URL getURL()
          This method returns the document source URL.
 HTMLElement searchElement(Criteria searchCriteria)
          This method searches recursively inside the document elements and returns the first occurrence of the results list.
 HTMLElement searchElement(java.lang.String searchCriteria)
          This method searches recursively inside the document elements and returns the first occurrence of the results list.
 HTMLElement[] searchElements(Criteria searchCriteria)
          This method searches recursively inside the document elements.
 HTMLElement[] searchElements(java.lang.String searchCriteria)
          This method searches recursively inside the document elements.
 void setURL(java.net.URL url)
          This method sets the document source URL.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

setURL

public void setURL(java.net.URL url)
This method sets the document source URL.

Parameters:
url - The document source URL.

getURL

public java.net.URL getURL()
This method returns the document source URL.

Returns:
The document source URL.

getElement

public HTMLElement getElement(int index)
This method returns the element at the given index.

Parameters:
index - The index, starting from 0 untill getElementCount() - 1.
Returns:
The element at the given index.

getElementCount

public int getElementCount()
This method returns the number of the first-level elements in the document.

Returns:
The number of the first-level elements in the document

getElements

public HTMLElement[] getElements()
This method returns an array with all the document first-level elements.

Returns:
An array with all the document first-level elements

getElementById

public HTMLElement getElementById(java.lang.String id)
This method explores recursively the document elements, searching the first occurrence of an element with the given value in its "id" attribute.

Parameters:
id - The id of the wanted sub-element.
Returns:
The element, or null if not found.

getElementsByTag

public HTMLElement[] getElementsByTag(java.lang.String tagName)
This method searches recursively inside the document elements, selecting the ones whose name is equal to the given tag name.

Parameters:
tagName - The tag name.
Returns:
An array with the elements that satisfy the search criteria.

getElementsByAttribute

public HTMLElement[] getElementsByAttribute(java.lang.String attributeName,
                                            java.lang.String attributeValue)
This method searches recursively inside the document elements, selecting the ones whose have a given attribute with a given value.

Parameters:
attributeName - The attribute name.
attributeValue - The attribute value.
Returns:
An array with the sub-elements that satisfy the search criteria.

searchElements

public HTMLElement[] searchElements(java.lang.String searchCriteria)
                             throws InvalidCriteriaException
This method searches recursively inside the document elements.

Parameters:
searchCriteria - The search criteria.
Returns:
An array with the sub-elements that satisfy the search criteria.
Throws:
InvalidCriteriaException - If the given criteria is invalid.
See Also:
Criteria

searchElement

public HTMLElement searchElement(java.lang.String searchCriteria)
                          throws InvalidCriteriaException
This method searches recursively inside the document elements and returns the first occurrence of the results list.

Parameters:
searchCriteria - The search criteria.
Returns:
The first occurrence of the results list, or null if no result is found.
Throws:
InvalidCriteriaException - If the given criteria is invalid.
See Also:
Criteria

searchElements

public HTMLElement[] searchElements(Criteria searchCriteria)
This method searches recursively inside the document elements.

Parameters:
searchCriteria - The search criteria.
Returns:
An array with the sub-elements that satisfy the search criteria.

searchElement

public HTMLElement searchElement(Criteria searchCriteria)
This method searches recursively inside the document elements and returns the first occurrence of the results list.

Parameters:
searchCriteria - The search criteria.
Returns:
The first occurrence of the results list, or null if no result is found.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object