KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
26 import org.xmlpull.v1.XmlPullParser;
27
28 /**
29 * The DiscoverInfoProvider parses Service Discovery items packets.
30 *
31 * @author Gaston Dombiak
32 */

33 public class DiscoverItemsProvider implements IQProvider {
34
35     public IQ parseIQ(XmlPullParser parser) throws Exception JavaDoc {
36         DiscoverItems discoverItems = new DiscoverItems();
37         boolean done = false;
38         DiscoverItems.Item item = null;
39         String JavaDoc jid = "";
40         String JavaDoc name = "";
41         String JavaDoc action = "";
42         String JavaDoc node = "";
43         discoverItems.setNode(parser.getAttributeValue("", "node"));
44         while (!done) {
45             int eventType = parser.next();
46             if (eventType == XmlPullParser.START_TAG) {
47                 if (parser.getName().equals("item")) {
48                     // Initialize the variables from the parsed XML
49
jid = parser.getAttributeValue("", "jid");
50                     name = parser.getAttributeValue("", "name");
51                     node = parser.getAttributeValue("", "node");
52                     action = parser.getAttributeValue("", "action");
53                 }
54             } else if (eventType == XmlPullParser.END_TAG) {
55                 if (parser.getName().equals("item")) {
56                     // Create a new Item and add it to DiscoverItems.
57
item = new DiscoverItems.Item(jid);
58                     item.setName(name);
59                     item.setNode(node);
60                     item.setAction(action);
61                     discoverItems.addItem(item);
62                 }
63                 if (parser.getName().equals("query")) {
64                     done = true;
65                 }
66             }
67         }
68
69         return discoverItems;
70     }
71 }
Popular Tags