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 field
already has one or more values,
the new date will be added to the list of
existing values, unless "overwrite" is set to true
.
Can be used both as a pre-parse or post-parse handler.
Since 2.5.2, 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).
<tagger class="com.norconex.importer.handler.tagger.impl.CurrentDateTagger" field="(target field)" format="(date format)" locale="(locale)" overwrite="[false|true]" > <restrictTo caseSensitive="[false|true]" field="(name of header/metadata field name to match)"> (regular expression of value to match) </restrictTo> <!-- multiple "restrictTo" tags allowed (only one needs to match) --> </tagger>
The following will store the current date along with hours and minutes in a "crawl_date" field.
<tagger class="com.norconex.importer.handler.tagger.impl.CurrentDateTagger" field="crawl_date" format="yyyy-MM-dd HH:mm" />
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() |
String |
getFormat() |
Locale |
getLocale()
Gets the locale used for formatting.
|
int |
hashCode() |
boolean |
isOverwrite() |
protected void |
loadHandlerFromXML(org.apache.commons.configuration.XMLConfiguration xml)
Loads configuration settings specific to the implementing class.
|
protected void |
saveHandlerToXML(EnhancedXMLStreamWriter writer)
Saves configuration settings specific to the implementing class.
|
void |
setField(String toField) |
void |
setFormat(String toFormat) |
void |
setLocale(Locale locale)
Sets the locale used for formatting.
|
void |
setOverwrite(boolean overwrite) |
void |
tagApplicableDocument(String reference,
InputStream document,
ImporterMetadata metadata,
boolean parsed) |
String |
toString() |
tagDocument
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
public static final String DEFAULT_FIELD
public void tagApplicableDocument(String reference, InputStream document, ImporterMetadata metadata, boolean parsed) throws ImporterHandlerException
tagApplicableDocument
in class AbstractDocumentTagger
ImporterHandlerException
public String getField()
public void setField(String toField)
public String getFormat()
public void setFormat(String toFormat)
public Locale getLocale()
public void setLocale(Locale locale)
locale
- localepublic boolean isOverwrite()
public void setOverwrite(boolean overwrite)
protected void loadHandlerFromXML(org.apache.commons.configuration.XMLConfiguration xml) throws IOException
AbstractImporterHandler
loadHandlerFromXML
in class AbstractImporterHandler
xml
- xml configurationIOException
- could not load from XMLprotected void saveHandlerToXML(EnhancedXMLStreamWriter writer) throws XMLStreamException
AbstractImporterHandler
saveHandlerToXML
in class AbstractImporterHandler
writer
- the xml writerXMLStreamException
- could not save to XMLpublic String toString()
toString
in class AbstractImporterHandler
public boolean equals(Object other)
equals
in class AbstractImporterHandler
public int hashCode()
hashCode
in class AbstractImporterHandler
Copyright © 2009–2021 Norconex Inc.. All rights reserved.