public class DSCParser extends java.lang.Object implements DSCParserConstants
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.
|
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.
|
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.
|
protected void |
parseNext()
Parses the next event.
|
DSCEvent |
peek()
Returns the next event without moving the cursor to the next event.
|
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.
|
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 specpublic 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 filepublic 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()
Copyright 1999-2012 The Apache Software Foundation. All Rights Reserved.