1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-08 20:11:08 +01:00

Add support Multi-User Chat Light

Fixes SMACK-740
This commit is contained in:
Fernando Ramirez 2016-11-02 12:10:56 -03:00 committed by Florian Schmaus
parent eb9242768c
commit 5372c1bcf4
39 changed files with 4053 additions and 0 deletions

View file

@ -0,0 +1,40 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight;
import java.util.Locale;
/**
* MUCLight affiliations enum.
*
* @author Fernando Ramirez
*
*/
public enum MUCLightAffiliation {
owner,
member,
none;
public static MUCLightAffiliation fromString(String string) {
if (string == null) {
return null;
}
return MUCLightAffiliation.valueOf(string.toLowerCase(Locale.US));
}
}

View file

@ -0,0 +1,73 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight;
import java.util.HashMap;
/**
* MUC Light room configuration class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightRoomConfiguration {
private final String roomName;
private final String subject;
private final HashMap<String, String> customConfigs;
/**
* MUC Light room configuration model constructor.
*
* @param roomName
* @param subject
* @param customConfigs
*/
public MUCLightRoomConfiguration(String roomName, String subject, HashMap<String, String> customConfigs) {
this.roomName = roomName;
this.subject = subject;
this.customConfigs = customConfigs;
}
/**
* Returns the room name.
*
* @return the name of the room.
*/
public String getRoomName() {
return roomName;
}
/**
* Returns the room subject.
*
* @return the subject of the room.
*/
public String getSubject() {
return subject;
}
/**
* Returns the room custom configurations.
*
* @return the custom configurations of the room.
*/
public HashMap<String, String> getCustomConfigs() {
return customConfigs;
}
}

View file

@ -0,0 +1,86 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight;
import java.util.HashMap;
import org.jxmpp.jid.Jid;
/**
* MUC Light room info class.
*
* @author Fernando Ramirez
*/
public class MUCLightRoomInfo {
private final String version;
private final Jid room;
private final MUCLightRoomConfiguration configuration;
private final HashMap<Jid, MUCLightAffiliation> occupants;
/**
* MUC Light room info model constructor.
*
* @param version
* @param roomJid
* @param configuration
* @param occupants
*/
public MUCLightRoomInfo(String version, Jid roomJid, MUCLightRoomConfiguration configuration,
HashMap<Jid, MUCLightAffiliation> occupants) {
this.version = version;
this.room = roomJid;
this.configuration = configuration;
this.occupants = occupants;
}
/**
* Returns the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
/**
* Returns the JID of the room whose information was discovered.
*
* @return the JID of the room whose information was discovered.
*/
public Jid getRoom() {
return room;
}
/**
* Returns the configuration.
*
* @return the room configuration
*/
public MUCLightRoomConfiguration getConfiguration() {
return configuration;
}
/**
* Returns the room occupants.
*
* @return the occupants of the room.
*/
public HashMap<Jid, MUCLightAffiliation> getOccupants() {
return occupants;
}
}

View file

