From 35c1c035e83714041ce574eac943067b47e62fe4 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Thu, 1 Apr 2004 21:47:52 +0000 Subject: [PATCH] Adds parsing for "destroy" elements git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2269 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/provider/MUCUserProvider.java | 126 ++++++++++++++---- 1 file changed, 98 insertions(+), 28 deletions(-) diff --git a/source/org/jivesoftware/smackx/provider/MUCUserProvider.java b/source/org/jivesoftware/smackx/provider/MUCUserProvider.java index 20acaed93..bcb2146ed 100644 --- a/source/org/jivesoftware/smackx/provider/MUCUserProvider.java +++ b/source/org/jivesoftware/smackx/provider/MUCUserProvider.java @@ -82,47 +82,29 @@ public class MUCUserProvider implements PacketExtensionProvider { public PacketExtension parseExtension(XmlPullParser parser) throws Exception { MUCUser mucUser = new MUCUser(); boolean done = false; - MUCUser.Item item = null; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { + if (parser.getName().equals("invite")) { + mucUser.setInvite(parseInvite(parser)); + } if (parser.getName().equals("item")) { - item = - new MUCUser.Item( - parser.getAttributeValue("", "affiliation"), - parser.getAttributeValue("", "role")); - item.setNick(parser.getAttributeValue("", "nick")); - item.setJid(parser.getAttributeValue("", "jid")); - } - if (parser.getName().equals("actor")) { - item.setActor(parser.getAttributeValue("", "jid")); - } - if (parser.getName().equals("reason")) { - item.setReason(parser.getText()); + mucUser.setItem(parseItem(parser)); } if (parser.getName().equals("password")) { mucUser.setPassword(parser.getText()); } - if (parser.getName().equals("alt")) { - // TODO Implement alt? Is it being used? - System.out.println("alt - Not implemented yet!"); - } - if (parser.getName().equals("invite")) { - // TODO Implement invitation decoding - System.out.println("invite - Not implemented yet!"); - } - if (parser.getName().equals("decline")) { - // TODO Implement decline decoding - System.out.println("decline - Not implemented yet!"); - } if (parser.getName().equals("status")) { mucUser.setStatus(new MUCUser.Status(parser.getAttributeValue("", "code"))); } + if (parser.getName().equals("decline")) { + mucUser.setDecline(parseDecline(parser)); + } + if (parser.getName().equals("destroy")) { + mucUser.setDestroy(parseDestroy(parser)); + } } else if (eventType == XmlPullParser.END_TAG) { - if (parser.getName().equals("item")) { - mucUser.setItem(item); - } if (parser.getName().equals("x")) { done = true; } @@ -132,4 +114,92 @@ public class MUCUserProvider implements PacketExtensionProvider { return mucUser; } + private MUCUser.Item parseItem(XmlPullParser parser) throws Exception { + boolean done = false; + MUCUser.Item item = + new MUCUser.Item( + parser.getAttributeValue("", "affiliation"), + parser.getAttributeValue("", "role")); + item.setNick(parser.getAttributeValue("", "nick")); + item.setJid(parser.getAttributeValue("", "jid")); + while (!done) { + int eventType = parser.next(); + if (eventType == XmlPullParser.START_TAG) { + if (parser.getName().equals("actor")) { + item.setActor(parser.getAttributeValue("", "jid")); + } + if (parser.getName().equals("reason")) { + item.setReason(parser.getText()); + } + } + else if (eventType == XmlPullParser.END_TAG) { + if (parser.getName().equals("item")) { + done = true; + } + } + } + return item; + } + + private MUCUser.Invite parseInvite(XmlPullParser parser) throws Exception { + boolean done = false; + MUCUser.Invite invite = new MUCUser.Invite(); + invite.setFrom(parser.getAttributeValue("", "from")); + invite.setTo(parser.getAttributeValue("", "to")); + while (!done) { + int eventType = parser.next(); + if (eventType == XmlPullParser.START_TAG) { + if (parser.getName().equals("reason")) { + invite.setReason(parser.getText()); + } + } + else if (eventType == XmlPullParser.END_TAG) { + if (parser.getName().equals("invite")) { + done = true; + } + } + } + return invite; + } + + private MUCUser.Decline parseDecline(XmlPullParser parser) throws Exception { + boolean done = false; + MUCUser.Decline decline = new MUCUser.Decline(); + decline.setFrom(parser.getAttributeValue("", "from")); + decline.setTo(parser.getAttributeValue("", "to")); + while (!done) { + int eventType = parser.next(); + if (eventType == XmlPullParser.START_TAG) { + if (parser.getName().equals("reason")) { + decline.setReason(parser.getText()); + } + } + else if (eventType == XmlPullParser.END_TAG) { + if (parser.getName().equals("decline")) { + done = true; + } + } + } + return decline; + } + + private MUCUser.Destroy parseDestroy(XmlPullParser parser) throws Exception { + boolean done = false; + MUCUser.Destroy destroy = new MUCUser.Destroy(); + destroy.setJid(parser.getAttributeValue("", "jid")); + while (!done) { + int eventType = parser.next(); + if (eventType == XmlPullParser.START_TAG) { + if (parser.getName().equals("reason")) { + destroy.setReason(parser.getText()); + } + } + else if (eventType == XmlPullParser.END_TAG) { + if (parser.getName().equals("destroy")) { + done = true; + } + } + } + return destroy; + } }