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 nofield
is 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
format
attribute, 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 String
DEFAULT_FIELD
-
Constructor Summary
Constructors Constructor Description CurrentDateTagger()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
equals(Object other)
String
getField()
Deprecated.Since 3.0.0, usegetToField()
String
getFormat()
Locale
getLocale()
Gets the locale used for formatting.PropertySetter
getOnSet()
Gets the property setter to use when a value is set.String
getToField()
Gets the target field.int
hashCode()
boolean
isOverwrite()
Deprecated.Since 3.0.0 usegetOnSet()
.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
setField(String toField)
Deprecated.Since 3.0.0, usesetToField(String)
void
setFormat(String toFormat)
void
setLocale(Locale locale)
Sets the locale used for formatting.void
setOnSet(PropertySetter onSet)
Sets the property setter to use when a value is set.void
setOverwrite(boolean overwrite)
Deprecated.Since 3.0.0 usesetOnSet(PropertySetter)
.void
setToField(String toField)
Sets the target field.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
-
-
-
-
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:
tagApplicableDocument
in 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:
true
if 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
-true
if overwriting existing value.
-
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
-
-