public class PacketParserUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
PacketParserUtils.UnparsedResultIQ
This class represents and unparsed IQ of the type 'result'.
|
Constructor and Description |
---|
PacketParserUtils() |
Modifier and Type | Method and Description |
---|---|
static org.xmlpull.v1.XmlPullParser |
newXmppParser()
Creates a new XmlPullParser suitable for parsing XMPP.
|
static Collection<String> |
parseCompressionMethods(org.xmlpull.v1.XmlPullParser parser)
Parse the available compression methods reported from the server.
|
static String |
parseContent(org.xmlpull.v1.XmlPullParser parser)
Returns the content of a element as string.
|
static String |
parseContentDepth(org.xmlpull.v1.XmlPullParser parser,
int depth) |
static String |
parseContentDepth(org.xmlpull.v1.XmlPullParser parser,
int depth,
boolean fullNamespaces)
Returns the content from the current position of the parser up to the closing tag of the
given depth.
|
static String |
parseElement(org.xmlpull.v1.XmlPullParser parser)
Returns the current element as string.
|
static String |
parseElement(org.xmlpull.v1.XmlPullParser parser,
boolean fullNamespaces) |
static String |
parseElementText(org.xmlpull.v1.XmlPullParser parser)
Returns the textual content of an element as String.
|
static XMPPError |
parseError(org.xmlpull.v1.XmlPullParser parser)
Parses error sub-packets.
|
static IQ |
parseIQ(org.xmlpull.v1.XmlPullParser parser,
XMPPConnection connection)
Parses an IQ packet.
|
static Collection<String> |
parseMechanisms(org.xmlpull.v1.XmlPullParser parser)
Parse the available SASL mechanisms reported from the server.
|
static Message |
parseMessage(org.xmlpull.v1.XmlPullParser parser)
Parses a message packet.
|
static PacketExtension |
parsePacketExtension(String elementName,
String namespace,
org.xmlpull.v1.XmlPullParser parser)
Parses a packet extension sub-packet.
|
static Presence |
parsePresence(org.xmlpull.v1.XmlPullParser parser)
Parses a presence packet.
|
static SASLMechanism.SASLFailure |
parseSASLFailure(org.xmlpull.v1.XmlPullParser parser)
Parses SASL authentication error packets.
|
static StreamError |
parseStreamError(org.xmlpull.v1.XmlPullParser parser)
Parses stream error packets.
|
static Object |
parseWithIntrospection(String elementName,
Class<?> objectClass,
org.xmlpull.v1.XmlPullParser parser) |
public PacketParserUtils()
public static org.xmlpull.v1.XmlPullParser newXmppParser() throws org.xmlpull.v1.XmlPullParserException
Note that not all XmlPullParser implementations will return a String on
getText()
if the parser is on START_TAG or END_TAG. So you must not rely on this
behavior when using the parser.
org.xmlpull.v1.XmlPullParserException
public static Message parseMessage(org.xmlpull.v1.XmlPullParser parser) throws Exception
parser
- the XML parser, positioned at the start of a message packet.Exception
- if an exception occurs while parsing the packet.public static String parseElementText(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, IOException
The parser must be positioned on a START_TAG of an element which MUST NOT contain Mixed Content (as defined in XML 3.2.2), or else an XmlPullParserException will be thrown.
This method is used for the parts where the XMPP specification requires elements that contain only text or are the empty element.parser
- org.xmlpull.v1.XmlPullParserException
IOException
public static String parseElement(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, IOException
The parser must be positioned on START_TAG.
Note that only the outermost namespace attributes ("xmlns") will be returned, not nested ones.parser
- the XML pull parserorg.xmlpull.v1.XmlPullParserException
IOException
public static String parseElement(org.xmlpull.v1.XmlPullParser parser, boolean fullNamespaces) throws org.xmlpull.v1.XmlPullParserException, IOException
org.xmlpull.v1.XmlPullParserException
IOException
public static String parseContent(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, IOException
The parser must be positioned on the START_TAG of the element which content is going to get returned. If the current element is the empty element, then the empty string is returned. If it is a element which contains just text, then just the text is returned. If it contains nested elements (and text), then everything from the current opening tag to the corresponding closing tag of the same depth is returned as String.
Note that only the outermost namespace attributes ("xmlns") will be returned, not nested ones.parser
- the XML pull parserorg.xmlpull.v1.XmlPullParserException
- if parser encounters invalid XMLIOException
- if an IO error occurspublic static String parseContentDepth(org.xmlpull.v1.XmlPullParser parser, int depth) throws org.xmlpull.v1.XmlPullParserException, IOException
org.xmlpull.v1.XmlPullParserException
IOException
public static String parseContentDepth(org.xmlpull.v1.XmlPullParser parser, int depth, boolean fullNamespaces) throws org.xmlpull.v1.XmlPullParserException, IOException
fullNamespaces
is false. If it is true, then namespaces of
parent elements will be added to child elements that don't define a different namespace.
This method is able to parse the content with MX- and KXmlParser. In order to achieve
this some trade-off has to be make, because KXmlParser does not support xml-roundtrip (ie.
return a String on getText() on START_TAG and END_TAG). We are therefore required to work
around this limitation, which results in only partial support for XML namespaces ("xmlns"):
Only the outermost namespace of elements will be included in the resulting String, if
fullNamespaces
is set to false.
parser
- depth
- fullNamespaces
- org.xmlpull.v1.XmlPullParserException
IOException
public static Presence parsePresence(org.xmlpull.v1.XmlPullParser parser) throws Exception
parser
- the XML parser, positioned at the start of a presence packet.Exception
- if an exception occurs while parsing the packet.public static IQ parseIQ(org.xmlpull.v1.XmlPullParser parser, XMPPConnection connection) throws Exception
parser
- the XML parser, positioned at the start of an IQ packet.Exception
- if an exception occurs while parsing the packet.public static Collection<String> parseMechanisms(org.xmlpull.v1.XmlPullParser parser) throws Exception
parser
- the XML parser, positioned at the start of the mechanisms stanza.Exception
- if an exception occurs while parsing the stanza.public static Collection<String> parseCompressionMethods(org.xmlpull.v1.XmlPullParser parser) throws IOException, org.xmlpull.v1.XmlPullParserException
parser
- the XML parser, positioned at the start of the compression stanza.org.xmlpull.v1.XmlPullParserException
- if an exception occurs while parsing the stanza.IOException
public static SASLMechanism.SASLFailure parseSASLFailure(org.xmlpull.v1.XmlPullParser parser) throws Exception
parser
- the XML parser.Exception
- if an exception occurs while parsing the packet.public static StreamError parseStreamError(org.xmlpull.v1.XmlPullParser parser) throws IOException, org.xmlpull.v1.XmlPullParserException
parser
- the XML parser.org.xmlpull.v1.XmlPullParserException
- if an exception occurs while parsing the packet.IOException
public static XMPPError parseError(org.xmlpull.v1.XmlPullParser parser) throws Exception
parser
- the XML parser.Exception
- if an exception occurs while parsing the packet.public static PacketExtension parsePacketExtension(String elementName, String namespace, org.xmlpull.v1.XmlPullParser parser) throws Exception
elementName
- the XML element name of the packet extension.namespace
- the XML namespace of the packet extension.parser
- the XML parser, positioned at the starting element of the extension.Exception
- if a parsing error occurs.