2013-02-07 15:19:47 +01:00
|
|
|
/**
|
|
|
|
*
|
2013-04-07 21:15:32 +02:00
|
|
|
* Copyright 2005 Jive Software.
|
2013-02-07 15:19:47 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2013-02-07 15:19:47 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2014-02-17 23:58:40 +01:00
|
|
|
package org.jivesoftware.smackx.sharedgroups.packet;
|
|
|
|
|
2017-06-14 17:12:43 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2019-02-15 23:21:30 +01:00
|
|
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smack.provider.IQProvider;
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
|
|
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* IQ stanza used for discovering the user's shared groups and for getting the answer back
|
2014-02-17 23:58:40 +01:00
|
|
|
* from the server.<p>
|
|
|
|
*
|
|
|
|
* Important note: This functionality is not part of the XMPP spec and it will only work
|
|
|
|
* with Wildfire.
|
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
|
|
|
public class SharedGroupsInfo extends IQ {
|
|
|
|
|
2014-11-07 21:12:01 +01:00
|
|
|
public static final String ELEMENT = "sharedgroup";
|
|
|
|
public static final String NAMESPACE = "http://www.jivesoftware.org/protocol/sharedgroup";
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private final List<String> groups = new ArrayList<>();
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2014-11-07 21:12:01 +01:00
|
|
|
public SharedGroupsInfo() {
|
|
|
|
super(ELEMENT, NAMESPACE);
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
* Returns a collection with the shared group names returned from the server.
|
|
|
|
*
|
|
|
|
* @return collection with the shared group names returned from the server.
|
|
|
|
*/
|
|
|
|
public List<String> getGroups() {
|
|
|
|
return groups;
|
|
|
|
}
|
|
|
|
|
2014-11-07 21:12:01 +01:00
|
|
|
@Override
|
|
|
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
|
|
|
|
buf.rightAngleBracket();
|
2014-04-09 08:26:28 +02:00
|
|
|
for (String group : groups) {
|
2014-11-07 21:12:01 +01:00
|
|
|
buf.element("group", group);
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
2014-11-07 21:12:01 +01:00
|
|
|
return buf;
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal Search service Provider.
|
|
|
|
*/
|
2014-10-07 21:15:20 +02:00
|
|
|
public static class Provider extends IQProvider<SharedGroupsInfo> {
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
@Override
|
2019-02-15 23:21:30 +01:00
|
|
|
public SharedGroupsInfo parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
|
2014-10-07 21:15:20 +02:00
|
|
|
throws XmlPullParserException, IOException {
|
2014-02-17 23:58:40 +01:00
|
|
|
SharedGroupsInfo groupsInfo = new SharedGroupsInfo();
|
|
|
|
|
|
|
|
boolean done = false;
|
|
|
|
while (!done) {
|
2019-05-06 22:06:13 +02:00
|
|
|
XmlPullParser.Event eventType = parser.next();
|
|
|
|
if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getName().equals("group")) {
|
2014-02-17 23:58:40 +01:00
|
|
|
groupsInfo.getGroups().add(parser.nextText());
|
|
|
|
}
|
2019-05-06 22:06:13 +02:00
|
|
|
else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
2014-02-17 23:58:40 +01:00
|
|
|
if (parser.getName().equals("sharedgroup")) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return groupsInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|