java.lang.Object
org.htmlunit.cyberneko.HTMLConfiguration
- All Implemented Interfaces:
XMLParserConfiguration
An XNI-based parser configuration that can be used to parse HTML
documents. This configuration can be used directly in order to
parse HTML documents or can be used in conjunction with any XNI
based tools, such as the Xerces2 implementation.
This configuration recognizes the following features:
- http://cyberneko.org/html/features/augmentations
- http://cyberneko.org/html/features/report-errors
- http://cyberneko.org/html/features/report-errors/simple
- and
- the features supported by the scanner and tag balancer components.
This configuration recognizes the following properties:
- http://cyberneko.org/html/properties/names/elems
- http://cyberneko.org/html/properties/names/attrs
- http://cyberneko.org/html/properties/filters
- http://cyberneko.org/html/properties/error-reporter
- and
- the properties supported by the scanner and tag balancer.
For complete usage information, refer to the documentation.
- Author:
- Andy Clark
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classDefines an error reporter for reporting HTML errors. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringInclude infoset augmentations.protected static final StringError domain.protected static final StringError reporter.static final StringPipeline filters.protected static final StringModify HTML attribute names: { "upper", "lower", "default" }.protected static final StringModify HTML element names: { "upper", "lower", "default" }.protected static final StringNamespaces.protected static final StringReport errors.protected static final StringSimple report format. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.HTMLConfiguration(HTMLElements htmlElements) HTMLConfiguration(HTMLElementsProvider htmlElements) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddComponent(HTMLComponent component) voidaddRecognizedFeatures(String[] featureIds) Allows a parser to add parser specific features to be recognized and managed by the parser configuration.voidaddRecognizedProperties(String[] propertyIds) Allows a parser to add parser specific properties to be recognized and managed by the parser configuration.protected voidcheckFeature(String featureId) Check a feature.protected voidcheckProperty(String propertyId) Check a property.voidcleanup()If the application decides to terminate parsing before the xml document is fully parsed, the application should call this method to free any resource allocated during parsing.protected HTMLScannervoidevaluateInputSource(XMLInputSource inputSource) EXPERIMENTAL: may change in next release
Immediately evaluates an input source and add the new content (e.g.Return the registered document handler.Returns the registered error handler.booleangetFeature(String featureId) Returns the state of a feature.getProperty(String propertyId) Returns the value of a property.booleanparse(boolean complete) Parses the document in a pull parsing fashion.voidparse(XMLInputSource source) Parses a document.voidpushInputSource(XMLInputSource inputSource) Pushes an input source onto the current entity stack.protected voidreset()Resets the parser configuration.voidsetDocumentHandler(XMLDocumentHandler handler) Sets the document handler to receive information about the document.voidsetErrorHandler(XMLErrorHandler handler) Sets the error handler.voidsetFeature(String featureId, boolean state) Set the state of a feature.voidsetInputSource(XMLInputSource inputSource) Sets the input source for the document to parse.voidsetProperty(String propertyId, Object value) setProperty.
-
Field Details
-
NAMESPACES
Namespaces.- See Also:
-
AUGMENTATIONS
Include infoset augmentations.- See Also:
-
REPORT_ERRORS
Report errors.- See Also:
-
SIMPLE_ERROR_FORMAT
Simple report format.- See Also:
-
NAMES_ELEMS
Modify HTML element names: { "upper", "lower", "default" }.- See Also:
-
NAMES_ATTRS
Modify HTML attribute names: { "upper", "lower", "default" }.- See Also:
-
FILTERS
Pipeline filters.- See Also:
-
ERROR_REPORTER
Error reporter.- See Also:
-
ERROR_DOMAIN
Error domain.- See Also:
-
-
Constructor Details
-
HTMLConfiguration
public HTMLConfiguration()Default constructor. -
HTMLConfiguration
-
HTMLConfiguration
-
-
Method Details
-
createDocumentScanner
-
pushInputSource
Pushes an input source onto the current entity stack. This enables the scanner to transparently scan new content (e.g. the output written by an embedded script). At the end of the current entity, the scanner returns where it left off at the time this entity source was pushed.Hint: To use this feature to insert the output of <SCRIPT> tags, remember to buffer the entire output of the processed instructions before pushing a new input source. Otherwise, events may appear out of sequence.
- Parameters:
inputSource- The new input source to start scanning.- See Also:
-
evaluateInputSource
EXPERIMENTAL: may change in next release
Immediately evaluates an input source and add the new content (e.g. the output written by an embedded script).- Parameters:
inputSource- The new input source to start scanning.- See Also:
-
setFeature
Set the state of a feature.Set the state of any feature in a SAX2 parser. The parser might not recognize the feature, and if it does recognize it, it might not be able to fulfill the request.
- Specified by:
setFeaturein interfaceXMLParserConfiguration- Parameters:
featureId- The unique identifier (URI) of the feature.state- The requested state of the feature (true or false).- Throws:
XMLConfigurationException- If the requested feature is not known.
-
setProperty
setProperty.- Specified by:
setPropertyin interfaceXMLParserConfiguration- Parameters:
propertyId- the property idvalue- the value- Throws:
XMLConfigurationException- If the requested feature is not known.
-
setDocumentHandler
Description copied from interface:XMLParserConfigurationSets the document handler to receive information about the document.- Specified by:
setDocumentHandlerin interfaceXMLParserConfiguration- Parameters:
handler- The document handler.
-
getDocumentHandler
Return the registered document handler.- Specified by:
getDocumentHandlerin interfaceXMLParserConfiguration- Returns:
- the registered document handler.
-
setErrorHandler
Description copied from interface:XMLParserConfigurationSets the error handler.- Specified by:
setErrorHandlerin interfaceXMLParserConfiguration- Parameters:
handler- The error resolver.
-
getErrorHandler
Returns the registered error handler.- Specified by:
getErrorHandlerin interfaceXMLParserConfiguration- Returns:
- the registered error handler.
-
getHtmlElements
- Returns:
- the configured
HTMLElements
-
getHtmlComponents
- Returns:
- the configured
ListofHTMLComponent's
-
getDocumentScanner
- Returns:
- the configured
HTMLScanner
-
getTagBalancer
- Returns:
- the configured
HTMLTagBalancer
-
getNamespaceBinder
- Returns:
- the configured
NamespaceBinder
-
parse
Parses a document.- Specified by:
parsein interfaceXMLParserConfiguration- Parameters:
source- The input source for the top-level of the XML document.- Throws:
XNIException- Any XNI exception, possibly wrapping another exception.IOException- An IO exception from the parser, possibly from a byte stream or character stream supplied by the parser.
-
setInputSource
public void setInputSource(XMLInputSource inputSource) throws XMLConfigurationException, IOException Sets the input source for the document to parse.- Specified by:
setInputSourcein interfaceXMLParserConfiguration- Parameters:
inputSource- The document's input source.- Throws:
XMLConfigurationException- Thrown if there is a configuration error when initializing the parser.IOException- Thrown on I/O error.- See Also:
-
parse
Parses the document in a pull parsing fashion.- Specified by:
parsein interfaceXMLParserConfiguration- Parameters:
complete- True if the pull parser should parse the remaining document completely.- Returns:
- True if there is more document to parse.
- Throws:
XNIException- Any XNI exception, possibly wrapping another exception.IOException- An IO exception from the parser, possibly from a byte stream or character stream supplied by the parser.- See Also:
-
cleanup
public void cleanup()If the application decides to terminate parsing before the xml document is fully parsed, the application should call this method to free any resource allocated during parsing. For example, close all opened streams.- Specified by:
cleanupin interfaceXMLParserConfiguration
-
addComponent
-
reset
Resets the parser configuration.- Throws:
XMLConfigurationException
-
addRecognizedFeatures
Allows a parser to add parser specific features to be recognized and managed by the parser configuration.- Specified by:
addRecognizedFeaturesin interfaceXMLParserConfiguration- Parameters:
featureIds- An array of the additional feature identifiers to be recognized.
-
addRecognizedProperties
Allows a parser to add parser specific properties to be recognized and managed by the parser configuration.- Specified by:
addRecognizedPropertiesin interfaceXMLParserConfiguration- Parameters:
propertyIds- An array of the additional property identifiers to be recognized.
-
getFeature
Returns the state of a feature.- Specified by:
getFeaturein interfaceXMLParserConfiguration- Parameters:
featureId- the unique identifier of the feature- Returns:
trueif the feature is enabled,falseotherwise- Throws:
XMLConfigurationException- if the feature identifier is not recognized or if a configuration error occurs
-
getProperty
Returns the value of a property.- Specified by:
getPropertyin interfaceXMLParserConfiguration- Parameters:
propertyId- the unique identifier of the property- Returns:
- the value associated with the property, or
nullif none is set - Throws:
XMLConfigurationException- if the property identifier is not recognized or if a configuration error occurs
-
checkFeature
Check a feature. If feature is known and supported, this method simply returns. Otherwise, the appropriate exception is thrown.- Parameters:
featureId- The unique identifier (URI) of the feature.- Throws:
XMLConfigurationException- If the requested feature is not known.
-
checkProperty
Check a property. If the property is known and supported, this method simply returns. Otherwise, the appropriate exception is thrown.- Parameters:
propertyId- The unique identifier (URI) of the property being set.- Throws:
XMLConfigurationException- If the requested feature is not known.
-