Class ReplaceTagger
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.tagger.AbstractDocumentTagger
-
- com.norconex.importer.handler.tagger.impl.ReplaceTagger
-
- All Implemented Interfaces:
IXMLConfigurable,IImporterHandler,IDocumentTagger
public class ReplaceTagger extends AbstractDocumentTagger
Replaces an existing metadata value with another one. The "toField" argument is optional.
It is possible to only keep values that changed from a replacement and discard others by setting "discardUnchanged" to
true.Storing values in an existing field
If a target field with the same name already exists for a document, values will be added to the end of the existing value list. It is possible to change this default behavior by supplying a
PropertySetter.Not specifying a "toValue" will delete the matches from sources values.
Can be used both as a pre-parse or post-parse handler.
You can specify whether matches should be made against the whole field value or not (default). You can also specify whether replacement should be attempted on first match only (default) or all occurrences. This last option is only applicable when whole value matching is
false.XML configuration usage:
<handler class="com.norconex.importer.handler.tagger.impl.ReplaceTagger"> <!-- 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 toField="(optional target field name)"> discardUnchanged="[false|true]"> <fieldMatcher> (one or more matching fields to have their values replaced) </fieldMatcher> <valueMatcher>(one or more source values to replace)</valueMatcher> <toValue>(replacement value)</toValue> </replace> </handler>XML usage example:
<handler class="ReplaceTagger"> <replace> <fieldMatcher>fruit</fieldMatcher> <valueMatcher replaceAll="true"> apple </valueMatcher> <toValue>orange</toValue> </replace> </handler>The following example replaces occurrences of "apple" to "orange" in the "fruit" field.
- Author:
- Pascal Essiembre
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReplaceTagger.Replacement
-
Constructor Summary
Constructors Constructor Description ReplaceTagger()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddReplacement(ReplaceTagger.Replacement replacement)Adds a replacement.booleanequals(Object other)List<ReplaceTagger.Replacement>getReplacements()inthashCode()protected voidloadHandlerFromXML(XML xml)Loads configuration settings specific to the implementing class.voidremoveReplacement(String fromField)Deprecated.protected voidsaveHandlerToXML(XML xml)Saves configuration settings specific to the implementing class.voidtagApplicableDocument(HandlerDoc doc, InputStream document, ParseState parseState)StringtoString()-
Methods inherited from class com.norconex.importer.handler.tagger.AbstractDocumentTagger
tagDocument
-
Methods inherited from class com.norconex.importer.handler.AbstractImporterHandler
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
-
-
-
-
Method Detail
-
tagApplicableDocument
public void tagApplicableDocument(HandlerDoc doc, InputStream document, ParseState parseState) throws ImporterHandlerException
- Specified by:
tagApplicableDocumentin classAbstractDocumentTagger- Throws:
ImporterHandlerException
-
getReplacements
public List<ReplaceTagger.Replacement> getReplacements()
-
removeReplacement
@Deprecated public void removeReplacement(String fromField)
Deprecated.
-
addReplacement
public void addReplacement(ReplaceTagger.Replacement replacement)
Adds a replacement.- Parameters:
replacement- the replacement- Since:
- 2.2.0
-
loadHandlerFromXML
protected void loadHandlerFromXML(XML xml)
Description copied from class:AbstractImporterHandlerLoads configuration settings specific to the implementing class.- Specified by:
loadHandlerFromXMLin classAbstractImporterHandler- Parameters:
xml- XML configuration
-
saveHandlerToXML
protected void saveHandlerToXML(XML xml)
Description copied from class:AbstractImporterHandlerSaves configuration settings specific to the implementing class.- Specified by:
saveHandlerToXMLin classAbstractImporterHandler- Parameters:
xml- the XML
-
equals
public boolean equals(Object other)
- Overrides:
equalsin classAbstractImporterHandler
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractImporterHandler
-
toString
public String toString()
- Overrides:
toStringin classAbstractImporterHandler
-
-