Class HTMLConfiguration

java.lang.Object
org.htmlunit.cyberneko.HTMLConfiguration
All Implemented Interfaces:
XMLParserConfiguration

public class HTMLConfiguration extends Object implements 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:
  • Field Details

  • Constructor Details

    • HTMLConfiguration

      public HTMLConfiguration()
      Default constructor.
    • HTMLConfiguration

      public HTMLConfiguration(HTMLElements htmlElements)
    • HTMLConfiguration

      public HTMLConfiguration(HTMLElementsProvider htmlElements)
  • Method Details

    • createDocumentScanner

      protected HTMLScanner createDocumentScanner()
    • pushInputSource

      public void pushInputSource(XMLInputSource inputSource)
      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

      public void evaluateInputSource(XMLInputSource inputSource)
      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

      public void setFeature(String featureId, boolean state) throws XMLConfigurationException
      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:
      setFeature in interface XMLParserConfiguration
      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

      public void setProperty(String propertyId, Object value) throws XMLConfigurationException
      setProperty.
      Specified by:
      setProperty in interface XMLParserConfiguration
      Parameters:
      propertyId - the property id
      value - the value
      Throws:
      XMLConfigurationException - If the requested feature is not known.
    • setDocumentHandler

      public void setDocumentHandler(XMLDocumentHandler handler)
      Description copied from interface: XMLParserConfiguration
      Sets the document handler to receive information about the document.
      Specified by:
      setDocumentHandler in interface XMLParserConfiguration
      Parameters:
      handler - The document handler.
    • getDocumentHandler

      public XMLDocumentHandler getDocumentHandler()
      Return the registered document handler.
      Specified by:
      getDocumentHandler in interface XMLParserConfiguration
      Returns:
      the registered document handler.
    • setErrorHandler

      public void setErrorHandler(XMLErrorHandler handler)
      Description copied from interface: XMLParserConfiguration
      Sets the error handler.
      Specified by:
      setErrorHandler in interface XMLParserConfiguration
      Parameters:
      handler - The error resolver.
    • getErrorHandler

      public XMLErrorHandler getErrorHandler()
      Returns the registered error handler.
      Specified by:
      getErrorHandler in interface XMLParserConfiguration
      Returns:
      the registered error handler.
    • getHtmlElements

      public HTMLElementsProvider getHtmlElements()
      Returns:
      the configured HTMLElements
    • getHtmlComponents

      public List<HTMLComponent> getHtmlComponents()
      Returns:
      the configured List of HTMLComponent's
    • getDocumentScanner

      public HTMLScanner getDocumentScanner()
      Returns:
      the configured HTMLScanner
    • getTagBalancer

      public HTMLTagBalancer getTagBalancer()
      Returns:
      the configured HTMLTagBalancer
    • getNamespaceBinder

      public NamespaceBinder getNamespaceBinder()
      Returns:
      the configured NamespaceBinder
    • parse

      public void parse(XMLInputSource source) throws XNIException, IOException
      Parses a document.
      Specified by:
      parse in interface XMLParserConfiguration
      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:
      setInputSource in interface XMLParserConfiguration
      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

      public boolean parse(boolean complete) throws XNIException, IOException
      Parses the document in a pull parsing fashion.
      Specified by:
      parse in interface XMLParserConfiguration
      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:
      cleanup in interface XMLParserConfiguration
    • addComponent

      protected void addComponent(HTMLComponent component)
    • reset

      protected void reset() throws XMLConfigurationException
      Resets the parser configuration.
      Throws:
      XMLConfigurationException
    • addRecognizedFeatures

      public void addRecognizedFeatures(String[] featureIds)
      Allows a parser to add parser specific features to be recognized and managed by the parser configuration.
      Specified by:
      addRecognizedFeatures in interface XMLParserConfiguration
      Parameters:
      featureIds - An array of the additional feature identifiers to be recognized.
    • addRecognizedProperties

      public void addRecognizedProperties(String[] propertyIds)
      Allows a parser to add parser specific properties to be recognized and managed by the parser configuration.
      Specified by:
      addRecognizedProperties in interface XMLParserConfiguration
      Parameters:
      propertyIds - An array of the additional property identifiers to be recognized.
    • getFeature

      public boolean getFeature(String featureId) throws XMLConfigurationException
      Returns the state of a feature.
      Specified by:
      getFeature in interface XMLParserConfiguration
      Parameters:
      featureId - the unique identifier of the feature
      Returns:
      true if the feature is enabled, false otherwise
      Throws:
      XMLConfigurationException - if the feature identifier is not recognized or if a configuration error occurs
    • getProperty

      public Object getProperty(String propertyId) throws XMLConfigurationException
      Returns the value of a property.
      Specified by:
      getProperty in interface XMLParserConfiguration
      Parameters:
      propertyId - the unique identifier of the property
      Returns:
      the value associated with the property, or null if none is set
      Throws:
      XMLConfigurationException - if the property identifier is not recognized or if a configuration error occurs
    • checkFeature

      protected void checkFeature(String featureId) throws XMLConfigurationException
      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

      protected void checkProperty(String propertyId) throws XMLConfigurationException
      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.