Class GenericCanonicalLinkDetector
java.lang.Object
com.norconex.crawler.web.doc.operations.canon.impl.GenericCanonicalLinkDetector
- All Implemented Interfaces:
Configurable<GenericCanonicalLinkDetectorConfig>,CanonicalLinkDetector
public class GenericCanonicalLinkDetector
extends Object
implements CanonicalLinkDetector, Configurable<GenericCanonicalLinkDetectorConfig>
Generic canonical link detector. It detects links from the HTTP headers as well as HTML files. Good canonical reference documentation can be found on this Google Webmaster Tools help page.
HTTP Headers
This detector will look for a metadata field (normally obtained from the HTTP Headers) name called "Link" with a value following this pattern:
<http://www.example.com/sample.pdf> rel="canonical"
All documents will be verified for a canonical link (not just HTML).
Document content
This detector will look within the HTML <head> tags for a <link> tag following this pattern:
<link rel="canonical" href="https://www.example.com/sample" />
Only HTML documents will be verified for a canonical link. By default, these content-types are considered HTML:
text/html, application/xhtml+xml, vnd.wap.xhtml+xml, x-asp
You can specify your own content types as long as they contain HTML text.
The above example ignores canonical link resolution.
- Since:
- 2.2.0
-
Field Summary
Fields inherited from interface com.norconex.commons.lang.config.Configurable
PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleandetectFromContent(String reference, InputStream is, ContentType contentType) Detects from a document content the presence of a canonical URL.detectFromMetadata(String reference, Properties metadata) Detects from metadata gathered so far, which when invoked, is normally the HTTP header values.booleaninthashCode()toString()
-
Constructor Details
-
GenericCanonicalLinkDetector
public GenericCanonicalLinkDetector()
-
-
Method Details
-
getConfiguration
- Specified by:
getConfigurationin interfaceConfigurable<GenericCanonicalLinkDetectorConfig>
-
detectFromMetadata
Description copied from interface:CanonicalLinkDetectorDetects from metadata gathered so far, which when invoked, is normally the HTTP header values.- Specified by:
detectFromMetadatain interfaceCanonicalLinkDetector- Parameters:
reference- document referencemetadata- metadata object containing HTTP headers- Returns:
- the detected canonical URL or
nullif none is found.
-
detectFromContent
public String detectFromContent(String reference, InputStream is, ContentType contentType) throws IOException Description copied from interface:CanonicalLinkDetectorDetects from a document content the presence of a canonical URL. This occur before a document gets parsed and may apply to only a few content types.- Specified by:
detectFromContentin interfaceCanonicalLinkDetector- Parameters:
reference- document referenceis- the document content input streamcontentType- the document content type- Returns:
- the detected canonical URL or
nullif none is found. - Throws:
IOException- problem reading content
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-