Class XMPPPacketReader
XMPPPacketReader
is a Reader of DOM4J documents that
uses the fast
XML Pull Parser 3.x.
It is very fast for use in SOAP style environments.
- Author:
- Pelle Braendgaard, James Strachan
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Collection<String>
Stream of various endpoints (eg: s2s, c2s) use different default namespaces. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHandler
(String path, org.dom4j.ElementHandler handler) Adds theElementHandler
to be called when the specified path is encounted.protected Reader
Factory method to create a Reader from the given InputStream.protected org.dom4j.io.DispatchHandler
org.dom4j.DocumentFactory
long
Returns the last time a full Document was read or a heartbeat was received.static Set<org.dom4j.Namespace>
getPrefixedNamespacesOnCurrentElement
(org.xmlpull.v1.XmlPullParser xpp) Retrieves a collection of namespaces declared in the current element that the parser is on, that are not defined inIGNORED_NAMESPACE_ON_STANZA
, is not "http://etherx.jabber.org/streams" and that are not the default namespace (the namespaces returned all have a defined prefix).org.xmlpull.v1.XmlPullParserFactory
org.dom4j.Document
org.dom4j.Document
parseDocument
(String xml) org.dom4j.Document
read
(char[] text) Reads a Document from the given array of charactersorg.dom4j.Document
Reads a Document from the givenFile
org.dom4j.Document
read
(InputStream in) Reads a Document from the given streamorg.dom4j.Document
read
(InputStream in, String systemID) Reads a Document from the given streamorg.dom4j.Document
Reads a Document from the givenReader
org.dom4j.Document
Reads a Document from the givenReader
org.dom4j.Document
Reads a Document from the given URL or filename.org.dom4j.Document
read
(String charSet, InputStream in) Reads a Document from the given streamorg.dom4j.Document
Reads a Document from the givenURL
void
removeHandler
(String path) Removes theElementHandler
from the event based processor, for the specified path.void
setDefaultHandler
(org.dom4j.ElementHandler handler) When multipleElementHandler
instances have been registered, this will set a defaultElementHandler
to be called for any path which does NOT have a handler registered.protected void
setDispatchHandler
(org.dom4j.io.DispatchHandler dispatchHandler) void
setDocumentFactory
(org.dom4j.DocumentFactory factory) This sets theDocumentFactory
used to create new documents.void
setXPPFactory
(org.xmlpull.v1.XmlPullParserFactory xppFactory)
-
Field Details
-
IGNORED_NAMESPACE_ON_STANZA
Stream of various endpoints (eg: s2s, c2s) use different default namespaces. To be able to use a stanza that's parsed on one type of endpoint in the context of another endpoint, we explicitly ignore these namespaced. This allows us to forward, for instance, a stanza received via C2S (which has the "jabber:client" default namespace) on a S2S stream (which has the "jabber:server" default namespace).- See Also:
-
-
Constructor Details
-
XMPPPacketReader
public XMPPPacketReader() -
XMPPPacketReader
public XMPPPacketReader(org.dom4j.DocumentFactory factory)
-
-
Method Details
-
getPrefixedNamespacesOnCurrentElement
@Nonnull public static Set<org.dom4j.Namespace> getPrefixedNamespacesOnCurrentElement(org.xmlpull.v1.XmlPullParser xpp) throws org.xmlpull.v1.XmlPullParserException Retrieves a collection of namespaces declared in the current element that the parser is on, that are not defined inIGNORED_NAMESPACE_ON_STANZA
, is not "http://etherx.jabber.org/streams" and that are not the default namespace (the namespaces returned all have a defined prefix).- Parameters:
xpp
- the parser- Returns:
- A collection of namespaces
- Throws:
org.xmlpull.v1.XmlPullParserException
- On any problem thrown by the XML parser.
-
read
public org.dom4j.Document read(File file) throws org.dom4j.DocumentException, IOException, org.xmlpull.v1.XmlPullParserException Reads a Document from the given
File
- Parameters:
file
- is theFile
to read from.- Returns:
- the newly created Document instance
- Throws:
org.dom4j.DocumentException
- if an error occurs during parsing.IOException
- if an error occurs during readingorg.xmlpull.v1.XmlPullParserException
- if an error occurs creating a pull parser
-
read
public org.dom4j.Document read(URL url) throws org.dom4j.DocumentException, IOException, org.xmlpull.v1.XmlPullParserException Reads a Document from the given
URL
- Parameters:
url
-URL
to read from.- Returns:
- the newly created Document instance
- Throws:
org.dom4j.DocumentException
- if an error occurs during parsing.IOException
- if an error occurs during readingorg.xmlpull.v1.XmlPullParserException
- if an error occurs creating a pull parser
-
read
public org.dom4j.Document read(String systemID) throws org.dom4j.DocumentException, IOException, org.xmlpull.v1.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 aURL
or aFile
instance instead of aString
to denote the source of the document.- Parameters:
systemID
- is a URL for a document or a file name.- Returns:
- the newly created Document instance
- Throws:
org.dom4j.DocumentException
- if an error occurs during parsing.IOException
- if an error occurs during readingorg.xmlpull.v1.XmlPullParserException
- if an error occurs creating a pull parser
-
read
public org.dom4j.Document read(InputStream in) throws org.dom4j.DocumentException, IOException, org.xmlpull.v1.XmlPullParserException Reads a Document from the given stream
- Parameters:
in
-InputStream
to read from.- Returns:
- the newly created Document instance
- Throws:
org.dom4j.DocumentException
- if an error occurs during parsing.IOException
- if an error occurs during readingorg.xmlpull.v1.XmlPullParserException
- if an error occurs creating a pull parser
-
read
public org.dom4j.Document read(String charSet, InputStream in) throws org.dom4j.DocumentException, IOException, org.xmlpull.v1.XmlPullParserException Reads a Document from the given stream
- Parameters:
charSet
- the charSet that the input is encoded inin
-InputStream
to read from.- Returns:
- the newly created Document instance
- Throws:
org.dom4j.DocumentException
- if an error occurs during parsing.IOException
- if an error occurs during readingorg.xmlpull.v1.XmlPullParserException
- if an error occurs creating a pull parser
-
read
public org.dom4j.Document read(Reader reader) throws org.dom4j.DocumentException, IOException, org.xmlpull.v1.XmlPullParserException Reads a Document from the given
Reader
- Parameters:
reader
- is the reader for the input- Returns:
- the newly created Document instance
- Throws:
org.dom4j.DocumentException
- if an error occurs during parsing.IOException
- if an error occurs during readingorg.xmlpull.v1.XmlPullParserException
- if an error occurs creating a pull parser
-
read
public org.dom4j.Document read(char[] text) throws org.dom4j.DocumentException, IOException, org.xmlpull.v1.XmlPullParserException Reads a Document from the given array of characters
- Parameters:
text
- is the text to parse- Returns:
- the newly created Document instance
- Throws:
org.dom4j.DocumentException
- if an error occurs during parsing.IOException
- if an error occurs during readingorg.xmlpull.v1.XmlPullParserException
- if an error occurs creating a pull parser
-
read
public org.dom4j.Document read(InputStream in, String systemID) throws org.dom4j.DocumentException, IOException, org.xmlpull.v1.XmlPullParserException Reads a Document from the given stream
- Parameters:
in
-InputStream
to read from.systemID
- is the URI for the input- Returns:
- the newly created Document instance
- Throws:
org.dom4j.DocumentException
- if an error occurs during parsing.IOException
- if an error occurs during readingorg.xmlpull.v1.XmlPullParserException
- if an error occurs creating a pull parser
-
read
public org.dom4j.Document read(Reader reader, String systemID) throws org.dom4j.DocumentException, IOException, org.xmlpull.v1.XmlPullParserException Reads a Document from the given
Reader
- Parameters:
reader
- is the reader for the inputsystemID
- is the URI for the input- Returns:
- the newly created Document instance
- Throws:
org.dom4j.DocumentException
- if an error occurs during parsing.IOException
- if an error occurs during readingorg.xmlpull.v1.XmlPullParserException
- if an error occurs creating a pull parser
-
getXPPParser
- Throws:
org.xmlpull.v1.XmlPullParserException
-
getXPPFactory
public org.xmlpull.v1.XmlPullParserFactory getXPPFactory() throws org.xmlpull.v1.XmlPullParserException- Throws:
org.xmlpull.v1.XmlPullParserException
-
setXPPFactory
public void setXPPFactory(org.xmlpull.v1.XmlPullParserFactory xppFactory) -
getDocumentFactory
public org.dom4j.DocumentFactory getDocumentFactory()- Returns:
- the
DocumentFactory
used to create document objects
-
setDocumentFactory
public void setDocumentFactory(org.dom4j.DocumentFactory factory) 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 ofDocumentFactory
- Parameters:
factory
-DocumentFactory
used to create DOM4J objects
-
addHandler
Adds theElementHandler
to be called when the specified path is encounted.- Parameters:
path
- is the path to be handledhandler
- is theElementHandler
to be called by the event based processor.
-
removeHandler
Removes theElementHandler
from the event based processor, for the specified path.- Parameters:
path
- is the path to remove theElementHandler
for.
-
setDefaultHandler
public void setDefaultHandler(org.dom4j.ElementHandler handler) When multipleElementHandler
instances have been registered, this will set a defaultElementHandler
to be called for any path which does NOT have a handler registered.- Parameters:
handler
- is theElementHandler
to be called by the event based processor.
-
getLastActive
public long getLastActive()Returns the last time a full Document was read or a heartbeat was received. Hearbeats are represented as whitespaces or \n received while a Document is not being parsed.- Returns:
- the time in milliseconds when the last document or heartbeat was received.
-
parseDocument
- Throws:
org.dom4j.DocumentException
-
parseDocument
public org.dom4j.Document parseDocument() throws org.dom4j.DocumentException, IOException, org.xmlpull.v1.XmlPullParserException- Throws:
org.dom4j.DocumentException
IOException
org.xmlpull.v1.XmlPullParserException
-
getDispatchHandler
protected org.dom4j.io.DispatchHandler getDispatchHandler() -
setDispatchHandler
protected void setDispatchHandler(org.dom4j.io.DispatchHandler dispatchHandler) -
createReader
Factory method to create a Reader from the given InputStream.- Parameters:
in
- the input stream- Returns:
- the reader
- Throws:
IOException
- never
-