Class DomConditionConfig
- All Implemented Interfaces:
Labelable
A condition using a Document Object Model (DOM) representation of an HTML, XHTML, or XML document content to match an element, attribute or value.
In order to construct a DOM tree, text is loaded entirely
into memory. It uses the document content to create the DOM by default,
but it can also use metadata fields. If more than one metadata field
values are identified as the source of DOM content, only one needs to
match for this condition to be true.
Use this condition with caution if you know you'll need to parse
huge files. You can use TextFilter instead if this is a
concern.
The jsoup parser library is used to load the content into a DOM tree. Elements are referenced using a CSS or JQuery-like syntax.
The use of a value matcher is optional. Without one, any element found by the provided DOM selector will constitute a match. If both a DOM selector and a value matcher are provided, the matching selector element value(s) will be retrieved and the value matcher will be applied against it (or them) for a match.
It is possible to control what gets extracted
exactly for matching purposes thanks to the "extract" argument of the
new method setExtract(String). Possible values are:
DomUtil.getElementValue(org.jsoup.nodes.Element,java.lang.String)
Should be used as a pre-parse handler.
Content-types
If you are dealing with multiple document types and you are using this condition on the document content, it is important to restrict this condition to text-based XML-like content only to prevent DOM-parsing errors.
By default this condition only applies to documents matching
the content types listed in CommonMatchers.DOM_CONTENT_TYPES.
Other content types always make this condition false.
You can overwrite these default content types by providing your own content type matcher. Make sure the content types you use represent a file with HTML or XML-like markup tags.
Character encoding
When used as a pre-parse handler, this condition uses the detected
character encoding unless the character encoding
was specified using setSourceCharset(Charset). Since document
parsing should always converts content to UTF-8, UTF-8 is always
assumed when used as a post-parse handler.
XML vs HTML
You can specify which DOM parser to use when reading documents. The default is "html" and will try to normalize/fix the content as HTML. This is generally a desired behavior, but this can sometimes have your selector fail. If you encounter this problem, try switching to "xml" parser, which does not attempt normalization on the content. The drawback with "xml" is you may not get all HTML-specific selector options to work. If you know you are dealing with XML to begin with, specifying "xml" is a good option.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleanGets this condition content-type matcher.Gets what should be extracted for the value.Gets this filter field matcher.Gets the parser to use when creating the DOM-tree.The presumed source character encoding.Gets this condition value matcher.inthashCode()setContentTypeMatcher(TextMatcher contentTypeMatcher) Sets this condition content-type matcher.setExtract(String extract) Sets what should be extracted for the value.setFieldMatcher(TextMatcher fieldMatcher) Sets this condition field matcher.Sets the parser to use when creating the DOM-tree.setSelector(String selector) setSourceCharset(Charset sourceCharset) The presumed source character encoding.setValueMatcher(TextMatcher valueMatcher) Sets this condition value matcher.toString()Methods inherited from class com.norconex.importer.handler.BaseLabelableConfig
getLabel, setLabel
-
Constructor Details
-
DomConditionConfig
public DomConditionConfig()
-
-
Method Details
-
getFieldMatcher
Gets this filter field matcher.- Returns:
- field matcher
-
setFieldMatcher
Sets this condition field matcher.- Parameters:
fieldMatcher- field matcher
-
getValueMatcher
Gets this condition value matcher.- Returns:
- value matcher
-
setValueMatcher
Sets this condition value matcher.- Parameters:
valueMatcher- value matcher
-
getContentTypeMatcher
Gets this condition content-type matcher.- Returns:
- content-type matcher
-
setContentTypeMatcher
Sets this condition content-type matcher.- Parameters:
contentTypeMatcher- content-type matcher
-
getExtract
Gets what should be extracted for the value. One of "text" (default), "html", or "outerHtml".nullmeans this class will use the default ("text").- Returns:
- what should be extracted for the value
-
setExtract
Sets what should be extracted for the value. One of "text" (default), "html", or "outerHtml".nullmeans this class will use the default ("text").- Parameters:
extract- what should be extracted for the value
-
getParser
Gets the parser to use when creating the DOM-tree.- Returns:
html(default) orxml.
-
setParser
Sets the parser to use when creating the DOM-tree.- Parameters:
parser-htmlorxml.
-
getSelector
-
setSelector
-
getSourceCharset
The presumed source character encoding. Usually ignored and presumed to be UTF-8 if the document has been parsed already.- Returns:
- character encoding of the source to be transformed
-
setSourceCharset
The presumed source character encoding. Usually ignored and presumed to be UTF-8 if the document has been parsed already.- Parameters:
sourceCharset- character encoding of the source to be transformed- Returns:
this.
-
equals
- Overrides:
equalsin classBaseLabelableConfig
-
canEqual
- Overrides:
canEqualin classBaseLabelableConfig
-
hashCode
public int hashCode()- Overrides:
hashCodein classBaseLabelableConfig
-
toString
- Overrides:
toStringin classBaseLabelableConfig
-