From 3157a29d2888aa2760aafc9c188a9f6b824e5559 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Wed, 23 Feb 2005 03:32:10 +0000 Subject: [PATCH] Public API for parsing Messages and Presences. SMACK-47 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2462 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smack/PacketReader.java | 274 +----------------- .../smack/util/PacketParserUtils.java | 265 ++++++++++++++++- 2 files changed, 270 insertions(+), 269 deletions(-) diff --git a/source/org/jivesoftware/smack/PacketReader.java b/source/org/jivesoftware/smack/PacketReader.java index cfe3464aa..f3d739c1e 100644 --- a/source/org/jivesoftware/smack/PacketReader.java +++ b/source/org/jivesoftware/smack/PacketReader.java @@ -24,14 +24,11 @@ import org.xmlpull.v1.*; import java.util.*; import java.util.List; -import java.io.ObjectInputStream; -import java.io.ByteArrayInputStream; import org.jivesoftware.smack.packet.*; import org.jivesoftware.smack.packet.XMPPError; import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.util.*; -import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.provider.*; /** @@ -44,12 +41,6 @@ import org.jivesoftware.smack.provider.*; */ class PacketReader { - /** - * Namespace used to store packet properties. - */ - private static final String PROPERTIES_NAMESPACE = - "http://www.jivesoftware.com/xmlns/xmpp/properties"; - private Thread readerThread; private Thread listenerThread; @@ -245,13 +236,13 @@ class PacketReader { do { if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("message")) { - processPacket(parseMessage(parser)); + processPacket(PacketParserUtils.parseMessage(parser)); } else if (parser.getName().equals("iq")) { processPacket(parseIQ(parser)); } else if (parser.getName().equals("presence")) { - processPacket(parsePresence(parser)); + processPacket(PacketParserUtils.parsePresence(parser)); } // We found an opening stream. Record information about it, then notify // the connectionID lock so that the packet reader startup can finish. @@ -349,7 +340,7 @@ class PacketReader { String elementName = parser.getName(); String namespace = parser.getNamespace(); if (elementName.equals("error")) { - error = parseError(parser); + error = PacketParserUtils.parseError(parser); } else if (elementName.equals("query") && namespace.equals("jabber:iq:auth")) { iqPacket = parseAuthentication(parser); @@ -381,11 +372,11 @@ class PacketReader { } } } - // Decide what to do when an IQ packet was not understood + // Decide what to do when an IQ packet was not understood if (iqPacket == null) { if (IQ.Type.GET == type || IQ.Type.SET == type ) { - // If the IQ stanza is of type "get" or "set" containing a child element - // qualified by a namespace it does not understand, then answer an IQ of + // If the IQ stanza is of type "get" or "set" containing a child element + // qualified by a namespace it does not understand, then answer an IQ of // type "error" with code 501 ("feature-not-implemented") iqPacket = new IQ() { public String getChildElementXML() { @@ -409,7 +400,7 @@ class PacketReader { }; } } - + // Set basic values on the iq packet. iqPacket.setPacketID(id); iqPacket.setTo(to); @@ -538,257 +529,6 @@ class PacketReader { return registration; } - /** - * Parses error sub-packets. - * - * @param parser the XML parser. - * @return an error sub-packet. - * @throws Exception if an exception occurs while parsing the packet. - */ - private XMPPError parseError(XmlPullParser parser) throws Exception { - String errorCode = "-1"; - String message = null; - for (int i=0; i