public class ScriptFilter extends AbstractStringFilter
Filter incoming documents using a scripting language.
The default script engine is JavaScript
.
Refer to ScriptRunner
for more information on using a scripting
language with Norconex Importer.
The following are variables made available to your script for each document:
maxReadSize
length).ImporterMetadata
object.The expected return value from your script is a boolean indicating whether the document was matched or not.
<filter class="com.norconex.importer.handler.filter.impl.ScriptFilter" engineName="(script engine name)" onMatch="[include|exclude]" sourceCharset="(character encoding)" maxReadSize="(max content 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) --> <script>(your script)</script> </filter>
<filter class="com.norconex.importer.handler.filter.impl.ScriptFilter"> <script><![CDATA[ var isAppleDoc = metadata.getString('fruit') == 'apple' || content.indexOf('Apple') > -1; /*return*/ isAppleDoc; ]]></script> </filter>
<filter class="com.norconex.importer.handler.filter.impl.ScriptFilter" engineName="lua"> <script><![CDATA[ local isAppleDoc = metadata:getString('fruit') == 'apple' and content:find('Apple') ~= nil; return isAppleDoc; ]]></script> </filter>
ScriptRunner
Constructor and Description |
---|
ScriptFilter() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
String |
getEngineName() |
String |
getScript() |
int |
hashCode() |
protected boolean |
isStringContentMatching(String reference,
StringBuilder content,
ImporterMetadata metadata,
boolean parsed,
int sectionIndex) |
protected void |
loadStringFilterFromXML(org.apache.commons.configuration.XMLConfiguration xml)
Loads configuration settings specific to the implementing class.
|
protected void |
saveStringFilterToXML(EnhancedXMLStreamWriter writer)
Saves configuration settings specific to the implementing class.
|
void |
setEngineName(String engineName) |
void |
setScript(String script) |
String |
toString() |
getMaxReadSize, isTextDocumentMatching, loadCharStreamFilterFromXML, saveCharStreamFilterToXML, setMaxReadSize
getSourceCharset, isDocumentMatched, loadFilterFromXML, saveFilterToXML, setSourceCharset
acceptDocument, getOnMatch, loadHandlerFromXML, saveHandlerToXML, setOnMatch
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
public String getEngineName()
public void setEngineName(String engineName)
public String getScript()
public void setScript(String script)
protected boolean isStringContentMatching(String reference, StringBuilder content, ImporterMetadata metadata, boolean parsed, int sectionIndex) throws ImporterHandlerException
isStringContentMatching
in class AbstractStringFilter
ImporterHandlerException
protected void saveStringFilterToXML(EnhancedXMLStreamWriter writer) throws XMLStreamException
AbstractStringFilter
saveStringFilterToXML
in class AbstractStringFilter
writer
- the xml writerXMLStreamException
- could not save to XMLprotected void loadStringFilterFromXML(org.apache.commons.configuration.XMLConfiguration xml) throws IOException
AbstractStringFilter
loadStringFilterFromXML
in class AbstractStringFilter
xml
- xml configurationIOException
- could not load from XMLpublic boolean equals(Object other)
equals
in class AbstractStringFilter
public int hashCode()
hashCode
in class AbstractStringFilter
public String toString()
toString
in class AbstractStringFilter
Copyright © 2009–2021 Norconex Inc.. All rights reserved.