public class ReplaceTransformer extends AbstractStringTransformer implements IXMLConfigurable
Replaces every occurrences of the given replacements (document content only).
This class can be used as a pre-parsing (text content-types only) or post-parsing handlers.
<transformer class="com.norconex.importer.handler.transformer.impl.ReplaceTransformer" 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) --> <replace> <fromValue>(regex of value to replace)</fromValue> <toValue>(replacement value)</toValue> </replace> <!-- multiple replace tags allowed --> </transformer>
Note: To preserve white space add xml:space="preserve"
to the "toValue" tag, like this:
<toValue xml:space="preserve"> </toValue>
The following reduces all occurrences of "junk food" with "healthy food".
<transformer class="com.norconex.importer.handler.transformer.impl.ReplaceTransformer"> <replace> <fromValue>junk food</fromValue> <toValue>healthy food</toValue> </replace> </transformer>
Constructor and Description |
---|
ReplaceTransformer() |
Modifier and Type | Method and Description |
---|---|
void |
addReplacement(String from,
String to) |
boolean |
equals(Object other) |
Map<String,String> |
getReplacements() |
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.
|
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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
loadFromXML, saveToXML
protected void transformStringContent(String reference, StringBuilder content, ImporterMetadata metadata, boolean parsed, int sectionIndex)
transformStringContent
in class AbstractStringTransformer
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.