Search in sources :

Example 1 with BlockListIQ

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());
}
Also used : BlockListIQ(org.jivesoftware.smackx.blocking.element.BlockListIQ) Test(org.junit.Test)

Example 2 with BlockListIQ

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);
}
Also used : BlockListIQ(org.jivesoftware.smackx.blocking.element.BlockListIQ)

Example 3 with BlockListIQ

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;
}
Also used : Jid(org.jxmpp.jid.Jid) ArrayList(java.util.ArrayList) BlockListIQ(org.jivesoftware.smackx.blocking.element.BlockListIQ)

Example 4 with 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());
}
Also used : BlockListIQ(org.jivesoftware.smackx.blocking.element.BlockListIQ) IQ(org.jivesoftware.smack.packet.IQ) BlockListIQ(org.jivesoftware.smackx.blocking.element.BlockListIQ) Test(org.junit.Test)

Aggregations

BlockListIQ (org.jivesoftware.smackx.blocking.element.BlockListIQ)4 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 IQ (org.jivesoftware.smack.packet.IQ)1 Jid (org.jxmpp.jid.Jid)1