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 Charsetprivate final StateControllerprivate booleanprivate final List<XMLParserListener> private final XMLParserMemoryprivate ParserMonitorprivate Stateprivate TagStateprivate 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 noParserListeneris added, parsing with the parser seems useless no?append(char character) append(char[] bytes) Appends the given string to the buffer.intprivate voidcallText()Call this method to submit the text to listeners.voidcomment()Triggered for comments.current()Returns the current content of the text buffer.charGet the current tagGet the state of the current tagprivate voidcurrentTagState(TagState state) Set the state of the current tagDetects encoding from a stream.voidTriggered when a closing tag has been encountered.voidflush()Flushes the currently stored data in the buffer.Returns the current used character set.booleanmemory()Returns the XMLParserMemory.voidparse(InputStream in) Parse an InputStream with default encoding setvoidparse(InputStream in, boolean detectEncoding) Parse an InputStream that optionally detects encoding from the streamvoidparse(InputStream in, Charset charSet) Parses an InputStream using the given encodingvoidParse an Readerprivate voidparseWithReader(Reader reader) The actual parse methodRemoves a Listener from the list of listeners.The state controller of the parservoidsetDecodeSpecialChars(boolean decodeSpecialChars) Determines whether special chars like > will be decodedvoidsetMonitor(ParserMonitor monitor) protected voidSet the current state.voidTriggered when an opening tag has been encountered.voidTriggered when content has been encountered.voidTriggered 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 noParserListeneris 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- theXMLParserListenerto 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
-
append
- Parameters:
character- the character to append- Returns:
- the parser
-
selectState
-
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
-
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
-
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
-
getCharset
-