Package com.itextpdf.tool.xml.parser
Class XMLParser
java.lang.Object
com.itextpdf.tool.xml.parser.XMLParser
Reads an XML file. Attach a
XMLParserListener
for receiving events.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Charset
private final StateController
private boolean
private final List
<XMLParserListener> private final XMLParserMemory
private ParserMonitor
private State
private TagState
private String
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a default XMLParser ready for HTML/XHTML processing.XMLParser
(boolean b, XMLParserListener listener) Constructs a new Parser with the default jvm charset.XMLParser
(boolean isHtml, XMLParserListener listener, Charset charset) Construct a XMLParser with the given XMLParserConfig.Constructs a XMLParser.XMLParser
(XMLParserListener listener) Constructs a new Parser with HTML parsing set to true and the default jvm charset.XMLParser
(XMLParserListener listener, Charset charset) Construct an XMLParser with the given XMLParserConfig ready for HTML/XHTML processing.. -
Method Summary
Modifier and TypeMethodDescriptionIf noParserListener
is added, parsing with the parser seems useless no?append
(char character) append
(char[] bytes) Appends the given string to the buffer.int
private void
callText()
Call this method to submit the text to listeners.void
comment()
Triggered for comments.current()
Returns the current content of the text buffer.char
Get the current tagGet the state of the current tagprivate void
currentTagState
(TagState state) Set the state of the current tagDetects encoding from a stream.void
Triggered when a closing tag has been encountered.void
flush()
Flushes the currently stored data in the buffer.Returns the current used character set.boolean
memory()
Returns the XMLParserMemory.void
parse
(InputStream in) Parse an InputStream with default encoding setvoid
parse
(InputStream in, boolean detectEncoding) Parse an InputStream that optionally detects encoding from the streamvoid
parse
(InputStream in, Charset charSet) Parses an InputStream using the given encodingvoid
Parse an Readerprivate void
parseWithReader
(Reader reader) The actual parse methodRemoves a Listener from the list of listeners.The state controller of the parservoid
setDecodeSpecialChars
(boolean decodeSpecialChars) Determines whether special chars like > will be decodedvoid
setMonitor
(ParserMonitor monitor) protected void
Set the current state.void
Triggered when an opening tag has been encountered.void
Triggered when content has been encountered.void
Triggered when the UnknownState encountered anything before encountering a tag.
-
Field Details
-
state
-
controller
-
listeners
-
memory
-
monitor
-
text
-
tagState
-
charset
-
decodeSpecialChars
private boolean decodeSpecialChars
-
-
Constructor Details
-
XMLParser
public XMLParser()Constructs a default XMLParser ready for HTML/XHTML processing. -
XMLParser
Constructs a XMLParser.- Parameters:
isHtml
- false if this parser is not going to parse HTML and whitespace should be submitted as text too.charset
- charset
-
XMLParser
Construct an XMLParser with the given XMLParserConfig ready for HTML/XHTML processing..- Parameters:
listener
- the listenercharset
- the Charset
-
XMLParser
Construct a XMLParser with the given XMLParserConfig.- Parameters:
isHtml
- false if this parser is not going to parse HTML and whitespace should be submitted as text too.listener
- the listenercharset
- the Charset to use
-
XMLParser
Constructs a new Parser with the default jvm charset.- Parameters:
b
- true if HTML is being parsedlistener
- the XMLParserListener
-
XMLParser
Constructs a new Parser with HTML parsing set to true and the default jvm charset.- Parameters:
listener
- the XMLParserListener
-
-
Method Details
-
addListener
If noParserListener
is added, parsing with the parser seems useless no?- Parameters:
pl
- theXMLParserListener
- Returns:
- the parser
-
removeListener
Removes a Listener from the list of listeners.- Parameters:
pl
- theXMLParserListener
to remove- Returns:
- the parser
-
parse
Parse an InputStream with default encoding set- Parameters:
in
- the InputStream to parse- Throws:
IOException
- if IO went wrong
-
parse
Parse an InputStream that optionally detects encoding from the stream- Parameters:
in
- the InputStream to parsedetectEncoding
- true if encoding should be detected from the stream- Throws:
IOException
- if IO went wrong
-
parse
Parses an InputStream using the given encoding- Parameters:
in
- the stream to readcharSet
- to use for the constructed reader.- Throws:
IOException
- if reading fails
-
parse
Parse an Reader- Parameters:
reader
- the reader- Throws:
IOException
- if IO went wrong
-
parseWithReader
The actual parse method- Parameters:
reader
-- Throws:
IOException
-
detectEncoding
public InputStreamReader detectEncoding(InputStream in) throws IOException, UnsupportedEncodingException Detects encoding from a stream.- Parameters:
in
- the stream- Returns:
- a Reader with the deduced encoding.
- Throws:
IOException
- if IO went wrongUnsupportedEncodingException
- if unsupported encoding was detected
-
setState
Set the current state.- Parameters:
state
- the current state
-
append
- Parameters:
character
- the character to append- Returns:
- the parser
-
selectState
The state controller of the parser- Returns:
StateController
-
unknownData
public void unknownData()Triggered when the UnknownState encountered anything before encountering a tag. -
flush
public void flush()Flushes the currently stored data in the buffer. -
current
Returns the current content of the text buffer.- Returns:
- current buffer content
-
memory
Returns the XMLParserMemory.- Returns:
- the memory
-
startElement
public void startElement()Triggered when an opening tag has been encountered. -
callText
private void callText()Call this method to submit the text to listeners. -
endElement
public void endElement()Triggered when a closing tag has been encountered. -
text
Triggered when content has been encountered.- Parameters:
bs
- the content
-
comment
public void comment()Triggered for comments. -
currentLastChar
public char currentLastChar()- Returns:
- the current last character of the buffer or ' ' if none.
-
currentTag
Get the current tag- Returns:
- the current tag.
-
currentTagState
Get the state of the current tag- Returns:
- the state of the current tag
-
currentTagState
Set the state of the current tag- Parameters:
state
- the state of the current tag
-
setMonitor
- Parameters:
monitor
- the monitor to set
-
setDecodeSpecialChars
public void setDecodeSpecialChars(boolean decodeSpecialChars) Determines whether special chars like > will be decoded- Parameters:
decodeSpecialChars
- true to decode, false to not decode
-
isDecodeSpecialChars
public boolean isDecodeSpecialChars() -
bufferToString
- Returns:
- the current buffer as a String
-
append
- Parameters:
bytes
- the byte array to append- Returns:
- this instance of the XMLParser
-
bufferSize
public int bufferSize()- Returns:
- the size of the buffer
-
append
Appends the given string to the buffer.- Parameters:
string
- the String to append- Returns:
- this instance of the XMLParser
-
getCharset
Returns the current used character set.- Returns:
- the charset
-