Class ConstantTagger
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.tagger.AbstractDocumentTagger
-
- com.norconex.importer.handler.tagger.impl.ConstantTagger
-
- All Implemented Interfaces:
IXMLConfigurable
,IImporterHandler
,IDocumentTagger
public class ConstantTagger extends AbstractDocumentTagger
Define and add constant values to documents. To add multiple constant values under the same constant name, repeat the constant entry with a different value.
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 with
setOnSet(PropertySetter)
.Can be used both as a pre-parse or post-parse handler.
XML configuration usage:
<handler class="com.norconex.importer.handler.tagger.impl.ConstantTagger"> <!-- multiple "restrictTo" tags allowed (only one needs to match) --> <restrictTo> <fieldMatcher>(field-matching expression)</fieldMatcher> <valueMatcher>(value-matching expression)</valueMatcher> </restrictTo> <!-- multiple constant tags allowed --> <constant name="CONSTANT_NAME"> Constant Value </constant> </handler>
XML usage example:
<handler class="ConstantTagger"> <constant name="source"> web </constant> </handler>
The above example adds a constant to incoming documents to identify they were web documents.
- Author:
- Pascal Essiembre
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConstantTagger.OnConflict
Deprecated.
-
Constructor Summary
Constructors Constructor Description ConstantTagger()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addConstant(String name, String value)
boolean
equals(Object other)
Map<String,List<String>>
getConstants()
ConstantTagger.OnConflict
getOnConflict()
Deprecated.Since 3.0.0, usegetOnSet()
insteadPropertySetter
getOnSet()
Gets the property setter to use when a value is set.int
hashCode()
protected void
loadHandlerFromXML(XML xml)
Loads configuration settings specific to the implementing class.void
removeConstant(String name)
protected void
saveHandlerToXML(XML xml)
Saves configuration settings specific to the implementing class.void
setOnConflict(ConstantTagger.OnConflict onConflict)
Deprecated.Since 3.0.0, usesetOnSet(PropertySetter)
insteadvoid
setOnSet(PropertySetter onSet)
Sets the property setter to use when a value is set.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
-
getOnSet
public PropertySetter getOnSet()
Gets the property setter to use when a value is set.- Returns:
- property setter
- Since:
- 3.0.0
-
setOnSet
public void setOnSet(PropertySetter onSet)
Sets the property setter to use when a value is set.- Parameters:
onSet
- property setter- Since:
- 3.0.0
-
getOnConflict
@Deprecated public ConstantTagger.OnConflict getOnConflict()
Deprecated.Since 3.0.0, usegetOnSet()
insteadGets the conflict resolution strategy.- Returns:
- conflict resolution strategy
- Since:
- 2.7.0
-
setOnConflict
@Deprecated public void setOnConflict(ConstantTagger.OnConflict onConflict)
Deprecated.Since 3.0.0, usesetOnSet(PropertySetter)
insteadSets the conflict resolution strategy.- Parameters:
onConflict
- conflict resolution strategy.- Since:
- 2.7.0
-
removeConstant
public void removeConstant(String name)
-
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
-
-