Class RtfParser
java.lang.Object
com.lowagie.text.rtf.parser.RtfParser
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.
- Since:
- 2.0.8
- Author:
- Mark Hall (Mark.Hall@mail.room3b.eu), Howard Shank (hgshank@yahoo.com)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDestination is normal.static final intDestination is skipping.static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intCurrently the parser is in an error state.static final intThe parser reached the end of the file.static final intCurrently a blipuid control word is being parsed.static final intCurrently the RTF charset is being parsed.static final intCurrently the RTF color table is being parsed.static final intCurrently the RTF deffont is being parsed.static final intCurrently the RTF document content is being parsed.static final intCurrently the RTF filetbl is being parsed.static final intCurrently the RTF font table is being parsed.static final intCurrently a RTF font table info element is being parsed.static final intCurrently the RTF generator is being parsed.static final intCurrently the RTF document header is being parsed.static final intCurrently the RTF info group is being parsed.static final intCurrently the Latent Style and Formatting usage restrictionsstatic final intCurrently the RTF listtables is being parsed.static final intCurrently the RTF listtable override is being parsed.static final intCurrently the RTF Old Properties.static final intCurrently the RTF Old Properties.static final intCurrently the RTF Old Properties.static final intCurrently the RTF Old Properties.static final intstatic final intCurrently the RTF Paragraph group properties Table (word 2002)static final intCurrently a picprop control word is being parsed.static final intCurrently a pict control word is being parsed.static final intCurrently the RTF User Protection Information.static final intCurrently the RTF revtbl is being parsed.static final intCurrently the RTF rsidtable is being parsed.static final intCurrently a shppict control word is being parsed.static final intCurrently the RTF stylesheet is being parsed.static final intCurrently the parser is in an unknown state.static final intstatic final intThe parser is at the beginning or the end of the file.static final intThe RtfTokeniser is currently reading binary stream.static final intThe RtfTokeniser is currently reading hex data.static final intThe RtfTokeniser ignore resultstatic final intThe RtfTokeniser is in its ground state.static final intThe last token parsed was a slash.static final intThe RtfTokeniser is currently tokenising a control word.static final intThe RtfTokeniser is currently in error statestatic final intThe RtfTokeniser is currently in an unkown statestatic final intConversion type is a conversion.static final intConversion type is an import of a partial file/fragment.static final intConversion type is an import.static final intConversion type to import a document into an element. i.e.static final intConversion type is unknown -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(EventListener listener) Adds aEventListenerto theRtfCtrlWordMgr.voidconvertRtfDocument(InputStream readerIn, com.lowagie.text.Document doc) Converts an RTF document to an iText document.intGet the conversion type.Get the current destination object.getDestination(String destination) Get a destination from the mapcom.lowagie.text.DocumentGet the Document object.booleanHelper method to indicate if this control word was a \* control word.Get the RtfImportHeader object.intgetLevel()Gets the current group levelGet the logfile name.intGet the current state of the parser.Get the RTF Document object.getState()Get the state of the parser.intGet the current state of the tokeniser.inthandleCharacter(int nextChar) Handles text tokens.intHandles close group tokens. (})inthandleCtrlWord(RtfCtrlWordData ctrlWordData) Handles control word tokens.intHandles open group tokens. ({)voidimportRtfDocument(InputStream readerIn, RtfDocument rtfDoc) Imports a complete RTF document.voidimportRtfDocumentIntoElement(com.lowagie.text.Element elem, InputStream readerIn, RtfDocument rtfDoc) Imports a complete RTF document into an Element, i.e.voidimportRtfFragment(InputStream readerIn, RtfDocument rtfDoc, RtfImportMappings importMappings) Imports an RTF fragment.protected voidInitialize the statistics values.booleanHelper method to determin if conversion is TYPE_CONVERTbooleanisImport()Helper method to determin if conversion is TYPE_IMPORT_FULL or TYPE_IMPORT_FRAGMENTbooleanHelper method to determin if conversion is TYPE_IMPORT_FRAGMENTbooleanHelper method to determin if conversion is TYPE_IMPORT_FULLbooleanbooleanGet flag indicating if logging is on or off.booleanHelper method to determine if this is a new group.static voidoutputDebug(Object doc, int groupLevel, String str) voidremoveListener(EventListener listener) Removes aEventListenerfrom theRtfCtrlWordMgr.booleansetCurrentDestination(String destination) Set the current destination object for the current state.booleansetExtendedDestination(boolean value) Helper method to set the extended control word flag.voidsetLogAppend(boolean logAppend) voidsetLogFile(String logFile) Set the logFile namevoidsetLogFile(String logFile, boolean logAppend) Set the logFile namevoidsetLogging(boolean logging) Set flag indicating if logging is on or offbooleansetNewGroup(boolean value) Helper method to set the new group flagintsetParserState(int newState) Set the state value of the parser.voidsetTokeniserSkipBytes(long numberOfBytesToSkip) Sets the number of bytes to skip and the state of the tokeniser.intsetTokeniserState(int value) Set the current state of the tokeniser.voidsetTokeniserStateBinary(int binaryCount) Sets the number of binary bytes.voidsetTokeniserStateBinary(long binaryCount) Sets the number of binary bytes.voidSet the tokeniser state to skip to the end of the group.voidSet the tokeniser state to skip to the end of the group.voidtokenise()Read through the input file and parse the data stream into tokens.
-
Field Details
-
PARSER_IN_HEADER
public static final int PARSER_IN_HEADERCurrently the RTF document header is being parsed.- See Also:
-
PARSER_IN_CHARSET
public static final int PARSER_IN_CHARSETCurrently the RTF charset is being parsed.- See Also:
-
PARSER_IN_DEFFONT
public static final int PARSER_IN_DEFFONTCurrently the RTF deffont is being parsed.- See Also:
-
PARSER_IN_FONT_TABLE
public static final int PARSER_IN_FONT_TABLECurrently the RTF font table is being parsed.- See Also:
-
PARSER_IN_FONT_TABLE_INFO
public static final int PARSER_IN_FONT_TABLE_INFOCurrently a RTF font table info element is being parsed.- See Also:
-
PARSER_IN_FILE_TABLE
public static final int PARSER_IN_FILE_TABLECurrently the RTF filetbl is being parsed.- See Also:
-
PARSER_IN_COLOR_TABLE
public static final int PARSER_IN_COLOR_TABLECurrently the RTF color table is being parsed.- See Also:
-
PARSER_IN_STYLESHEET
public static final int PARSER_IN_STYLESHEETCurrently the RTF stylesheet is being parsed.- See Also:
-
PARSER_IN_LIST_TABLE
public static final int PARSER_IN_LIST_TABLECurrently the RTF listtables is being parsed.- See Also:
-
PARSER_IN_LISTOVERRIDE_TABLE
public static final int PARSER_IN_LISTOVERRIDE_TABLECurrently the RTF listtable override is being parsed.- See Also:
-
PARSER_IN_REV_TABLE
public static final int PARSER_IN_REV_TABLECurrently the RTF revtbl is being parsed.- See Also:
-
PARSER_IN_RSID_TABLE
public static final int PARSER_IN_RSID_TABLECurrently the RTF rsidtable is being parsed.- See Also:
-
PARSER_IN_GENERATOR
public static final int PARSER_IN_GENERATORCurrently the RTF generator is being parsed.- See Also:
-
PARSER_IN_PARAGRAPH_TABLE
public static final int PARSER_IN_PARAGRAPH_TABLECurrently the RTF Paragraph group properties Table (word 2002)- See Also:
-
PARSER_IN_OLDCPROPS
public static final int PARSER_IN_OLDCPROPSCurrently the RTF Old Properties.- See Also:
-
PARSER_IN_OLDPPROPS
public static final int PARSER_IN_OLDPPROPSCurrently the RTF Old Properties.- See Also:
-
PARSER_IN_OLDTPROPS
public static final int PARSER_IN_OLDTPROPSCurrently the RTF Old Properties.- See Also:
-
PARSER_IN_OLDSPROPS
public static final int PARSER_IN_OLDSPROPSCurrently the RTF Old Properties.- See Also:
-
PARSER_IN_PROT_USER_TABLE
public static final int PARSER_IN_PROT_USER_TABLECurrently the RTF User Protection Information.- See Also:
-
PARSER_IN_LATENTSTYLES
public static final int PARSER_IN_LATENTSTYLESCurrently the Latent Style and Formatting usage restrictions- See Also:
-
PARSER_IN_PARAGRAPH_GROUP_PROPERTIES
public static final int PARSER_IN_PARAGRAPH_GROUP_PROPERTIES- See Also:
-
PARSER_IN_DOCUMENT
public static final int PARSER_IN_DOCUMENTCurrently the RTF document content is being parsed.- See Also:
-
PARSER_IN_INFO_GROUP
public static final int PARSER_IN_INFO_GROUPCurrently the RTF info group is being parsed.- See Also:
-
PARSER_IN_UPR
public static final int PARSER_IN_UPR- See Also:
-
PARSER_IN_SHPPICT
public static final int PARSER_IN_SHPPICTCurrently a shppict control word is being parsed.- See Also:
-
PARSER_IN_PICT
public static final int PARSER_IN_PICTCurrently a pict control word is being parsed.- See Also:
-
PARSER_IN_PICPROP
public static final int PARSER_IN_PICPROPCurrently a picprop control word is being parsed.- See Also:
-
PARSER_IN_BLIPUID
public static final int PARSER_IN_BLIPUIDCurrently a blipuid control word is being parsed.- See Also:
-
PARSER_STARTSTOP
public static final int PARSER_STARTSTOPThe parser is at the beginning or the end of the file.- See Also:
-
PARSER_ERROR
public static final int PARSER_ERRORCurrently the parser is in an error state.- See Also:
-
PARSER_ERROR_EOF
public static final int PARSER_ERROR_EOFThe parser reached the end of the file.- See Also:
-
PARSER_IN_UNKNOWN
public static final int PARSER_IN_UNKNOWNCurrently the parser is in an unknown state.- See Also:
-
TYPE_UNIDENTIFIED
public static final int TYPE_UNIDENTIFIEDConversion type is unknown- See Also:
-
TYPE_IMPORT_FULL
public static final int TYPE_IMPORT_FULLConversion type is an import. Uses direct content to add everything. This is what the original import does.- See Also:
-
TYPE_IMPORT_FRAGMENT
public static final int TYPE_IMPORT_FRAGMENTConversion type is an import of a partial file/fragment. Uses direct content to add everything.- See Also:
-
TYPE_CONVERT
public static final int TYPE_CONVERTConversion type is a conversion. This uses the document (not rtfDoc) to add all the elements making it a different supported documents depending on the writer used.- See Also:
-
TYPE_IMPORT_INTO_ELEMENT
public static final int TYPE_IMPORT_INTO_ELEMENTConversion type to import a document into an element. i.e. Chapter, Section, Table Cell, etc.- Since:
- 2.1.4
- See Also:
-
DESTINATION_NORMAL
public static final int DESTINATION_NORMALDestination is normal. Text is processed.- See Also:
-
DESTINATION_SKIP
public static final int DESTINATION_SKIPDestination is skipping. Text is ignored.- See Also:
-
TOKENISER_NORMAL
public static final int TOKENISER_NORMALThe RtfTokeniser is in its ground state. Any token may follow.- See Also:
-
TOKENISER_SKIP_BYTES
public static final int TOKENISER_SKIP_BYTESThe last token parsed was a slash.- See Also:
-
TOKENISER_SKIP_GROUP
public static final int TOKENISER_SKIP_GROUPThe RtfTokeniser is currently tokenising a control word.- See Also:
-
TOKENISER_BINARY
public static final int TOKENISER_BINARYThe RtfTokeniser is currently reading binary stream.- See Also:
-
TOKENISER_HEX
public static final int TOKENISER_HEXThe RtfTokeniser is currently reading hex data.- See Also:
-
TOKENISER_IGNORE_RESULT
public static final int TOKENISER_IGNORE_RESULTThe RtfTokeniser ignore result- See Also:
-
TOKENISER_STATE_IN_ERROR
public static final int TOKENISER_STATE_IN_ERRORThe RtfTokeniser is currently in error state- See Also:
-
TOKENISER_STATE_IN_UNKOWN
public static final int TOKENISER_STATE_IN_UNKOWNThe RtfTokeniser is currently in an unkown state- See Also:
-
errOK
public static final int errOK- See Also:
-
errStackUnderflow
public static final int errStackUnderflow- See Also:
-
errStackOverflow
public static final int errStackOverflow- See Also:
-
errUnmatchedBrace
public static final int errUnmatchedBrace- See Also:
-
errInvalidHex
public static final int errInvalidHex- See Also:
-
errBadTable
public static final int errBadTable- See Also:
-
errAssertion
public static final int errAssertion- See Also:
-
errEndOfFile
public static final int errEndOfFile- See Also:
-
errCtrlWordNotFound
public static final int errCtrlWordNotFound- See Also:
-
-
Constructor Details
-
RtfParser
public RtfParser(com.lowagie.text.Document doc) Constructor- Parameters:
doc-- Since:
- 2.1.3
-
-
Method Details
-
importRtfDocument
Imports a complete RTF document.- Parameters:
readerIn- The Reader to read the RTF document from.rtfDoc- The RtfDocument to add the imported document to.- Throws:
IOException- On I/O errors.- Since:
- 2.1.3
-
importRtfDocumentIntoElement
public void importRtfDocumentIntoElement(com.lowagie.text.Element elem, InputStream readerIn, RtfDocument rtfDoc) throws IOException Imports a complete RTF document into an Element, i.e. Chapter, section, Table Cell, etc.- Parameters:
elem- The Element the document is to be imported into.readerIn- The Reader to read the RTF document from.rtfDoc- The RtfDocument to add the imported document to.- Throws:
IOException- On I/O errors.- Since:
- 2.1.4
-
convertRtfDocument
public void convertRtfDocument(InputStream readerIn, com.lowagie.text.Document doc) throws IOException Converts an RTF document to an iText document. Usage: Create a parser object and call this method with the input stream and the iText Document object- Parameters:
readerIn- The Reader to read the RTF file from.doc- The iText document that the RTF file is to be added to.- Throws:
IOException- On I/O errors.- Since:
- 2.1.3
-
importRtfFragment
public void importRtfFragment(InputStream readerIn, RtfDocument rtfDoc, RtfImportMappings importMappings) throws IOException Imports an RTF fragment.- Parameters:
readerIn- 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.- Since:
- 2.1.3
-
addListener
Adds aEventListenerto theRtfCtrlWordMgr.- Parameters:
listener- the new EventListener.- Since:
- 2.1.3
-
removeListener
Removes aEventListenerfrom theRtfCtrlWordMgr.- Parameters:
listener- the EventListener that has to be removed.- Since:
- 2.1.3
-
init_stats
protected void init_stats()Initialize the statistics values.- Since:
- 2.1.3
-
handleOpenGroup
public int handleOpenGroup()Handles open group tokens. ({)- Returns:
- errOK if ok, other if an error occurred.
- Since:
- 2.1.3
-
outputDebug
-
handleCloseGroup
public int handleCloseGroup()Handles close group tokens. (})- Returns:
- errOK if ok, other if an error occurred.
- Since:
- 2.1.3
-
handleCtrlWord
Handles control word tokens. Depending on the current state a control word can lead to a state change. When parsing the actual document contents, certain tabled values are remapped. i.e. colors, fonts, styles, etc.- Parameters:
ctrlWordData- The control word to handle.- Returns:
- errOK if ok, other if an error occurred.
- Since:
- 2.1.3
-
handleCharacter
public int handleCharacter(int nextChar) Handles text tokens. These are either handed on to the appropriate destination handler.- Parameters:
nextChar- The text token to handle.- Returns:
- errOK if ok, other if an error occurred.
- Since:
- 2.1.3
-
getState
Get the state of the parser.- Returns:
- The current RtfParserState state object.
- Since:
- 2.1.3
-
getParserState
public int getParserState()Get the current state of the parser.- Returns:
- The current state of the parser.
- Since:
- 2.1.3
-
setParserState
public int setParserState(int newState) Set the state value of the parser.- Parameters:
newState- The new state for the parser- Returns:
- The state of the parser.
- Since:
- 2.1.3
-
getConversionType
public int getConversionType()Get the conversion type.- Returns:
- The type of the conversion. Import or Convert.
- Since:
- 2.1.3
-
getRtfDocument
Get the RTF Document object.- Returns:
- Returns the object rtfDoc.
- Since:
- 2.1.3
-
getDocument
public com.lowagie.text.Document getDocument()Get the Document object.- Returns:
- Returns the object rtfDoc.
- Since:
- 2.1.3
-
getImportManager
Get the RtfImportHeader object.- Returns:
- Returns the object importHeader.
- Since:
- 2.1.3
-
setCurrentDestination
Set the current destination object for the current state.- Parameters:
destination- The destination value to set.- Since:
- 2.1.3
-
getCurrentDestination
Get the current destination object.- Returns:
- The current state destination
- Since:
- 2.1.3
-
getDestination
Get a destination from the map- Parameters:
destination- The string destination.- Returns:
- The destination object from the map
- Since:
- 2.1.3
-
isNewGroup
public boolean isNewGroup()Helper method to determine if this is a new group.- Returns:
- true if this is a new group, otherwise it returns false.
- Since:
- 2.1.3
-
setNewGroup
public boolean setNewGroup(boolean value) Helper method to set the new group flag- Parameters:
value- The boolean value to set the flag- Returns:
- The value of newGroup
- Since:
- 2.1.3
-
tokenise
Read through the input file and parse the data stream into tokens.- Throws:
IOException- on IO error.- Since:
- 2.1.3
-
setTokeniserState
public int setTokeniserState(int value) Set the current state of the tokeniser.- Parameters:
value- The new state of the tokeniser.- Returns:
- The state of the tokeniser.
- Since:
- 2.1.3
-
getTokeniserState
public int getTokeniserState()Get the current state of the tokeniser.- Returns:
- The current state of the tokeniser.
- Since:
- 2.1.3
-
getLevel
public int getLevel()Gets the current group level- Returns:
- The current group level value.
- Since:
- 2.1.3
-
setTokeniserStateNormal
public void setTokeniserStateNormal()Set the tokeniser state to skip to the end of the group. Sets the state to TOKENISER_SKIP_GROUP and skipGroupLevel to the current group level.- Since:
- 2.1.3
-
setTokeniserStateSkipGroup
public void setTokeniserStateSkipGroup()Set the tokeniser state to skip to the end of the group. Sets the state to TOKENISER_SKIP_GROUP and skipGroupLevel to the current group level.- Since:
- 2.1.3
-
setTokeniserSkipBytes
public void setTokeniserSkipBytes(long numberOfBytesToSkip) Sets the number of bytes to skip and the state of the tokeniser.- Parameters:
numberOfBytesToSkip- The numbere of bytes to skip in the file.- Since:
- 2.1.3
-
setTokeniserStateBinary
public void setTokeniserStateBinary(int binaryCount) Sets the number of binary bytes.- Parameters:
binaryCount- The number of binary bytes.- Since:
- 2.1.3
-
setTokeniserStateBinary
public void setTokeniserStateBinary(long binaryCount) Sets the number of binary bytes.- Parameters:
binaryCount- The number of binary bytes.- Since:
- 2.1.3
-
isConvert
public boolean isConvert()Helper method to determin if conversion is TYPE_CONVERT- Returns:
- true if TYPE_CONVERT, otherwise false
- Since:
- 2.1.3
- See Also:
-
isImport
public boolean isImport()Helper method to determin if conversion is TYPE_IMPORT_FULL or TYPE_IMPORT_FRAGMENT- Returns:
- true if TYPE_CONVERT, otherwise false
- Since:
- 2.1.3
- See Also:
-
isImportFull
public boolean isImportFull()Helper method to determin if conversion is TYPE_IMPORT_FULL- Returns:
- true if TYPE_CONVERT, otherwise false
- Since:
- 2.1.3
- See Also:
-
isImportFragment
public boolean isImportFragment()Helper method to determin if conversion is TYPE_IMPORT_FRAGMENT- Returns:
- true if TYPE_CONVERT, otherwise false
- Since:
- 2.1.3
- See Also:
-
getExtendedDestination
public boolean getExtendedDestination()Helper method to indicate if this control word was a \* control word.- Returns:
- true if it was a \* control word, otherwise false
- Since:
- 2.1.3
-
setExtendedDestination
public boolean setExtendedDestination(boolean value) Helper method to set the extended control word flag.- Parameters:
value- Boolean to set the value to.- Returns:
- isExtendedDestination.
- Since:
- 2.1.3
-
getLogFile
-
setLogFile
Set the logFile name- Parameters:
logFile- the logFile to set- Since:
- 2.1.3
-
setLogFile
Set the logFile name- Parameters:
logFile- the logFile to set- Since:
- 2.1.3
-
isLogging
public boolean isLogging()Get flag indicating if logging is on or off.- Returns:
- the logging
- Since:
- 2.1.3
-
setLogging
public void setLogging(boolean logging) Set flag indicating if logging is on or off- Parameters:
logging-trueto turn on logging,falseto turn off logging.- Since:
- 2.1.3
-
isLogAppend
public boolean isLogAppend()- Returns:
- the logAppend
- Since:
- 2.1.3
-
setLogAppend
public void setLogAppend(boolean logAppend) - Parameters:
logAppend- the logAppend to set- Since:
- 2.1.3
-