@ -0,0 +1,502 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.chat.ChatManager;
import org.jivesoftware.smack.chat.ChatMessageListener;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.muclight.element.MUCLightAffiliationsIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightChangeAffiliationsIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightConfigurationIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightCreateIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightDestroyIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightGetAffiliationsIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightGetConfigsIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightGetInfoIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightInfoIQ;
import org.jivesoftware.smackx.muclight.element.MUCLightSetConfigsIQ;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.Jid;
/**
* MUCLight class.
*
* @author Fernando Ramirez
*/
public class MultiUserChatLight {
public static final String NAMESPACE = "urn:xmpp:muclight:0";
public static final String AFFILIATIONS = "#affiliations";
public static final String INFO = "#info";
public static final String CONFIGURATION = "#configuration";
public static final String CREATE = "#create";
public static final String DESTROY = "#destroy";
public static final String BLOCKING = "#blocking";
private final XMPPConnection connection;
private final EntityJid room;
private final Set<MessageListener> messageListeners = new CopyOnWriteArraySet<MessageListener>();
/**
* This filter will match all stanzas send from the groupchat or from one if
* the groupchat occupants.
*/
private final StanzaFilter fromRoomFilter;
/**
* Same as {@link #fromRoomFilter} together with
* {@link MessageTypeFilter#GROUPCHAT}.
*/
private final StanzaFilter fromRoomGroupchatFilter;
private final StanzaListener messageListener;
private PacketCollector messageCollector;
MultiUserChatLight(XMPPConnection connection, EntityJid room) {
this.connection = connection;
this.room = room;
fromRoomFilter = FromMatchesFilter.create(room);
fromRoomGroupchatFilter = new AndFilter(fromRoomFilter, MessageTypeFilter.GROUPCHAT);
messageListener = new StanzaListener() {
@Override
public void processPacket(Stanza packet) throws NotConnectedException {
Message message = (Message) packet;
for (MessageListener listener : messageListeners) {
listener.processMessage(message);
}
}
};
connection.addSyncStanzaListener(messageListener, fromRoomGroupchatFilter);
}
/**
* Returns the JID of the room.
*
* @return the MUCLight room JID.
*/
public EntityJid getRoom() {
return room;
}
/**
* Sends a message to the chat room.
*
* @param text
* the text of the message to send.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendMessage(String text) throws NotConnectedException, InterruptedException {
Message message = createMessage();
message.setBody(text);
connection.sendStanza(message);
}
/**
* Returns a new Chat for sending private messages to a given room occupant.
* The Chat's occupant address is the room's JID (i.e.
* roomName@service/nick). The server service will change the 'from' address
* to the sender's room JID and delivering the message to the intended
* recipient's full JID.
*
* @param occupant
* occupant unique room JID (e.g.
* 'darkcave@macbeth.shakespeare.lit/Paul').
* @param listener
* the listener is a message listener that will handle messages
* for the newly created chat.
* @return new Chat for sending private messages to a given room occupant.
*/
public Chat createPrivateChat(EntityJid occupant, ChatMessageListener listener) {
return ChatManager.getInstanceFor(connection).createChat(occupant, listener);
}
/**
* Creates a new Message to send to the chat room.
*
* @return a new Message addressed to the chat room.
*/
public Message createMessage() {
return new Message(room, Message.Type.groupchat);
}
/**
* Sends a Message to the chat room.
*
* @param message
* the message.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendMessage(Message message) throws NotConnectedException, InterruptedException {
message.setTo(room);
message.setType(Message.Type.groupchat);
connection.sendStanza(message);
}
/**
* Polls for and returns the next message.
*
* @return the next message if one is immediately available
*/
public Message pollMessage() {
return messageCollector.pollResult();
}
/**
* Returns the next available message in the chat. The method call will
* block (not return) until a message is available.
*
* @return the next message.
* @throws InterruptedException
*/
public Message nextMessage() throws InterruptedException {
return messageCollector.nextResult();
}
/**
* Returns the next available message in the chat.
*
* @param timeout
* the maximum amount of time to wait for the next message.
* @return the next message, or null if the timeout elapses without a
* message becoming available.
* @throws InterruptedException
*/
public Message nextMessage(long timeout) throws InterruptedException {
return messageCollector.nextResult(timeout);
}
/**
* Adds a stanza(/packet) listener that will be notified of any new messages
* in the group chat. Only "group chat" messages addressed to this group
* chat will be delivered to the listener.
*
* @param listener
* a stanza(/packet) listener.
* @return true if the listener was not already added.
*/
public boolean addMessageListener(MessageListener listener) {
return messageListeners.add(listener);
}
/**
* Removes a stanza(/packet) listener that was being notified of any new
* messages in the MUCLight. Only "group chat" messages addressed to this
* MUCLight were being delivered to the listener.
*
* @param listener
* a stanza(/packet) listener.
* @return true if the listener was removed, otherwise the listener was not
* added previously.
*/
public boolean removeMessageListener(MessageListener listener) {
return messageListeners.remove(listener);
}
/**
* Remove the connection callbacks used by this MUC Light from the
* connection.
*/
private void removeConnectionCallbacks() {
connection.removeSyncStanzaListener(messageListener);
if (messageCollector != null) {
messageCollector.cancel();
messageCollector = null;
}
}
@Override
public String toString() {
return "MUC Light: " + room + "(" + connection.getUser() + ")";
}
/**
* Create new MUCLight.
*
* @param roomName
* @param subject
* @param customConfigs
* @param occupants
* @throws Exception
*/
public void create(String roomName, String subject, HashMap<String, String> customConfigs, List<Jid> occupants)
throws Exception {
MUCLightCreateIQ createMUCLightIQ = new MUCLightCreateIQ(room, roomName, occupants);
messageCollector = connection.createPacketCollector(fromRoomGroupchatFilter);
try {
connection.createPacketCollectorAndSend(createMUCLightIQ).nextResultOrThrow();
} catch (InterruptedException | NoResponseException | XMPPErrorException e) {
removeConnectionCallbacks();
throw e;
}
}
/**
* Create new MUCLight.
*
* @param roomName
* @param occupants
* @throws Exception
*/
public void create(String roomName, List<Jid> occupants) throws Exception {
create(roomName, null, null, occupants);
}
/**
* Leave the MUCLight.
*
* @throws NotConnectedException
* @throws InterruptedException
* @throws NoResponseException
* @throws XMPPErrorException
*/
public void leave() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>();
affiliations.put(connection.getUser(), MUCLightAffiliation.none);
MUCLightChangeAffiliationsIQ changeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(room, affiliations);
IQ responseIq = connection.createPacketCollectorAndSend(changeAffiliationsIQ).nextResultOrThrow();
boolean roomLeft = responseIq.getType().equals(IQ.Type.result);
if (roomLeft) {
removeConnectionCallbacks();
}
}
/**
* Get the MUC Light info.
*
* @param version
* @return the room info
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public MUCLightRoomInfo getFullInfo(String version)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightGetInfoIQ mucLightGetInfoIQ = new MUCLightGetInfoIQ(room, version);
IQ responseIq = connection.createPacketCollectorAndSend(mucLightGetInfoIQ).nextResultOrThrow();
MUCLightInfoIQ mucLightInfoResponseIQ = (MUCLightInfoIQ) responseIq;
return new MUCLightRoomInfo(mucLightInfoResponseIQ.getVersion(), room,
mucLightInfoResponseIQ.getConfiguration(), mucLightInfoResponseIQ.getOccupants());
}
/**
* Get the MUC Light info.
*
* @return the room info
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public MUCLightRoomInfo getFullInfo()
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return getFullInfo(null);
}
/**
* Get the MUC Light configuration.
*
* @param version
* @return the room configuration
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public MUCLightRoomConfiguration getConfiguration(String version)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightGetConfigsIQ mucLightGetConfigsIQ = new MUCLightGetConfigsIQ(room, version);
IQ responseIq = connection.createPacketCollectorAndSend(mucLightGetConfigsIQ).nextResultOrThrow();
MUCLightConfigurationIQ mucLightConfigurationIQ = (MUCLightConfigurationIQ) responseIq;
return mucLightConfigurationIQ.getConfiguration();
}
/**
* Get the MUC Light configuration.
*
* @return the room configuration
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public MUCLightRoomConfiguration getConfiguration()
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return getConfiguration(null);
}
/**
* Get the MUC Light affiliations.
*
* @param version
* @return the room affiliations
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public HashMap<Jid, MUCLightAffiliation> getAffiliations(String version)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightGetAffiliationsIQ mucLightGetAffiliationsIQ = new MUCLightGetAffiliationsIQ(room, version);
IQ responseIq = connection.createPacketCollectorAndSend(mucLightGetAffiliationsIQ).nextResultOrThrow();
MUCLightAffiliationsIQ mucLightAffiliationsIQ = (MUCLightAffiliationsIQ) responseIq;
return mucLightAffiliationsIQ.getAffiliations();
}
/**
* Get the MUC Light affiliations.
*
* @return the room affiliations
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public HashMap<Jid, MUCLightAffiliation> getAffiliations()
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return getAffiliations(null);
}
/**
* Change the MUC Light affiliations.
*
* @param affiliations
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void changeAffiliations(HashMap<Jid, MUCLightAffiliation> affiliations)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightChangeAffiliationsIQ changeAffiliationsIQ = new MUCLightChangeAffiliationsIQ(room, affiliations);
connection.createPacketCollectorAndSend(changeAffiliationsIQ).nextResultOrThrow();
}
/**
* Destroy the MUC Light. Only will work if it is requested by the owner.
*
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void destroy() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightDestroyIQ mucLightDestroyIQ = new MUCLightDestroyIQ(room);
IQ responseIq = connection.createPacketCollectorAndSend(mucLightDestroyIQ).nextResultOrThrow();
boolean roomDestroyed = responseIq.getType().equals(IQ.Type.result);
if (roomDestroyed) {
removeConnectionCallbacks();
}
}
/**
* Change the subject of the MUC Light.
*
* @param subject
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void changeSubject(String subject)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, null, subject, null);
connection.createPacketCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow();
}
/**
* Change the name of the room.
*
* @param roomName
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void changeRoomName(String roomName)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, roomName, null);
connection.createPacketCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow();
}
/**
* Set the room configurations.
*
* @param customConfigs
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void setRoomConfigs(HashMap<String, String> customConfigs)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
setRoomConfigs(null, customConfigs);
}
/**
* Set the room configurations.
*
* @param roomName
* @param customConfigs
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void setRoomConfigs(String roomName, HashMap<String, String> customConfigs)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightSetConfigsIQ mucLightSetConfigIQ = new MUCLightSetConfigsIQ(room, roomName, customConfigs);
connection.createPacketCollectorAndSend(mucLightSetConfigIQ).nextResultOrThrow();
}
}

View file

@ -0,0 +1,416 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.Jid;
/**
* Multi-User Chat Light manager class.
*
* @author Fernando Ramirez
*
*/
public final class MultiUserChatLightManager extends Manager {
private static final Map<XMPPConnection, MultiUserChatLightManager> INSTANCES = new WeakHashMap<XMPPConnection, MultiUserChatLightManager>();
/**
* Get a instance of a MUC Light manager for the given connection.
*
* @param connection
* @return a MUCLight manager.
*/
public static synchronized MultiUserChatLightManager getInstanceFor(XMPPConnection connection) {
MultiUserChatLightManager multiUserChatLightManager = INSTANCES.get(connection);
if (multiUserChatLightManager == null) {
multiUserChatLightManager = new MultiUserChatLightManager(connection);
INSTANCES.put(connection, multiUserChatLightManager);
}
return multiUserChatLightManager;
}
/**
* A Map of MUC Light JIDs to instances. We use weak references for the
* values in order to allow those instances to get garbage collected.
*/
private final Map<EntityBareJid, WeakReference<MultiUserChatLight>> multiUserChatLights = new HashMap<>();
private MultiUserChatLightManager(XMPPConnection connection) {
super(connection);
}
/**
* Obtain the MUC Light.
*
* @param jid
* @return the MUCLight.
*/
public synchronized MultiUserChatLight getMultiUserChatLight(EntityBareJid jid) {
WeakReference<MultiUserChatLight> weakRefMultiUserChat = multiUserChatLights.get(jid);
if (weakRefMultiUserChat == null) {
return createNewMucLightAndAddToMap(jid);
}
MultiUserChatLight multiUserChatLight = weakRefMultiUserChat.get();
if (multiUserChatLight == null) {
return createNewMucLightAndAddToMap(jid);
}
return multiUserChatLight;
}
private MultiUserChatLight createNewMucLightAndAddToMap(EntityBareJid jid) {
MultiUserChatLight multiUserChatLight = new MultiUserChatLight(connection(), jid);
multiUserChatLights.put(jid, new WeakReference<MultiUserChatLight>(multiUserChatLight));
return multiUserChatLight;
}
/**
* Returns true if Multi-User Chat Light feature is supported by the server.
*
* @param mucLightService
* @return true if Multi-User Chat Light feature is supported by the server.
* @throws NotConnectedException
* @throws XMPPErrorException
* @throws NoResponseException
* @throws InterruptedException
*/
public boolean isFeatureSupported(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).discoverInfo(mucLightService)
.containsFeature(MultiUserChatLight.NAMESPACE);
}
/**
* Returns a List of the rooms the user occupies.
*
* @param mucLightService
* @return a List of the rooms the user occupies.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Jid> getOccupiedRooms(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(mucLightService);
List<DiscoverItems.Item> items = result.getItems();
List<Jid> answer = new ArrayList<>(items.size());
for (DiscoverItems.Item item : items) {
Jid mucLight = item.getEntityID();
answer.add(mucLight);
}
return answer;
}
/**
* Returns a collection with the XMPP addresses of the MUC Light services.
*
* @return a collection with the XMPP addresses of the MUC Light services.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<DomainBareJid> getLocalServices()
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection());
return sdm.findServices(MultiUserChatLight.NAMESPACE, false, false);
}
/**
* Get users and rooms blocked.
*
* @param mucLightService
* @return the list of users and rooms blocked
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Jid> getUsersAndRoomsBlocked(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightBlockingIQ muclIghtBlockingIQResult = getBlockingList(mucLightService);
List<Jid> jids = new ArrayList<>();
if (muclIghtBlockingIQResult.getRooms() != null) {
jids.addAll(muclIghtBlockingIQResult.getRooms().keySet());
}
if (muclIghtBlockingIQResult.getUsers() != null) {
jids.addAll(muclIghtBlockingIQResult.getUsers().keySet());
}
return jids;
}
/**
* Get rooms blocked.
*
* @param mucLightService
* @return the list of rooms blocked
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Jid> getRoomsBlocked(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightBlockingIQ muclIghtBlockingIQResult = getBlockingList(mucLightService);
List<Jid> jids = new ArrayList<>();
if (muclIghtBlockingIQResult.getRooms() != null) {
jids.addAll(muclIghtBlockingIQResult.getRooms().keySet());
}
return jids;
}
/**
* Get users blocked.
*
* @param mucLightService
* @return the list of users blocked
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Jid> getUsersBlocked(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCLightBlockingIQ muclIghtBlockingIQResult = getBlockingList(mucLightService);
List<Jid> jids = new ArrayList<>();
if (muclIghtBlockingIQResult.getUsers() != null) {
jids.addAll(muclIghtBlockingIQResult.getUsers().keySet());
}
return jids;
}
private MUCLightBlockingIQ getBlockingList(DomainBareJid mucLightService)
throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, null);
mucLightBlockingIQ.setType(Type.get);
mucLightBlockingIQ.setTo(mucLightService);
StanzaFilter responseFilter = new IQReplyFilter(mucLightBlockingIQ, connection());
IQ responseIq = connection().createPacketCollectorAndSend(responseFilter, mucLightBlockingIQ)
.nextResultOrThrow();
MUCLightBlockingIQ muclIghtBlockingIQResult = (MUCLightBlockingIQ) responseIq;
return muclIghtBlockingIQResult;
}
/**
* Block a room.
*
* @param mucLightService
* @param roomJid
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void blockRoom(DomainBareJid mucLightService, Jid roomJid)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> rooms = new HashMap<>();
rooms.put(roomJid, false);
sendBlockRooms(mucLightService, rooms);
}
/**
* Block rooms.
*
* @param mucLightService
* @param roomsJids
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void blockRooms(DomainBareJid mucLightService, List<Jid> roomsJids)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> rooms = new HashMap<>();
for (Jid jid : roomsJids) {
rooms.put(jid, false);
}
sendBlockRooms(mucLightService, rooms);
}
private void sendBlockRooms(DomainBareJid mucLightService, HashMap<Jid, Boolean> rooms)
throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createPacketCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
}
/**
* Block a user.
*
* @param mucLightService
* @param userJid
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void blockUser(DomainBareJid mucLightService, Jid userJid)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> users = new HashMap<>();
users.put(userJid, false);
sendBlockUsers(mucLightService, users);
}
/**
* Block users.
*
* @param mucLightService
* @param usersJids
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void blockUsers(DomainBareJid mucLightService, List<Jid> usersJids)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> users = new HashMap<>();
for (Jid jid : usersJids) {
users.put(jid, false);
}
sendBlockUsers(mucLightService, users);
}
private void sendBlockUsers(DomainBareJid mucLightService, HashMap<Jid, Boolean> users)
throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createPacketCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
}
/**
* Unblock a room.
*
* @param mucLightService
* @param roomJid
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unblockRoom(DomainBareJid mucLightService, Jid roomJid)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> rooms = new HashMap<>();
rooms.put(roomJid, true);
sendUnblockRooms(mucLightService, rooms);
}
/**
* Unblock rooms.
*
* @param mucLightService
* @param roomsJids
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unblockRooms(DomainBareJid mucLightService, List<Jid> roomsJids)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> rooms = new HashMap<>();
for (Jid jid : roomsJids) {
rooms.put(jid, true);
}
sendUnblockRooms(mucLightService, rooms);
}
private void sendUnblockRooms(DomainBareJid mucLightService, HashMap<Jid, Boolean> rooms)
throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createPacketCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
}
/**
* Unblock a user.
*
* @param mucLightService
* @param userJid
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unblockUser(DomainBareJid mucLightService, Jid userJid)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> users = new HashMap<>();
users.put(userJid, true);
sendUnblockUsers(mucLightService, users);
}
/**
* Unblock users.
*
* @param mucLightService
* @param usersJids
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unblockUsers(DomainBareJid mucLightService, List<Jid> usersJids)
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
HashMap<Jid, Boolean> users = new HashMap<>();
for (Jid jid : usersJids) {
users.put(jid, true);
}
sendUnblockUsers(mucLightService, users);
}
private void sendUnblockUsers(DomainBareJid mucLightService, HashMap<Jid, Boolean> users)
throws NoResponseException, XMPPErrorException, InterruptedException, NotConnectedException {
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users);
mucLightBlockingIQ.setType(Type.set);
mucLightBlockingIQ.setTo(mucLightService);
connection().createPacketCollectorAndSend(mucLightBlockingIQ).nextResultOrThrow();
}
}

View file

@ -0,0 +1,87 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.UserWithAffiliationElement;
import org.jxmpp.jid.Jid;
/**
* MUC Light affiliations response IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightAffiliationsIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;
private final String version;
private HashMap<Jid, MUCLightAffiliation> affiliations;
/**
* MUC Light affiliations response IQ constructor.
*
* @param version
* @param affiliations
*/
public MUCLightAffiliationsIQ(String version, HashMap<Jid, MUCLightAffiliation> affiliations) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.affiliations = affiliations;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = affiliations.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
xml.element(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
}
return xml;
}
/**
* Returns the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
/**
* Returns the room affiliations.
*
* @return the affiliations of the room
*/
public HashMap<Jid, MUCLightAffiliation> getAffiliations() {
return affiliations;
}
}

