Class URLExtractorTagger
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.tagger.AbstractDocumentTagger
-
- com.norconex.importer.handler.tagger.AbstractCharStreamTagger
-
- com.norconex.importer.handler.tagger.impl.URLExtractorTagger
-
- All Implemented Interfaces:
IXMLConfigurable,IImporterHandler,IDocumentTagger
public class URLExtractorTagger extends AbstractCharStreamTagger implements IXMLConfigurable
Extracts unique URLs matching specific patterns in plain text content and store them in a given field.
URL-matching patterns used are relatively simple. It looks for strings starting with
http://,https://, orwww.. The later is prefixed withhttps://when encountered (to make it absolute).The matching is case-insensitive. If you need alternate ways to detect URLs, you can use a combination of
RegexTagger,ReplaceTagger, or create your own implementation.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.If no URLs are found, the target field values (if any) are left intact.
Content source
It is possible to specify a
fromFieldas the source of the text to use instead of using the document content.This class is typically e used as a post-parsing handler only (to ensure we are dealing with text).
XML configuration usage:
<handler class="com.norconex.importer.handler.tagger.impl.URLExtractorTagger" toField="(target field where to store extracted URLs)" maxReadSize="(max characters to read at once)" sourceCharset="(character encoding)"> <!-- multiple "restrictTo" tags allowed (only one needs to match) --> <restrictTo> <fieldMatcher>(field-matching expression)</fieldMatcher> <valueMatcher>(value-matching expression)</valueMatcher> </restrictTo> <fieldMatcher> (Optional field of text to use. Default uses document content.) </fieldMatcher> </handler>XML usage example:
<handler class="URLExtractorTagger" toField="documentURLs"> <restrictTo> <fieldMatcher>document.contentType</fieldMatcher> <valueMatcher>application/pdf</valueMatcher> </restrictTo> </handler>The above example is used as a post-parse handler. It detects URLs in parsed PDFs and store those URLs in a field call "documentURLs".
- Since:
- 3.0.0
- Author:
- Pascal Essiembre
-
-
Constructor Summary
Constructors Constructor Description URLExtractorTagger()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)TextMatchergetFieldMatcher()Gets field matcher for fields containing text.intgetMaxReadSize()Gets the maximum number of characters to read from content for tagging at once.PropertySettergetOnSet()Gets the property setter to use when a value is set.StringgetToField()inthashCode()protected voidloadCharStreamTaggerFromXML(XML xml)Loads configuration settings specific to the implementing class.protected voidsaveCharStreamTaggerToXML(XML xml)Saves configuration settings specific to the implementing class.voidsetFieldMatcher(TextMatcher fieldMatcher)Sets the field matcher for fields containing text.voidsetMaxReadSize(int maxReadSize)Sets the maximum number of characters to read from content for tagging at once.voidsetOnSet(PropertySetter onSet)Sets the property setter to use when a value is set.voidsetToField(String toField)protected voidtagTextDocument(HandlerDoc doc, Reader input, ParseState parseState)StringtoString()-
Methods inherited from class com.norconex.importer.handler.tagger.AbstractCharStreamTagger
getSourceCharset, loadHandlerFromXML, saveHandlerToXML, setSourceCharset, tagApplicableDocument
-
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
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.norconex.commons.lang.xml.IXMLConfigurable
loadFromXML, saveToXML
-
-
-
-
Method Detail
-
tagTextDocument
protected void tagTextDocument(HandlerDoc doc, Reader input, ParseState parseState) throws ImporterHandlerException
- Specified by:
tagTextDocumentin classAbstractCharStreamTagger- Throws:
ImporterHandlerException
-
getToField
public String getToField()
-
setToField
public void setToField(String toField)
-
getFieldMatcher
public TextMatcher getFieldMatcher()
Gets field matcher for fields containing text.- Returns:
- field matcher
-
setFieldMatcher
public void setFieldMatcher(TextMatcher fieldMatcher)
Sets the field matcher for fields containing text.- Parameters:
fieldMatcher- field matcher
-
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
-
getMaxReadSize
public int getMaxReadSize()
Gets the maximum number of characters to read from content for tagging at once. Default isTextReader.DEFAULT_MAX_READ_SIZE.- Returns:
- maximum read size
-
setMaxReadSize
public void setMaxReadSize(int maxReadSize)
Sets the maximum number of characters to read from content for tagging at once.- Parameters:
maxReadSize- maximum read size
-
loadCharStreamTaggerFromXML
protected void loadCharStreamTaggerFromXML(XML xml)
Description copied from class:AbstractCharStreamTaggerLoads configuration settings specific to the implementing class.- Specified by:
loadCharStreamTaggerFromXMLin classAbstractCharStreamTagger- Parameters:
xml- xml configuration
-
saveCharStreamTaggerToXML
protected void saveCharStreamTaggerToXML(XML xml)
Description copied from class:AbstractCharStreamTaggerSaves configuration settings specific to the implementing class. The parent tag along with the "class" attribute are already written. Implementors must not close the writer.- Specified by:
saveCharStreamTaggerToXMLin classAbstractCharStreamTagger- Parameters:
xml- the XML
-
equals
public boolean equals(Object other)
- Overrides:
equalsin classAbstractCharStreamTagger
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractCharStreamTagger
-
toString
public String toString()
- Overrides:
toStringin classAbstractCharStreamTagger
-
-