public class DSCParser extends Object implements DSCParserConstants
COMMENT, DSC_COMMENT, EOF, HEADER_COMMENT, LINE
Constructor and Description |
---|
DSCParser(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.
|
InputStream |
getInputStream()
Returns the InputStream the PostScript code is read from.
|
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(String name)
Advances to the next DSC comment with the given name.
|
DSCComment |
nextDSCComment(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(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 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(String msg)
This method is used to write out warning messages for the parsing process.
|
public DSCParser(InputStream in) throws IOException, DSCException
in
- InputStream to read the PostScript file from
(the stream is not closed by this class, the caller is responsible for that)IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic InputStream getInputStream()
protected void warn(String msg)
msg
- the warning messageprotected String readLine() throws IOException, DSCException
IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic void parse(DSCHandler handler) throws IOException, DSCException
handler
- the DSCHandler instance to send the events toIOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic boolean hasNext()
public int next() throws IOException, DSCException
DSCParserConstants
)IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specNoSuchElementException
- If an attempt was made to advance beyond the end of the filepublic DSCEvent nextEvent() throws IOException, DSCException
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 IOException, DSCException
IOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic String getLine()
IllegalStateException
- if the current event is not a normal PostScript linepublic DSCComment nextDSCComment(String name) throws IOException, DSCException
name
- the name of the DSC commentIOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic DSCComment nextDSCComment(String name, PSGenerator gen) throws IOException, DSCException
name
- the name of the DSC commentgen
- PSGenerator to pass the skipped events though toIOException
- In case of an I/O errorDSCException
- In case of a violation of the DSC specpublic PostScriptComment nextPSComment(String prefix, PSGenerator gen) throws 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 toIOException
- 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 © 2019 Apache Software Foundation. All rights reserved.