View file

@ -0,0 +1,95 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.BlockingElement;
import org.jxmpp.jid.Jid;
/**
* MUC Light blocking IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightBlockingIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.BLOCKING;
private final HashMap<Jid, Boolean> rooms;
private final HashMap<Jid, Boolean> users;
/**
* MUC Light blocking IQ constructor.
*
* @param rooms
* @param users
*/
public MUCLightBlockingIQ(HashMap<Jid, Boolean> rooms, HashMap<Jid, Boolean> users) {
super(ELEMENT, NAMESPACE);
this.rooms = rooms;
this.users = users;
}
/**
* Get rooms JIDs with booleans (true if allow, false if deny).
*
* @return the rooms JIDs with booleans (true if allow, false if deny)
*/
public HashMap<Jid, Boolean> getRooms() {
return rooms;
}
/**
* Get users JIDs with booleans (true if allow, false if deny).
*
* @return the users JIDs with booleans (true if allow, false if deny)
*/
public HashMap<Jid, Boolean> getUsers() {
return users;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
if (rooms != null) {
parseBlocking(xml, rooms, true);
}
if (users != null) {
parseBlocking(xml, users, false);
}
return xml;
}
private void parseBlocking(IQChildElementXmlStringBuilder xml, HashMap<Jid, Boolean> map, boolean isRoom) {
Iterator<Map.Entry<Jid, Boolean>> it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Jid, Boolean> pair = it.next();
xml.element(new BlockingElement(pair.getKey(), pair.getValue(), isRoom));
}
}
}

View file

@ -0,0 +1,79 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.UserWithAffiliationElement;
import org.jxmpp.jid.Jid;
/**
* MUCLight change affiliations IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightChangeAffiliationsIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;
private HashMap<Jid, MUCLightAffiliation> affiliations;
/**
* MUCLight change affiliations IQ constructor.
*
* @param room
* @param affiliations
*/
public MUCLightChangeAffiliationsIQ(Jid room, HashMap<Jid, MUCLightAffiliation> affiliations) {
super(ELEMENT, NAMESPACE);
this.setType(Type.set);
this.setTo(room);
this.affiliations = affiliations;
}
/**
* Get the affiliations.
*
* @return the affiliations
*/
public HashMap<Jid, MUCLightAffiliation> getAffiliations() {
return affiliations;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
if (affiliations != null) {
Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = affiliations.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
xml.element(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
}
}
return xml;
}
}

View file

@ -0,0 +1,76 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationElement;
/**
* MUC Light configuration response IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightConfigurationIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;
private final String version;
private final MUCLightRoomConfiguration configuration;
/**
* MUC Light configuration response IQ constructor.
*
* @param version
* @param configuration
*/
public MUCLightConfigurationIQ(String version, MUCLightRoomConfiguration configuration) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.configuration = configuration;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
xml.element(new ConfigurationElement(configuration));
return xml;
}
/**
* Returns the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
/**
* Returns the room configuration.
*
* @return the configuration of the room
*/
public MUCLightRoomConfiguration getConfiguration() {
return configuration;
}
}

View file

@ -0,0 +1,109 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import java.util.HashMap;
import java.util.List;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationElement;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.OccupantsElement;
import org.jxmpp.jid.EntityJid;
import org.jxmpp.jid.Jid;
/**
* MUCLight create IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightCreateIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CREATE;
private MUCLightRoomConfiguration configuration;
private final HashMap<Jid, MUCLightAffiliation> occupants;
/**
* MUCLight create IQ constructor.
*
* @param room
* @param roomName
* @param subject
* @param customConfigs
* @param occupants
*/
public MUCLightCreateIQ(EntityJid room, String roomName, String subject, HashMap<String, String> customConfigs,
List<Jid> occupants) {
super(ELEMENT, NAMESPACE);
this.configuration = new MUCLightRoomConfiguration(roomName, subject, customConfigs);
this.occupants = new HashMap<>();
for (Jid occupant : occupants) {
this.occupants.put(occupant, MUCLightAffiliation.member);
}
this.setType(Type.set);
this.setTo(room);
}
/**
* MUCLight create IQ constructor.
*
* @param room
* @param roomName
* @param occupants
*/
public MUCLightCreateIQ(EntityJid room, String roomName, List<Jid> occupants) {
this(room, roomName, null, null, occupants);
}
/**
* Get the room configuration.
*
* @return the room configuration
*/
public MUCLightRoomConfiguration getConfiguration() {
return configuration;
}
/**
* Get the room occupants.
*
* @return the room occupants
*/
public HashMap<Jid, MUCLightAffiliation> getOccupants() {
return occupants;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.element(new ConfigurationElement(configuration));
if (!occupants.isEmpty()) {
xml.element(new OccupantsElement(occupants));
}
return xml;
}
}

View file

@ -0,0 +1,51 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jxmpp.jid.Jid;
/**
* MUC Light destroy IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightDestroyIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.DESTROY;
/**
* MUC Light destroy IQ constructor.
*
* @param roomJid
*/
public MUCLightDestroyIQ(Jid roomJid) {
super(ELEMENT, NAMESPACE);
this.setType(Type.set);
this.setTo(roomJid);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.setEmptyElement();
return xml;
}
}

View file

@ -0,0 +1,392 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.jxmpp.jid.Jid;
public abstract class MUCLightElements {
/**
* Affiliations change extension element class.
*
* @author Fernando Ramirez
*
*/
public static class AffiliationsChangeExtension implements ExtensionElement {
public static final String ELEMENT = DataForm.ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;
private final HashMap<Jid, MUCLightAffiliation> affiliations;
private final String prevVersion;
private final String version;
public AffiliationsChangeExtension(HashMap<Jid, MUCLightAffiliation> affiliations, String prevVersion,
String version) {
this.affiliations = affiliations;
this.prevVersion = prevVersion;
this.version = version;
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
/**
* Get the affiliations.
*
* @return the affiliations
*/
public HashMap<Jid, MUCLightAffiliation> getAffiliations() {
return affiliations;
}
/**
* Get the previous version.
*
* @return the previous version
*/
public String getPrevVersion() {
return prevVersion;
}
/**
* Get the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.rightAngleBracket();
xml.optElement("prev-version", prevVersion);
xml.optElement("version", version);
Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = affiliations.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
xml.element(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
}
xml.closeElement(this);
return xml;
}
public static AffiliationsChangeExtension from(Message message) {
return message.getExtension(AffiliationsChangeExtension.ELEMENT, AffiliationsChangeExtension.NAMESPACE);
}
}
/**
* Configurations change extension element class.
*
* @author Fernando Ramirez
*
*/
public static class ConfigurationsChangeExtension implements ExtensionElement {
public static final String ELEMENT = DataForm.ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;
private final String prevVersion;
private final String version;
private final String roomName;
private final String subject;
private final HashMap<String, String> customConfigs;
/**
* Configurations change extension constructor.
*
* @param prevVersion
* @param version
* @param roomName
* @param subject
* @param customConfigs
*/
public ConfigurationsChangeExtension(String prevVersion, String version, String roomName, String subject,
HashMap<String, String> customConfigs) {
this.prevVersion = prevVersion;
this.version = version;
this.roomName = roomName;
this.subject = subject;
this.customConfigs = customConfigs;
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
/**
* Get the previous version.
*
* @return the previous version
*/
public String getPrevVersion() {
return prevVersion;
}
/**
* Get the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
/**
* Get the room name.
*
* @return the room name
*/
public String getRoomName() {
return roomName;
}
/**
* Get the room subject.
*
* @return the room subject
*/
public String getSubject() {
return subject;
}
/**
* Get the room custom configurations.
*
* @return the room custom configurations
*/
public HashMap<String, String> getCustomConfigs() {
return customConfigs;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.rightAngleBracket();
xml.optElement("prev-version", prevVersion);
xml.optElement("version", version);
xml.optElement("roomname", roomName);
xml.optElement("subject", subject);
if (customConfigs != null) {
Iterator<Map.Entry<String, String>> it = customConfigs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
xml.element(pair.getKey(), pair.getValue());
}
}
xml.closeElement(this);
return xml;
}
public static ConfigurationsChangeExtension from(Message message) {
return message.getExtension(ConfigurationsChangeExtension.ELEMENT, ConfigurationsChangeExtension.NAMESPACE);
}
}
/**
* Configuration element class.
*
* @author Fernando Ramirez
*
*/
public static class ConfigurationElement implements Element {
private MUCLightRoomConfiguration configuration;
/**
* Configuration element constructor.
*
* @param configuration
*/
public ConfigurationElement(MUCLightRoomConfiguration configuration) {
this.configuration = configuration;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.openElement("configuration");
xml.element("roomname", configuration.getRoomName());
xml.optElement("subject", configuration.getSubject());
if (configuration.getCustomConfigs() != null) {
Iterator<Map.Entry<String, String>> it = configuration.getCustomConfigs().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
xml.element(pair.getKey(), pair.getValue());
}
}
xml.closeElement("configuration");
return xml;
}
}
/**
* Occupants element class.
*
* @author Fernando Ramirez
*
*/
public static class OccupantsElement implements Element {
private HashMap<Jid, MUCLightAffiliation> occupants;
/**
* Occupants element constructor.
*
* @param occupants
*/
public OccupantsElement(HashMap<Jid, MUCLightAffiliation> occupants) {
this.occupants = occupants;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.openElement("occupants");
Iterator<Map.Entry<Jid, MUCLightAffiliation>> it = occupants.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Jid, MUCLightAffiliation> pair = it.next();
xml.element(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
}
xml.closeElement("occupants");
return xml;
}
}
/**
* User with affiliation element class.
*
* @author Fernando Ramirez
*
*/
public static class UserWithAffiliationElement implements Element {
private Jid user;
private MUCLightAffiliation affiliation;
/**
* User with affiliations element constructor.
*
* @param user
* @param affiliation
*/
public UserWithAffiliationElement(Jid user, MUCLightAffiliation affiliation) {
this.user = user;
this.affiliation = affiliation;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement("user");
xml.attribute("affiliation", affiliation);
xml.rightAngleBracket();
xml.escape(user);
xml.closeElement("user");
return xml;
}
}
/**
* Blocking element class.
*
* @author Fernando Ramirez
*
*/
public static class BlockingElement implements Element {
private Jid jid;
private Boolean allow;
private Boolean isRoom;
/**
* Blocking element constructor.
*
* @param jid
* @param allow
* @param isRoom
*/
public BlockingElement(Jid jid, Boolean allow, Boolean isRoom) {
this.jid = jid;
this.allow = allow;
this.isRoom = isRoom;
}
@Override
public CharSequence toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
String tag = isRoom ? "room" : "user";
xml.halfOpenElement(tag);
String action = allow ? "allow" : "deny";
xml.attribute("action", action);
xml.rightAngleBracket();
xml.escape(jid);
xml.closeElement(tag);
return xml;
}
}
}

View file

@ -0,0 +1,65 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jxmpp.jid.Jid;
/**
* MUC Light get affiliations IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightGetAffiliationsIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.AFFILIATIONS;
private String version;
/**
* MUC Light get affiliations IQ constructor.
*
* @param roomJid
* @param version
*/
public MUCLightGetAffiliationsIQ(Jid roomJid, String version) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.setType(Type.get);
this.setTo(roomJid);
}
/**
* MUC Light get affiliations IQ constructor.
*
* @param roomJid
*/
public MUCLightGetAffiliationsIQ(Jid roomJid) {
this(roomJid, null);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
return xml;
}
}

View file

@ -0,0 +1,65 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jxmpp.jid.Jid;
/**
* MUC Light get configurations IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightGetConfigsIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;
private String version;
/**
* MUC Light get configurations IQ constructor.
*
* @param roomJid
* @param version
*/
public MUCLightGetConfigsIQ(Jid roomJid, String version) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.setType(Type.get);
this.setTo(roomJid);
}
/**
* MUC Light get configurations IQ constructor.
*
* @param roomJid
*/
public MUCLightGetConfigsIQ(Jid roomJid) {
this(roomJid, null);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
return xml;
}
}

View file

@ -0,0 +1,65 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jxmpp.jid.Jid;
/**
* MUC Light get info IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightGetInfoIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.INFO;
private String version;
/**
* MUC Light get info IQ constructor.
*
* @param roomJid
* @param version
*/
public MUCLightGetInfoIQ(Jid roomJid, String version) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.setType(Type.get);
this.setTo(roomJid);
}
/**
* MUC Light get info IQ constructor.
*
* @param roomJid
*/
public MUCLightGetInfoIQ(Jid roomJid) {
this(roomJid, null);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
return xml;
}
}

View file

@ -0,0 +1,95 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationElement;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.OccupantsElement;
import org.jxmpp.jid.Jid;
/**
* MUC Light info response IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightInfoIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.INFO;
private final String version;
private final MUCLightRoomConfiguration configuration;
private final HashMap<Jid, MUCLightAffiliation> occupants;
/**
* MUCLight info response IQ constructor.
*
* @param version
* @param configuration
* @param occupants
*/
public MUCLightInfoIQ(String version, MUCLightRoomConfiguration configuration,
HashMap<Jid, MUCLightAffiliation> occupants) {
super(ELEMENT, NAMESPACE);
this.version = version;
this.configuration = configuration;
this.occupants = occupants;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("version", version);
xml.element(new ConfigurationElement(configuration));
xml.element(new OccupantsElement(occupants));
return xml;
}
/**
* Returns the version.
*
* @return the version
*/
public String getVersion() {
return version;
}
/**
* Returns the room configuration.
*
* @return the configuration of the room
*/
public MUCLightRoomConfiguration getConfiguration() {
return configuration;
}
/**
* Returns the room occupants.
*
* @return the occupants of the room
*/
public HashMap<Jid, MUCLightAffiliation> getOccupants() {
return occupants;
}
}

View file

@ -0,0 +1,87 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.element;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.muclight.MultiUserChatLight;
import org.jxmpp.jid.Jid;
/**
* MUC Light set configurations IQ class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightSetConfigsIQ extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = MultiUserChatLight.NAMESPACE + MultiUserChatLight.CONFIGURATION;
private String roomName;
private String subject;
private HashMap<String, String> customConfigs;
/**
* MUC Light set configuration IQ constructor.
*
* @param roomJid
* @param roomName
* @param subject
* @param customConfigs
*/
public MUCLightSetConfigsIQ(Jid roomJid, String roomName, String subject, HashMap<String, String> customConfigs) {
super(ELEMENT, NAMESPACE);
this.roomName = roomName;
this.subject = subject;
this.customConfigs = customConfigs;
this.setType(Type.set);
this.setTo(roomJid);
}
/**
* MUC Light set configuration IQ constructor.
*
* @param roomJid
* @param roomName
* @param customConfigs
*/
public MUCLightSetConfigsIQ(Jid roomJid, String roomName, HashMap<String, String> customConfigs) {
this(roomJid, roomName, null, customConfigs);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.optElement("roomname", roomName);
xml.optElement("subject", subject);
if (customConfigs != null) {
Iterator<Map.Entry<String, String>> it = customConfigs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pair = it.next();
xml.element(pair.getKey(), pair.getValue());
}
}
return xml;
}
}

View file

@ -0,0 +1,25 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
/**
* Multi-User Chat Light (MUC Light) elements.
*
* @see <a href=
* "http://mongooseim.readthedocs.io/en/latest/open-extensions/xeps/xep-muc-light.html">
* XEP-xxxx: Multi-User Chat Light</a>
*
*/
package org.jivesoftware.smackx.muclight.element;

View file

@ -0,0 +1,25 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
/**
* Classes and Interfaces that implement Multi-User Chat Light (MUC Light).
*
* @see <a href=
* "http://mongooseim.readthedocs.io/en/latest/open-extensions/xeps/xep-muc-light.html">
* XEP-xxxx: Multi-User Chat Light</a>
*
*/
package org.jivesoftware.smackx.muclight;

View file

@ -0,0 +1,72 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.provider;
import java.util.HashMap;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.AffiliationsChangeExtension;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParser;
/**
* MUC Light Affiliations Change Provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightAffiliationsChangeProvider extends ExtensionElementProvider<AffiliationsChangeExtension> {
@Override
public AffiliationsChangeExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>();
String prevVersion = null;
String version = null;
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("prev-version")) {
prevVersion = parser.nextText();
}
if (parser.getName().equals("version")) {
version = parser.nextText();
}
if (parser.getName().equals("user")) {
MUCLightAffiliation mucLightAffiliation = MUCLightAffiliation
.fromString(parser.getAttributeValue("", "affiliation"));
Jid jid = JidCreate.from(parser.nextText());
affiliations.put(jid, mucLightAffiliation);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
return new AffiliationsChangeExtension(affiliations, prevVersion, version);
}
}

View file

@ -0,0 +1,66 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.provider;
import java.util.HashMap;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.element.MUCLightAffiliationsIQ;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParser;
/**
* MUC Light affiliations IQ provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightAffiliationsIQProvider extends IQProvider<MUCLightAffiliationsIQ> {
@Override
public MUCLightAffiliationsIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
String version = null;
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("version")) {
version = parser.nextText();
}
if (parser.getName().equals("user")) {
MUCLightAffiliation affiliation = MUCLightAffiliation
.fromString(parser.getAttributeValue("", "affiliation"));
occupants.put(JidCreate.from(parser.nextText()), affiliation);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
return new MUCLightAffiliationsIQ(version, occupants);
}
}

View file

@ -0,0 +1,84 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.provider;
import java.io.IOException;
import java.util.HashMap;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.stringprep.XmppStringprepException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* MUC Light blocking IQ provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightBlockingIQProvider extends IQProvider<MUCLightBlockingIQ> {
@Override
public MUCLightBlockingIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
HashMap<Jid, Boolean> rooms = null;
HashMap<Jid, Boolean> users = null;
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("room")) {
rooms = parseBlocking(parser, rooms);
}
if (parser.getName().equals("user")) {
users = parseBlocking(parser, users);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, users);
mucLightBlockingIQ.setType(Type.result);
return mucLightBlockingIQ;
}
private HashMap<Jid, Boolean> parseBlocking(XmlPullParser parser, HashMap<Jid, Boolean> map)
throws XmppStringprepException, XmlPullParserException, IOException {
if (map == null) {
map = new HashMap<>();
}
String action = parser.getAttributeValue("", "action");
if (action.equals("deny")) {
map.put(JidCreate.from(parser.nextText()), false);
} else if (action.equals("allow")) {
map.put(JidCreate.from(parser.nextText()), true);
}
return map;
}
}

View file

@ -0,0 +1,71 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.provider;
import java.util.HashMap;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.element.MUCLightConfigurationIQ;
import org.xmlpull.v1.XmlPullParser;
/**
* MUC Light configuration IQ provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightConfigurationIQProvider extends IQProvider<MUCLightConfigurationIQ> {
@Override
public MUCLightConfigurationIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
String version = null;
String roomName = null;
String subject = null;
HashMap<String, String> customConfigs = null;
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("version")) {
version = parser.nextText();
} else if (parser.getName().equals("roomname")) {
roomName = parser.nextText();
} else if (parser.getName().equals("subject")) {
subject = parser.nextText();
} else {
if (customConfigs == null) {
customConfigs = new HashMap<>();
}
customConfigs.put(parser.getName(), parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
MUCLightRoomConfiguration configuration = new MUCLightRoomConfiguration(roomName, subject, customConfigs);
return new MUCLightConfigurationIQ(version, configuration);
}
}

View file

@ -0,0 +1,71 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.provider;
import java.util.HashMap;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationsChangeExtension;
import org.xmlpull.v1.XmlPullParser;
/**
* MUC Light configurations change provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightConfigurationsChangeProvider extends ExtensionElementProvider<ConfigurationsChangeExtension> {
@Override
public ConfigurationsChangeExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
String prevVersion = null;
String version = null;
String roomName = null;
String subject = null;
HashMap<String, String> customConfigs = null;
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("prev-version")) {
prevVersion = parser.nextText();
} else if (parser.getName().equals("version")) {
version = parser.nextText();
} else if (parser.getName().equals("roomname")) {
roomName = parser.nextText();
} else if (parser.getName().equals("subject")) {
subject = parser.nextText();
} else {
if (customConfigs == null) {
customConfigs = new HashMap<>();
}
customConfigs.put(parser.getName(), parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
return new ConfigurationsChangeExtension(prevVersion, version, roomName, subject, customConfigs);
}
}

View file

@ -0,0 +1,116 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
package org.jivesoftware.smackx.muclight.provider;
import java.util.HashMap;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
import org.jivesoftware.smackx.muclight.element.MUCLightInfoIQ;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParser;
/**
* MUC Light info IQ provider class.
*
* @author Fernando Ramirez
*
*/
public class MUCLightInfoIQProvider extends IQProvider<MUCLightInfoIQ> {
@Override
public MUCLightInfoIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
String version = null;
String roomName = null;
String subject = null;
HashMap<String, String> customConfigs = null;
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("version")) {
version = parser.nextText();
}
if (parser.getName().equals("configuration")) {
int depth = parser.getDepth();
outerloop2: while (true) {
eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("roomname")) {
roomName = parser.nextText();
} else if (parser.getName().equals("subject")) {
subject = parser.nextText();
} else {
if (customConfigs == null) {
customConfigs = new HashMap<>();
}
customConfigs.put(parser.getName(), parser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == depth) {
break outerloop2;
}
}
}
}
if (parser.getName().equals("occupants")) {
occupants = iterateOccupants(parser);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == initialDepth) {
break outerloop;
}
}
}
return new MUCLightInfoIQ(version, new MUCLightRoomConfiguration(roomName, subject, customConfigs), occupants);
}
private HashMap<Jid, MUCLightAffiliation> iterateOccupants(XmlPullParser parser) throws Exception {
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
int depth = parser.getDepth();
outerloop: while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("user")) {
MUCLightAffiliation affiliation = MUCLightAffiliation
.fromString(parser.getAttributeValue("", "affiliation"));
occupants.put(JidCreate.from(parser.nextText()), affiliation);
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getDepth() == depth) {
break outerloop;
}
}
}
return occupants;
}
}

View file

@ -0,0 +1,25 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.
*/
/**
* Multi-User Chat Light (MUC Light) providers.
*
* @see <a href=
* "http://mongooseim.readthedocs.io/en/latest/open-extensions/xeps/xep-muc-light.html">
* XEP-xxxx: Multi-User Chat Light</a>
*
*/
package org.jivesoftware.smackx.muclight.provider;

View file

@ -51,6 +51,38 @@
<namespace>google:mobile:data</namespace>
<className>org.jivesoftware.smackx.gcm.provider.GcmExtensionProvider</className>
</extensionProvider>
<!-- XEP-xxxx: Multi-User Chat Light -->
<iqProvider>
<elementName>query</elementName>
<namespace>urn:xmpp:muclight:0#info</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightInfoIQProvider</className>
</iqProvider>
<extensionProvider>
<elementName>x</elementName>
<namespace>urn:xmpp:muclight:0#affiliations</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightAffiliationsChangeProvider</className>
</extensionProvider>
<extensionProvider>
<elementName>x</elementName>
<namespace>urn:xmpp:muclight:0#configuration</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightConfigurationsChangeProvider</className>
</extensionProvider>
<iqProvider>
<elementName>query</elementName>
<namespace>urn:xmpp:muclight:0#configuration</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightConfigurationIQProvider</className>
</iqProvider>
<iqProvider>
<elementName>query</elementName>
<namespace>urn:xmpp:muclight:0#affiliations</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightAffiliationsIQProvider</className>
</iqProvider>
<iqProvider>
<elementName>query</elementName>
<namespace>urn:xmpp:muclight:0#blocking</namespace>
<className>org.jivesoftware.smackx.muclight.provider.MUCLightBlockingIQProvider</className>
</iqProvider>
<!-- XEP-0313 Message Archive Management -->
<iqProvider>