public class CurrentDateTagger extends AbstractDocumentTagger
Adds the current computer UTC date to the specified field
.
If no field
is provided, the date will be added to
document.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 on SimpleDateFormat
.
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).
<handler
class="com.norconex.importer.handler.tagger.impl.CurrentDateTagger"
toField="(target field)"
format="(date format)"
locale="(locale)"
onSet="[append|prepend|replace|optional]">
<!-- multiple "restrictTo" tags allowed (only one needs to match) -->
<restrictTo>
<fieldMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(field-matching expression)
</fieldMatcher>
<valueMatcher
method="[basic|csv|wildcard|regex]"
ignoreCase="[false|true]"
ignoreDiacritic="[false|true]"
partial="[false|true]">
(value-matching expression)
</valueMatcher>
</restrictTo>
</handler>
<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.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_FIELD |
Constructor and Description |
---|
CurrentDateTagger()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
String |
getField()
Deprecated.
Since 3.0.0, use
getToField() |
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 use
getOnSet() . |
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, use
setToField(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 use
setOnSet(PropertySetter) . |
void |
setToField(String toField)
Sets the target field.
|
void |
tagApplicableDocument(HandlerDoc doc,
InputStream document,
ParseState parseState) |
String |
toString() |
tagDocument
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
public static final String DEFAULT_FIELD
public void tagApplicableDocument(HandlerDoc doc, InputStream document, ParseState parseState) throws ImporterHandlerException
tagApplicableDocument
in class AbstractDocumentTagger
ImporterHandlerException
public String getToField()
public void setToField(String toField)
toField
- target field@Deprecated public String getField()
getToField()
@Deprecated public void setField(String toField)
setToField(String)
toField
- target fieldpublic String getFormat()
public void setFormat(String toFormat)
public Locale getLocale()
public void setLocale(Locale locale)
locale
- localepublic PropertySetter getOnSet()
public void setOnSet(PropertySetter onSet)
onSet
- property setter@Deprecated public boolean isOverwrite()
getOnSet()
.true
if overwriting existing value.@Deprecated public void setOverwrite(boolean overwrite)
setOnSet(PropertySetter)
.overwrite
- true
if overwriting existing value.protected void loadHandlerFromXML(XML xml)
AbstractImporterHandler
loadHandlerFromXML
in class AbstractImporterHandler
xml
- XML configurationprotected void saveHandlerToXML(XML xml)
AbstractImporterHandler
saveHandlerToXML
in class AbstractImporterHandler
xml
- the XMLpublic boolean equals(Object other)
equals
in class AbstractImporterHandler
public int hashCode()
hashCode
in class AbstractImporterHandler
public String toString()
toString
in class AbstractImporterHandler
Copyright © 2009–2023 Norconex Inc.. All rights reserved.