Search in sources :

Example 41 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class MUCOwnerProvider method parse.

@Override
public MUCOwner parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
    MUCOwner mucOwner = new MUCOwner();
    boolean done = false;
    while (!done) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT) {
            if (parser.getName().equals("item")) {
                mucOwner.addItem(MUCParserUtils.parseItem(parser));
            } else if (parser.getName().equals("destroy")) {
                mucOwner.setDestroy(MUCParserUtils.parseDestroy(parser));
            } else // Otherwise, it must be a packet extension.
            {
                PacketParserUtils.addExtensionElement(mucOwner, parser, xmlEnvironment);
            }
        } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    return mucOwner;
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) MUCOwner(org.jivesoftware.smackx.muc.packet.MUCOwner)

Example 42 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class MUCAdminProvider method parse.

@Override
public MUCAdmin parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
    MUCAdmin mucAdmin = new MUCAdmin();
    boolean done = false;
    while (!done) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT) {
            if (parser.getName().equals("item")) {
                mucAdmin.addItem(MUCParserUtils.parseItem(parser));
            }
        } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    return mucAdmin;
}
Also used : MUCAdmin(org.jivesoftware.smackx.muc.packet.MUCAdmin) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser)

Example 43 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class SubscriptionProvider method parse.

@Override
public Subscription parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
    Jid jid = ParserUtils.getJidAttribute(parser);
    String nodeId = parser.getAttributeValue(null, "node");
    String subId = parser.getAttributeValue(null, "subid");
    String state = parser.getAttributeValue(null, "subscription");
    boolean isRequired = false;
    XmlPullParser.Event tag = parser.next();
    if ((tag == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals("subscribe-options")) {
        tag = parser.next();
        if ((tag == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals("required"))
            isRequired = true;
        while (tag != XmlPullParser.Event.END_ELEMENT && !parser.getName().equals("subscribe-options")) tag = parser.next();
    }
    while (parser.getEventType() != XmlPullParser.Event.END_ELEMENT) parser.next();
    return new Subscription(jid, nodeId, subId, state == null ? null : Subscription.State.valueOf(state), isRequired);
}
Also used : Jid(org.jxmpp.jid.Jid) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Subscription(org.jivesoftware.smackx.pubsub.Subscription)

Example 44 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class ForwardedTest method forwardedWithDelayTest.

@Test
public void forwardedWithDelayTest() throws Exception {
    XmlPullParser parser;
    String control;
    Forwarded<?> fwd;
    // @formatter:off
    control = XMLBuilder.create("forwarded").a("xmlns", "urn:xmpp:forwarded:0").e("message").a("from", "romeo@montague.com").up().e("delay").ns(DelayInformation.NAMESPACE).a("stamp", "2010-07-10T23:08:25Z").asString(outputProperties);
    // @formatter:on
    parser = PacketParserUtils.getParserFor(control);
    fwd = new ForwardedProvider().parse(parser);
    // assert there is delay information in packet
    DelayInformation delay = fwd.getDelayInformation();
    assertNotNull(delay);
    // check message
    assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedStanza().getFrom()));
    // check end of tag
    assertEquals(XmlPullParser.Event.END_ELEMENT, parser.getEventType());
    assertEquals("forwarded", parser.getName());
}
Also used : DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) ForwardedProvider(org.jivesoftware.smackx.forward.provider.ForwardedProvider) Test(org.junit.jupiter.api.Test)

Example 45 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class ForwardedTest method forwardedEmptyTest.

@Test
public void forwardedEmptyTest() throws Exception {
    XmlPullParser parser;
    String control;
    control = XMLBuilder.create("forwarded").a("xmlns", "urn:xmpp:forwarded:0").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    assertThrows(Exception.class, () -> {
        new ForwardedProvider().parse(parser);
    });
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) ForwardedProvider(org.jivesoftware.smackx.forward.provider.ForwardedProvider) Test(org.junit.jupiter.api.Test)

Aggregations

XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)139 Test (org.junit.jupiter.api.Test)69 Message (org.jivesoftware.smack.packet.Message)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Date (java.util.Date)12 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)11 Jid (org.jxmpp.jid.Jid)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 XmlPullParserException (org.jivesoftware.smack.xml.XmlPullParserException)10 EnumSource (org.junit.jupiter.params.provider.EnumSource)9 IQ (org.jivesoftware.smack.packet.IQ)8 Test (org.junit.Test)8 MarkupElement (org.jivesoftware.smackx.message_markup.element.MarkupElement)7 MarkupElementProvider (org.jivesoftware.smackx.message_markup.provider.MarkupElementProvider)7 XmlElement (org.jivesoftware.smack.packet.XmlElement)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 NamedElement (org.jivesoftware.smack.packet.NamedElement)4 HttpOverXmppResp (org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp)4