com.itextpdf.tool.xml.parser
Class XMLParser

java.lang.Object
  extended by com.itextpdf.tool.xml.parser.XMLParser

public class XMLParser
extends Object

Reads an XML file. Attach a XMLParserListener for receiving events.

Author:
redlab_b

Constructor Summary
XMLParser()
          Constructs a default XMLParser ready for HTML/XHTML processing.
XMLParser(boolean isHtml, Charset charset)
          Constructs a XMLParser.
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.
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
 XMLParser addListener(XMLParserListener pl)
          If no ParserListener is added, parsing with the parser seems useless no?
 XMLParser append(char character)
           
 XMLParser append(char[] bytes)
           
 XMLParser append(String string)
          Appends the given string to the buffer.
 int bufferSize()
           
 String bufferToString()
           
 void comment()
          Triggered for comments.
 String current()
          Returns the current content of the text buffer.
 char currentLastChar()
           
 String currentTag()
          Get the current tag
 TagState currentTagState()
          Get the state of the current tag
 InputStreamReader detectEncoding(InputStream in)
          Detects encoding from a stream.
 void endElement()
          Triggered when a closing tag has been encountered.
 void flush()
          Flushes the currently stored data in the buffer.
 Charset getCharset()
          Returns the current used character set.
 XMLParserMemory memory()
          Returns the XMLParserMemory.
 void parse(InputStream in)
          Parse an InputStream with default encoding set
 void parse(InputStream in, boolean detectEncoding)
          Parse an InputStream that optionally detects encoding from the stream
 void parse(InputStream in, Charset charSet)
          Parses an InputStream using the given encoding
 void parse(Reader reader)
          Parse an Reader
 XMLParser removeListener(XMLParserListener pl)
          Removes a Listener from the list of listeners.
 StateController selectState()
          The state controller of the parser
 void setMonitor(ParserMonitor monitor)
           
protected  void setState(State state)
          Set the current state.
 void startElement()
          Triggered when an opening tag has been encountered.
 void text(String bs)
          Triggered when content has been encountered.
 void unknownData()
          Triggered when the UnknownState encountered anything before encountering a tag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLParser

public XMLParser()
Constructs a default XMLParser ready for HTML/XHTML processing.


XMLParser

public XMLParser(boolean isHtml,
                 Charset charset)
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

public XMLParser(XMLParserListener listener,
                 Charset charset)
Construct an XMLParser with the given XMLParserConfig ready for HTML/XHTML processing..

Parameters:
listener - the listener
charset - the Charset

XMLParser

public XMLParser(boolean isHtml,
                 XMLParserListener listener,
                 Charset charset)
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 listener
charset - the Charset to use

XMLParser

public XMLParser(boolean b,
                 XMLParserListener listener)
Constructs a new Parser with the default jvm charset.

Parameters:
b - true if HTML is being parsed
listener - the XMLParserListener

XMLParser

public XMLParser(XMLParserListener listener)
Constructs a new Parser with HTML parsing set to true and the default jvm charset.

Parameters:
listener - the XMLParserListener
Method Detail

addListener

public XMLParser addListener(XMLParserListener pl)
If no ParserListener is added, parsing with the parser seems useless no?

Parameters:
pl - the XMLParserListener
Returns:
the parser

removeListener

public XMLParser removeListener(XMLParserListener pl)
Removes a Listener from the list of listeners.

Parameters:
pl - the XMLParserListener to remove
Returns:
the parser

parse

public void parse(InputStream in)
           throws IOException
Parse an InputStream with default encoding set

Parameters:
in - the InputStream to parse
Throws:
IOException - if IO went wrong

parse

public void parse(InputStream in,
                  boolean detectEncoding)
           throws IOException
Parse an InputStream that optionally detects encoding from the stream

Parameters:
in - the InputStream to parse
detectEncoding - true if encoding should be detected from the stream
Throws:
IOException - if IO went wrong

parse

public void parse(InputStream in,
                  Charset charSet)
           throws IOException
Parses an InputStream using the given encoding

Parameters:
in - the stream to read
charSet - to use for the constructed reader.
Throws:
IOException - if reading fails

parse

public void parse(Reader reader)
           throws IOException
Parse an Reader

Parameters:
reader - the reader
Throws:
IOException - if IO went wrong

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 wrong
UnsupportedEncodingException - if unsupported encoding was detected

setState

protected void setState(State state)
Set the current state.

Parameters:
state - the current state

append

public XMLParser append(char character)
Parameters:
character - the character to append
Returns:
the parser

selectState

public StateController 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

public String current()
Returns the current content of the text buffer.

Returns:
current buffer content

memory

public XMLParserMemory memory()
Returns the XMLParserMemory.

Returns:
the memory

startElement

public void startElement()
Triggered when an opening tag has been encountered.


endElement

public void endElement()
Triggered when a closing tag has been encountered.


text

public void text(String bs)
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

public String currentTag()
Get the current tag

Returns:
the current tag.

currentTagState

public TagState currentTagState()
Get the state of the current tag

Returns:
the state of the current tag

setMonitor

public void setMonitor(ParserMonitor monitor)
Parameters:
monitor - the monitor to set

bufferToString

public String bufferToString()
Returns:
the current buffer as a String

append

public XMLParser append(char[] bytes)
Parameters:
bytes - the byte array to append
Returns:
this instance of the XMLParser

bufferSize

public int bufferSize()
Returns:
the size of the buffer

append

public XMLParser append(String string)
Appends the given string to the buffer.

Parameters:
string - the String to append
Returns:
this instance of the XMLParser

getCharset

public Charset getCharset()
Returns the current used character set.

Returns:
the charset


Copyright © 2012. All Rights Reserved.