Class StandardRtfParser

  • All Implemented Interfaces:
    IRtfListener, IRtfParser

    public class StandardRtfParser
    extends java.lang.Object
    implements IRtfParser, IRtfListener
    This class builds on the RawRtfParser to provide a parser which can deal with character encodings and Unicode. All of the character data it reads is presented back to the client as Unicode strings to make it as simple as possible to deal with.
    • Constructor Detail

      • StandardRtfParser

        public StandardRtfParser()
    • Method Detail

      • parse

        public void parse​(IRtfSource source,
                          IRtfListener listener)
                   throws java.io.IOException
        Main entry point: parse RTF data from the input stream, and pass events based on the RTF content to the listener.
        Specified by:
        parse in interface IRtfParser
        Throws:
        java.io.IOException
      • processGroupStart

        public void processGroupStart()
        Handle event from the RawRtfParser.
        Specified by:
        processGroupStart in interface IRtfListener
      • processGroupEnd

        public void processGroupEnd()
        Handle event from the RawRtfParser.
        Specified by:
        processGroupEnd in interface IRtfListener
      • processCharacterBytes

        public void processCharacterBytes​(byte[] data)
        Handle event from the RawRtfParser.
        Specified by:
        processCharacterBytes in interface IRtfListener
      • currentEncoding

        private java.lang.String currentEncoding()
        Determine which encoding to use, one defined by the current font, or the current default encoding.
      • processDocumentEnd

        public void processDocumentEnd()
        Handle event from the RawRtfParser.
        Specified by:
        processDocumentEnd in interface IRtfListener
      • processBinaryBytes

        public void processBinaryBytes​(byte[] data)
        Handle event from the RawRtfParser.
        Specified by:
        processBinaryBytes in interface IRtfListener
      • processString

        public void processString​(java.lang.String string)
        Handle event from the RawRtfParser.
        Specified by:
        processString in interface IRtfListener
      • processCommand

        public void processCommand​(Command command,
                                   int parameter,
                                   boolean hasParameter,
                                   boolean optional)
        Handle event from the RawRtfParser.
        Specified by:
        processCommand in interface IRtfListener
      • processFont

        private void processFont​(int parameter)
        Set the current font and current font encoding in the state.
      • processFontCharset

        private void processFontCharset​(int parameter)
        Set the charset for the current font.
      • processFontCodepage

        private void processFontCodepage​(int parameter)
      • setFontEncoding

        private void setFontEncoding​(java.lang.String charset)
      • processEncoding

        private void processEncoding​(Command command,
                                     boolean hasParameter,
                                     int parameter)
        Switch the encoding based on the RTF command received.
      • processUnicode

        private void processUnicode​(int parameter)
        Process an RTF command parameter representing a Unicode character.
      • processUnicodeAlternateSkipCount

        private void processUnicodeAlternateSkipCount​(int parameter)
        Set the number of bytes to skip after a Unicode character.
      • processUpr

        private void processUpr​(IParserEvent command)
        Process a upr command: consume all of the RTF commands relating to this and emit events representing the Unicode content.
        Parameters:
        command -
      • processCharacter

        private void processCharacter​(char c)
        Process a single character.
      • handleCommand

        private void handleCommand​(Command command,
                                   int parameter,
                                   boolean hasParameter,
                                   boolean optional)
        Process an RTF command.
      • handleEvent

        private void handleEvent​(IParserEvent event)
        Pass an event to the event handler, pop the event handler stack if the current event handler has consumed all of the events it can.
      • unsignedValue

        private int unsignedValue​(int parameter)