Class DefaultFilter

java.lang.Object
org.htmlunit.cyberneko.filters.DefaultFilter
All Implemented Interfaces:
HTMLComponent, XMLComponent, XMLDocumentFilter, XMLDocumentSource, XMLDocumentHandler
Direct Known Subclasses:
HTMLWriterFilter, NamespaceBinder

public class DefaultFilter extends Object implements XMLDocumentFilter, HTMLComponent
This class implements a filter that simply passes document events to the next handler. It can be used as a base class to simplify the development of new document filters.
  • Field Details

  • Constructor Details

    • DefaultFilter

      public DefaultFilter()
  • Method Details

    • setDocumentHandler

      public void setDocumentHandler(XMLDocumentHandler handler)
      Sets the document handler.
      Specified by:
      setDocumentHandler in interface XMLDocumentSource
      Parameters:
      handler - the new handler
    • getDocumentHandler

      public XMLDocumentHandler getDocumentHandler()
      Returns the document handler.
      Specified by:
      getDocumentHandler in interface XMLDocumentSource
      Returns:
      the document handler
    • setDocumentSource

      public void setDocumentSource(XMLDocumentSource source)
      Sets the document source.
      Specified by:
      setDocumentSource in interface XMLDocumentHandler
      Parameters:
      source - the new source
    • getDocumentSource

      public XMLDocumentSource getDocumentSource()
      Specified by:
      getDocumentSource in interface XMLDocumentHandler
      Returns:
      the document source.
    • startDocument

      public void startDocument(XMLLocator locator, String encoding, NamespaceContext nscontext, Augmentations augs) throws XNIException
      Start document.
      Specified by:
      startDocument in interface XMLDocumentHandler
      Parameters:
      locator - The document locator, or null if the document location cannot be reported during the parsing of this document. However, it is strongly recommended that a locator be supplied that can at least report the system identifier of the document.
      encoding - The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal entities or a document entity that is parsed from a java.io.Reader).
      nscontext - The namespace context in effect at the start of this document. This object represents the current context. Implementors of this class are responsible for copying the namespace bindings from the the current context (and its parent contexts) if that information is important.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • xmlDecl

      public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) throws XNIException
      XML declaration.
      Specified by:
      xmlDecl in interface XMLDocumentHandler
      Parameters:
      version - The XML version.
      encoding - The IANA encoding name of the document, or null if not specified.
      standalone - The standalone value, or null if not specified.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • doctypeDecl

      public void doctypeDecl(String root, String publicId, String systemId, Augmentations augs) throws XNIException
      Doctype declaration.
      Specified by:
      doctypeDecl in interface XMLDocumentHandler
      Parameters:
      root - The name of the root element.
      publicId - The public identifier if an external DTD or null if the external DTD is specified using SYSTEM.
      systemId - The system identifier if an external DTD, null otherwise.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • comment

      public void comment(XMLString text, Augmentations augs) throws XNIException
      Comment.
      Specified by:
      comment in interface XMLDocumentHandler
      Parameters:
      text - The text in the comment.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by application to signal an error.
    • processingInstruction

      public void processingInstruction(String target, XMLString data, Augmentations augs) throws XNIException
      Processing instruction.
      Specified by:
      processingInstruction in interface XMLDocumentHandler
      Parameters:
      target - The target.
      data - The data or null if none specified.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • startElement

      public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException
      Start element.
      Specified by:
      startElement in interface XMLDocumentHandler
      Parameters:
      element - The name of the element.
      attributes - The element attributes.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • emptyElement

      public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException
      Empty element.
      Specified by:
      emptyElement in interface XMLDocumentHandler
      Parameters:
      element - The name of the element.
      attributes - The element attributes.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • characters

      public void characters(XMLString text, Augmentations augs) throws XNIException
      Characters.
      Specified by:
      characters in interface XMLDocumentHandler
      Parameters:
      text - The content.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • startCDATA

      public void startCDATA(Augmentations augs) throws XNIException
      Start CDATA section.
      Specified by:
      startCDATA in interface XMLDocumentHandler
      Parameters:
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • endCDATA

      public void endCDATA(Augmentations augs) throws XNIException
      End CDATA section.
      Specified by:
      endCDATA in interface XMLDocumentHandler
      Parameters:
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • endElement

      public void endElement(QName element, Augmentations augs) throws XNIException
      End element.
      Specified by:
      endElement in interface XMLDocumentHandler
      Parameters:
      element - The name of the element.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • endDocument

      public void endDocument(Augmentations augs) throws XNIException
      End document.
      Specified by:
      endDocument in interface XMLDocumentHandler
      Parameters:
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • getRecognizedFeatures

      public String[] getRecognizedFeatures()
      Returns a list of feature identifiers that are recognized by this component. This method may return null if no features are recognized by this component.
      Specified by:
      getRecognizedFeatures in interface XMLComponent
      Returns:
      an array of feature identifiers that are recognized by this component. This method may return null if no features are recognized by this component.
    • getFeatureDefault

      public Boolean getFeatureDefault(String featureId)
      Returns the default state for a feature, or null if this component does not want to report a default value for this feature.
      Specified by:
      getFeatureDefault in interface HTMLComponent
      Specified by:
      getFeatureDefault in interface XMLComponent
      Parameters:
      featureId - The feature identifier.
      Returns:
      the default state for a feature, or null if this component does not want to report a default value for this feature.
    • getRecognizedProperties

      public String[] getRecognizedProperties()
      Returns a list of property identifiers that are recognized by this component. This method may return null if no properties are recognized by this component.
      Specified by:
      getRecognizedProperties in interface XMLComponent
      Returns:
      an array of property identifiers that are recognized by this component. This method may return null if no properties are recognized by this component.
    • getPropertyDefault

      public Object getPropertyDefault(String propertyId)
      Returns the default state for a property, or null if this component does not want to report a default value for this property.
      Specified by:
      getPropertyDefault in interface HTMLComponent
      Specified by:
      getPropertyDefault in interface XMLComponent
      Parameters:
      propertyId - The property identifier.
      Returns:
      the default state for a property, or null if this component does not want to report a default value for this property
    • reset

      public void reset(XMLComponentManager componentManager) throws XMLConfigurationException
      Resets the component. The component can query the component manager about any features and properties that affect the operation of the component.
      Specified by:
      reset in interface XMLComponent
      Parameters:
      componentManager - The component manager.
      Throws:
      XNIException - Thrown by component on initialization error.
      XMLConfigurationException
    • setFeature

      public void setFeature(String featureId, boolean state) throws XMLConfigurationException
      Sets the state of a feature. This method is called by the component manager any time after reset when a feature changes state.

      Note: Components should silently ignore features that do not affect the operation of the component.

      Specified by:
      setFeature in interface XMLComponent
      Parameters:
      featureId - The feature identifier.
      state - The state of the feature.
      Throws:
      XMLConfigurationException - Thrown for configuration error. In general, components should only throw this exception if it is really a critical error.
    • setProperty

      public void setProperty(String propertyId, Object value) throws XMLConfigurationException
      Sets the value of a property. This method is called by the component manager any time after reset when a property changes value.

      Note: Components should silently ignore properties that do not affect the operation of the component.

      Specified by:
      setProperty in interface XMLComponent
      Parameters:
      propertyId - The property identifier.
      value - The value of the property.
      Throws:
      XMLConfigurationException - Thrown for configuration error. In general, components should only throw this exception if it is really a critical error.
    • merge

      protected static String[] merge(String[] array1, String[] array2)
      Utility method for merging string arrays for recognized features and recognized properties.
      Parameters:
      array1 - array1
      array2 - array2
      Returns:
      the merged array