Class 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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void flushEvents()
      Passes any remaining events in the buffer to the listener and clears the event buffer,
      IParserEvent getLastEvent()
      Allows the caller to see the event at the end of the buffer.
      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.
      boolean isComplete()
      It's always valid for this handler to continue processing events, so we always return false.
      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.
      void removeLastEvent()
      Allows the caller to remove the last event from the buffer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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:
        handleEvent in interface IParserEventHandler
      • isComplete

        public boolean isComplete()
        It's always valid for this handler to continue processing events, so we always return false.
        Specified by:
        isComplete in interface IParserEventHandler
      • removeLastEvent

        public void removeLastEvent()
        Allows the caller to remove the last event from the buffer.
        Specified by:
        removeLastEvent in interface IParserEventHandler
      • 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,