Package com.rtfparserkit.parser.standard
Class StandardRtfParser
- java.lang.Object
-
- com.rtfparserkit.parser.standard.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.
-
-
Field Summary
Fields Modifier and Type Field Description private static IParserEventDOCUMENT_ENDprivate static IParserEventDOCUMENT_STARTprivate static IParserEventGROUP_ENDprivate static IParserEventGROUP_STARTprivate IParserEventHandlerhandlerprivate java.util.Deque<IParserEventHandler>handlerStackprivate java.util.Map<java.lang.Integer,java.lang.String>m_fontEncodingsprivate intskipBytesprivate java.util.Deque<ParserState>stackprivate ParserStatestate
-
Constructor Summary
Constructors Constructor Description StandardRtfParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.StringcurrentEncoding()Determine which encoding to use, one defined by the current font, or the current default encoding.private voidhandleCommand(Command command, int parameter, boolean hasParameter, boolean optional)Process an RTF command.private voidhandleEvent(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.voidparse(IRtfSource source, IRtfListener listener)Main entry point: parse RTF data from the input stream, and pass events based on the RTF content to the listener.voidprocessBinaryBytes(byte[] data)Handle event from the RawRtfParser.private voidprocessCharacter(char c)Process a single character.voidprocessCharacterBytes(byte[] data)Handle event from the RawRtfParser.voidprocessCommand(Command command, int parameter, boolean hasParameter, boolean optional)Handle event from the RawRtfParser.voidprocessDocumentEnd()Handle event from the RawRtfParser.voidprocessDocumentStart()Handle event from the RawRtfParser.private voidprocessEncoding(Command command, boolean hasParameter, int parameter)Switch the encoding based on the RTF command received.private voidprocessFont(int parameter)Set the current font and current font encoding in the state.private voidprocessFontCharset(int parameter)Set the charset for the current font.private voidprocessFontCodepage(int parameter)voidprocessGroupEnd()Handle event from the RawRtfParser.voidprocessGroupStart()Handle event from the RawRtfParser.voidprocessString(java.lang.String string)Handle event from the RawRtfParser.private voidprocessUnicode(int parameter)Process an RTF command parameter representing a Unicode character.private voidprocessUnicodeAlternateSkipCount(int parameter)Set the number of bytes to skip after a Unicode character.private voidprocessUpr(IParserEvent command)Process a upr command: consume all of the RTF commands relating to this and emit events representing the Unicode content.private voidsetFontEncoding(java.lang.String charset)private intunsignedValue(int parameter)
-
-
-
Field Detail
-
handler
private IParserEventHandler handler
-
handlerStack
private final java.util.Deque<IParserEventHandler> handlerStack
-
state
private ParserState state
-
stack
private final java.util.Deque<ParserState> stack
-
skipBytes
private int skipBytes
-
m_fontEncodings
private java.util.Map<java.lang.Integer,java.lang.String> m_fontEncodings
-
DOCUMENT_START
private static final IParserEvent DOCUMENT_START
-
DOCUMENT_END
private static final IParserEvent DOCUMENT_END
-
GROUP_START
private static final IParserEvent GROUP_START
-
GROUP_END
private static final IParserEvent GROUP_END
-
-
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:
parsein interfaceIRtfParser- Throws:
java.io.IOException
-
processGroupStart
public void processGroupStart()
Handle event from the RawRtfParser.- Specified by:
processGroupStartin interfaceIRtfListener
-
processGroupEnd
public void processGroupEnd()
Handle event from the RawRtfParser.- Specified by:
processGroupEndin interfaceIRtfListener
-
processCharacterBytes
public void processCharacterBytes(byte[] data)
Handle event from the RawRtfParser.- Specified by:
processCharacterBytesin interfaceIRtfListener
-
currentEncoding
private java.lang.String currentEncoding()
Determine which encoding to use, one defined by the current font, or the current default encoding.
-
processDocumentStart
public void processDocumentStart()
Handle event from the RawRtfParser.- Specified by:
processDocumentStartin interfaceIRtfListener
-
processDocumentEnd
public void processDocumentEnd()
Handle event from the RawRtfParser.- Specified by:
processDocumentEndin interfaceIRtfListener
-
processBinaryBytes
public void processBinaryBytes(byte[] data)
Handle event from the RawRtfParser.- Specified by:
processBinaryBytesin interfaceIRtfListener
-
processString
public void processString(java.lang.String string)
Handle event from the RawRtfParser.- Specified by:
processStringin interfaceIRtfListener
-
processCommand
public void processCommand(Command command, int parameter, boolean hasParameter, boolean optional)
Handle event from the RawRtfParser.- Specified by:
processCommandin interfaceIRtfListener
-
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)
-
-