Package org.htmlparser.filters
Class HasParentFilter
java.lang.Object
org.htmlparser.filters.HasParentFilter
- All Implemented Interfaces:
Serializable,Cloneable,NodeFilter
This class accepts all tags that have a parent acceptable to another filter.
It can be set to operate recursively, that is perform a scan up the node
heirarchy looking for any ancestor that matches the predicate filter.
End tags are not considered to be children of any tag.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected NodeFilterThe filter to apply to the parent.protected booleanPerforms a recursive search up the node heirarchy iftrue. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of HasParentFilter.HasParentFilter(NodeFilter filter) Creates a new instance of HasParentFilter that accepts nodes with the direct parent acceptable to the filter.HasParentFilter(NodeFilter filter, boolean recursive) Creates a new instance of HasParentFilter that accepts nodes with a parent acceptable to the filter. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAccept tags with parent acceptable to the filter.Get the filter used by this HasParentFilter.booleanGet the recusion setting for the filter.voidsetParentFilter(NodeFilter filter) Set the filter for this HasParentFilter.voidsetRecursive(boolean recursive) Sets whether the filter is recursive or not.
-
Field Details
-
mParentFilter
The filter to apply to the parent. -
mRecursive
protected boolean mRecursivePerforms a recursive search up the node heirarchy iftrue.
-
-
Constructor Details
-
HasParentFilter
public HasParentFilter()Creates a new instance of HasParentFilter. With no parent filter, this would always returnfalsefromaccept(org.htmlparser.Node). -
HasParentFilter
Creates a new instance of HasParentFilter that accepts nodes with the direct parent acceptable to the filter.- Parameters:
filter- The filter to apply to the parent.
-
HasParentFilter
Creates a new instance of HasParentFilter that accepts nodes with a parent acceptable to the filter.- Parameters:
filter- The filter to apply to the parent.recursive- Iftrue, any enclosing node acceptable to the given filter causes the node being tested to be accepted (i.e. a recursive scan through the parent nodes up the node heirarchy is performed).
-
-
Method Details
-
getParentFilter
Get the filter used by this HasParentFilter.- Returns:
- The filter to apply to parents.
-
setParentFilter
Set the filter for this HasParentFilter.- Parameters:
filter- The filter to apply to parents inaccept(org.htmlparser.Node).
-
getRecursive
public boolean getRecursive()Get the recusion setting for the filter.- Returns:
- Returns
trueif the filter is recursive up the node heirarchy.
-
setRecursive
public void setRecursive(boolean recursive) Sets whether the filter is recursive or not.- Parameters:
recursive- The recursion setting for the filter.
-
accept
Accept tags with parent acceptable to the filter. If recursion is enabled, each parent in turn up to the topmost enclosing node is checked. Recursion only proceeds while no parent satisfies the filter.- Specified by:
acceptin interfaceNodeFilter- Parameters:
node- The node to check.- Returns:
trueif the node has an acceptable parent,falseotherwise.
-