Package org.jdom.filter
Class ContentFilter
- java.lang.Object
-
- org.jdom.filter.AbstractFilter
-
- org.jdom.filter.ContentFilter
-
- All Implemented Interfaces:
java.io.Serializable
,Filter
public class ContentFilter extends AbstractFilter
A general purpose Filter able to represent all legal JDOM objects or a specific subset. Filtering is accomplished by way of a filtering mask in which each bit represents whether a JDOM object is visible or not. For example to view all Text and CDATA nodes in the content of element x.Filter filter = new ContentFilter(ContentFilter.TEXT | ContentFilter.CDATA); List content = x.getContent(filter);
For those who don't like bit-masking, set methods are provided as an alternative. For example to allow everything except Comment nodes.
Filter filter = new ContentFilter(); filter.setCommentVisible(false); List content = x.getContent(filter);
The default is to allow all valid JDOM objects.
- Version:
- $Revision: 1.15 $, $Date: 2007/11/10 05:29:00 $
- Author:
- Bradley S. Huffman
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
CDATA
Mask for JDOMCDATA
objectsstatic int
COMMENT
Mask for JDOMComment
objectsstatic int
DOCTYPE
Mask for JDOMDocType
objectstatic int
DOCUMENT
Mask for JDOMDocument
objectstatic int
ELEMENT
Mask for JDOMElement
objectsstatic int
ENTITYREF
Mask for JDOMEntityRef
objectsstatic int
PI
Mask for JDOMProcessingInstruction
objectsstatic int
TEXT
Mask for JDOMText
objects
-
Constructor Summary
Constructors Constructor Description ContentFilter()
Default constructor that allows any legal JDOM objects.ContentFilter(boolean allVisible)
Set whether all JDOM objects are visible or not.ContentFilter(int mask)
Filter out JDOM objects according to a filtering mask.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
Returns whether the two filters are equivalent (i.e. the matching mask values are identical).int
getFilterMask()
Return current filtering mask.int
hashCode()
boolean
matches(java.lang.Object obj)
Check to see if the object matches according to the filter mask.void
setCDATAVisible(boolean visible)
Set visiblity ofCDATA
objects.void
setCommentVisible(boolean visible)
Set visiblity ofComment
objects.void
setDefaultMask()
Set this filter to allow all legal JDOM objects.void
setDocTypeVisible(boolean visible)
Set visiblity ofDocType
objects.void
setDocumentContent()
Set filter to match only JDOM objects that are legal document content.void
setElementContent()
Set filter to match only JDOM objects that are legal element content.void
setElementVisible(boolean visible)
Set visiblity ofElement
objects.void
setEntityRefVisible(boolean visible)
Set visiblity ofEntityRef
objects.void
setFilterMask(int mask)
Set filtering mask.void
setPIVisible(boolean visible)
Set visiblity ofProcessingInstruction
objects.void
setTextVisible(boolean visible)
Set visiblity ofText
objects.-
Methods inherited from class org.jdom.filter.AbstractFilter
and, negate, or
-
-
-
-
Field Detail
-
ELEMENT
public static final int ELEMENT
Mask for JDOMElement
objects- See Also:
- Constant Field Values
-
CDATA
public static final int CDATA
Mask for JDOMCDATA
objects- See Also:
- Constant Field Values
-
TEXT
public static final int TEXT
Mask for JDOMText
objects- See Also:
- Constant Field Values
-
COMMENT
public static final int COMMENT
Mask for JDOMComment
objects- See Also:
- Constant Field Values
-
PI
public static final int PI
Mask for JDOMProcessingInstruction
objects- See Also:
- Constant Field Values
-
ENTITYREF
public static final int ENTITYREF
Mask for JDOMEntityRef
objects- See Also:
- Constant Field Values
-
DOCUMENT
public static final int DOCUMENT
Mask for JDOMDocument
object- See Also:
- Constant Field Values
-
DOCTYPE
public static final int DOCTYPE
Mask for JDOMDocType
object- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ContentFilter
public ContentFilter()
Default constructor that allows any legal JDOM objects.
-
ContentFilter
public ContentFilter(boolean allVisible)
Set whether all JDOM objects are visible or not.- Parameters:
allVisible
-true
all JDOM objects are visible,false
all JDOM objects are hidden.
-
ContentFilter
public ContentFilter(int mask)
Filter out JDOM objects according to a filtering mask.- Parameters:
mask
- Mask of JDOM objects to allow.
-
-
Method Detail
-
getFilterMask
public int getFilterMask()
Return current filtering mask.- Returns:
- the current filtering mask
-
setFilterMask
public void setFilterMask(int mask)
Set filtering mask.- Parameters:
mask
- the new filtering mask
-
setDefaultMask
public void setDefaultMask()
Set this filter to allow all legal JDOM objects.
-
setDocumentContent
public void setDocumentContent()
Set filter to match only JDOM objects that are legal document content.
-
setElementContent
public void setElementContent()
Set filter to match only JDOM objects that are legal element content.
-
setElementVisible
public void setElementVisible(boolean visible)
Set visiblity ofElement
objects.- Parameters:
visible
- whether Elements are visible,true
if yes,false
if not
-
setCDATAVisible
public void setCDATAVisible(boolean visible)
Set visiblity ofCDATA
objects.- Parameters:
visible
- whether CDATA nodes are visible,true
if yes,false
if not
-
setTextVisible
public void setTextVisible(boolean visible)
Set visiblity ofText
objects.- Parameters:
visible
- whether Text nodes are visible,true
if yes,false
if not
-
setCommentVisible
public void setCommentVisible(boolean visible)
Set visiblity ofComment
objects.- Parameters:
visible
- whether Comments are visible,true
if yes,false
if not
-
setPIVisible
public void setPIVisible(boolean visible)
Set visiblity ofProcessingInstruction
objects.- Parameters:
visible
- whether ProcessingInstructions are visible,true
if yes,false
if not
-
setEntityRefVisible
public void setEntityRefVisible(boolean visible)
Set visiblity ofEntityRef
objects.- Parameters:
visible
- whether EntityRefs are visible,true
if yes,false
if not
-
setDocTypeVisible
public void setDocTypeVisible(boolean visible)
Set visiblity ofDocType
objects.- Parameters:
visible
- whether the DocType is visible,true
if yes,false
if not
-
matches
public boolean matches(java.lang.Object obj)
Check to see if the object matches according to the filter mask.- Parameters:
obj
- The object to verify.- Returns:
true
if the objected matched a predfined set of rules.
-
equals
public boolean equals(java.lang.Object obj)
Returns whether the two filters are equivalent (i.e. the matching mask values are identical).- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to compare against- Returns:
- whether the two filters are equal
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-