com.lowagie.text.rtf.direct

Class RtfParser

public class RtfParser extends Object

The RtfParser allows the importing of RTF documents or RTF document fragments. The RTF document or fragment is tokenised, font and color definitions corrected and then added to the document being written.

Version: $Revision: 2377 $

Author: Mark Hall (mhall@edu.uni-klu.ac.at)

Field Summary
RtfColorTableParsercolorTableParser
The RtfColorTableParser to use for parsing the color table.
RtfFontTableParserfontTableParser
The RtfFontTableParser to use for parsing the font table.
RtfImportHeaderimportHeader
The RtfImportHeader to store imported font and color mappings in.
static intPARSER_IN_COLOR_TABLE
Currently the RTF color table is being parsed.
static intPARSER_IN_DOCUMENT
Currently the RTF document content is being parsed.
static intPARSER_IN_FONT_TABLE
Currently the RTF font table is being parsed.
static intPARSER_IN_HEADER
Currently the RTF document header is being parsed.
static intPARSER_IN_INFO_GROUP
Currently the RTF info group is being parsed.
RtfDocumentrtfDoc
The RtfDocument to add the RTF document or fragment to.
intstate
The current parser state.
RtfTokenisertokeniser
The RtfTokeniser to use for tokenising the RTF document or fragment.
Method Summary
voidhandleCloseGroup(int groupLevel)
Handles close group tokens.
voidhandleCtrlCharacter(String ctrlCharacter, int groupLevel)
Handles single control character tokens.
voidhandleCtrlWord(String ctrlWord, int groupLevel)
Handles control word tokens.
voidhandleImportMappings(RtfImportMappings importMappings)
Imports the mappings defined in the RtfImportMappings into the RtfImportHeader of this RtfParser.
voidhandleOpenGroup(int groupLevel)
Handles open group tokens.
voidhandleText(String text, int groupLevel)
Handles text tokens.
voidimportRtfDocument(Reader reader, RtfDocument rtfDoc)
Imports a complete RTF document.
voidimportRtfFragment(Reader reader, RtfDocument rtfDoc, RtfImportMappings importMappings)
Imports an RTF fragment.

Field Detail

colorTableParser

private RtfColorTableParser colorTableParser
The RtfColorTableParser to use for parsing the color table.

fontTableParser

private RtfFontTableParser fontTableParser
The RtfFontTableParser to use for parsing the font table.

importHeader

private RtfImportHeader importHeader
The RtfImportHeader to store imported font and color mappings in.

PARSER_IN_COLOR_TABLE

private static final int PARSER_IN_COLOR_TABLE
Currently the RTF color table is being parsed.

PARSER_IN_DOCUMENT

private static final int PARSER_IN_DOCUMENT
Currently the RTF document content is being parsed.

PARSER_IN_FONT_TABLE

private static final int PARSER_IN_FONT_TABLE
Currently the RTF font table is being parsed.

PARSER_IN_HEADER

private static final int PARSER_IN_HEADER
Currently the RTF document header is being parsed.

PARSER_IN_INFO_GROUP

private static final int PARSER_IN_INFO_GROUP
Currently the RTF info group is being parsed.

rtfDoc

private RtfDocument rtfDoc
The RtfDocument to add the RTF document or fragment to.

state

private int state
The current parser state.

tokeniser

private RtfTokeniser tokeniser
The RtfTokeniser to use for tokenising the RTF document or fragment.

Method Detail

handleCloseGroup

public void handleCloseGroup(int groupLevel)
Handles close group tokens. Depending on what is currently being parsed the parse state may change.

Parameters: groupLevel The current group nesting level.

handleCtrlCharacter

public void handleCtrlCharacter(String ctrlCharacter, int groupLevel)
Handles single control character tokens.

Parameters: ctrlCharacter The control character to handle. groupLevel The current group nesting level.

handleCtrlWord

public void handleCtrlWord(String ctrlWord, int groupLevel)
Handles control word tokens. Depending on the current state a control word can lead to a state change. When parsing the actual document contents, The font number, color number and background color number are remapped.

Parameters: ctrlWord The control word to handle. groupLevel The current group nesting level.

handleImportMappings

private void handleImportMappings(RtfImportMappings importMappings)
Imports the mappings defined in the RtfImportMappings into the RtfImportHeader of this RtfParser.

Parameters: importMappings The RtfImportMappings to import.

handleOpenGroup

public void handleOpenGroup(int groupLevel)
Handles open group tokens.

Parameters: groupLevel The current group nesting level.

handleText

public void handleText(String text, int groupLevel)
Handles text tokens. These are either handed on to the RtfColorTableParser or RtfFontTableParser or added directly to the document.

Parameters: text The text token to handle. groupLevel The current group nesting level.

importRtfDocument

public void importRtfDocument(Reader reader, RtfDocument rtfDoc)
Imports a complete RTF document.

Parameters: reader The Reader to read the RTF document from. rtfDoc The RtfDocument to add the imported document to.

Throws: IOException On I/O errors.

importRtfFragment

public void importRtfFragment(Reader reader, RtfDocument rtfDoc, RtfImportMappings importMappings)
Imports an RTF fragment.

Parameters: reader The Reader to read the RTF fragment from. rtfDoc The RTF document to add the RTF fragment to. importMappings The RtfImportMappings defining font and color mappings for the fragment.

Throws: IOException On I/O errors.