com.lowagie.text.rtf.direct
Class RtfParser

java.lang.Object
  extended by com.lowagie.text.rtf.direct.RtfParser

public class RtfParser
extends java.lang.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: 1.4 $
Author:
Mark Hall (mhall@edu.uni-klu.ac.at)

Field Summary
private  RtfColorTableParser colorTableParser
          The RtfColorTableParser to use for parsing the color table.
private  RtfFontTableParser fontTableParser
          The RtfFontTableParser to use for parsing the font table.
private  RtfImportHeader importHeader
          The RtfImportHeader to store imported font and color mappings in.
private static int PARSER_IN_COLOR_TABLE
          Currently the RTF color table is being parsed.
private static int PARSER_IN_DOCUMENT
          Currently the RTF document content is being parsed.
private static int PARSER_IN_FONT_TABLE
          Currently the RTF font table is being parsed.
private static int PARSER_IN_HEADER
          Currently the RTF document header is being parsed.
private static int PARSER_IN_INFO_GROUP
          Currently the RTF info group is being parsed.
private  RtfDocument rtfDoc
          The RtfDocument to add the RTF document or fragment to.
private  int state
          The current parser state.
private  RtfTokeniser tokeniser
          The RtfTokeniser to use for tokenising the RTF document or fragment.
 
Constructor Summary
RtfParser()
           
 
Method Summary
 void handleCloseGroup(int groupLevel)
          Handles close group tokens.
 void handleCtrlCharacter(java.lang.String ctrlCharacter, int groupLevel)
          Handles single control character tokens.
 void handleCtrlWord(java.lang.String ctrlWord, int groupLevel)
          Handles control word tokens.
private  void handleImportMappings(RtfImportMappings importMappings)
          Imports the mappings defined in the RtfImportMappings into the RtfImportHeader of this RtfParser.
 void handleOpenGroup(int groupLevel)
          Handles open group tokens.
 void handleText(java.lang.String text, int groupLevel)
          Handles text tokens.
 void importRtfDocument(java.io.Reader reader, RtfDocument rtfDoc)
          Imports a complete RTF document.
 void importRtfFragment(java.io.Reader reader, RtfDocument rtfDoc, RtfImportMappings importMappings)
          Imports an RTF fragment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARSER_IN_HEADER

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

See Also:
Constant Field Values

PARSER_IN_FONT_TABLE

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

See Also:
Constant Field Values

PARSER_IN_COLOR_TABLE

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

See Also:
Constant Field Values

PARSER_IN_INFO_GROUP

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

See Also:
Constant Field Values

PARSER_IN_DOCUMENT

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

See Also:
Constant Field Values

rtfDoc

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


tokeniser

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


importHeader

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


fontTableParser

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


colorTableParser

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


state

private int state
The current parser state.

Constructor Detail

RtfParser

public RtfParser()
Method Detail

importRtfDocument

public void importRtfDocument(java.io.Reader reader,
                              RtfDocument rtfDoc)
                       throws java.io.IOException,
                              DocumentException
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:
java.io.IOException - On I/O errors.
DocumentException - On document writing errors.

importRtfFragment

public void importRtfFragment(java.io.Reader reader,
                              RtfDocument rtfDoc,
                              RtfImportMappings importMappings)
                       throws java.io.IOException,
                              DocumentException
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:
java.io.IOException - On I/O errors.
DocumentException - On document writing errors.

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)
                     throws DocumentException
Handles open group tokens.

Parameters:
groupLevel - The current group nesting level.
Throws:
DocumentException - On document writing errors.

handleCloseGroup

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

Parameters:
groupLevel - The current group nesting level.
Throws:
DocumentException - On document writing errors.

handleCtrlCharacter

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

Parameters:
ctrlCharacter - The control character to handle.
groupLevel - The current group nesting level.
Throws:
DocumentException - On document writing errors.

handleCtrlWord

public void handleCtrlWord(java.lang.String ctrlWord,
                           int groupLevel)
                    throws DocumentException
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.
Throws:
DocumentException - On document writing errors.

handleText

public void handleText(java.lang.String text,
                       int groupLevel)
                throws DocumentException
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.
Throws:
DocumentException - On document writing errors.