Class ReplaceTransformer

All Implemented Interfaces:
IXMLConfigurable, IImporterHandler, IDocumentTransformer

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.

XML configuration usage:


<handler
    class="com.norconex.importer.handler.transformer.impl.ReplaceTransformer"
    maxReadSize="(max characters to read at once)"
    sourceCharset="(character encoding)">
  <!-- multiple "restrictTo" tags allowed (only one needs to match) -->
  <restrictTo>
    <fieldMatcher>(field-matching expression)</fieldMatcher>
    <valueMatcher>(value-matching expression)</valueMatcher>
  </restrictTo>
  <!-- multiple replace tags allowed -->
  <replace>
    <valueMatcher>(one or more source values to replace)</valueMatcher>
    <toValue>(replacement value)</toValue>
  </replace>
</handler>

XML usage example:


<handler
    class="ReplaceTransformer">
  <replace>
    <valueMatcher
        replaceAll="true">
      junk food
    </valueMatcher>
    <toValue>healthy food</toValue>
  </replace>
</handler>

The above example reduces all occurrences of "junk food" with "healthy food".

Since:
1.2.0
Author:
Pascal Essiembre