Top Description Fields Constructors Methods
org.jdom2.filter

public Class ContentFilter

extends AbstractFilter<Content>
Class Inheritance
Imports
org.jdom2.*

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

Field Summary

Modifier and TypeField and Description
public static final int
CDATA

Mask for JDOM CDATA objects

public static final int
COMMENT

Mask for JDOM Comment objects

public static final int
DOCTYPE

Mask for JDOM DocType object

public static final int
DOCUMENT

Mask for JDOM Document object

public static final int
ELEMENT

Mask for JDOM Element objects

public static final int
ENTITYREF

Mask for JDOM EntityRef objects

private int
filterMask

The JDOM object mask

public static final int
PI

Mask for JDOM ProcessingInstruction objects

private static final long
serialVersionUID

Hides org.jdom2.filter.AbstractFilter.serialVersionUID.

JDOM2 Serialization: Default mechanism
public static final int
TEXT

Mask for JDOM Text objects

Constructor Summary

AccessConstructor and Description
public
ContentFilter()

Default constructor that allows any legal JDOM objects.

public
ContentFilter(boolean
true all JDOM objects are visible, false all JDOM objects are hidden.
allVisible
)

Set whether all JDOM objects are visible or not.

public
ContentFilter(int
Mask of JDOM objects to allow.
mask
)

Filter out JDOM objects according to a filtering mask.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

whether the two filters are equal
equals
(Object
the object to compare against
obj
)

Overrides java.lang.Object.equals.

Returns whether the two filters are equivalent (i.e. the matching mask values are identical).
public Content

Returns:

true if the objected matched a predfined set of rules.
filter
(Object
The object to verify.
obj
)

Implements org.jdom2.filter.Filter.filter.

Check to see if the object matches according to the filter mask.
public int

Returns:

the current filtering mask
getFilterMask
()

Return current filtering mask.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public void
setCDATAVisible(boolean
whether CDATA nodes are visible, true if yes, false if not
visible
)

Set visibility of CDATA objects.

public void
setCommentVisible(boolean
whether Comments are visible, true if yes, false if not
visible
)

Set visibility of Comment objects.

public void
setDefaultMask()

Set this filter to allow all legal JDOM objects.

public void
setDocTypeVisible(boolean
whether the DocType is visible, true if yes, false if not
visible
)

Set visibility of DocType objects.

public void
setDocumentContent()

Set filter to match only JDOM objects that are legal document content.

public void
setElementContent()

Set filter to match only JDOM objects that are legal element content.

public void
setElementVisible(boolean
whether Elements are visible, true if yes, false if not
visible
)

Set visibility of Element objects.

public void
setEntityRefVisible(boolean
whether EntityRefs are visible, true if yes, false if not
visible
)

Set visibility of EntityRef objects.

public void
setFilterMask(int
the new filtering mask
mask
)

Set filtering mask.

public void
setPIVisible(boolean
whether ProcessingInstructions are visible, true if yes, false if not
visible
)

Set visibility of ProcessingInstruction objects.

public void
setTextVisible(boolean
whether Text nodes are visible, true if yes, false if not
visible
)

Set visibility of Text objects.

Inherited from org.jdom2.filter.AbstractFilter:
andfiltermatchesnegateorrefine

Field Detail

CDATAback to summary
public static final int CDATA

Mask for JDOM CDATA objects

COMMENTback to summary
public static final int COMMENT

Mask for JDOM Comment objects

DOCTYPEback to summary
public static final int DOCTYPE

Mask for JDOM DocType object

DOCUMENTback to summary
public static final int DOCUMENT

Mask for JDOM Document object

ELEMENTback to summary
public static final int ELEMENT

Mask for JDOM Element objects

ENTITYREFback to summary
public static final int ENTITYREF

Mask for JDOM EntityRef objects

filterMaskback to summary
private int filterMask

The JDOM object mask

PIback to summary
public static final int PI

Mask for JDOM ProcessingInstruction objects

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.jdom2.filter.AbstractFilter.serialVersionUID.

JDOM2 Serialization: Default mechanism

TEXTback to summary
public static final int TEXT

Mask for JDOM Text objects

Constructor Detail

ContentFilterback to summary
public ContentFilter()

Default constructor that allows any legal JDOM objects.

ContentFilterback to summary
public ContentFilter(boolean allVisible)

Set whether all JDOM objects are visible or not.

Parameters
allVisible:boolean

true all JDOM objects are visible, false all JDOM objects are hidden.

ContentFilterback to summary
public ContentFilter(int mask)

Filter out JDOM objects according to a filtering mask.

Parameters
mask:int

Mask of JDOM objects to allow.

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Returns whether the two filters are equivalent (i.e. the matching mask values are identical).

Parameters
obj:Object

the object to compare against

Returns:boolean

whether the two filters are equal

Annotations
@Override
filterback to summary
public Content filter(Object obj)

Implements org.jdom2.filter.Filter.filter.

Check to see if the object matches according to the filter mask.

Parameters
obj:Object

The object to verify.

Returns:Content

true if the objected matched a predfined set of rules.

Annotations
@Override
getFilterMaskback to summary
public int getFilterMask()

Return current filtering mask.

Returns:int

the current filtering mask

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
setCDATAVisibleback to summary
public void setCDATAVisible(boolean visible)

Set visibility of CDATA objects.

Parameters
visible:boolean

whether CDATA nodes are visible, true if yes, false if not

setCommentVisibleback to summary
public void setCommentVisible(boolean visible)

Set visibility of Comment objects.

Parameters
visible:boolean

whether Comments are visible, true if yes, false if not

setDefaultMaskback to summary
public void setDefaultMask()

Set this filter to allow all legal JDOM objects.

setDocTypeVisibleback to summary
public void setDocTypeVisible(boolean visible)

Set visibility of DocType objects.

Parameters
visible:boolean

whether the DocType is visible, true if yes, false if not

setDocumentContentback to summary
public void setDocumentContent()

Set filter to match only JDOM objects that are legal document content.

setElementContentback to summary
public void setElementContent()

Set filter to match only JDOM objects that are legal element content.

setElementVisibleback to summary
public void setElementVisible(boolean visible)

Set visibility of Element objects.

Parameters
visible:boolean

whether Elements are visible, true if yes, false if not

setEntityRefVisibleback to summary
public void setEntityRefVisible(boolean visible)

Set visibility of EntityRef objects.

Parameters
visible:boolean

whether EntityRefs are visible, true if yes, false if not

setFilterMaskback to summary
public void setFilterMask(int mask)

Set filtering mask.

Parameters
mask:int

the new filtering mask

setPIVisibleback to summary
public void setPIVisible(boolean visible)

Set visibility of ProcessingInstruction objects.

Parameters
visible:boolean

whether ProcessingInstructions are visible, true if yes, false if not

setTextVisibleback to summary
public void setTextVisible(boolean visible)

Set visibility of Text objects.

Parameters
visible:boolean

whether Text nodes are visible, true if yes, false if not