Class AbstractStringTransformer
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.transformer.AbstractDocumentTransformer
-
- com.norconex.importer.handler.transformer.AbstractCharStreamTransformer
-
- com.norconex.importer.handler.transformer.AbstractStringTransformer
-
- All Implemented Interfaces:
IXMLConfigurable,IImporterHandler,IDocumentTransformer
- Direct Known Subclasses:
ReduceConsecutivesTransformer,ReplaceTransformer,ScriptTransformer,StripAfterTransformer,StripBeforeTransformer,StripBetweenTransformer
public abstract class AbstractStringTransformer extends AbstractCharStreamTransformer
Base class to facilitate creating transformers on text content, loading text into a
StringBuilderfor memory processing.Since 2.2.0 this class limits the memory used for content transformation by reading one section of text at a time. Each sections are sent for transformation once they are read, so that no two sections exists in memory at once. Sub-classes should respect this approach. Each of them 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 byTextReader.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.
Implementors should be conscious about memory when dealing with the string builder.
XML configuration usage:
maxReadSize="(max characters to read at once)" sourceCharset="(character encoding)"Subclasses inherit the above
IXMLConfigurableattribute(s), in addition to <restrictTo>.Subclasses inherit this
IXMLConfigurableconfiguration:<!-- parent tag has these attribute: maxReadSize="(max characters to read at once)" sourceCharset="(character encoding)" --> <restrictTo caseSensitive="[false|true]" field="(name of header/metadata field name to match)" > (regular expression of value to match) </restrictTo> <!-- multiple "restrictTo" tags allowed (only one needs to match) -->- Author:
- Pascal Essiembre
-
-
Constructor Summary
Constructors Constructor Description AbstractStringTransformer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)intgetMaxReadSize()Gets the maximum number of characters to read and transform at once.inthashCode()protected voidloadCharStreamTransformerFromXML(XML xml)Loads configuration settings specific to the implementing class.protected abstract voidloadStringTransformerFromXML(XML xml)Loads configuration settings specific to the implementing class.protected voidsaveCharStreamTransformerToXML(XML xml)Saves configuration settings specific to the implementing class.protected abstract voidsaveStringTransformerToXML(XML xml)Saves configuration settings specific to the implementing class.voidsetMaxReadSize(int maxReadSize)Sets the maximum number of characters to read and transform at once.StringtoString()protected abstract voidtransformStringContent(HandlerDoc doc, StringBuilder content, ParseState parseState, int sectionIndex)protected voidtransformTextDocument(HandlerDoc doc, Reader input, Writer output, ParseState parseState)-
Methods inherited from class com.norconex.importer.handler.transformer.AbstractCharStreamTransformer
getSourceCharset, loadHandlerFromXML, saveHandlerToXML, setSourceCharset, transformApplicableDocument
-
Methods inherited from class com.norconex.importer.handler.transformer.AbstractDocumentTransformer
transformDocument
-
Methods inherited from class com.norconex.importer.handler.AbstractImporterHandler
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
-
-
-
-
Method Detail
-
transformTextDocument
protected final void transformTextDocument(HandlerDoc doc, Reader input, Writer output, ParseState parseState) throws ImporterHandlerException
- Specified by:
transformTextDocumentin classAbstractCharStreamTransformer- Throws:
ImporterHandlerException
-
getMaxReadSize
public int getMaxReadSize()
Gets the maximum number of characters to read and transform at once. Default isTextReader.DEFAULT_MAX_READ_SIZE.- Returns:
- maximum read size
-
setMaxReadSize
public void setMaxReadSize(int maxReadSize)
Sets the maximum number of characters to read and transform at once.- Parameters:
maxReadSize- maximum read size
-
transformStringContent
protected abstract void transformStringContent(HandlerDoc doc, StringBuilder content, ParseState parseState, int sectionIndex) throws ImporterHandlerException
- Throws:
ImporterHandlerException
-
saveCharStreamTransformerToXML
protected final void saveCharStreamTransformerToXML(XML xml)
Description copied from class:AbstractCharStreamTransformerSaves configuration settings specific to the implementing class. The parent tag along with the "class" attribute are already written. Implementors must not close the writer.- Specified by:
saveCharStreamTransformerToXMLin classAbstractCharStreamTransformer- Parameters:
xml- the XML
-
saveStringTransformerToXML
protected abstract void saveStringTransformerToXML(XML xml)
Saves configuration settings specific to the implementing class. The parent tag along with the "class" attribute are already written. Implementors must not close the writer.- Parameters:
xml- the XML
-
loadCharStreamTransformerFromXML
protected final void loadCharStreamTransformerFromXML(XML xml)
Description copied from class:AbstractCharStreamTransformerLoads configuration settings specific to the implementing class.- Specified by:
loadCharStreamTransformerFromXMLin classAbstractCharStreamTransformer- Parameters:
xml- XML configuration
-
loadStringTransformerFromXML
protected abstract void loadStringTransformerFromXML(XML xml)
Loads configuration settings specific to the implementing class.- Parameters:
xml- XML configuration
-
equals
public boolean equals(Object other)
- Overrides:
equalsin classAbstractCharStreamTransformer
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractCharStreamTransformer
-
toString
public String toString()
- Overrides:
toStringin classAbstractCharStreamTransformer
-
-