Package org.jdom2.filter
Class ContentFilter
- All Implemented Interfaces:
Serializable
,Filter<Content>
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.
- Author:
- Bradley S. Huffman
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Mask for JDOMCDATA
objectsstatic final int
Mask for JDOMComment
objectsstatic final int
Mask for JDOMDocType
objectstatic final int
Mask for JDOMDocument
objectstatic final int
Mask for JDOMElement
objectsstatic final int
Mask for JDOMEntityRef
objectsstatic final int
Mask for JDOMProcessingInstruction
objectsstatic final int
Mask for JDOMText
objects -
Constructor Summary
ConstructorsConstructorDescriptionDefault 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
Modifier and TypeMethodDescriptionboolean
Returns whether the two filters are equivalent (i.e. the matching mask values are identical).Check to see if the object matches according to the filter mask.int
Return current filtering mask.int
hashCode()
void
setCDATAVisible
(boolean visible) Set visibility ofCDATA
objects.void
setCommentVisible
(boolean visible) Set visibility ofComment
objects.void
Set this filter to allow all legal JDOM objects.void
setDocTypeVisible
(boolean visible) Set visibility ofDocType
objects.void
Set filter to match only JDOM objects that are legal document content.void
Set filter to match only JDOM objects that are legal element content.void
setElementVisible
(boolean visible) Set visibility ofElement
objects.void
setEntityRefVisible
(boolean visible) Set visibility ofEntityRef
objects.void
setFilterMask
(int mask) Set filtering mask.void
setPIVisible
(boolean visible) Set visibility ofProcessingInstruction
objects.void
setTextVisible
(boolean visible) Set visibility ofText
objects.
-
Field Details
-
ELEMENT
public static final int ELEMENTMask for JDOMElement
objects- See Also:
-
CDATA
public static final int CDATAMask for JDOMCDATA
objects- See Also:
-
TEXT
public static final int TEXTMask for JDOMText
objects- See Also:
-
COMMENT
public static final int COMMENTMask for JDOMComment
objects- See Also:
-
PI
public static final int PIMask for JDOMProcessingInstruction
objects- See Also:
-
ENTITYREF
public static final int ENTITYREFMask for JDOMEntityRef
objects- See Also:
-
DOCUMENT
public static final int DOCUMENTMask for JDOMDocument
object- See Also:
-
DOCTYPE
public static final int DOCTYPEMask for JDOMDocType
object- See Also:
-
-
Constructor Details
-
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 Details
-
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 visibility ofElement
objects.- Parameters:
visible
- whether Elements are visible,true
if yes,false
if not
-
setCDATAVisible
public void setCDATAVisible(boolean visible) Set visibility ofCDATA
objects.- Parameters:
visible
- whether CDATA nodes are visible,true
if yes,false
if not
-
setTextVisible
public void setTextVisible(boolean visible) Set visibility ofText
objects.- Parameters:
visible
- whether Text nodes are visible,true
if yes,false
if not
-
setCommentVisible
public void setCommentVisible(boolean visible) Set visibility ofComment
objects.- Parameters:
visible
- whether Comments are visible,true
if yes,false
if not
-
setPIVisible
public void setPIVisible(boolean visible) Set visibility ofProcessingInstruction
objects.- Parameters:
visible
- whether ProcessingInstructions are visible,true
if yes,false
if not
-
setEntityRefVisible
public void setEntityRefVisible(boolean visible) Set visibility ofEntityRef
objects.- Parameters:
visible
- whether EntityRefs are visible,true
if yes,false
if not
-
setDocTypeVisible
public void setDocTypeVisible(boolean visible) Set visibility ofDocType
objects.- Parameters:
visible
- whether the DocType is visible,true
if yes,false
if not
-
filter
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
Returns whether the two filters are equivalent (i.e. the matching mask values are identical). -
hashCode
public int hashCode()
-