public abstract class AbstractStringFilter extends AbstractCharStreamFilter
Base class to facilitate creating filters based on text content, loading
text into StringBuilder
for memory processing.
Since 2.2.0 this class limits the memory used for content
filtering by reading one section of text at a time. Each
sections are sent for filtering once they are read until a match is found.
No two sections exists in memory at once. Sub-classes should
respect this approach. Each section have a maximum number of characters
equal to the maximum read size defined using setMaxReadSize(int)
.
When none is set, the default read size is defined by
TextReader.DEFAULT_MAX_READ_SIZE
.
An attempt is made to break sections nicely after a paragraph, sentence, or word. When not possible, long text will be cut at a size equal to the maximum read size.
Since 3.0.0 the
isStringContentMatching(HandlerDoc, StringBuilder, ParseState, int)
method is invoked at least once, even if there is no content. This gives
subclasses a chance to act on metadata even if there is no content.
Implementors should be conscious about memory when dealing with the string builder.
maxReadSize="(max characters to read at once)"
sourceCharset="(character encoding)"
onMatch="[include|exclude]"
Subclasses inherit the above IXMLConfigurable
attribute(s),
in addition to
<restrictTo>.
Constructor and Description |
---|
AbstractStringFilter() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
int |
getMaxReadSize()
Gets the maximum number of characters to read for filtering
at once.
|
int |
hashCode() |
protected abstract boolean |
isStringContentMatching(HandlerDoc doc,
StringBuilder content,
ParseState parseState,
int sectionIndex) |
protected boolean |
isTextDocumentMatching(HandlerDoc doc,
Reader input,
ParseState parseState) |
protected void |
loadCharStreamFilterFromXML(XML xml)
Loads configuration settings specific to the implementing class.
|
protected abstract void |
loadStringFilterFromXML(XML xml)
Loads configuration settings specific to the implementing class.
|
protected void |
saveCharStreamFilterToXML(XML xml)
Saves configuration settings specific to the implementing class.
|
protected abstract void |
saveStringFilterToXML(XML xml)
Saves configuration settings specific to the implementing class.
|
void |
setMaxReadSize(int maxReadSize)
Sets the maximum number of characters to read for filtering
at once.
|
String |
toString() |
getSourceCharset, isDocumentMatched, loadFilterFromXML, saveFilterToXML, setSourceCharset
acceptDocument, getOnMatch, loadHandlerFromXML, saveHandlerToXML, setOnMatch
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
protected final boolean isTextDocumentMatching(HandlerDoc doc, Reader input, ParseState parseState) throws ImporterHandlerException
isTextDocumentMatching
in class AbstractCharStreamFilter
ImporterHandlerException
public int getMaxReadSize()
TextReader.DEFAULT_MAX_READ_SIZE
.public void setMaxReadSize(int maxReadSize)
maxReadSize
- maximum read sizeprotected abstract boolean isStringContentMatching(HandlerDoc doc, StringBuilder content, ParseState parseState, int sectionIndex) throws ImporterHandlerException
ImporterHandlerException
protected final void saveCharStreamFilterToXML(XML xml)
AbstractCharStreamFilter
saveCharStreamFilterToXML
in class AbstractCharStreamFilter
xml
- the XMLprotected abstract void saveStringFilterToXML(XML xml)
xml
- the XMLprotected final void loadCharStreamFilterFromXML(XML xml)
AbstractCharStreamFilter
loadCharStreamFilterFromXML
in class AbstractCharStreamFilter
xml
- XML configurationprotected abstract void loadStringFilterFromXML(XML xml)
xml
- XML configurationpublic boolean equals(Object other)
equals
in class AbstractCharStreamFilter
public int hashCode()
hashCode
in class AbstractCharStreamFilter
public String toString()
toString
in class AbstractCharStreamFilter
Copyright © 2009–2023 Norconex Inc.. All rights reserved.