public class PacketParserUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FEATURE_XML_ROUNDTRIP |
static boolean |
XML_PULL_PARSER_SUPPORTS_ROUNDTRIP
True if the XmlPullParser supports the XML_ROUNDTRIP feature.
|
Constructor and Description |
---|
PacketParserUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addExtensionElement(java.util.Collection<ExtensionElement> collection,
org.xmlpull.v1.XmlPullParser parser) |
static void |
addExtensionElement(java.util.Collection<ExtensionElement> collection,
org.xmlpull.v1.XmlPullParser parser,
java.lang.String elementName,
java.lang.String namespace) |
static void |
addExtensionElement(Stanza packet,
org.xmlpull.v1.XmlPullParser parser) |
static void |
addExtensionElement(Stanza packet,
org.xmlpull.v1.XmlPullParser parser,
java.lang.String elementName,
java.lang.String namespace) |
static void |
addPacketExtension(java.util.Collection<ExtensionElement> collection,
org.xmlpull.v1.XmlPullParser parser)
Deprecated.
|
static void |
addPacketExtension(java.util.Collection<ExtensionElement> collection,
org.xmlpull.v1.XmlPullParser parser,
java.lang.String elementName,
java.lang.String namespace)
Deprecated.
|
static void |
addPacketExtension(Stanza packet,
org.xmlpull.v1.XmlPullParser parser)
Deprecated.
|
static void |
addPacketExtension(Stanza packet,
org.xmlpull.v1.XmlPullParser parser,
java.lang.String elementName,
java.lang.String namespace)
Deprecated.
|
static org.xmlpull.v1.XmlPullParser |
getParserFor(java.io.Reader reader) |
static org.xmlpull.v1.XmlPullParser |
getParserFor(java.lang.String stanza) |
static org.xmlpull.v1.XmlPullParser |
getParserFor(java.lang.String stanza,
java.lang.String startTag) |
static org.xmlpull.v1.XmlPullParser |
newXmppParser()
Creates a new XmlPullParser suitable for parsing XMPP.
|
static org.xmlpull.v1.XmlPullParser |
newXmppParser(java.io.Reader reader)
Creates a new XmlPullParser suitable for parsing XMPP.
|
static Compress.Feature |
parseCompressionFeature(org.xmlpull.v1.XmlPullParser parser)
Parse the Compression Feature reported from the server.
|
static java.lang.CharSequence |
parseContent(org.xmlpull.v1.XmlPullParser parser)
Returns the content of a element.
|
static java.lang.CharSequence |
parseContentDepth(org.xmlpull.v1.XmlPullParser parser,
int depth) |
static java.lang.CharSequence |
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 java.util.Map<java.lang.String,java.lang.String> |
parseDescriptiveTexts(org.xmlpull.v1.XmlPullParser parser,
java.util.Map<java.lang.String,java.lang.String> descriptiveTexts) |
static java.lang.CharSequence |
parseElement(org.xmlpull.v1.XmlPullParser parser)
Returns the current element as string.
|
static java.lang.CharSequence |
parseElement(org.xmlpull.v1.XmlPullParser parser,
boolean fullNamespaces) |
static java.lang.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 ExtensionElement |
parseExtensionElement(java.lang.String elementName,
java.lang.String namespace,
org.xmlpull.v1.XmlPullParser parser)
Parses an extension element.
|
static IQ |
parseIQ(org.xmlpull.v1.XmlPullParser parser)
Parses an IQ packet.
|
static java.util.Collection<java.lang.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 ExtensionElement |
parsePacketExtension(java.lang.String elementName,
java.lang.String namespace,
org.xmlpull.v1.XmlPullParser parser)
Deprecated.
use
parseExtensionElement(String, String, XmlPullParser) instead. |
static Presence |
parsePresence(org.xmlpull.v1.XmlPullParser parser)
Parses a presence packet.
|
static SaslStreamElements.SASLFailure |
parseSASLFailure(org.xmlpull.v1.XmlPullParser parser)
Parses SASL authentication error packets.
|
static Session.Feature |
parseSessionFeature(org.xmlpull.v1.XmlPullParser parser) |
static Stanza |
parseStanza(java.lang.String stanza) |
static Stanza |
parseStanza(org.xmlpull.v1.XmlPullParser parser)
Tries to parse and return either a Message, IQ or Presence stanza.
|
static StartTls |
parseStartTlsFeature(org.xmlpull.v1.XmlPullParser parser) |
static StreamError |
parseStreamError(org.xmlpull.v1.XmlPullParser parser)
Parses stream error packets.
|
public static final java.lang.String FEATURE_XML_ROUNDTRIP
public static final boolean XML_PULL_PARSER_SUPPORTS_ROUNDTRIP
public static org.xmlpull.v1.XmlPullParser getParserFor(java.lang.String stanza) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public static org.xmlpull.v1.XmlPullParser getParserFor(java.io.Reader reader) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public static org.xmlpull.v1.XmlPullParser getParserFor(java.lang.String stanza, java.lang.String startTag) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public static Stanza parseStanza(java.lang.String stanza) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
public static Stanza parseStanza(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
parser
- org.xmlpull.v1.XmlPullParserException
SmackException
java.io.IOException
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 org.xmlpull.v1.XmlPullParser newXmppParser(java.io.Reader reader) 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.
reader
- org.xmlpull.v1.XmlPullParserException
public static Message parseMessage(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
parser
- the XML parser, positioned at the start of a message packet.java.io.IOException
org.xmlpull.v1.XmlPullParserException
SmackException
public static java.lang.String parseElementText(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.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
java.io.IOException
public static java.lang.CharSequence parseElement(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.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
java.io.IOException
public static java.lang.CharSequence parseElement(org.xmlpull.v1.XmlPullParser parser, boolean fullNamespaces) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public static java.lang.CharSequence parseContent(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.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 XMLjava.io.IOException
- if an IO error occurspublic static java.lang.CharSequence parseContentDepth(org.xmlpull.v1.XmlPullParser parser, int depth) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public static java.lang.CharSequence parseContentDepth(org.xmlpull.v1.XmlPullParser parser, int depth, boolean fullNamespaces) throws org.xmlpull.v1.XmlPullParserException, java.io.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. KXmlParser does not support
xml-roundtrip. i.e. return a String on getText() on START_TAG and END_TAG. We check for the
XML_ROUNDTRIP feature. If it's not found we are 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.
In particular Android's XmlPullParser does not support XML_ROUNDTRIP.
parser
- depth
- fullNamespaces
- org.xmlpull.v1.XmlPullParserException
java.io.IOException
public static Presence parsePresence(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
parser
- the XML parser, positioned at the start of a presence packet.java.io.IOException
org.xmlpull.v1.XmlPullParserException
SmackException
public static IQ parseIQ(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
parser
- the XML parser, positioned at the start of an IQ packet.org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
public static java.util.Collection<java.lang.String> parseMechanisms(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
parser
- the XML parser, positioned at the start of the mechanisms stanza.java.io.IOException
org.xmlpull.v1.XmlPullParserException
public static Compress.Feature parseCompressionFeature(org.xmlpull.v1.XmlPullParser parser) throws java.io.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.java.io.IOException
public static java.util.Map<java.lang.String,java.lang.String> parseDescriptiveTexts(org.xmlpull.v1.XmlPullParser parser, java.util.Map<java.lang.String,java.lang.String> descriptiveTexts) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public static SaslStreamElements.SASLFailure parseSASLFailure(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
parser
- the XML parser.java.io.IOException
org.xmlpull.v1.XmlPullParserException
public static StreamError parseStreamError(org.xmlpull.v1.XmlPullParser parser) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException, SmackException
parser
- the XML parser.org.xmlpull.v1.XmlPullParserException
- if an exception occurs while parsing the packet.SmackException
java.io.IOException
public static XMPPError parseError(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
parser
- the XML parser.java.io.IOException
org.xmlpull.v1.XmlPullParserException
SmackException
@Deprecated public static ExtensionElement parsePacketExtension(java.lang.String elementName, java.lang.String namespace, org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
parseExtensionElement(String, String, XmlPullParser)
instead.org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
public static ExtensionElement parseExtensionElement(java.lang.String elementName, java.lang.String namespace, org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
elementName
- the XML element name of the extension element.namespace
- the XML namespace of the stanza(/packet) extension.parser
- the XML parser, positioned at the starting element of the extension.org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
public static StartTls parseStartTlsFeature(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
public static Session.Feature parseSessionFeature(org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
@Deprecated public static void addPacketExtension(Stanza packet, org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
@Deprecated public static void addPacketExtension(Stanza packet, org.xmlpull.v1.XmlPullParser parser, java.lang.String elementName, java.lang.String namespace) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
@Deprecated public static void addPacketExtension(java.util.Collection<ExtensionElement> collection, org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
@Deprecated public static void addPacketExtension(java.util.Collection<ExtensionElement> collection, org.xmlpull.v1.XmlPullParser parser, java.lang.String elementName, java.lang.String namespace) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
public static void addExtensionElement(Stanza packet, org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
public static void addExtensionElement(Stanza packet, org.xmlpull.v1.XmlPullParser parser, java.lang.String elementName, java.lang.String namespace) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
public static void addExtensionElement(java.util.Collection<ExtensionElement> collection, org.xmlpull.v1.XmlPullParser parser) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException
public static void addExtensionElement(java.util.Collection<ExtensionElement> collection, org.xmlpull.v1.XmlPullParser parser, java.lang.String elementName, java.lang.String namespace) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException, SmackException
org.xmlpull.v1.XmlPullParserException
java.io.IOException
SmackException