Package com.rtfparserkit.parser.standard
Class DefaultEventHandler
- java.lang.Object
-
- com.rtfparserkit.parser.standard.DefaultEventHandler
-
- All Implemented Interfaces:
IParserEventHandler
class DefaultEventHandler extends java.lang.Object implements IParserEventHandler
Default parser event handler. Passes events to the listener. In this implementation the events are queued to allow later events to modify earlier events before they are passed to the listener. For example, we coalesce consecutive string events together.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Deque<IParserEvent>eventsprivate IRtfListenerlistenerprivate static intMAX_EVENTS
-
Constructor Summary
Constructors Constructor Description DefaultEventHandler(IRtfListener listener)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidflushEvents()Passes any remaining events in the buffer to the listener and clears the event buffer,IParserEventgetLastEvent()Allows the caller to see the event at the end of the buffer.voidhandleEvent(IParserEvent event)If we've reached the end of the document, flush all queued events to the listener and pass on the document end event.booleanisComplete()It's always valid for this handler to continue processing events, so we always return false.private IParserEventmergeStringEvents(StringEvent event)Removes the string event from the end of the buffer, merges it with the string event we've just received, and adds the new event to the end of the buffer.voidremoveLastEvent()Allows the caller to remove the last event from the buffer.
-
-
-
Field Detail
-
MAX_EVENTS
private static final int MAX_EVENTS
- See Also:
- Constant Field Values
-
listener
private final IRtfListener listener
-
events
private final java.util.Deque<IParserEvent> events
-
-
Constructor Detail
-
DefaultEventHandler
public DefaultEventHandler(IRtfListener listener)
Constructor.
-
-
Method Detail
-
handleEvent
public void handleEvent(IParserEvent event)
If we've reached the end of the document, flush all queued events to the listener and pass on the document end event. If we have received consecutive string events, coalesce them into a single event in the buffer. If the buffer has reached its maximum size, remove the event from the front of the buffer and pass this to the listener.- Specified by:
handleEventin interfaceIParserEventHandler
-
isComplete
public boolean isComplete()
It's always valid for this handler to continue processing events, so we always return false.- Specified by:
isCompletein interfaceIParserEventHandler
-
getLastEvent
public IParserEvent getLastEvent()
Allows the caller to see the event at the end of the buffer.- Specified by:
getLastEventin interfaceIParserEventHandler
-
removeLastEvent
public void removeLastEvent()
Allows the caller to remove the last event from the buffer.- Specified by:
removeLastEventin interfaceIParserEventHandler
-
mergeStringEvents
private IParserEvent mergeStringEvents(StringEvent event)
Removes the string event from the end of the buffer, merges it with the string event we've just received, and adds the new event to the end of the buffer.
-
flushEvents
private void flushEvents()
Passes any remaining events in the buffer to the listener and clears the event buffer,
-
-