Home | History | Annotate | Download | only in provider
      1 /**
      2  * $RCSfile$
      3  * $Revision: 7071 $
      4  * $Date: 2007-02-12 08:59:05 +0800 (Mon, 12 Feb 2007) $
      5  *
      6  * Copyright 2003-2007 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 {
     36         DiscoverItems discoverItems = new DiscoverItems();
     37         boolean done = false;
     38         DiscoverItems.Item item;
     39         String jid = "";
     40         String name = "";
     41         String action = "";
     42         String node = "";
     43         discoverItems.setNode(parser.getAttributeValue("", "node"));
     44         while (!done) {
     45             int eventType = parser.next();
     46 
     47             if (eventType == XmlPullParser.START_TAG && "item".equals(parser.getName())) {
     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 && "item".equals(parser.getName())) {
     55                 // Create a new Item and add it to DiscoverItems.
     56                 item = new DiscoverItems.Item(jid);
     57                 item.setName(name);
     58                 item.setNode(node);
     59                 item.setAction(action);
     60                 discoverItems.addItem(item);
     61             }
     62             else if (eventType == XmlPullParser.END_TAG && "query".equals(parser.getName())) {
     63                 done = true;
     64             }
     65         }
     66 
     67         return discoverItems;
     68     }
     69 }