Class ScriptTransformer
java.lang.Object
com.norconex.importer.handler.transformer.impl.ScriptTransformer
- All Implemented Interfaces:
Configurable<ScriptTransformerConfig>,ConfigurableDocHandler<ScriptTransformerConfig>,DocHandler
public class ScriptTransformer
extends Object
implements ConfigurableDocHandler<ScriptTransformerConfig>
Transform incoming documents using a scripting language.
Refer to ScriptRunner for more information on using a scripting
language with Norconex Importer.
How to transform documents with scripting:
The following are variables made available to your script for each document:
- reference: Document unique reference as a string.
- content: Document content, as a string
(of
maxReadSizelength). - metadata: Document metadata as an
Propertiesobject. - parsed: Whether the document was already parsed, as a boolean.
- sectionIndex: Content section index if it had to be split
(as per
maxReadSize), as an integer.
The expected return value from your script is a string holding the modified content.
Usage examples:
The following examples replace all occurrences of "Alice" with "Roger" in a document content.
- See Also:
-
Field Summary
Fields inherited from interface com.norconex.commons.lang.config.Configurable
PROPERTYFields inherited from interface com.norconex.importer.handler.DocHandler
NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleanbooleanhandle(DocHandlerContext docCtx) Perform any operations on a document.inthashCode()voidsetScriptRunner(ScriptRunner<Object> scriptRunner) toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.norconex.importer.handler.DocHandler
close, init
-
Constructor Details
-
ScriptTransformer
public ScriptTransformer()
-
-
Method Details
-
handle
Description copied from interface:DocHandlerPerform any operations on a document.- Specified by:
handlein interfaceDocHandler- Parameters:
docCtx- the document handling context- Returns:
falseto stop processing and reject a document ortrueto proceed to the next configured handler.- Throws:
IOException- An I/O exception of some sort has occurred
-
getConfiguration
- Specified by:
getConfigurationin interfaceConfigurable<ScriptTransformerConfig>
-
getScriptRunner
-
setScriptRunner
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-