use of org.jivesoftware.smackx.blocking.element.BlockListIQ in project Smack by igniterealtime.
the class GetBlockingListTest method checkGetBlockingListIQStanza.
@Test
public void checkGetBlockingListIQStanza() throws Exception {
BlockListIQ getBlockListIQ = new BlockListIQ(null);
getBlockListIQ.setType(Type.get);
getBlockListIQ.setStanzaId("blocklist1");
Assert.assertEquals(getBlockingListIQExample, getBlockListIQ.toXML().toString());
}
use of org.jivesoftware.smackx.blocking.element.BlockListIQ in project Smack by igniterealtime.
the class BlockingCommandManager method getBlockList.
/**
* Returns the block list.
*
* @return the blocking list
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Jid> getBlockList() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
if (blockListCached == null) {
BlockListIQ blockListIQ = new BlockListIQ();
BlockListIQ blockListIQResult = connection().createStanzaCollectorAndSend(blockListIQ).nextResultOrThrow();
blockListCached = blockListIQResult.getBlockedJidsCopy();
}
return Collections.unmodifiableList(blockListCached);
}
use of org.jivesoftware.smackx.blocking.element.BlockListIQ in project Smack by igniterealtime.
the class BlockListIQProvider method parse.
@Override
public BlockListIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
List<Jid> jids = null;
outerloop: while (true) {
int eventType = parser.next();
switch(eventType) {
case XmlPullParser.START_TAG:
if (parser.getName().equals("item")) {
if (jids == null) {
jids = new ArrayList<>();
}
Jid jid = ParserUtils.getJidAttribute(parser);
jids.add(jid);
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
BlockListIQ blockListIQ = new BlockListIQ(jids);
blockListIQ.setType(Type.result);
return blockListIQ;
}
use of org.jivesoftware.smackx.blocking.element.BlockListIQ in project Smack by igniterealtime.
the class GetBlockingListTest method checkBlockListIQ.
@Test
public void checkBlockListIQ() throws Exception {
IQ iq = (IQ) PacketParserUtils.parseStanza(blockListIQExample);
BlockListIQ blockListIQ = (BlockListIQ) iq;
Assert.assertEquals(2, blockListIQ.getBlockedJids().size());
Assert.assertEquals(JidCreate.from("romeo@montague.net"), blockListIQ.getBlockedJids().get(0));
Assert.assertEquals(JidCreate.from("iago@shakespeare.lit"), blockListIQ.getBlockedJids().get(1));
IQ iq2 = (IQ) PacketParserUtils.parseStanza(emptyBlockListIQExample);
BlockListIQ emptyBlockListIQ = (BlockListIQ) iq2;
Assert.assertEquals(0, emptyBlockListIQ.getBlockedJids().size());
}
Aggregations