public class FilterBean
extends java.lang.Object
implements java.io.Serializable
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 ());
Modifier and Type | Field and Description |
---|---|
protected NodeFilter[] |
mFilters
The filter set.
|
protected NodeList |
mNodes
The nodes extracted from the URL.
|
protected Parser |
mParser
The parser used to filter.
|
protected java.beans.PropertyChangeSupport |
mPropertySupport
Bound property support.
|
static java.lang.String |
PROP_CONNECTION_PROPERTY
Property name in event where the connection changes.
|
static java.lang.String |
PROP_NODES_PROPERTY
Property name in event where the URL contents changes.
|
static java.lang.String |
PROP_TEXT_PROPERTY
Property name in event where the URL contents changes.
|
static java.lang.String |
PROP_URL_PROPERTY
Property name in event where the URL changes.
|
Constructor and Description |
---|
FilterBean()
Create a FilterBean object.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list.
|
protected NodeList |
applyFilters()
Apply each of the filters.
|
java.net.URLConnection |
getConnection()
Get the current connection.
|
NodeFilter[] |
getFilters()
Get the current filter set.
|
NodeList |
getNodes()
Return the nodes of the URL matching the filter.
|
Parser |
getParser()
Get the parser used to fetch nodes.
|
java.lang.String |
getText()
Convenience method to apply a
StringBean to the filter results. |
java.lang.String |
getURL()
Get the current URL.
|
static void |
main(java.lang.String[] args)
Unit test.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list.
|
void |
setConnection(java.net.URLConnection connection)
Set the parser's connection.
|
void |
setFilters(NodeFilter[] filters)
Set the filters for the bean.
|
protected void |
setNodes()
Fetch the URL contents and filter it.
|
void |
setParser(Parser parser)
Set the parser for the bean.
|
void |
setURL(java.lang.String url)
Set the URL to extract strings from.
|
protected void |
updateNodes(NodeList nodes)
Assign the
Nodes property, firing the property change. |
public static final java.lang.String PROP_NODES_PROPERTY
public static final java.lang.String PROP_TEXT_PROPERTY
public static final java.lang.String PROP_URL_PROPERTY
public static final java.lang.String PROP_CONNECTION_PROPERTY
protected java.beans.PropertyChangeSupport mPropertySupport
protected Parser mParser
protected NodeFilter[] mFilters
protected NodeList mNodes
protected void updateNodes(NodeList nodes)
Nodes
property, firing the property change.nodes
- The new value of the Nodes
property.protected NodeList applyFilters() throws ParserException
ParserException
- If an encoding change occurs
or there is some other problem.protected void setNodes()
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The PropertyChangeListener to be added.public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The PropertyChangeListener to be removed.public NodeList getNodes()
public java.lang.String getURL()
null
if this property has not been set yet.public void setURL(java.lang.String url)
url
- The URL that text should be fetched from.public java.net.URLConnection getConnection()
null
if it
hasn't been set or the parser hasn't been constructed yet.public void setConnection(java.net.URLConnection connection)
connection
- New value of property Connection.public NodeFilter[] getFilters()
public void setFilters(NodeFilter[] filters)
filters
- The filter set to use.public Parser getParser()
public void setParser(Parser parser)
parser
- The parser to use.public java.lang.String getText()
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.public static void main(java.lang.String[] args)
args
- Pass arg[0] as the URL to process,
and optionally a node name for filtering.HTML Parser is an open source library released under LGPL.