org.htmlparser.beans
Class FilterBean
- Serializable
public class FilterBean
implements Serializable
Extract nodes from a URL using a filter.
FilterBean fb = new FilterBean ("http://cbc.ca");
fb.setFilters (new NodeFilter[] { new TagNameFilter ("META") });
fb.setURL ("http://cbc.ca");
System.out.println (fb.getNodes ().toHtml ());
PROP_CONNECTION_PROPERTY
public static final String PROP_CONNECTION_PROPERTY
Property name in event where the connection changes.
PROP_NODES_PROPERTY
public static final String PROP_NODES_PROPERTY
Property name in event where the URL contents changes.
PROP_TEXT_PROPERTY
public static final String PROP_TEXT_PROPERTY
Property name in event where the URL contents changes.
PROP_URL_PROPERTY
public static final String PROP_URL_PROPERTY
Property name in event where the URL changes.
mFilters
protected NodeFilter[] mFilters
The filter set.
mNodes
protected NodeList mNodes
The nodes extracted from the URL.
mParser
protected Parser mParser
The parser used to filter.
mPropertySupport
protected PropertyChangeSupport mPropertySupport
Bound property support.
mRecursive
protected boolean mRecursive
The recursion behaviour for elements of the filter array.
If true
the filters are applied recursively.
FilterBean
public FilterBean()
Create a FilterBean object.
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list.
The listener is registered for all properties.
listener
- The PropertyChangeListener to be added.
applyFilters
protected NodeList applyFilters()
throws ParserException
Apply each of the filters.
The first filter is applied to the output of the parser.
Subsequent filters are applied to the output of the prior filter.
- A list of nodes passed through all filters.
If there are no filters, returns the entire page.
ParserException
- If an encoding change occurs
or there is some other problem.
getConnection
public URLConnection getConnection()
Get the current connection.
- The connection that the parser has or
null
if it
hasn't been set or the parser hasn't been constructed yet.
getFilters
public NodeFilter[] getFilters()
Get the current filter set.
getNodes
public NodeList getNodes()
Return the nodes of the URL matching the filter.
This is the primary output of the bean.
- The nodes from the URL matching the current filter.
getParser
public Parser getParser()
Get the parser used to fetch nodes.
- The parser used by the bean.
getRecursive
public boolean getRecursive()
Get the current recursion behaviour.
- The recursion (applies to children, children's children, etc)
behavior currently being used.
getText
public String getText()
Convenience method to apply a
StringBean
to the filter results.
This may yield duplicate or multiple text elements if the node list
contains nodes from two or more levels in the same nested tag heirarchy,
but if the node list contains only one tag, it provides access to the
text within the node.
- The textual contents of the nodes that pass through the filter set,
as collected by the StringBean.
getURL
public String getURL()
Get the current URL.
- The URL from which text has been extracted, or
null
if this property has not been set yet.
main
public static void main(String[] args)
Unit test.
args
- Pass arg[0] as the URL to process,
and optionally a node name for filtering.
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list.
This removes a registered PropertyChangeListener.
listener
- The PropertyChangeListener to be removed.
setConnection
public void setConnection(URLConnection connection)
Set the parser's connection.
The text from the URL will be fetched, which may be expensive, so this
property should be set last.
connection
- New value of property Connection.
setFilters
public void setFilters(NodeFilter[] filters)
Set the filters for the bean.
If the parser has been set, it is reset and
the nodes are refetched with the new filters.
filters
- The filter set to use.
setNodes
protected void setNodes()
Fetch the URL contents and filter it.
Only do work if there is a valid parser with it's URL set.
setParser
public void setParser(Parser parser)
Set the parser for the bean.
The parser is used immediately to fetch the nodes,
which for a null filter means all the nodes
parser
- The parser to use.
setRecursive
public void setRecursive(boolean recursive)
Set the recursion behaviour.
recursive
- If true
the
extractAllNodesThatMatch()
call is performed recursively.
setURL
public void setURL(String url)
Set the URL to extract strings from.
The text from the URL will be fetched, which may be expensive, so this
property should be set last.
url
- The URL that text should be fetched from.
updateNodes
protected void updateNodes(NodeList nodes)
Assign the Nodes
property, firing the property change.
nodes
- The new value of the Nodes
property.
| © 2005 Derrick Oswald Mai 08, 2008 |
HTML Parser is an open source library released under LGPL. |  |