Smack

org.jivesoftware.smack.util
Class PacketParserUtils

java.lang.Object
  extended by org.jivesoftware.smack.util.PacketParserUtils

public class PacketParserUtils
extends java.lang.Object

Utility class that helps to parse packets. Any parsing packets method that must be shared between many clients must be placed in this utility class.

Author:
Gaston Dombiak

Nested Class Summary
static class PacketParserUtils.UnparsedResultIQ
          This class represents and unparsed IQ of the type 'result'.
 
Constructor Summary
PacketParserUtils()
           
 
Method Summary
static java.util.Collection<java.lang.String> parseCompressionMethods(org.xmlpull.v1.XmlPullParser parser)
          Parse the available compression methods reported from the server.
static XMPPError parseError(org.xmlpull.v1.XmlPullParser parser)
          Parses error sub-packets.
static IQ parseIQ(org.xmlpull.v1.XmlPullParser parser, Connection connection)
          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 Packet parseMessage(org.xmlpull.v1.XmlPullParser parser)
          Parses a message packet.
static PacketExtension parsePacketExtension(java.lang.String elementName, java.lang.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 java.util.Map<java.lang.String,java.lang.Object> parseProperties(org.xmlpull.v1.XmlPullParser parser)
          Parse a properties sub-packet.
static SASLMechanism.Failure parseSASLFailure(org.xmlpull.v1.XmlPullParser parser)
          Parses SASL authentication error packets.
static StreamError parseStreamError(org.xmlpull.v1.XmlPullParser parser)
          Parses stream error packets.
static java.lang.Object parseWithIntrospection(java.lang.String elementName, java.lang.Class<?> objectClass, org.xmlpull.v1.XmlPullParser parser)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PacketParserUtils

public PacketParserUtils()
Method Detail

parseMessage

public static Packet parseMessage(org.xmlpull.v1.XmlPullParser parser)
                           throws java.lang.Exception
Parses a message packet.

Parameters:
parser - the XML parser, positioned at the start of a message packet.
Returns:
a Message packet.
Throws:
java.lang.Exception - if an exception occurs while parsing the packet.

parsePresence

public static Presence parsePresence(org.xmlpull.v1.XmlPullParser parser)
                              throws java.lang.Exception
Parses a presence packet.

Parameters:
parser - the XML parser, positioned at the start of a presence packet.
Returns:
a Presence packet.
Throws:
java.lang.Exception - if an exception occurs while parsing the packet.

parseIQ

public static IQ parseIQ(org.xmlpull.v1.XmlPullParser parser,
                         Connection connection)
                  throws java.lang.Exception
Parses an IQ packet.

Parameters:
parser - the XML parser, positioned at the start of an IQ packet.
Returns:
an IQ object.
Throws:
java.lang.Exception - if an exception occurs while parsing the packet.

parseMechanisms

public static java.util.Collection<java.lang.String> parseMechanisms(org.xmlpull.v1.XmlPullParser parser)
                                                              throws java.lang.Exception
Parse the available SASL mechanisms reported from the server.

Parameters:
parser - the XML parser, positioned at the start of the mechanisms stanza.
Returns:
a collection of Stings with the mechanisms included in the mechanisms stanza.
Throws:
java.lang.Exception - if an exception occurs while parsing the stanza.

parseCompressionMethods

public static java.util.Collection<java.lang.String> parseCompressionMethods(org.xmlpull.v1.XmlPullParser parser)
                                                                      throws java.io.IOException,
                                                                             org.xmlpull.v1.XmlPullParserException
Parse the available compression methods reported from the server.

Parameters:
parser - the XML parser, positioned at the start of the compression stanza.
Returns:
a collection of Stings with the methods included in the compression stanza.
Throws:
java.lang.Exception - if an exception occurs while parsing the stanza.
java.io.IOException
org.xmlpull.v1.XmlPullParserException

parseProperties

public static java.util.Map<java.lang.String,java.lang.Object> parseProperties(org.xmlpull.v1.XmlPullParser parser)
                                                                        throws java.lang.Exception
Parse a properties sub-packet. If any errors occur while de-serializing Java object properties, an exception will be printed and not thrown since a thrown exception will shut down the entire connection. ClassCastExceptions will occur when both the sender and receiver of the packet don't have identical versions of the same class.

Parameters:
parser - the XML parser, positioned at the start of a properties sub-packet.
Returns:
a map of the properties.
Throws:
java.lang.Exception - if an error occurs while parsing the properties.

parseSASLFailure

public static SASLMechanism.Failure parseSASLFailure(org.xmlpull.v1.XmlPullParser parser)
                                              throws java.lang.Exception
Parses SASL authentication error packets.

Parameters:
parser - the XML parser.
Returns:
a SASL Failure packet.
Throws:
java.lang.Exception - if an exception occurs while parsing the packet.

parseStreamError

public static StreamError parseStreamError(org.xmlpull.v1.XmlPullParser parser)
                                    throws java.io.IOException,
                                           org.xmlpull.v1.XmlPullParserException
Parses stream error packets.

Parameters:
parser - the XML parser.
Returns:
an stream error packet.
Throws:
java.lang.Exception - if an exception occurs while parsing the packet.
java.io.IOException
org.xmlpull.v1.XmlPullParserException

parseError

public static XMPPError parseError(org.xmlpull.v1.XmlPullParser parser)
                            throws java.lang.Exception
Parses error sub-packets.

Parameters:
parser - the XML parser.
Returns:
an error sub-packet.
Throws:
java.lang.Exception - if an exception occurs while parsing the packet.

parsePacketExtension

public static PacketExtension parsePacketExtension(java.lang.String elementName,
                                                   java.lang.String namespace,
                                                   org.xmlpull.v1.XmlPullParser parser)
                                            throws java.lang.Exception
Parses a packet extension sub-packet.

Parameters:
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.
Returns:
a PacketExtension.
Throws:
java.lang.Exception - if a parsing error occurs.

parseWithIntrospection

public static java.lang.Object parseWithIntrospection(java.lang.String elementName,
                                                      java.lang.Class<?> objectClass,
                                                      org.xmlpull.v1.XmlPullParser parser)
                                               throws java.lang.Exception
Throws:
java.lang.Exception

Smack

Copyright © 2003-2007 Jive Software.