Search in sources :

Example 1 with MamFinIQ

use of org.jivesoftware.smackx.mam.element.MamFinIQ in project Smack by igniterealtime.

the class MamFinProviderTest method checkMamFinProvider.

@Test
public void checkMamFinProvider() throws Exception {
    XmlPullParser parser = PacketParserUtils.getParserFor(exmapleMamFinXml);
    MamFinIQ mamFinIQ = new MamFinIQProvider().parse(parser);
    Assert.assertFalse(mamFinIQ.isComplete());
    Assert.assertTrue(mamFinIQ.isStable());
    Assert.assertNull(mamFinIQ.getQueryId());
    RSMSet rsmSet = mamFinIQ.getRSMSet();
    Assert.assertEquals(rsmSet.getAfter(), "09af3-cc343-b409f");
    Assert.assertEquals(rsmSet.getMax(), 10);
}
Also used : MamFinIQProvider(org.jivesoftware.smackx.mam.provider.MamFinIQProvider) RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) XmlPullParser(org.xmlpull.v1.XmlPullParser) MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ) Test(org.junit.Test)

Example 2 with MamFinIQ

use of org.jivesoftware.smackx.mam.element.MamFinIQ in project Smack by igniterealtime.

the class MamFinIQProvider method parse.

@Override
public MamFinIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
    String queryId = parser.getAttributeValue("", "queryid");
    boolean complete = ParserUtils.getBooleanAttribute(parser, "complete", false);
    boolean stable = ParserUtils.getBooleanAttribute(parser, "stable", true);
    RSMSet rsmSet = null;
    outerloop: while (true) {
        int eventType = parser.next();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                if (parser.getName().equals(RSMSet.ELEMENT)) {
                    rsmSet = RSMSetProvider.INSTANCE.parse(parser);
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new MamFinIQ(queryId, rsmSet, complete, stable);
}
Also used : RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ)

Example 3 with MamFinIQ

use of org.jivesoftware.smackx.mam.element.MamFinIQ in project Smack by igniterealtime.

the class MamFinProviderTest method checkQueryLimitedResults.

@Test
public void checkQueryLimitedResults() throws Exception {
    // @formatter:off
    final String IQ_LIMITED_RESULTS_EXAMPLE = "<iq type='result' id='u29303'>" + "<fin xmlns='urn:xmpp:mam:1' complete='true'>" + "<set xmlns='http://jabber.org/protocol/rsm'>" + "<first index='0'>23452-4534-1</first>" + "<last>390-2342-22</last>" + "<count>16</count>" + "</set>" + "</fin>" + "</iq>";
    // @formatter:on
    IQ iq = (IQ) PacketParserUtils.parseStanza(IQ_LIMITED_RESULTS_EXAMPLE);
    MamFinIQ mamFinIQ = (MamFinIQ) iq;
    Assert.assertEquals(mamFinIQ.getType(), Type.result);
    Assert.assertTrue(mamFinIQ.isComplete());
    Assert.assertEquals(mamFinIQ.getRSMSet().getCount(), 16);
    Assert.assertEquals(mamFinIQ.getRSMSet().getFirst(), "23452-4534-1");
    Assert.assertEquals(mamFinIQ.getRSMSet().getFirstIndex(), 0);
    Assert.assertEquals(mamFinIQ.getRSMSet().getLast(), "390-2342-22");
}
Also used : MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ) IQ(org.jivesoftware.smack.packet.IQ) MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ) Test(org.junit.Test)

Example 4 with MamFinIQ

use of org.jivesoftware.smackx.mam.element.MamFinIQ in project Smack by igniterealtime.

the class MamManager method queryArchive.

private MamQueryResult queryArchive(MamQueryIQ mamQueryIq) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    MamFinIQ mamFinIQ = null;
    StanzaCollector mamFinIQCollector = connection.createStanzaCollector(new IQReplyFilter(mamQueryIq, connection));
    StanzaCollector.Configuration resultCollectorConfiguration = StanzaCollector.newConfiguration().setStanzaFilter(new MamResultFilter(mamQueryIq)).setCollectorToReset(mamFinIQCollector);
    StanzaCollector resultCollector = connection.createStanzaCollector(resultCollectorConfiguration);
    try {
        connection.sendStanza(mamQueryIq);
        mamFinIQ = mamFinIQCollector.nextResultOrThrow();
    } finally {
        mamFinIQCollector.cancel();
        resultCollector.cancel();
    }
    List<Forwarded> forwardedMessages = new ArrayList<>(resultCollector.getCollectedCount());
    for (Message resultMessage = resultCollector.pollResult(); resultMessage != null; resultMessage = resultCollector.pollResult()) {
        MamElements.MamResultExtension mamResultExtension = MamElements.MamResultExtension.from(resultMessage);
        forwardedMessages.add(mamResultExtension.getForwarded());
    }
    return new MamQueryResult(forwardedMessages, mamFinIQ, mamQueryIq.getNode(), DataForm.from(mamQueryIq));
}
Also used : Message(org.jivesoftware.smack.packet.Message) IQReplyFilter(org.jivesoftware.smack.filter.IQReplyFilter) ArrayList(java.util.ArrayList) XMPPConnection(org.jivesoftware.smack.XMPPConnection) MamElements(org.jivesoftware.smackx.mam.element.MamElements) MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) MamResultFilter(org.jivesoftware.smackx.mam.filter.MamResultFilter) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Aggregations

MamFinIQ (org.jivesoftware.smackx.mam.element.MamFinIQ)4 RSMSet (org.jivesoftware.smackx.rsm.packet.RSMSet)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 StanzaCollector (org.jivesoftware.smack.StanzaCollector)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 IQReplyFilter (org.jivesoftware.smack.filter.IQReplyFilter)1 IQ (org.jivesoftware.smack.packet.IQ)1 Message (org.jivesoftware.smack.packet.Message)1 Forwarded (org.jivesoftware.smackx.forward.packet.Forwarded)1 MamElements (org.jivesoftware.smackx.mam.element.MamElements)1 MamResultFilter (org.jivesoftware.smackx.mam.filter.MamResultFilter)1 MamFinIQProvider (org.jivesoftware.smackx.mam.provider.MamFinIQProvider)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1