@SuppressWarnings("unchecked") @Override protected AffiliationsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) { AffiliationNamespace affiliationsNamespace = AffiliationNamespace.fromXmlns(currentNamespace); return new AffiliationsExtension(affiliationsNamespace, (List<Affiliation>) content); }
/** * Gets the affiliations on the root node. * * @return List of affiliations * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException * */ public List<Affiliation> getAffiliations() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS), null); AffiliationsExtension listElem = reply.getExtension(PubSubElementType.AFFILIATIONS); return listElem.getAffiliations(); }
@Override public CharSequence toXML(String enclosingNamespace) { if ((items == null) || (items.size() == 0)) { return super.toXML(enclosingNamespace); } else { // Can't use XmlStringBuilder(this), because we don't want the namespace to be included XmlStringBuilder xml = new XmlStringBuilder(); xml.halfOpenElement(getElementName()); xml.optAttribute("node", node); xml.rightAngleBracket(); xml.append(items); xml.closeElement(this); return xml; } } }
@Test public void testAffiliationsExtensionToXml() throws SAXException, IOException { BareJid affiliatedJid = JidTestUtil.BARE_JID_1; Affiliation affiliation = new Affiliation(affiliatedJid, Type.member); List<Affiliation> affiliationsList = new ArrayList<>(); affiliationsList.add(affiliation); AffiliationsExtension affiliationsExtension = new AffiliationsExtension(affiliationsList, "testNode"); CharSequence xml = affiliationsExtension.toXML(null); assertXMLEqual("<affiliations node='testNode'><affiliation xmlns='http://jabber.org/protocol/pubsub#owner' jid='one@exampleone.org' affiliation='member'/></affiliations>", xml.toString()); }
builder.append(getElementName()); if (getNode() != null) builder.append(getNode()); builder.append("'"); builder.append(getElementName()); builder.append(">"); return builder.toString();
/** * 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 ('pubsub#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(AffiliationNamespace.owner, affiliations, getId())); return sendPubsubPacket(pubSub); }
private List<Affiliation> getAffiliations(AffiliationNamespace affiliationsNamespace, List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSubElementType pubSubElementType = affiliationsNamespace.type; PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(pubSubElementType, getId())); if (additionalExtensions != null) { for (ExtensionElement pe : additionalExtensions) { pubSub.addExtension(pe); } } PubSub reply = sendPubsubPacket(pubSub); if (returnedExtensions != null) { returnedExtensions.addAll(reply.getExtensions()); } AffiliationsExtension affilElem = reply.getExtension(pubSubElementType); return affilElem.getAffiliations(); }
@Override public String toXML() { if ((items == null) || (items.size() == 0)) { return super.toXML(); } else { StringBuilder builder = new StringBuilder("<"); builder.append(getElementName()); builder.append(">"); for (Affiliation item : items) { builder.append(item.toXML()); } builder.append("</"); builder.append(getElementName()); builder.append(">"); return builder.toString(); } } }
new Affiliation(JidTestUtil.BARE_JID_2, Affiliation.Type.publisher) ); AffiliationsExtension affiliationsExtension = new AffiliationsExtension(AffiliationNamespace.owner, affiliations); PubSub response = new PubSub(JidTestUtil.PUBSUB_EXAMPLE_ORG, Type.result, PubSubNamespace.owner); response.addExtension(affiliationsExtension);
/** * Gets the affiliations on the root node. * * @return List of affiliations * * @throws XMPPException */ public List<Affiliation> getAffiliations() throws XMPPException { PubSub reply = (PubSub)sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.AFFILIATIONS)); AffiliationsExtension listElem = (AffiliationsExtension)reply.getExtension(PubSubElementType.AFFILIATIONS); return listElem.getAffiliations(); }
@Override public String toXML() { if ((items == null) || (items.size() == 0)) { return super.toXML(); } else { StringBuilder builder = new StringBuilder("<"); builder.append(getElementName()); builder.append(">"); for (Affiliation item : items) { builder.append(item.toXML()); } builder.append("</"); builder.append(getElementName()); builder.append(">"); return builder.toString(); } } }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new AffiliationsExtension((List<Affiliation>)content); }
/** * Gets the affiliations on the root node. * * @return List of affiliations * * @throws XMPPException */ public List<Affiliation> getAffiliations() throws XMPPException { PubSub reply = (PubSub)sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.AFFILIATIONS)); AffiliationsExtension listElem = (AffiliationsExtension)reply.getExtension(PubSubElementType.AFFILIATIONS); return listElem.getAffiliations(); }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new AffiliationsExtension((List<Affiliation>)content); }
/** * Gets the affiliations on the root node. * * @return List of affiliations * * @throws XMPPException */ public List<Affiliation> getAffiliations() throws XMPPException { PubSub reply = (PubSub)sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.AFFILIATIONS)); AffiliationsExtension listElem = (AffiliationsExtension)reply.getExtension(PubSubElementType.AFFILIATIONS); return listElem.getAffiliations(); }
@Override protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content) { return new AffiliationsExtension(attributeMap.get("node"), (List<Affiliation>)content); }