Top Description Fields Constructors Methods
org.dom4j.io

public Class XPPReader

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .File, .FileReader, .IOException, .InputStream, .InputStreamReader, .Reader, java.net.URL, org.dom4j.Document, .DocumentException, .DocumentFactory, .Element, .ElementHandler, org.dom4j.xpp.ProxyXmlStartTag, org.gjt.xpp.XmlEndTag, .XmlPullParser, .XmlPullParserException, .XmlPullParserFactory

XPPReader is a Reader of DOM4J documents that uses the fast XML Pull Parser 2.x . It does not currently support comments, CDATA or ProcessingInstructions or validation but it is very fast for use in SOAP style environments.

Author
James Strachan
Version
$Revision: 1.7 $

Field Summary

Modifier and TypeField and Description
private DispatchHandler
dispatchHandler

DispatchHandler to call when each Element is encountered

private DocumentFactory
factory

DocumentFactory used to create new document objects

private XmlPullParserFactory
xppFactory

XmlPullParser used to parse XML

private XmlPullParser
xppParser

XmlPullParser used to parse XML

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
addHandler(String
is the path to be handled
path
,
ElementHandler
is the ElementHandler to be called by the event based processor.
handler
)

Adds the ElementHandler to be called when the specified path is encounted.

protected Reader

Returns:

DOCUMENT ME!
createReader
(InputStream
DOCUMENT ME!
in
)

Factory method to create a Reader from the given InputStream.

protected DispatchHandler
public DocumentFactory

Returns:

the DocumentFactory used to create document objects
getDocumentFactory
()

DOCUMENT ME!

public XmlPullParserFactory
public XmlPullParser
protected Document
public Document

Returns:

the newly created Document instance
read
(File
is the File to read from.
file
)

Reads a Document from the given File

public Document

Returns:

the newly created Document instance
read
(URL
URL to read from.
url
)

Reads a Document from the given URL

public Document

Returns:

the newly created Document instance
read
(String
is a URL for a document or a file name.
systemID
)

Reads a Document from the given URL or filename.

public Document

Returns:

the newly created Document instance
read
(InputStream
InputStream to read from.
in
)

Reads a Document from the given stream

public Document

Returns:

the newly created Document instance
read
(Reader
is the reader for the input
reader
)

Reads a Document from the given Reader

public Document

Returns:

the newly created Document instance
read
(char[]
is the text to parse
text
)

Reads a Document from the given array of characters

public Document

Returns:

the newly created Document instance
read
(InputStream
InputStream to read from.
in
,
String
is the URI for the input
systemID
)

Reads a Document from the given stream

public Document

Returns:

the newly created Document instance
read
(Reader
is the reader for the input
reader
,
String
is the URI for the input
systemID
)

Reads a Document from the given Reader

public void
removeHandler(String
is the path to remove the ElementHandler for.
path
)

Removes the ElementHandler from the event based processor, for the specified path.

public void
setDefaultHandler(ElementHandler
is the ElementHandler to be called by the event based processor.
handler
)

When multiple ElementHandler instances have been registered, this will set a default ElementHandler to be called for any path which does NOT have a handler registered.

protected void
public void
setDocumentFactory(DocumentFactory
DocumentFactory used to create DOM4J objects
documentFactory
)

This sets the DocumentFactory used to create new documents.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dispatchHandlerback to summary
private DispatchHandler dispatchHandler

DispatchHandler to call when each Element is encountered

factoryback to summary
private DocumentFactory factory

DocumentFactory used to create new document objects

xppFactoryback to summary
private XmlPullParserFactory xppFactory

XmlPullParser used to parse XML

xppParserback to summary
private XmlPullParser xppParser

XmlPullParser used to parse XML

Constructor Detail

XPPReaderback to summary
public XPPReader()
XPPReaderback to summary
public XPPReader(DocumentFactory factory)

Method Detail

addHandlerback to summary
public void addHandler(String path, ElementHandler handler)

Adds the ElementHandler to be called when the specified path is encounted.

Parameters
path:String

is the path to be handled

handler:ElementHandler

is the ElementHandler to be called by the event based processor.

createReaderback to summary
protected Reader createReader(InputStream in) throws IOException

Factory method to create a Reader from the given InputStream.

Parameters
in:InputStream

DOCUMENT ME!

Returns:Reader

DOCUMENT ME!

