Class AbstractDocumentFilter
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.filter.AbstractDocumentFilter
-
- All Implemented Interfaces:
IXMLConfigurable,IDocumentFilter,IOnMatchFilter,IImporterHandler
- Direct Known Subclasses:
AbstractCharStreamFilter,DateMetadataFilter,DOMContentFilter,DOMFilter,EmptyFilter,EmptyMetadataFilter,NumericMetadataFilter,ReferenceFilter,RegexMetadataFilter,RegexReferenceFilter
public abstract class AbstractDocumentFilter extends AbstractImporterHandler implements IDocumentFilter, IOnMatchFilter
Base class for document filters. Subclasses can be set an attribute called "onMatch". The logic whether to include or exclude a document upon matching it is handled by this class. Subclasses only need to focus on whether the document gets matched or not by implementing the
isDocumentMatched(HandlerDoc, InputStream, ParseState)method.Inclusion/exclusion logic:
The logic for accepting or rejecting documents when a subclass condition is met ("matches") is as follow:
Inclusion/exclusion logic Matches? On match Expected behavior yes exclude Document is rejected. yes include Document is accepted. no exclude Document is accepted. no include Document is accepted if it was accepted by at least one filter with onMatch="include". If no other one exists or if none matched, the document is rejected. When multiple filters are defined and a combination of both "include" and "exclude" are possible, the "exclude" will always take precedence. In other words, it only take one matching "exclude" to reject a document, not matter how many matching "include" were triggered.
XML configuration usage:
onMatch="[include|exclude]"Subclasses inherit the above
IXMLConfigurableattribute(s), in addition to <restrictTo>.- Since:
- 2.0.0
- Author:
- Pascal Essiembre
-
-
Constructor Summary
Constructors Constructor Description AbstractDocumentFilter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanacceptDocument(HandlerDoc doc, InputStream input, ParseState parseState)Whether to accepts a document.booleanequals(Object other)OnMatchgetOnMatch()Gets the the on match action (exclude or include).inthashCode()protected abstract booleanisDocumentMatched(HandlerDoc doc, InputStream input, ParseState parseState)protected abstract voidloadFilterFromXML(XML xml)protected voidloadHandlerFromXML(XML xml)Loads configuration settings specific to the implementing class.protected abstract voidsaveFilterToXML(XML xml)protected voidsaveHandlerToXML(XML xml)Saves configuration settings specific to the implementing class.voidsetOnMatch(OnMatch onMatch)StringtoString()-
Methods inherited from class com.norconex.importer.handler.AbstractImporterHandler
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
-
-
-
-
Method Detail
-
getOnMatch
public OnMatch getOnMatch()
Description copied from interface:IOnMatchFilterGets the the on match action (exclude or include).- Specified by:
getOnMatchin interfaceIOnMatchFilter- Returns:
- on match (exclude or include)
-
setOnMatch
public final void setOnMatch(OnMatch onMatch)
-
acceptDocument
public boolean acceptDocument(HandlerDoc doc, InputStream input, ParseState parseState) throws ImporterHandlerException
Description copied from interface:IDocumentFilterWhether to accepts a document.- Specified by:
acceptDocumentin interfaceIDocumentFilter- Parameters:
doc- the document to evaluateinput- document contentparseState- whether the document has been parsed already or not (a parsed document should normally be text-based)- Returns:
trueif document is accepted- Throws:
ImporterHandlerException- problem reading the document
-
isDocumentMatched
protected abstract boolean isDocumentMatched(HandlerDoc doc, InputStream input, ParseState parseState) throws ImporterHandlerException
- Throws:
ImporterHandlerException
-
saveHandlerToXML
protected final void saveHandlerToXML(XML xml)
Description copied from class:AbstractImporterHandlerSaves configuration settings specific to the implementing class.- Specified by:
saveHandlerToXMLin classAbstractImporterHandler- Parameters:
xml- the XML
-
saveFilterToXML
protected abstract void saveFilterToXML(XML xml)
-
loadHandlerFromXML
protected final void loadHandlerFromXML(XML xml)
Description copied from class:AbstractImporterHandlerLoads configuration settings specific to the implementing class.- Specified by:
loadHandlerFromXMLin classAbstractImporterHandler- Parameters:
xml- XML configuration
-
loadFilterFromXML
protected abstract void loadFilterFromXML(XML xml)
-
equals
public boolean equals(Object other)
- Overrides:
equalsin classAbstractImporterHandler
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractImporterHandler
-
toString
public String toString()
- Overrides:
toStringin classAbstractImporterHandler
-
-