Class CopyTagger
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.tagger.AbstractDocumentTagger
-
- com.norconex.importer.handler.tagger.impl.CopyTagger
-
- All Implemented Interfaces:
IXMLConfigurable
,IImporterHandler
,IDocumentTagger
public class CopyTagger extends AbstractDocumentTagger
Copies metadata fields.
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
.Can be used both as a pre-parse or post-parse handler.
XML configuration usage:
<handler class="com.norconex.importer.handler.tagger.impl.CopyTagger"> <!-- multiple "restrictTo" tags allowed (only one needs to match) --> <restrictTo> <fieldMatcher>(field-matching expression)</fieldMatcher> <valueMatcher>(value-matching expression)</valueMatcher> </restrictTo> <!-- multiple copy tags allowed --> <copy toField="(to field)"> <fieldMatcher>(one or more matching fields to copy)</fieldMatcher> </copy> </handler>
XML usage example:
<handler class="CopyTagger"> <copy toField="author" onSet="append"> <fieldMatcher method="regex"> (creator|publisher) </fieldMatcher> </copy> </handler>
Copies the value of a "creator" and "publisher" fields into an "author" field, adding to any existing values in the "author" field.
- Since:
- 1.3.0
- Author:
- Pascal Essiembre
-
-
Constructor Summary
Constructors Constructor Description CopyTagger()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addCopyDetails(TextMatcher fieldMatcher, String toField, PropertySetter onSet)
Adds copy instructions.void
addCopyDetails(String fromField, String toField)
Adds copy instructions, adding to any existing values on the target field.void
addCopyDetails(String fromField, String toField, boolean overwrite)
Deprecated.Since 3.0.0, useaddCopyDetails(TextMatcher, String, PropertySetter)
.boolean
equals(Object other)
int
hashCode()
protected void
loadHandlerFromXML(XML xml)
Loads configuration settings specific to the implementing class.protected void
saveHandlerToXML(XML xml)
Saves configuration settings specific to the implementing class.void
tagApplicableDocument(HandlerDoc doc, InputStream document, ParseState parseState)
String
toString()
-
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:
tagApplicableDocument
in classAbstractDocumentTagger
- Throws:
ImporterHandlerException
-
addCopyDetails
public void addCopyDetails(String fromField, String toField)
Adds copy instructions, adding to any existing values on the target field.- Parameters:
fromField
- source field nametoField
- target field name
-
addCopyDetails
public void addCopyDetails(TextMatcher fieldMatcher, String toField, PropertySetter onSet)
Adds copy instructions.- Parameters:
fieldMatcher
- source field(s)toField
- target field nameonSet
- strategy to use when a value is copied over an existing one- Since:
- 3.0.0
-
addCopyDetails
@Deprecated public void addCopyDetails(String fromField, String toField, boolean overwrite)
Deprecated.Since 3.0.0, useaddCopyDetails(TextMatcher, String, PropertySetter)
.Adds copy instructions.- Parameters:
fromField
- source field nametoField
- target field nameoverwrite
- whether toField overwrite target field if it exists
-
loadHandlerFromXML
protected void loadHandlerFromXML(XML xml)
Description copied from class:AbstractImporterHandler
Loads configuration settings specific to the implementing class.- Specified by:
loadHandlerFromXML
in classAbstractImporterHandler
- Parameters:
xml
- XML configuration
-
saveHandlerToXML
protected void saveHandlerToXML(XML xml)
Description copied from class:AbstractImporterHandler
Saves configuration settings specific to the implementing class.- Specified by:
saveHandlerToXML
in classAbstractImporterHandler
- Parameters:
xml
- the XML
-
equals
public boolean equals(Object other)
- Overrides:
equals
in classAbstractImporterHandler
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractImporterHandler
-
toString
public String toString()
- Overrides:
toString
in classAbstractImporterHandler
-
-