Package com.rtfparserkit.parser.raw
Class RawRtfParser
- java.lang.Object
-
- com.rtfparserkit.parser.raw.RawRtfParser
-
- All Implemented Interfaces:
IRtfParser
public class RawRtfParser extends java.lang.Object implements IRtfParser
This class implements a low level RTF parser. It performs the minimum amount of processing on the data read from an RTF file, just passing the caller a stream of events representing the commands and character bytes. In particular the parser doesn't not deal with character encodings or the various Unicode related commands which may be present in an RTF file. This code is based on the approach outlined in the sample C code provided in the RTF Specification 1.9.1 (http://www.microsoft.com/en-gb/download/details.aspx?id=10725)
-
-
Field Summary
Fields Modifier and Type Field Description private ByteBufferbufferprivate intgroupDepthprivate IRtfListenerlistenerprivate static intMAX_COMMAND_LENGTHprivate static intMAX_PARAMETER_LENGTHprivate booleanparsingHexprivate IRtfSourcesource
-
Constructor Summary
Constructors Constructor Description RawRtfParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidhandleBinaryData(int size)Pass binary data to the listener.private voidhandleCharacterByte(int ch)Process a single character byte, or hex encoded character byte.private voidhandleCharacterData()Pass accumulated character data to the listener.private voidhandleCommand()Read and process an RTF command.private voidhandleCommand(java.lang.StringBuilder commandBuffer, int parameter, boolean hasParameter)Determine what to do with the extracted command.private voidhandleGroupEnd()Inform the listener of a group end.private voidhandleGroupStart()Inform the listener of a group start.voidparse(IRtfSource source, IRtfListener listener)Parse RTF data from an input source.
-
-
-
Field Detail
-
source
private IRtfSource source
-
groupDepth
private int groupDepth
-
parsingHex
private boolean parsingHex
-
buffer
private ByteBuffer buffer
-
listener
private IRtfListener listener
-
MAX_PARAMETER_LENGTH
private static final int MAX_PARAMETER_LENGTH
- See Also:
- Constant Field Values
-
MAX_COMMAND_LENGTH
private static final int MAX_COMMAND_LENGTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
parse
public void parse(IRtfSource source, IRtfListener listener) throws java.io.IOException
Parse RTF data from an input source.- Specified by:
parsein interfaceIRtfParser- Throws:
java.io.IOException
-
handleCharacterByte
private void handleCharacterByte(int ch) throws java.io.IOExceptionProcess a single character byte, or hex encoded character byte.- Throws:
java.io.IOException
-
handleCommand
private void handleCommand() throws java.io.IOExceptionRead and process an RTF command.- Throws:
java.io.IOException
-
handleCommand
private void handleCommand(java.lang.StringBuilder commandBuffer, int parameter, boolean hasParameter) throws java.io.IOExceptionDetermine what to do with the extracted command.- Throws:
java.io.IOException
-
handleCharacterData
private void handleCharacterData()
Pass accumulated character data to the listener.
-
handleBinaryData
private void handleBinaryData(int size) throws java.io.IOExceptionPass binary data to the listener.- Throws:
java.io.IOException
-
handleGroupStart
private void handleGroupStart()
Inform the listener of a group start.
-
handleGroupEnd
private void handleGroupEnd()
Inform the listener of a group end.
-
-