Class CurrentDateTagger
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.tagger.AbstractDocumentTagger
-
- com.norconex.importer.handler.tagger.impl.CurrentDateTagger
-
- All Implemented Interfaces:
IXMLConfigurable,IImporterHandler,IDocumentTagger
public class CurrentDateTagger extends AbstractDocumentTagger
Adds the current computer UTC date to the specified
field. If nofieldis provided, the date will be added todocument.importedDate.The default date format is EPOCH (the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC). A custom date format can be specified with the
formatattribute, as per the formatting options found onSimpleDateFormat.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.
It is possible to specify a locale used for formatting dates. The locale is the ISO two-letter language code, with an optional ISO country code, separated with an underscore (e.g., "fr" for French, "fr_CA" for Canadian French). When no locale is specified, the default is "en_US" (US English).
XML configuration usage:
<handler class="com.norconex.importer.handler.tagger.impl.CurrentDateTagger" toField="(target field)" format="(date format)" locale="(locale)"> <!-- multiple "restrictTo" tags allowed (only one needs to match) --> <restrictTo> <fieldMatcher>(field-matching expression)</fieldMatcher> <valueMatcher>(value-matching expression)</valueMatcher> </restrictTo> </handler>XML usage example:
<handler class="CurrentDateTagger" toField="crawl_date" format="yyyy-MM-dd HH:mm"/>The above will store the current date along with hours and minutes in a "crawl_date" field.
- Since:
- 2.2.0
- Author:
- Pascal Essiembre
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_FIELD
-
Constructor Summary
Constructors Constructor Description CurrentDateTagger()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(Object other)StringgetField()Deprecated.Since 3.0.0, usegetToField()StringgetFormat()LocalegetLocale()Gets the locale used for formatting.PropertySettergetOnSet()Gets the property setter to use when a value is set.StringgetToField()Gets the target field.inthashCode()booleanisOverwrite()Deprecated.Since 3.0.0 usegetOnSet().protected voidloadHandlerFromXML(XML xml)Loads configuration settings specific to the implementing class.protected voidsaveHandlerToXML(XML xml)Saves configuration settings specific to the implementing class.voidsetField(String toField)Deprecated.Since 3.0.0, usesetToField(String)voidsetFormat(String toFormat)voidsetLocale(Locale locale)Sets the locale used for formatting.voidsetOnSet(PropertySetter onSet)Sets the property setter to use when a value is set.voidsetOverwrite(boolean overwrite)Deprecated.Since 3.0.0 usesetOnSet(PropertySetter).voidsetToField(String toField)Sets the target field.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
-
-
-
-
Field Detail
-
DEFAULT_FIELD
public static final String DEFAULT_FIELD
- See Also:
- Constant Field Values
-
-
Method Detail
-
tagApplicableDocument
public void tagApplicableDocument(HandlerDoc doc, InputStream document, ParseState parseState) throws ImporterHandlerException
- Specified by:
tagApplicableDocumentin classAbstractDocumentTagger- Throws:
ImporterHandlerException
-
getToField
public String getToField()
Gets the target field.- Returns:
- target field
- Since:
- 3.0.0
-
setToField
public void setToField(String toField)
Sets the target field.- Parameters:
toField- target field- Since:
- 3.0.0
-
getField
@Deprecated public String getField()
Deprecated.Since 3.0.0, usegetToField()Gets the target field.- Returns:
- target field
-
setField
@Deprecated public void setField(String toField)
Deprecated.Since 3.0.0, usesetToField(String)Sets the target field.- Parameters:
toField- target field
-
getFormat
public String getFormat()
-
setFormat
public void setFormat(String toFormat)
-
getLocale
public Locale getLocale()
Gets the locale used for formatting.- Returns:
- locale
- Since:
- 2.5.2
-
setLocale
public void setLocale(Locale locale)
Sets the locale used for formatting.- Parameters:
locale- locale- Since:
- 2.5.2
-
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
-
isOverwrite
@Deprecated public boolean isOverwrite()
Deprecated.Since 3.0.0 usegetOnSet().Gets whether existing value for the same field should be overwritten.- Returns:
trueif overwriting existing value.
-
setOverwrite
@Deprecated public void setOverwrite(boolean overwrite)
Deprecated.Since 3.0.0 usesetOnSet(PropertySetter).Sets whether existing value for the same field should be overwritten.- Parameters:
overwrite-trueif overwriting existing value.
-
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
-
-