• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * $RCSfile$
3  * $Revision$
4  * $Date$
5  *
6  * Copyright 2005 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 package org.jivesoftware.smackx.packet;
21 
22 import org.jivesoftware.smack.packet.IQ;
23 import org.jivesoftware.smack.provider.IQProvider;
24 import org.xmlpull.v1.XmlPullParser;
25 
26 import java.util.ArrayList;
27 import java.util.Iterator;
28 import java.util.List;
29 
30 /**
31  * IQ packet used for discovering the user's shared groups and for getting the answer back
32  * from the server.<p>
33  *
34  * Important note: This functionality is not part of the XMPP spec and it will only work
35  * with Wildfire.
36  *
37  * @author Gaston Dombiak
38  */
39 public class SharedGroupsInfo extends IQ {
40 
41     private List<String> groups = new ArrayList<String>();
42 
43     /**
44      * Returns a collection with the shared group names returned from the server.
45      *
46      * @return collection with the shared group names returned from the server.
47      */
getGroups()48     public List<String> getGroups() {
49         return groups;
50     }
51 
getChildElementXML()52     public String getChildElementXML() {
53         StringBuilder buf = new StringBuilder();
54         buf.append("<sharedgroup xmlns=\"http://www.jivesoftware.org/protocol/sharedgroup\">");
55         for (Iterator<String> it=groups.iterator(); it.hasNext();) {
56             buf.append("<group>").append(it.next()).append("</group>");
57         }
58         buf.append("</sharedgroup>");
59         return buf.toString();
60     }
61 
62     /**
63      * Internal Search service Provider.
64      */
65     public static class Provider implements IQProvider {
66 
67         /**
68          * Provider Constructor.
69          */
Provider()70         public Provider() {
71             super();
72         }
73 
parseIQ(XmlPullParser parser)74         public IQ parseIQ(XmlPullParser parser) throws Exception {
75             SharedGroupsInfo groupsInfo = new SharedGroupsInfo();
76 
77             boolean done = false;
78             while (!done) {
79                 int eventType = parser.next();
80                 if (eventType == XmlPullParser.START_TAG && parser.getName().equals("group")) {
81                     groupsInfo.getGroups().add(parser.nextText());
82                 }
83                 else if (eventType == XmlPullParser.END_TAG) {
84                     if (parser.getName().equals("sharedgroup")) {
85                         done = true;
86                     }
87                 }
88             }
89             return groupsInfo;
90         }
91     }
92 }
93