Exceptions
IOException:
DOCUMENT ME!
getDispatchHandlerback to summary
protected DispatchHandler getDispatchHandler()
getDocumentFactoryback to summary
public DocumentFactory getDocumentFactory()

DOCUMENT ME!

Returns:DocumentFactory

the DocumentFactory used to create document objects

getXPPFactoryback to summary
public XmlPullParserFactory getXPPFactory() throws XmlPullParserException
getXPPParserback to summary
public XmlPullParser getXPPParser() throws XmlPullParserException
parseDocumentback to summary
protected Document parseDocument() throws DocumentException, IOException, XmlPullParserException
readback to summary
public Document read(File file) throws DocumentException, IOException, XmlPullParserException

Reads a Document from the given File

Parameters
file:File

is the File to read from.

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
if an error occurs during parsing.
IOException:
if a URL could not be made for the given File
XmlPullParserException:
DOCUMENT ME!
readback to summary
public Document read(URL url) throws DocumentException, IOException, XmlPullParserException

Reads a Document from the given URL

Parameters
url:URL

URL to read from.

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
if an error occurs during parsing.
IOException:
DOCUMENT ME!
XmlPullParserException:
DOCUMENT ME!
readback to summary
public Document read(String systemID) throws DocumentException, IOException, XmlPullParserException

Reads a Document from the given URL or filename.

If the systemID contains a ':' character then it is assumed to be a URL otherwise its assumed to be a file name. If you want finer grained control over this mechansim then please explicitly pass in either a URLor a Fileinstance instead of a String to denote the source of the document.

Parameters
systemID:String

is a URL for a document or a file name.

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
if an error occurs during parsing.
IOException:
if a URL could not be made for the given File
XmlPullParserException:
DOCUMENT ME!
readback to summary
public Document read(InputStream in) throws DocumentException, IOException, XmlPullParserException

Reads a Document from the given stream

Parameters
in:InputStream

InputStream to read from.

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
if an error occurs during parsing.
IOException:
DOCUMENT ME!
XmlPullParserException:
DOCUMENT ME!
readback to summary
public Document read(Reader reader) throws DocumentException, IOException, XmlPullParserException

Reads a Document from the given Reader

Parameters
reader:Reader

is the reader for the input

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
if an error occurs during parsing.
IOException:
DOCUMENT ME!
XmlPullParserException:
DOCUMENT ME!
readback to summary
public Document read(char[] text) throws DocumentException, IOException, XmlPullParserException

Reads a Document from the given array of characters

Parameters
text:char[]

is the text to parse

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
if an error occurs during parsing.
IOException:
DOCUMENT ME!
XmlPullParserException:
DOCUMENT ME!
readback to summary
public Document read(InputStream in, String systemID) throws DocumentException, IOException, XmlPullParserException

Reads a Document from the given stream

Parameters
in:InputStream

InputStream to read from.

systemID:String

is the URI for the input

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
if an error occurs during parsing.
IOException:
DOCUMENT ME!
XmlPullParserException:
DOCUMENT ME!
readback to summary
public Document read(Reader reader, String systemID) throws DocumentException, IOException, XmlPullParserException

Reads a Document from the given Reader

Parameters
reader:Reader

is the reader for the input

systemID:String

is the URI for the input

Returns:Document

the newly created Document instance

Exceptions
DocumentException:
if an error occurs during parsing.
IOException:
DOCUMENT ME!
XmlPullParserException:
DOCUMENT ME!
removeHandlerback to summary
public void removeHandler(String path)

Removes the ElementHandler from the event based processor, for the specified path.

Parameters
path:String

is the path to remove the ElementHandler for.

setDefaultHandlerback to summary
public void setDefaultHandler(ElementHandler handler)

When multiple ElementHandler instances have been registered, this will set a default ElementHandler to be called for any path which does NOT have a handler registered.

Parameters
handler:ElementHandler

is the ElementHandler to be called by the event based processor.

setDispatchHandlerback to summary
protected void setDispatchHandler(DispatchHandler dispatchHandler)
setDocumentFactoryback to summary
public void setDocumentFactory(DocumentFactory documentFactory)

This sets the DocumentFactory used to create new documents. This method allows the building of custom DOM4J tree objects to be implemented easily using a custom derivation of DocumentFactory

Parameters
documentFactory:DocumentFactory

DocumentFactory used to create DOM4J objects

setXPPFactoryback to summary
public void setXPPFactory(XmlPullParserFactory xPPFactory)