org.jdom.filter

Class ContentFilter

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.14 $, $Date: 2004/08/31 04:56:07 $

Author: Bradley S. Huffman

Field Summary
static intCDATA
Mask for JDOM {@link CDATA} objects
static intCOMMENT
Mask for JDOM {@link Comment} objects
static intDOCTYPE
Mask for JDOM {@link DocType} object
static intDOCUMENT
Mask for JDOM {@link Document} object
static intELEMENT
Mask for JDOM {@link Element} objects
static intENTITYREF
Mask for JDOM {@link EntityRef} objects
static intPI
Mask for JDOM {@link ProcessingInstruction} objects
static intTEXT
Mask for JDOM {@link Text} objects
Constructor Summary
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
booleanequals(Object obj)
Returns whether the two filters are equivalent (i.e. the matching mask values are identical).
intgetFilterMask()
Return current filtering mask.
inthashCode()
booleanmatches(Object obj)
Check to see if the object matches according to the filter mask.
voidsetCDATAVisible(boolean visible)
Set visiblity of CDATA objects.
voidsetCommentVisible(boolean visible)
Set visiblity of Comment objects.
voidsetDefaultMask()
Set this filter to allow all legal JDOM objects.
voidsetDocTypeVisible(boolean visible)
Set visiblity of DocType objects.
voidsetDocumentContent()
Set filter to match only JDOM objects that are legal document content.
voidsetElementContent()
Set filter to match only JDOM objects that are legal element content.
voidsetElementVisible(boolean visible)
Set visiblity of Element objects.
voidsetEntityRefVisible(boolean visible)
Set visiblity of EntityRef objects.
voidsetFilterMask(int mask)
Set filtering mask.
voidsetPIVisible(boolean visible)
Set visiblity of ProcessingInstruction objects.
voidsetTextVisible(boolean visible)
Set visiblity of Text objects.

Field Detail

CDATA

public static final int CDATA
Mask for JDOM {@link CDATA} objects

COMMENT

public static final int COMMENT
Mask for JDOM {@link Comment} objects

DOCTYPE

public static final int DOCTYPE
Mask for JDOM {@link DocType} object

DOCUMENT

public static final int DOCUMENT
Mask for JDOM {@link Document} object

ELEMENT

public static final int ELEMENT
Mask for JDOM {@link Element} objects

ENTITYREF

public static final int ENTITYREF
Mask for JDOM {@link EntityRef} objects

PI

public static final int PI
Mask for JDOM {@link ProcessingInstruction} objects

TEXT

public static final int TEXT
Mask for JDOM {@link Text} objects

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

equals

public boolean equals(Object obj)
Returns whether the two filters are equivalent (i.e. the matching mask values are identical).

Parameters: obj the object to compare against

Returns: whether the two filters are equal

getFilterMask

public int getFilterMask()
Return current filtering mask.

Returns: the current filtering mask

hashCode

public int hashCode()

matches

public boolean matches(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.

setCDATAVisible

public void setCDATAVisible(boolean visible)
Set visiblity of CDATA objects.

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

setCommentVisible

public void setCommentVisible(boolean visible)
Set visiblity of Comment objects.

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

setDefaultMask

public void setDefaultMask()
Set this filter to allow all legal JDOM objects.

setDocTypeVisible

public void setDocTypeVisible(boolean visible)
Set visiblity of DocType objects.

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

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 of Element objects.

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

setEntityRefVisible

public void setEntityRefVisible(boolean visible)
Set visiblity of EntityRef objects.

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

setFilterMask

public void setFilterMask(int mask)
Set filtering mask.

Parameters: mask the new filtering mask

setPIVisible

public void setPIVisible(boolean visible)
Set visiblity of ProcessingInstruction objects.

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

setTextVisible

public void setTextVisible(boolean visible)
Set visiblity of Text objects.

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

Copyright © 2004 Jason Hunter, Brett McLaughlin. All Rights Reserved.