mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
Add support for PubSub affiliation actions as owner
SMACK-675.
This commit is contained in:
parent
f7782aa466
commit
fce0aeadef
3 changed files with 116 additions and 24 deletions
|
@ -130,6 +130,20 @@ public class Affiliation implements ExtensionElement
|
||||||
return namespace;
|
return namespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this is an affiliation element to modify affiliations on a node.
|
||||||
|
*
|
||||||
|
* @return <code>true</code> if this is an affiliation element to modify affiliations on a node, <code>false</code> otherwise.
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public boolean isAffiliationModification() {
|
||||||
|
if (jid != null && affiliation != null) {
|
||||||
|
assert(node == null && namespace == PubSubNamespace.OWNER);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder toXML() {
|
public XmlStringBuilder toXML() {
|
||||||
XmlStringBuilder xml = new XmlStringBuilder(this);
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
||||||
|
|
|
@ -19,26 +19,33 @@ package org.jivesoftware.smackx.pubsub;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the <b>affiliations</b> element of the reply to a request for affiliations.
|
* Represents the <b>affiliations</b> element of the reply to a request for affiliations.
|
||||||
* It is defined in the specification in section <a href="http://xmpp.org/extensions/xep-0060.html#entity-affiliations">5.7 Retrieve Affiliations</a>.
|
* It is defined in the specification in section <a href="http://xmpp.org/extensions/xep-0060.html#entity-affiliations">5.7 Retrieve Affiliations</a> and
|
||||||
|
* <a href="http://www.xmpp.org/extensions/xep-0060.html#owner-affiliations">8.9 Manage Affiliations</a>.
|
||||||
*
|
*
|
||||||
* @author Robin Collier
|
* @author Robin Collier
|
||||||
*/
|
*/
|
||||||
public class AffiliationsExtension extends NodeExtension
|
public class AffiliationsExtension extends NodeExtension
|
||||||
{
|
{
|
||||||
protected List<Affiliation> items = Collections.emptyList();
|
protected List<Affiliation> items = Collections.emptyList();
|
||||||
|
private final String node;
|
||||||
|
|
||||||
public AffiliationsExtension()
|
public AffiliationsExtension() {
|
||||||
{
|
this(null, null);
|
||||||
super(PubSubElementType.AFFILIATIONS);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public AffiliationsExtension(List<Affiliation> subList)
|
public AffiliationsExtension(List<Affiliation> subList) {
|
||||||
{
|
this(subList, null);
|
||||||
super(PubSubElementType.AFFILIATIONS);
|
}
|
||||||
items = subList;
|
|
||||||
}
|
public AffiliationsExtension(List<Affiliation> subList, String node) {
|
||||||
|
super(PubSubElementType.AFFILIATIONS);
|
||||||
|
items = subList;
|
||||||
|
this.node = node;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Affiliation> getAffiliations()
|
public List<Affiliation> getAffiliations()
|
||||||
{
|
{
|
||||||
|
@ -54,19 +61,14 @@ public class AffiliationsExtension extends NodeExtension
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder("<");
|
// Can't use XmlStringBuilder(this), because we don't want the namespace to be included
|
||||||
builder.append(getElementName());
|
XmlStringBuilder xml = new XmlStringBuilder();
|
||||||
builder.append(">");
|
xml.openElement(getElementName());
|
||||||
|
xml.optAttribute("node", node);
|
||||||
for (Affiliation item : items)
|
xml.rightAngleBracket();
|
||||||
{
|
xml.append(items);
|
||||||
builder.append(item.toXML());
|
xml.closeElement(this);
|
||||||
}
|
return xml;
|
||||||
|
|
||||||
builder.append("</");
|
|
||||||
builder.append(getElementName());
|
|
||||||
builder.append(">");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,54 @@ abstract public class Node
|
||||||
public List<Affiliation> getAffiliations(List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions)
|
public List<Affiliation> getAffiliations(List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions)
|
||||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
|
|
||||||
PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS, getId()));
|
return getAffiliations(PubSubNamespace.BASIC, additionalExtensions, returnedExtensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the affiliation list for this node as owner.
|
||||||
|
*
|
||||||
|
* @return list of entities whose affiliation is not 'none'.
|
||||||
|
* @throws NoResponseException
|
||||||
|
* @throws XMPPErrorException
|
||||||
|
* @throws NotConnectedException
|
||||||
|
* @throws InterruptedException
|
||||||
|
* @see #getAffiliations(List, Collection)
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public List<Affiliation> getAffiliationsAsOwner()
|
||||||
|
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
|
|
||||||
|
return getAffiliationsAsOwner(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the affiliation list for this node as owner.
|
||||||
|
* <p>
|
||||||
|
* Note that this is an <b>optional</b> PubSub feature ('pubusb#modify-affiliations').
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param additionalExtensions optional additional extension elements add to the request.
|
||||||
|
* @param returnedExtensions an optional collection that will be filled with the returned
|
||||||
|
* extension elements.
|
||||||
|
* @return list of entities whose affiliation is not 'none'.
|
||||||
|
* @throws NoResponseException
|
||||||
|
* @throws XMPPErrorException
|
||||||
|
* @throws NotConnectedException
|
||||||
|
* @throws InterruptedException
|
||||||
|
* @see <a href="http://www.xmpp.org/extensions/xep-0060.html#owner-affiliations-retrieve">XEP-60 § 8.9.1 Retrieve Affiliations List</a>
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public List<Affiliation> getAffiliationsAsOwner(List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions)
|
||||||
|
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
|
|
||||||
|
return getAffiliations(PubSubNamespace.OWNER, additionalExtensions, returnedExtensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Affiliation> getAffiliations(PubSubNamespace namespace, List<ExtensionElement> additionalExtensions,
|
||||||
|
Collection<ExtensionElement> returnedExtensions) throws NoResponseException, XMPPErrorException,
|
||||||
|
NotConnectedException, InterruptedException {
|
||||||
|
|
||||||
|
PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS, getId()), namespace);
|
||||||
if (additionalExtensions != null) {
|
if (additionalExtensions != null) {
|
||||||
for (ExtensionElement pe : additionalExtensions) {
|
for (ExtensionElement pe : additionalExtensions) {
|
||||||
pubSub.addExtension(pe);
|
pubSub.addExtension(pe);
|
||||||
|
@ -270,6 +317,35 @@ abstract public class Node
|
||||||
return affilElem.getAffiliations();
|
return affilElem.getAffiliations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the affiliations for this PubSub node as owner. The {@link Affiliation}s given must be created with the
|
||||||
|
* {@link Affiliation#Affiliation(org.jxmpp.jid.BareJid, Affiliation.Type)} constructor.
|
||||||
|
* <p>
|
||||||
|
* Note that this is an <b>optional</b> PubSub feature ('pubusb#modify-affiliations').
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param affiliations
|
||||||
|
* @return <code>null</code> or a PubSub stanza with additional information on success.
|
||||||
|
* @throws NoResponseException
|
||||||
|
* @throws XMPPErrorException
|
||||||
|
* @throws NotConnectedException
|
||||||
|
* @throws InterruptedException
|
||||||
|
* @see <a href="http://www.xmpp.org/extensions/xep-0060.html#owner-affiliations-modify">XEP-60 § 8.9.2 Modify Affiliation</a>
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
public PubSub modifyAffiliationAsOwner(List<Affiliation> affiliations) throws NoResponseException,
|
||||||
|
XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
|
for (Affiliation affiliation : affiliations) {
|
||||||
|
if (affiliation.getPubSubNamespace() != PubSubNamespace.OWNER) {
|
||||||
|
throw new IllegalArgumentException("Must use Affiliation(BareJid, Type) affiliations");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PubSub pubSub = createPubsubPacket(Type.set, new AffiliationsExtension(affiliations, getId()),
|
||||||
|
PubSubNamespace.OWNER);
|
||||||
|
return sendPubsubPacket(pubSub);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user subscribes to the node using the supplied jid. The
|
* The user subscribes to the node using the supplied jid. The
|
||||||
* bare jid portion of this one must match the jid for the connection.
|
* bare jid portion of this one must match the jid for the connection.
|
||||||
|
|
Loading…
Reference in a new issue