SharedGroupManager.java

  1. /**
  2.  *
  3.  * Copyright 2005 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.sharedgroups;

  18. import org.jivesoftware.smack.SmackException.NoResponseException;
  19. import org.jivesoftware.smack.SmackException.NotConnectedException;
  20. import org.jivesoftware.smack.XMPPConnection;
  21. import org.jivesoftware.smack.XMPPException.XMPPErrorException;
  22. import org.jivesoftware.smack.packet.IQ;
  23. import org.jivesoftware.smackx.sharedgroups.packet.SharedGroupsInfo;

  24. import java.util.List;

  25. /**
  26.  * A SharedGroupManager provides services for discovering the shared groups where a user belongs.<p>
  27.  *
  28.  * Important note: This functionality is not part of the XMPP spec and it will only work
  29.  * with Wildfire.
  30.  *
  31.  * @author Gaston Dombiak
  32.  */
  33. public class SharedGroupManager {

  34.     /**
  35.      * Returns the collection that will contain the name of the shared groups where the user
  36.      * logged in with the specified session belongs.
  37.      *
  38.      * @param connection connection to use to get the user's shared groups.
  39.      * @return collection with the shared groups' name of the logged user.
  40.      * @throws XMPPErrorException
  41.      * @throws NoResponseException
  42.      * @throws NotConnectedException
  43.      * @throws InterruptedException
  44.      */
  45.     public static List<String> getSharedGroups(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  46.         // Discover the shared groups of the logged user
  47.         SharedGroupsInfo info = new SharedGroupsInfo();
  48.         info.setType(IQ.Type.get);

  49.         SharedGroupsInfo result = (SharedGroupsInfo) connection.createPacketCollectorAndSend(info).nextResultOrThrow();
  50.         return result.getGroups();
  51.     }
  52. }