KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smackx > provider > MUCAdminProvider


1 /**
2  * $RCSfile$
3  * $Revision: 2407 $
4  * $Date: 2004-11-02 20:37:00 -0300 (Tue, 02 Nov 2004) $
5  *
6  * Copyright 2003-2004 Jive Software.
7  *
8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */

20
21 package org.jivesoftware.smackx.provider;
22
23 import org.jivesoftware.smack.packet.IQ;
24 import org.jivesoftware.smack.provider.IQProvider;
25 import org.jivesoftware.smackx.packet.MUCAdmin;
26 import org.xmlpull.v1.XmlPullParser;
27
28 /**
29  * The MUCAdminProvider parses MUCAdmin packets. (@see MUCAdmin)
30  *
31  * @author Gaston Dombiak
32  */

33 public class MUCAdminProvider implements IQProvider {
34
35     public IQ parseIQ(XmlPullParser parser) throws Exception JavaDoc {
36         MUCAdmin mucAdmin = new MUCAdmin();
37         boolean done = false;
38         while (!done) {
39             int eventType = parser.next();
40             if (eventType == XmlPullParser.START_TAG) {
41                 if (parser.getName().equals("item")) {
42                     mucAdmin.addItem(parseItem(parser));
43                 }
44             }
45             else if (eventType == XmlPullParser.END_TAG) {
46                 if (parser.getName().equals("query")) {
47                     done = true;
48                 }
49             }
50         }
51
52         return mucAdmin;
53     }
54
55     private MUCAdmin.Item parseItem(XmlPullParser parser) throws Exception JavaDoc {
56         boolean done = false;
57         MUCAdmin.Item item =
58             new MUCAdmin.Item(
59                 parser.getAttributeValue("", "affiliation"),
60                 parser.getAttributeValue("", "role"));
61         item.setNick(parser.getAttributeValue("", "nick"));
62         item.setJid(parser.getAttributeValue("", "jid"));
63         while (!done) {
64             int eventType = parser.next();
65             if (eventType == XmlPullParser.START_TAG) {
66                 if (parser.getName().equals("actor")) {
67                     item.setActor(parser.getAttributeValue("", "jid"));
68                 }
69                 if (parser.getName().equals("reason")) {
70                     item.setReason(parser.nextText());
71                 }
72             }
73             else if (eventType == XmlPullParser.END_TAG) {
74                 if (parser.getName().equals("item")) {
75                     done = true;
76                 }
77             }
78         }
79         return item;
80     }
81 }
82
Popular Tags