public class DSCParser extends java.lang.Object implements DSCParserConstants
Modifier and Type | Class and Description |
---|---|
(package private) static class |
DSCParser.MyDSCListener |
Modifier and Type | Field and Description |
---|---|
private boolean |
checkEOF |
private DSCEvent |
currentEvent |
private boolean |
eofFound |
private DSCListener |
filterListener |
private java.io.InputStream |
in |
private java.util.List |
listeners |
private boolean |
listenersDisabled |
private static org.apache.commons.logging.Log |
LOG |
private DSCListener |
nestedDocumentHandler |
private DSCEvent |
nextEvent |
private java.io.BufferedReader |
reader |
COMMENT, DSC_COMMENT, EOF, HEADER_COMMENT, LINE
Constructor and Description |
---|
DSCParser(java.io.InputStream in)
Creates a new DSC parser.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(DSCListener listener)
Adds a DSC event listener.
|
private void |
checkLine(java.lang.String line) |
DSCEvent |
getCurrentEvent()
Returns the current event.
|
java.io.InputStream |
getInputStream()
Returns the InputStream the PostScript code is read from.
|
java.lang.String |
getLine()
Returns the current PostScript line.
|
boolean |
hasNext()
Indicates whether there are additional items.
|
boolean |
isCheckEOF()
Indicates whether the parser is configured to check for content after the EOF comment.
|
boolean |
isListenersDisabled()
Indicates whether the listeners are currently disabled.
|
private boolean |
isWhitespace(char c) |
int |
next()
Steps to the next item indicating the type of event.
|
DSCComment |
nextDSCComment(java.lang.String name)
Advances to the next DSC comment with the given name.
|
DSCComment |
nextDSCComment(java.lang.String name,
PSGenerator gen)
Advances to the next DSC comment with the given name.
|
DSCEvent |
nextEvent()
Steps to the next item returning the new event.
|
PostScriptComment |
nextPSComment(java.lang.String prefix,
PSGenerator gen)
Advances to the next PostScript comment with the given prefix.
|
void |
parse(DSCHandler handler)
Starts the parser in push parsing mode sending events to the DSCHandler instance.
|
private DSCComment |
parseDSCComment(java.lang.String name,
java.lang.String value) |
private DSCComment |
parseDSCLine(java.lang.String line) |
protected void |
parseNext()
Parses the next event.
|
DSCEvent |
peek()
Returns the next event without moving the cursor to the next event.
|
private void |
processListeners() |
protected java.lang.String |
readLine()
Reads one line from the input file
|
void |
removeListener(DSCListener listener)
Removes a DSC event listener.
|
void |
setCheckEOF(boolean value)
Tells the parser whether to check for content after the EOF comment.
|
void |
setFilter(DSCFilter filter)
Sets a filter for DSC events.
|
void |
setListenersDisabled(boolean value)
Allows to disable all listeners.
|
void |
setNestedDocumentHandler(NestedDocumentHandler handler)
Sets a NestedDocumentHandler which is used to skip nested documents like embedded EPS files.
|
protected void |
warn(java.lang.String msg)
This method is used to write out warning messages for the parsing process.
|
private static final org.apache.commons.logging.Log LOG
private java.io.InputStream in
private java.io.BufferedReader reader
private boolean eofFound
private boolean checkEOF
private DSCEvent currentEvent
private DSCEvent nextEvent
private DSCListener nestedDocumentHandler
private DSCListener filterListener
private java.util.List listeners
private boolean listenersDisabled
public DSCParser(java.io.InputStream in) throws java.io.IOException, DSCException
in
- InputStream to read the PostScript file from
(the stream is not closed by this class, the caller is responsible for that)java.io.IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic java.io.InputStream getInputStream()
protected void warn(java.lang.String msg)
msg
- the warning messageprotected java.lang.String readLine() throws java.io.IOException, DSCException
java.io.IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specprivate void checkLine(java.lang.String line) throws DSCException
DSCException
private boolean isWhitespace(char c)
private DSCComment parseDSCLine(java.lang.String line) throws java.io.IOException, DSCException
java.io.IOException
DSCException
private DSCComment parseDSCComment(java.lang.String name, java.lang.String value)
public void parse(DSCHandler handler) throws java.io.IOException, DSCException
handler
- the DSCHandler instance to send the events tojava.io.IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic boolean hasNext()
public int next() throws java.io.IOException, DSCException
DSCParserConstants
)java.io.IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specjava.util.NoSuchElementException
- If an attempt was made to advance beyond the end of the fileprivate void processListeners() throws java.io.IOException, DSCException
java.io.IOException
DSCException
public DSCEvent nextEvent() throws java.io.IOException, DSCException
java.io.IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic DSCEvent getCurrentEvent()
public DSCEvent peek()
protected void parseNext() throws java.io.IOException, DSCException
java.io.IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic java.lang.String getLine()
java.lang.IllegalStateException
- if the current event is not a normal PostScript linepublic DSCComment nextDSCComment(java.lang.String name) throws java.io.IOException, DSCException
name
- the name of the DSC commentjava.io.IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic DSCComment nextDSCComment(java.lang.String name, PSGenerator gen) throws java.io.IOException, DSCException
name
- the name of the DSC commentgen
- PSGenerator to pass the skipped events though tojava.io.IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic PostScriptComment nextPSComment(java.lang.String prefix, PSGenerator gen) throws java.io.IOException, DSCException
Example: To find FOP's custom comments, pass in "FOP" as a prefix. This will find comments like "%FOPFontSetup".
prefix
- the prefix of the extension commentgen
- PSGenerator to pass the skipped events though tojava.io.IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic void setFilter(DSCFilter filter)
filter
- the filter to use or null to disable filteringpublic void addListener(DSCListener listener)
listener
- the listenerpublic void removeListener(DSCListener listener)
listener
- the listener to removepublic void setListenersDisabled(boolean value)
value
- true to disable all listeners, false to re-enable thempublic boolean isListenersDisabled()
public void setNestedDocumentHandler(NestedDocumentHandler handler)
It is suggested to use the more generally usable addListener(DSCListener)
and
removeListener(DSCListener)
instead. NestedDocumentHandler is internally
mapped onto a DSCListener
.
handler
- the NestedDocumentHandler instance or null to disable the featurepublic void setCheckEOF(boolean value)
value
- true if the check is enabledpublic boolean isCheckEOF()