|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream javax.swing.text.rtf.AbstractFilter javax.swing.text.rtf.RTFParser javax.swing.text.rtf.RTFReader
Takes a sequence of RTF tokens and text and appends the text
described by the RTF to a StyledDocument
(the target).
The RTF is lexed
from the character stream by the RTFParser
which is this class's
superclass.
This class is an indirect subclass of OutputStream. It must be closed
in order to guarantee that all of the text has been sent to
the text acceptor.
RTFParser
,
OutputStream
Nested Class Summary | |
(package private) class |
RTFReader.AttributeTrackingDestination
RTFReader.TextHandlingDestination is an abstract RTF destination which simply tracks the attributes specified by the RTF control words in internal form and can produce acceptable AttributeSets for the current character, paragraph, and section attributes. |
(package private) class |
RTFReader.ColortblDestination
Reads the colortbl group. |
(package private) static interface |
RTFReader.Destination
An interface (could be an entirely abstract class) describing a destination. |
(package private) class |
RTFReader.DiscardingDestination
This data-sink class is used to implement ignored destinations (e.g. |
(package private) class |
RTFReader.DocumentDestination
RTFReader.DocumentDestination is a concrete subclass of TextHandlingDestination which appends the text to the StyledDocument given by the target ivar of the
containing RTFReader. |
(package private) class |
RTFReader.FonttblDestination
Reads the fonttbl group, inserting fonts into the RTFReader's fontTable dictionary. |
(package private) class |
RTFReader.InfoDestination
Handles the info group. |
(package private) class |
RTFReader.StylesheetDestination
Handles the stylesheet keyword. |
(package private) class |
RTFReader.TextHandlingDestination
RTFReader.TextHandlingDestination provides basic text handling functionality. |
Field Summary | |
(package private) static boolean[] |
allSpecialsTable
A specials table which indicates that all characters are special |
(package private) ByteArrayOutputStream |
binaryBuf
|
(package private) static Dictionary |
characterSets
|
(package private) Style[] |
characterStyles
This array maps character style numbers to Style objects. |
(package private) Color[] |
colorTable
This array maps color indices to Color objects. |
(package private) MutableAttributeSet |
documentAttributes
This holds the current document attributes. |
(package private) Dictionary |
fontTable
This Dictionary maps Integer font numbers to String font names. |
(package private) boolean |
ignoreGroupIfUnknownKeyword
true to indicate that if the next keyword is unknown,
the containing group should be ignored. |
(package private) static char[] |
latin1TranslationTable
A translation table which does ISO Latin-1 (trivial) |
int |
level
The current RTF group nesting level. |
private MockAttributeSet |
mockery
|
(package private) static boolean[] |
noSpecialsTable
A specials table which indicates that no characters are special |
(package private) Style[] |
paragraphStyles
This array maps paragraph style numbers to Style objects. |
(package private) Dictionary |
parserState
Miscellaneous information about the parser's state. |
(package private) RTFReader.Destination |
rtfDestination
This is the "dst" item from parserState. rtfDestination is the current rtf destination. |
(package private) static boolean[] |
rtfSpecialsTable
|
(package private) int |
rtfversion
This is the RTF version number, extracted from the \rtf keyword. |
(package private) Style[] |
sectionStyles
This array maps section style numbers to Style objects. |
(package private) int |
skippingCharacters
The parameter of the most recently parsed \\ucN keyword, used for skipping alternative representations after a Unicode character. |
protected boolean[] |
specialsTable
A table indicating which byte values should be interpreted as characters and which should be treated as formatting codes |
private static Dictionary |
straightforwardAttributes
|
(package private) static String |
TabAlignmentKey
|
(package private) static String |
TabLeaderKey
|
(package private) StyledDocument |
target
The object to which the parsed text is sent. |
(package private) static Dictionary |
textKeywords
textKeywords maps RTF keywords to single-character strings, for those keywords which simply insert some text. |
protected char[] |
translationTable
A table mapping bytes to characters |
(package private) static boolean |
useNeXTForAnsi
|
protected PrintStream |
warnings
A stream to which to write warnings and debugging information while parsing. |
Constructor Summary | |
RTFReader(StyledDocument destination)
Creates a new RTFReader instance. |
Method Summary | |
void |
begingroup()
Called by the superclass when a new RTF group is begun. |
void |
close()
Called by the user when there is no more input (i.e. |
(package private) Color |
defaultColor()
The default color for text which has no specified color. |
static void |
defineCharacterSet(String name,
char[] table)
Adds a character set to the RTFReader's list of known character sets |
void |
endgroup()
Called by the superclass when the current RTF group is closed. |
void |
flush()
Flushes any buffered but not yet written characters. |
static Object |
getCharacterSet(String name)
Looks up a named character set. |
void |
handleBinaryBlob(byte[] data)
Called when the RTFParser encounters a bin keyword in the RTF stream. |
boolean |
handleKeyword(String keyword)
Handles a parameterless RTF keyword. |
boolean |
handleKeyword(String keyword,
int parameter)
Handles an RTF keyword and its integer parameter. |
void |
handleText(char ch)
|
void |
handleText(String text)
Handles any pure text (containing no control characters) in the input stream. |
(package private) static char[] |
readCharset(InputStream strm)
Parses a character set from an InputStream. |
(package private) static char[] |
readCharset(URL href)
|
void |
readFromReader(Reader in)
|
void |
readFromStream(InputStream in)
A convenience method that reads text from a FileInputStream and writes it to the receiver. |
void |
setCharacterSet(String name)
setCharacterSet sets the current translation table to correspond with the named character set. |
protected void |
setRTFDestination(RTFReader.Destination newDestination)
|
private void |
setTargetAttribute(String name,
Object value)
|
protected void |
warning(String s)
|
void |
write(byte[] buf,
int off,
int len)
Implements the buffer-at-a-time write method for greater efficiency. |
void |
write(char ch)
Subclasses must provide an implementation of this method which accepts a single (non-special) character. |
void |
write(int b)
Implements the abstract method of OutputStream, of which this class is a subclass. |
void |
write(String s)
Hopefully, all subclasses will override this method to accept strings of text, but if they don't, AbstractFilter's implementation will spoon-feed them via write(char) . |
void |
writeSpecial(int b)
Subclasses must provide an implementation of this method which accepts a single special byte. |
Methods inherited from class java.io.OutputStream |
write |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
StyledDocument target
Dictionary parserState
RTFReader.Destination rtfDestination
MutableAttributeSet documentAttributes
Dictionary fontTable
Color[] colorTable
Style[] characterStyles
Style[] paragraphStyles
Style[] sectionStyles
int rtfversion
boolean ignoreGroupIfUnknownKeyword
true
to indicate that if the next keyword is unknown,
the containing group should be ignored.
int skippingCharacters
private static Dictionary straightforwardAttributes
private MockAttributeSet mockery
static Dictionary textKeywords
static final String TabAlignmentKey
static final String TabLeaderKey
static Dictionary characterSets
static boolean useNeXTForAnsi
public int level
ByteArrayOutputStream binaryBuf
protected PrintStream warnings
System.out
to log
any anomalous information to stdout.
static final boolean[] rtfSpecialsTable
protected char[] translationTable
protected boolean[] specialsTable
static final char[] latin1TranslationTable
static final boolean[] noSpecialsTable
static final boolean[] allSpecialsTable
Constructor Detail |
public RTFReader(StyledDocument destination)
destination
- The TextAcceptor which is to receive the text.Method Detail |
public void handleBinaryBlob(byte[] data)
handleBinaryBlob
in class RTFParser
RTFParser
public void handleText(String text)
handleText
in class RTFParser
Color defaultColor()
public void begingroup()
parserState
, and gives
the current destination a chance to save its own state.
begingroup
in class RTFParser
RTFParser.begingroup()
public void endgroup()
begingroup()
as well as invoking the endgroup method of the current
destination.
endgroup
in class RTFParser
RTFParser.endgroup()
protected void setRTFDestination(RTFReader.Destination newDestination)
public void close() throws IOException
close
in class RTFParser
IOException
OutputStream.close()
public boolean handleKeyword(String keyword)
handleKeyword
in class RTFParser
RTFParser.handleKeyword(java.lang.String)
public boolean handleKeyword(String keyword, int parameter)
handleKeyword
in class RTFParser
keyword
- The keyword, as with handleKeyword(String)
.parameter
- The parameter following the keyword.RTFParser.handleKeyword(java.lang.String)
private void setTargetAttribute(String name, Object value)
public void setCharacterSet(String name)
AbstractFilter
public static void defineCharacterSet(String name, char[] table)
public static Object getCharacterSet(String name) throws IOException
IOException
static char[] readCharset(InputStream strm) throws IOException
IOException
static char[] readCharset(URL href) throws IOException
IOException
public void handleText(char ch)
public void writeSpecial(int b) throws IOException
AbstractFilter
writeSpecial
in class AbstractFilter
b
- The byte written to the OutputStream.
IOException
protected void warning(String s)
public void write(String s) throws IOException
AbstractFilter
write(char)
.
write
in class AbstractFilter
s
- The string of non-special characters written to the
OutputStream.
IOException
public void write(char ch) throws IOException
AbstractFilter
write
in class AbstractFilter
ch
- The character written to the OutputStream.
IOException
public void flush() throws IOException
flush
in class OutputStream
IOException
- if an I/O error occurs.public void readFromStream(InputStream in) throws IOException
This method does not close the receiver after reaching EOF on
the input stream.
The user must call close()
to ensure that all
data are processed.
in
- An InputStream providing text.
IOException
public void readFromReader(Reader in) throws IOException
IOException
public void write(int b) throws IOException
write
in class OutputStream
b
- the byte
.
IOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
output stream has been closed.public void write(byte[] buf, int off, int len) throws IOException
PENDING: Does write(byte[])
call write(byte[], int, int)
or is it the other way
around?
write
in class OutputStream
buf
- the data.off
- the start offset in the data.len
- the number of bytes to write.
IOException
- if an I/O error occurs. In particular,
an IOException
is thrown if the output
stream is closed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |