2016-11-02 16:10:56 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2016-11-02 16:10:56 +01:00
|
|
|
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;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2016-11-02 16:10:56 +01:00
|
|
|
import org.jxmpp.jid.Jid;
|
|
|
|
|
|
|
|
public abstract class MUCLightElements {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Affiliations change extension element class.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @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.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @return the affiliations
|
|
|
|
*/
|
|
|
|
public HashMap<Jid, MUCLightAffiliation> getAffiliations() {
|
|
|
|
return affiliations;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the previous version.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @return the previous version
|
|
|
|
*/
|
|
|
|
public String getPrevVersion() {
|
|
|
|
return prevVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the version.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @return the version
|
|
|
|
*/
|
|
|
|
public String getVersion() {
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2016-11-02 16:10:56 +01:00
|
|
|
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();
|
2019-09-07 18:17:08 +02:00
|
|
|
xml.append(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
|
2016-11-02 16:10:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
xml.closeElement(this);
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AffiliationsChangeExtension from(Message message) {
|
|
|
|
return message.getExtension(AffiliationsChangeExtension.ELEMENT, AffiliationsChangeExtension.NAMESPACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configurations change extension element class.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @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.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param prevVersion TODO javadoc me please
|
|
|
|
* @param version TODO javadoc me please
|
|
|
|
* @param roomName TODO javadoc me please
|
|
|
|
* @param subject TODO javadoc me please
|
|
|
|
* @param customConfigs TODO javadoc me please
|
2016-11-02 16:10:56 +01:00
|
|
|
*/
|
|
|
|
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.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @return the previous version
|
|
|
|
*/
|
|
|
|
public String getPrevVersion() {
|
|
|
|
return prevVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the version.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @return the version
|
|
|
|
*/
|
|
|
|
public String getVersion() {
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the room name.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @return the room name
|
|
|
|
*/
|
|
|
|
public String getRoomName() {
|
|
|
|
return roomName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the room subject.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @return the room subject
|
|
|
|
*/
|
|
|
|
public String getSubject() {
|
|
|
|
return subject;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the room custom configurations.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @return the room custom configurations
|
|
|
|
*/
|
|
|
|
public HashMap<String, String> getCustomConfigs() {
|
|
|
|
return customConfigs;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2016-11-02 16:10:56 +01:00
|
|
|
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.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @author Fernando Ramirez
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class ConfigurationElement implements Element {
|
|
|
|
|
|
|
|
private MUCLightRoomConfiguration configuration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration element constructor.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param configuration TODO javadoc me please
|
2016-11-02 16:10:56 +01:00
|
|
|
*/
|
|
|
|
public ConfigurationElement(MUCLightRoomConfiguration configuration) {
|
|
|
|
this.configuration = configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2016-11-02 16:10:56 +01:00
|
|
|
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.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @author Fernando Ramirez
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class OccupantsElement implements Element {
|
|
|
|
|
|
|
|
private HashMap<Jid, MUCLightAffiliation> occupants;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Occupants element constructor.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param occupants TODO javadoc me please
|
2016-11-02 16:10:56 +01:00
|
|
|
*/
|
|
|
|
public OccupantsElement(HashMap<Jid, MUCLightAffiliation> occupants) {
|
|
|
|
this.occupants = occupants;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2016-11-02 16:10:56 +01:00
|
|
|
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();
|
2019-09-07 18:17:08 +02:00
|
|
|
xml.append(new UserWithAffiliationElement(pair.getKey(), pair.getValue()));
|
2016-11-02 16:10:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
xml.closeElement("occupants");
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User with affiliation element class.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @author Fernando Ramirez
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class UserWithAffiliationElement implements Element {
|
|
|
|
|
|
|
|
private Jid user;
|
|
|
|
private MUCLightAffiliation affiliation;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User with affiliations element constructor.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param user TODO javadoc me please
|
|
|
|
* @param affiliation TODO javadoc me please
|
2016-11-02 16:10:56 +01:00
|
|
|
*/
|
|
|
|
public UserWithAffiliationElement(Jid user, MUCLightAffiliation affiliation) {
|
|
|
|
this.user = user;
|
|
|
|
this.affiliation = affiliation;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2016-11-02 16:10:56 +01:00
|
|
|
XmlStringBuilder xml = new XmlStringBuilder();
|
|
|
|
xml.halfOpenElement("user");
|
|
|
|
xml.attribute("affiliation", affiliation);
|
|
|
|
xml.rightAngleBracket();
|
|
|
|
xml.escape(user);
|
|
|
|
xml.closeElement("user");
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blocking element class.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-11-02 16:10:56 +01:00
|
|
|
* @author Fernando Ramirez
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static class BlockingElement implements Element {
|
|
|
|
|
|
|
|
private Jid jid;
|
|
|
|
private Boolean allow;
|
|
|
|
private Boolean isRoom;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blocking element constructor.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param jid TODO javadoc me please
|
|
|
|
* @param allow TODO javadoc me please
|
|
|
|
* @param isRoom TODO javadoc me please
|
2016-11-02 16:10:56 +01:00
|
|
|
*/
|
|
|
|
public BlockingElement(Jid jid, Boolean allow, Boolean isRoom) {
|
|
|
|
this.jid = jid;
|
|
|
|
this.allow = allow;
|
|
|
|
this.isRoom = isRoom;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2016-11-02 16:10:56 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|