Class FilteredEventListener
- java.lang.Object
-
- com.itextpdf.kernel.pdf.canvas.parser.listener.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 Summary
Fields Modifier and Type Field Description protected java.util.List<IEventListener>delegatesprotected java.util.List<IEventFilter[]>filters
-
Constructor Summary
Constructors Constructor Description FilteredEventListener()Constructs aFilteredEventListenerempty instance.FilteredEventListener(IEventListener delegate, IEventFilter... filterSet)Constructs aFilteredEventListenerinstance with one delegate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends IEventListener>
TattachEventListener(T delegate, IEventFilter... filterSet)Attaches anotherIEventListenerdelegate with its filters.voideventOccurred(IEventData data, EventType type)Called when some event occurs during parsing a content stream.java.util.Set<EventType>getSupportedEvents()Provides the set of event types this listener supports.
-
-
-
Field Detail
-
delegates
protected final java.util.List<IEventListener> delegates
-
filters
protected final java.util.List<IEventFilter[]> filters
-
-
Constructor Detail
-
FilteredEventListener
public FilteredEventListener()
Constructs aFilteredEventListenerempty instance. UseattachEventListener(IEventListener, IEventFilter...)to add an event listener along with its filters.
-
FilteredEventListener
public FilteredEventListener(IEventListener delegate, IEventFilter... filterSet)
Constructs aFilteredEventListenerinstance with one delegate. UseattachEventListener(IEventListener, IEventFilter...)to add moreIEventListenerdelegates along with their filters.- Parameters:
delegate- a delegate that will be called when all the corresponding filters for an event passfilterSet- filters attached to the delegate that will be tested before passing an event on to the delegate
-
-
Method Detail
-
attachEventListener
public <T extends IEventListener> T attachEventListener(T delegate, IEventFilter... filterSet)
Attaches anotherIEventListenerdelegate 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 thisFilteredEventListenerinstance. The content stream will be parsed just once, so it is better for performance than creating multipleFilteredEventListenerinstances 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 passfilterSet- 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:IEventListenerCalled when some event occurs during parsing a content stream.- Specified by:
eventOccurredin interfaceIEventListener- 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:IEventListenerProvides the set of event types this listener supports. Returns null if all possible event types are supported.- Specified by:
getSupportedEventsin interfaceIEventListener- Returns:
- Set of event types supported by this listener or null if all possible event types are supported.
-
-