|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lowagie.text.rtf.parser.RtfParser
public class 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.
Field Summary | |
---|---|
private long |
binByteCount
When the tokeniser is Binary. |
private long |
binSkipByteCount
When the tokeniser is set to skip bytes, binSkipByteCount is the number of bytes to skip. |
private long |
byteCount
Total bytes read. |
private long |
characterCount
Total clear text characters processed. |
private long |
closeGroupCount
Total } encountered as a close group token. |
private int |
conversionType
Conversion type. |
private long |
ctrlWordCount
Total control words processed. |
private long |
ctrlWordHandledCount
Total control words recognized. |
private long |
ctrlWordNotHandledCount
Total control words not handled. |
private long |
ctrlWordSkippedCount
Total control words skipped. |
private RtfParserState |
currentState
The current parser state. |
private static boolean |
debugParser
Debugging flag. |
static int |
DESTINATION_NORMAL
Destination is normal. |
static int |
DESTINATION_SKIP
Destination is skipping. |
private RtfDestinationMgr |
destinationMgr
The RtfDestinationMgr object to manage destinations. |
private int |
docGroupLevel
The current document group nesting level. |
private Document |
document
The iText document to add the RTF document to. |
private Element |
elem
The iText element to add the RTF document to. |
private Date |
endDate
End date as a date. |
private long |
endTime
Stop time as a long. |
static int |
errAssertion
|
static int |
errBadTable
|
static int |
errCtrlWordNotFound
|
static int |
errEndOfFile
|
static int |
errInvalidHex
|
static int |
errOK
|
static int |
errStackOverflow
|
static int |
errStackUnderflow
|
static int |
errUnmatchedBrace
|
private int |
groupLevel
The current group nesting level. |
private long |
groupSkippedCount
Total groups skipped. |
private RtfImportMgr |
importMgr
The RtfImportHeader to store imported font and color mappings in. |
private RtfCtrlWordData |
lastCtrlWordParam
Last control word and parameter processed. |
private ArrayList |
listeners
The RtfCtrlWordListener . |
private boolean |
logAppend
|
private String |
logFile
|
private boolean |
logging
|
private long |
openGroupCount
Total { encountered as an open group token. |
static int |
PARSER_ERROR
Currently the parser is in an error state. |
static int |
PARSER_ERROR_EOF
The parser reached the end of the file. |
static int |
PARSER_IN_BLIPUID
Currently a blipuid control word is being parsed. |
static int |
PARSER_IN_CHARSET
Currently the RTF charset is being parsed. |
static int |
PARSER_IN_COLOR_TABLE
Currently the RTF color table is being parsed. |
static int |
PARSER_IN_DEFFONT
Currently the RTF deffont is being parsed. |
static int |
PARSER_IN_DOCUMENT
Currently the RTF document content is being parsed. |
static int |
PARSER_IN_FILE_TABLE
Currently the RTF filetbl is being parsed. |
static int |
PARSER_IN_FONT_TABLE
Currently the RTF font table is being parsed. |
static int |
PARSER_IN_FONT_TABLE_INFO
Currently a RTF font table info element is being parsed. |
static int |
PARSER_IN_GENERATOR
Currently the RTF generator is being parsed. |
static int |
PARSER_IN_HEADER
Currently the RTF document header is being parsed. |
static int |
PARSER_IN_INFO_GROUP
Currently the RTF info group is being parsed. |
static int |
PARSER_IN_LATENTSTYLES
Currently the Latent Style and Formatting usage restrictions |
static int |
PARSER_IN_LIST_TABLE
Currently the RTF listtables is being parsed. |
static int |
PARSER_IN_LISTOVERRIDE_TABLE
Currently the RTF listtable override is being parsed. |
static int |
PARSER_IN_OLDCPROPS
Currently the RTF Old Properties. |
static int |
PARSER_IN_OLDPPROPS
Currently the RTF Old Properties. |
static int |
PARSER_IN_OLDSPROPS
Currently the RTF Old Properties. |
static int |
PARSER_IN_OLDTPROPS
Currently the RTF Old Properties. |
static int |
PARSER_IN_PARAGRAPH_GROUP_PROPERTIES
|
static int |
PARSER_IN_PARAGRAPH_TABLE
Currently the RTF Paragraph group properties Table (word 2002) |
static int |
PARSER_IN_PICPROP
Currently a picprop control word is being parsed. |
static int |
PARSER_IN_PICT
Currently a pict control word is being parsed. |
static int |
PARSER_IN_PROT_USER_TABLE
Currently the RTF User Protection Information. |
static int |
PARSER_IN_REV_TABLE
Currently the RTF revtbl is being parsed. |
static int |
PARSER_IN_RSID_TABLE
Currently the RTF rsidtable is being parsed. |
static int |
PARSER_IN_SHPPICT
Currently a shppict control word is being parsed. |
static int |
PARSER_IN_STYLESHEET
Currently the RTF stylesheet is being parsed. |
static int |
PARSER_IN_UNKNOWN
Currently the parser is in an unknown state. |
static int |
PARSER_IN_UPR
|
static int |
PARSER_STARTSTOP
The parser is at the beginning or the end of the file. |
private PushbackInputStream |
pbReader
The pushback reader to read the input stream. |
private RtfDocument |
rtfDoc
The RtfDocument to add the RTF document or fragment to. |
private RtfCtrlWordMgr |
rtfKeywordMgr
The RtfKeywords that creates and handles keywords that are implemented. |
private int |
skipGroupLevel
When the tokeniser is set to skip to next group, this is the group indentifier to return to. |
private Stack |
stackState
Stack for saving states for groups |
private Date |
startDate
Start date as a date. |
private long |
startTime
Start time as a long. |
static int |
TOKENISER_BINARY
The RtfTokeniser is currently reading binary stream. |
static int |
TOKENISER_HEX
The RtfTokeniser is currently reading hex data. |
static int |
TOKENISER_IGNORE_RESULT
The RtfTokeniser ignore result |
static int |
TOKENISER_NORMAL
The RtfTokeniser is in its ground state. |
static int |
TOKENISER_SKIP_BYTES
The last token parsed was a slash. |
static int |
TOKENISER_SKIP_GROUP
The RtfTokeniser is currently tokenising a control word. |
static int |
TOKENISER_STATE_IN_ERROR
The RtfTokeniser is currently in error state |
static int |
TOKENISER_STATE_IN_UNKOWN
The RtfTokeniser is currently in an unkown state |
static int |
TYPE_CONVERT
Conversion type is a conversion. |
static int |
TYPE_IMPORT_FRAGMENT
Conversion type is an import of a partial file/fragment. |
static int |
TYPE_IMPORT_FULL
Conversion type is an import. |
static int |
TYPE_IMPORT_INTO_ELEMENT
Conversion type to import a document into an element. |
static int |
TYPE_UNIDENTIFIED
Conversion type is unknown |
Constructor Summary | |
---|---|
RtfParser(Document doc)
Constructor |
Method Summary | |
---|---|
void |
addListener(EventListener listener)
Adds a EventListener to the RtfCtrlWordMgr . |
void |
convertRtfDocument(InputStream readerIn,
Document doc)
Converts an RTF document to an iText document. |
int |
getConversionType()
Get the conversion type. |
RtfDestination |
getCurrentDestination()
Get the current destination object. |
RtfDestination |
getDestination(String destination)
Get a destination from the map |
Document |
getDocument()
Get the Document object. |
boolean |
getExtendedDestination()
Helper method to indicate if this control word was a \* control word. |
RtfImportMgr |
getImportManager()
Get the RtfImportHeader object. |
int |
getLevel()
Gets the current group level |
String |
getLogFile()
Get the logfile name. |
int |
getParserState()
Get the current state of the parser. |
RtfDocument |
getRtfDocument()
Get the RTF Document object. |
RtfParserState |
getState()
Get the state of the parser. |
int |
getTokeniserState()
Get the current state of the tokeniser. |
int |
handleCharacter(int nextChar)
Handles text tokens. |
int |
handleCloseGroup()
Handles close group tokens. |
int |
handleCtrlWord(RtfCtrlWordData ctrlWordData)
Handles control word tokens. |
private void |
handleImportMappings(RtfImportMappings importMappings)
Imports the mappings defined in the RtfImportMappings into the RtfImportHeader of this RtfParser2. |
int |
handleOpenGroup()
Handles open group tokens. |
void |
importRtfDocument(InputStream readerIn,
RtfDocument rtfDoc)
Imports a complete RTF document. |
void |
importRtfDocumentIntoElement(Element elem,
InputStream readerIn,
RtfDocument rtfDoc)
Imports a complete RTF document into an Element, i.e. |
void |
importRtfFragment(InputStream readerIn,
RtfDocument rtfDoc,
RtfImportMappings importMappings)
Imports an RTF fragment. |
private PushbackInputStream |
init_Reader(InputStream readerIn)
Casts the input reader to a PushbackReader or creates a new PushbackReader from the Reader passed in. |
protected void |
init_stats()
Initialize the statistics values. |
private void |
init(int type,
RtfDocument rtfDoc,
InputStream readerIn,
Document doc,
Element elem)
Initialize the parser object values. |
boolean |
isConvert()
Helper method to determin if conversion is TYPE_CONVERT |
boolean |
isImport()
Helper method to determin if conversion is TYPE_IMPORT_FULL or TYPE_IMPORT_FRAGMENT |
boolean |
isImportFragment()
Helper method to determin if conversion is TYPE_IMPORT_FRAGMENT |
boolean |
isImportFull()
Helper method to determin if conversion is TYPE_IMPORT_FULL |
boolean |
isLogAppend()
|
boolean |
isLogging()
Get flag indicating if logging is on or off. |
boolean |
isNewGroup()
Helper method to determine if this is a new group. |
static void |
outputDebug(Object doc,
int groupLevel,
String str)
|
private int |
parseChar(int nextChar)
Process the character and send it to the current destination. |
private int |
parseCtrlWord(PushbackInputStream reader)
Parses a keyword and it's parameter if one exists |
void |
removeListener(EventListener listener)
Removes a EventListener from the RtfCtrlWordMgr . |
boolean |
setCurrentDestination(String destination)
Set the current destination object for the current state. |
boolean |
setExtendedDestination(boolean value)
Helper method to set the extended control word flag. |
void |
setLogAppend(boolean logAppend)
|
void |
setLogFile(String logFile)
Set the logFile name |
void |
setLogFile(String logFile,
boolean logAppend)
Set the logFile name |
void |
setLogging(boolean logging)
Set flag indicating if logging is on or off |
boolean |
setNewGroup(boolean value)
Helper method to set the new group flag |
int |
setParserState(int newState)
Set the state value of the parser. |
void |
setTokeniserSkipBytes(long numberOfBytesToSkip)
Sets the number of bytes to skip and the state of the tokeniser. |
int |
setTokeniserState(int value)
Set the current state of the tokeniser. |
void |
setTokeniserStateBinary(int binaryCount)
Sets the number of binary bytes. |
void |
setTokeniserStateBinary(long binaryCount)
Sets the number of binary bytes. |
void |
setTokeniserStateNormal()
Set the tokeniser state to skip to the end of the group. |
void |
setTokeniserStateSkipGroup()
Set the tokeniser state to skip to the end of the group. |
void |
tokenise()
Read through the input file and parse the data stream into tokens. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final boolean debugParser
private String logFile
private boolean logging
private boolean logAppend
private Element elem
private Document document
private RtfDocument rtfDoc
private RtfCtrlWordMgr rtfKeywordMgr
private RtfImportMgr importMgr
private RtfDestinationMgr destinationMgr
private Stack stackState
private RtfParserState currentState
private PushbackInputStream pbReader
private int conversionType
public static final int PARSER_IN_HEADER
public static final int PARSER_IN_CHARSET
public static final int PARSER_IN_DEFFONT
public static final int PARSER_IN_FONT_TABLE
public static final int PARSER_IN_FONT_TABLE_INFO
public static final int PARSER_IN_FILE_TABLE
public static final int PARSER_IN_COLOR_TABLE
public static final int PARSER_IN_STYLESHEET
public static final int PARSER_IN_LIST_TABLE
public static final int PARSER_IN_LISTOVERRIDE_TABLE
public static final int PARSER_IN_REV_TABLE
public static final int PARSER_IN_RSID_TABLE
public static final int PARSER_IN_GENERATOR
public static final int PARSER_IN_PARAGRAPH_TABLE
public static final int PARSER_IN_OLDCPROPS
public static final int PARSER_IN_OLDPPROPS
public static final int PARSER_IN_OLDTPROPS
public static final int PARSER_IN_OLDSPROPS
public static final int PARSER_IN_PROT_USER_TABLE
public static final int PARSER_IN_LATENTSTYLES
public static final int PARSER_IN_PARAGRAPH_GROUP_PROPERTIES
public static final int PARSER_IN_DOCUMENT
public static final int PARSER_IN_INFO_GROUP
public static final int PARSER_IN_UPR
public static final int PARSER_IN_SHPPICT
public static final int PARSER_IN_PICT
public static final int PARSER_IN_PICPROP
public static final int PARSER_IN_BLIPUID
public static final int PARSER_STARTSTOP
public static final int PARSER_ERROR
public static final int PARSER_ERROR_EOF
public static final int PARSER_IN_UNKNOWN
public static final int TYPE_UNIDENTIFIED
public static final int TYPE_IMPORT_FULL
public static final int TYPE_IMPORT_FRAGMENT
public static final int TYPE_CONVERT
public static final int TYPE_IMPORT_INTO_ELEMENT
public static final int DESTINATION_NORMAL
public static final int DESTINATION_SKIP
public static final int TOKENISER_NORMAL
public static final int TOKENISER_SKIP_BYTES
public static final int TOKENISER_SKIP_GROUP
public static final int TOKENISER_BINARY
public static final int TOKENISER_HEX
public static final int TOKENISER_IGNORE_RESULT
public static final int TOKENISER_STATE_IN_ERROR
public static final int TOKENISER_STATE_IN_UNKOWN
private int groupLevel
private int docGroupLevel
private long binByteCount
private long binSkipByteCount
private int skipGroupLevel
public static final int errOK
public static final int errStackUnderflow
public static final int errStackOverflow
public static final int errUnmatchedBrace
public static final int errInvalidHex
public static final int errBadTable
public static final int errAssertion
public static final int errEndOfFile
public static final int errCtrlWordNotFound
private long byteCount
private long ctrlWordCount
ctrlWordCount
should equal
ctrlWrodHandlecCount
+ ctrlWordNotHandledCount
ctrlWordSkippedCount
private long openGroupCount
private long closeGroupCount
private long characterCount
private long ctrlWordHandledCount
private long ctrlWordNotHandledCount
private long ctrlWordSkippedCount
private long groupSkippedCount
private long startTime
private long endTime
private Date startDate
private Date endDate
private RtfCtrlWordData lastCtrlWordParam
private ArrayList listeners
RtfCtrlWordListener
.
Constructor Detail |
---|
public RtfParser(Document doc)
doc
- Method Detail |
---|
public void importRtfDocument(InputStream readerIn, RtfDocument rtfDoc) throws IOException
readerIn
- The Reader to read the RTF document from.rtfDoc
- The RtfDocument to add the imported document to.
IOException
- On I/O errors.public void importRtfDocumentIntoElement(Element elem, InputStream readerIn, RtfDocument rtfDoc) throws IOException
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.
IOException
- On I/O errors.public void convertRtfDocument(InputStream readerIn, Document doc) throws IOException
readerIn
- The Reader to read the RTF file from.doc
- The iText document that the RTF file is to be added to.
IOException
- On I/O errors.public void importRtfFragment(InputStream readerIn, RtfDocument rtfDoc, RtfImportMappings importMappings) throws IOException
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.
IOException
- On I/O errors.public void addListener(EventListener listener)
EventListener
to the RtfCtrlWordMgr
.
listener
- the new EventListener.public void removeListener(EventListener listener)
EventListener
from the RtfCtrlWordMgr
.
listener
- the EventListener that has to be removed.private void init(int type, RtfDocument rtfDoc, InputStream readerIn, Document doc, Element elem)
type
- Type of conversion or importrtfDoc
- The RtfDocument
readerIn
- The input streamdoc
- The iText Document
protected void init_stats()
private PushbackInputStream init_Reader(InputStream readerIn)
readerIn
- The Reader object for the input file.
private void handleImportMappings(RtfImportMappings importMappings)
importMappings
- The RtfImportMappings to import.public int handleOpenGroup()
public static void outputDebug(Object doc, int groupLevel, String str)
public int handleCloseGroup()
public int handleCtrlWord(RtfCtrlWordData ctrlWordData)
ctrlWordData
- The control word to handle.
public int handleCharacter(int nextChar)
nextChar
- The text token to handle.
public RtfParserState getState()
public int getParserState()
public int setParserState(int newState)
newState
- The new state for the parser
public int getConversionType()
public RtfDocument getRtfDocument()
public Document getDocument()
public RtfImportMgr getImportManager()
public boolean setCurrentDestination(String destination)
destination
- The destination value to set.public RtfDestination getCurrentDestination()
public RtfDestination getDestination(String destination)
destination
- The string destination.
public boolean isNewGroup()
public boolean setNewGroup(boolean value)
value
- The boolean value to set the flag
public void tokenise() throws IOException
IOException
- on IO error.private int parseChar(int nextChar)
nextChar
- The character to process
private int parseCtrlWord(PushbackInputStream reader) throws IOException
reader
- This is a pushback reader for file input.
IOException
- Catch any file read problem.public int setTokeniserState(int value)
value
- The new state of the tokeniser.
public int getTokeniserState()
public int getLevel()
public void setTokeniserStateNormal()
public void setTokeniserStateSkipGroup()
public void setTokeniserSkipBytes(long numberOfBytesToSkip)
numberOfBytesToSkip
- The numbere of bytes to skip in the file.public void setTokeniserStateBinary(int binaryCount)
binaryCount
- The number of binary bytes.public void setTokeniserStateBinary(long binaryCount)
binaryCount
- The number of binary bytes.public boolean isConvert()
TYPE_CONVERT
public boolean isImport()
TYPE_IMPORT_FULL
,
TYPE_IMPORT_FRAGMENT
public boolean isImportFull()
TYPE_IMPORT_FULL
public boolean isImportFragment()
TYPE_IMPORT_FRAGMENT
public boolean getExtendedDestination()
public boolean setExtendedDestination(boolean value)
value
- Boolean to set the value to.
public String getLogFile()
public void setLogFile(String logFile)
logFile
- the logFile to setpublic void setLogFile(String logFile, boolean logAppend)
logFile
- the logFile to setpublic boolean isLogging()
public void setLogging(boolean logging)
logging
- true
to turn on logging, false
to turn off logging.public boolean isLogAppend()
public void setLogAppend(boolean logAppend)
logAppend
- the logAppend to set
|
Hosted by Hostbasket | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |