Class FilteredEventListener

  • All Implemented Interfaces:
    IEventListener
    Direct Known Subclasses:
    FilteredTextEventListener

    public class FilteredEventListener
    extends java.lang.Object
    implements IEventListener
    An event listener which filters events on the fly before passing them on to the delegate.
    • Field Detail

      • filters

        protected final java.util.List<IEventFilter[]> filters
    • Method Detail

      • attachEventListener

        public <T extends IEventListener> T attachEventListener​(T delegate,
                                                                IEventFilter... filterSet)
        Attaches another IEventListener delegate with its filters. When all the filters attached to the delegate for an event accept the event, the event will be passed on to the delegate. You can attach multiple delegates to this FilteredEventListener instance. The content stream will be parsed just once, so it is better for performance than creating multiple FilteredEventListener instances and parsing the content stream multiple times. This is useful, for instance, when you want to extract content from multiple regions of a page.
        Type Parameters:
        T - the type of the delegate
        Parameters:
        delegate - a delegate that will be called when all the corresponding filters for an event pass
        filterSet - filters attached to the delegate that will be tested before passing an event on to the delegate
        Returns:
        delegate that has been passed to the method, used for convenient call chaining
      • eventOccurred

        public void eventOccurred​(IEventData data,
                                  EventType type)
        Description copied from interface: IEventListener
        Called when some event occurs during parsing a content stream.
        Specified by:
        eventOccurred in interface IEventListener
        Parameters:
        data - Combines the data required for processing corresponding event type.
        type - Event type.
      • getSupportedEvents

        public java.util.Set<EventType> getSupportedEvents()
        Description copied from interface: IEventListener
        Provides the set of event types this listener supports. Returns null if all possible event types are supported.
        Specified by:
        getSupportedEvents in interface IEventListener
        Returns:
        Set of event types supported by this listener or null if all possible event types are supported.