use of org.jivesoftware.smackx.pubsub.packet.PubSub in project ecf by eclipse.
the class PubSubManager method createPubsubPacket.
static PubSub createPubsubPacket(String to, Type type, PacketExtension ext, PubSubNamespace ns) {
PubSub request = new PubSub();
request.setTo(to);
request.setType(type);
if (ns != null) {
request.setPubSubNamespace(ns);
}
request.addExtension(ext);
return request;
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class PubSubProvider method parse.
@Override
public PubSub parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
String namespace = parser.getNamespace();
PubSubNamespace pubSubNamespace = PubSubNamespace.valueOfFromXmlns(namespace);
PubSub pubsub = new PubSub(pubSubNamespace);
outerloop: while (true) {
XmlPullParser.Event eventType = parser.next();
switch(eventType) {
case START_ELEMENT:
PacketParserUtils.addExtensionElement(pubsub, parser, xmlEnvironment);
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}
return pubsub;
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class PubSubManager method getAffiliations.
/**
* Gets the affiliations on the root node.
*
* @return List of affiliations
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws NoResponseException if there was no response from the remote entity.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
public List<Affiliation> getAffiliations() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub reply = sendPubsubPacket(IQ.Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS), null);
AffiliationsExtension listElem = reply.getExtension(PubSubElementType.AFFILIATIONS);
return listElem.getAffiliations();
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class PubSubNodeTest method getAffiliationsAsOwnerTest.
@Test
public void getAffiliationsAsOwnerTest() throws InterruptedException, SmackException, IOException, XMPPException, Exception {
Protocol protocol = new Protocol();
XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, JidTestUtil.FULL_JID_1_RESOURCE_1);
PubSubManager mgr = new PubSubManager(connection, JidTestUtil.PUBSUB_EXAMPLE_ORG);
Node testNode = new LeafNode(mgr, "princely_musings");
List<Affiliation> affiliations = Arrays.asList(new Affiliation(JidTestUtil.BARE_JID_1, Affiliation.Type.member), new Affiliation(JidTestUtil.BARE_JID_2, Affiliation.Type.publisher));
AffiliationsExtension affiliationsExtension = new AffiliationsExtension(AffiliationNamespace.owner, affiliations);
PubSub response = new PubSub(JidTestUtil.PUBSUB_EXAMPLE_ORG, IQ.Type.result, PubSubNamespace.owner);
response.addExtension(affiliationsExtension);
protocol.addResponse(response);
List<Affiliation> returnedAffiliations = testNode.getAffiliationsAsOwner();
PubSub request = (PubSub) protocol.getRequests().get(0);
assertEquals("http://jabber.org/protocol/pubsub#owner", request.getChildElementNamespace());
assertEquals("pubsub", request.getChildElementName());
Affiliation affiliationOne = returnedAffiliations.get(0);
assertEquals(affiliationOne.getJid(), JidTestUtil.BARE_JID_1);
assertEquals(affiliationOne.getAffiliation(), Affiliation.Type.member);
Affiliation affiliationTwo = returnedAffiliations.get(1);
assertEquals(affiliationTwo.getJid(), JidTestUtil.BARE_JID_2);
assertEquals(affiliationTwo.getAffiliation(), Affiliation.Type.publisher);
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class PubSubNodeTest method modifySubscriptionsAsOwnerTest.
@Test
public void modifySubscriptionsAsOwnerTest() throws InterruptedException, SmackException, IOException, XMPPException, Exception {
ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
PubSubManager mgr = new PubSubManager(con, JidTestUtil.PUBSUB_EXAMPLE_ORG);
Node testNode = new LeafNode(mgr, "princely_musings");
List<Subscription> ChangeSubs = Arrays.asList(new Subscription(JidCreate.from("romeo@montague.org"), Subscription.State.subscribed), new Subscription(JidCreate.from("juliet@capulet.org"), Subscription.State.none));
testNode.modifySubscriptionsAsOwner(ChangeSubs);
PubSub request = con.getSentPacket();
assertEquals("http://jabber.org/protocol/pubsub#owner", request.getChildElementNamespace());
assertEquals("pubsub", request.getChildElementName());
XmlPullParser parser = TestUtils.getIQParser(request.toXML().toString());
PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser);
SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS_OWNER);
List<Subscription> subscriptions = subElem.getSubscriptions();
assertEquals(2, subscriptions.size());
Subscription sub1 = subscriptions.get(0);
assertEquals("romeo@montague.org", sub1.getJid().toString());
assertEquals(Subscription.State.subscribed, sub1.getState());
Subscription sub2 = subscriptions.get(1);
assertEquals("juliet@capulet.org", sub2.getJid().toString());
assertEquals(Subscription.State.none, sub2.getState());
}
Aggregations