1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-27 22:57:58 +01:00

Adds parsing for "destroy" elements

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2269 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2004-04-01 21:47:52 +00:00 committed by gdombiak
parent fa8e0d0e9f
commit 35c1c035e8

View file

@ -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;
}
}