public class ReduceConsecutivesTransformer extends AbstractStringTransformer
Reduces specified consecutive characters or strings to only one instance (document content only). If reducing duplicate words, you usually have to add a space at the Beginning or end of the word.
This class can be used as a pre-parsing (text content-types only) or post-parsing handlers.
For more advanced replacement needs, consider using
ReplaceTransformer
instead.
<transformer class="com.norconex.importer.handler.transformer.impl.ReduceConsecutivesTransformer" caseSensitive="[false|true]" sourceCharset="(character encoding)" maxReadSize="(max characters to read at once)" > <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) --> <reduce>(character or string to strip)</reduce> <!-- multiple reduce tags allowed --> </transformer>
You can specify these special characters in your XML:
The following reduces multiple spaces into a single one.
<transformer class="com.norconex.importer.handler.transformer.impl.ReduceConsecutivesTransformer"> <reduce>\s</reduce> </transformer>
Constructor and Description |
---|
ReduceConsecutivesTransformer() |
Modifier and Type | Method and Description |
---|---|
void |
addReductions(String... reductions) |
boolean |
equals(Object other) |
List<String> |
getReductions() |
int |
hashCode() |
boolean |
isCaseSensitive() |
protected void |
loadStringTransformerFromXML(org.apache.commons.configuration.XMLConfiguration xml)
Loads configuration settings specific to the implementing class.
|
protected void |
saveStringTransformerToXML(EnhancedXMLStreamWriter writer)
Saves configuration settings specific to the implementing class.
|
void |
setCaseSensitive(boolean caseSensitive)
Sets whether to ignore case when matching characters or string
to reduce.
|
void |
setReductions(String... reductions) |
String |
toString() |
protected void |
transformStringContent(String reference,
StringBuilder content,
ImporterMetadata metadata,
boolean parsed,
int sectionIndex) |
getMaxReadSize, loadCharStreamTransformerFromXML, saveCharStreamTransformerToXML, setMaxReadSize, transformTextDocument
getSourceCharset, loadHandlerFromXML, saveHandlerToXML, setSourceCharset, transformApplicableDocument
transformDocument
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
protected void transformStringContent(String reference, StringBuilder content, ImporterMetadata metadata, boolean parsed, int sectionIndex)
transformStringContent
in class AbstractStringTransformer
public void setReductions(String... reductions)
public void addReductions(String... reductions)
public boolean isCaseSensitive()
public void setCaseSensitive(boolean caseSensitive)
caseSensitive
- true
to consider character caseprotected void loadStringTransformerFromXML(org.apache.commons.configuration.XMLConfiguration xml) throws IOException
AbstractStringTransformer
loadStringTransformerFromXML
in class AbstractStringTransformer
xml
- xml configurationIOException
- could not load from XMLprotected void saveStringTransformerToXML(EnhancedXMLStreamWriter writer) throws XMLStreamException
AbstractStringTransformer
saveStringTransformerToXML
in class AbstractStringTransformer
writer
- the xml writerXMLStreamException
- could not save to XMLpublic int hashCode()
hashCode
in class AbstractStringTransformer
public boolean equals(Object other)
equals
in class AbstractStringTransformer
public String toString()
toString
in class AbstractStringTransformer
Copyright © 2009–2021 Norconex Inc.. All rights reserved.