Search in sources :

Example 36 with XmlPullParser

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

the class HttpOverXmppReqProviderTest method parseReq.

private static HttpOverXmppReq parseReq(String string) throws Exception {
    HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(string);
    IQ iq = provider.parse(parser);
    assertTrue(iq instanceof HttpOverXmppReq);
    return (HttpOverXmppReq) iq;
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) IQ(org.jivesoftware.smack.packet.IQ) HttpOverXmppReq(org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq)

Example 37 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser 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);
    assertFalse(mamFinIQ.isComplete());
    assertTrue(mamFinIQ.isStable());
    assertNull(mamFinIQ.getQueryId());
    RSMSet rsmSet = mamFinIQ.getRSMSet();
    assertEquals(rsmSet.getAfter(), "09af3-cc343-b409f");
    assertEquals(rsmSet.getMax(), 10);
}
Also used : MamFinIQProvider(org.jivesoftware.smackx.mam.provider.MamFinIQProvider) RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ) Test(org.junit.jupiter.api.Test)

Example 38 with XmlPullParser

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

the class AMPExtensionProvider method parse.

/**
 * Parses a AMPExtension stanza (extension sub-packet).
 *
 * @param parser the XML parser, positioned at the starting element of the extension.
 * @return a PacketExtension.
 * @throws IOException if an I/O error occurred.
 * @throws XmlPullParserException if an error in the XML parser occurred.
 */
@Override
public AMPExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
    final String from = parser.getAttributeValue(null, "from");
    final String to = parser.getAttributeValue(null, "to");
    final String statusString = parser.getAttributeValue(null, "status");
    AMPExtension.Status status = null;
    if (statusString != null) {
        try {
            status = AMPExtension.Status.valueOf(statusString);
        } catch (IllegalArgumentException ex) {
            LOGGER.severe("Found invalid amp status " + statusString);
        }
    }
    AMPExtension ampExtension = new AMPExtension(from, to, status);
    String perHopValue = parser.getAttributeValue(null, "per-hop");
    if (perHopValue != null) {
        boolean perHop = Boolean.parseBoolean(perHopValue);
        ampExtension.setPerHop(perHop);
    }
    boolean done = false;
    while (!done) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT) {
            if (parser.getName().equals(AMPExtension.Rule.ELEMENT)) {
                String actionString = parser.getAttributeValue(null, AMPExtension.Action.ATTRIBUTE_NAME);
                String conditionName = parser.getAttributeValue(null, AMPExtension.Condition.ATTRIBUTE_NAME);
                String conditionValue = parser.getAttributeValue(null, "value");
                AMPExtension.Condition condition = createCondition(conditionName, conditionValue);
                AMPExtension.Action action = null;
                if (actionString != null) {
                    try {
                        action = AMPExtension.Action.valueOf(actionString);
                    } catch (IllegalArgumentException ex) {
                        LOGGER.severe("Found invalid rule action value " + actionString);
                    }
                }
                if (action == null || condition == null) {
                    LOGGER.severe("Rule is skipped because either it's action or it's condition is invalid");
                } else {
                    AMPExtension.Rule rule = new AMPExtension.Rule(action, condition);
                    ampExtension.addRule(rule);
                }
            }
        } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
            if (parser.getName().equals(AMPExtension.ELEMENT)) {
                done = true;
            }
        }
    }
    return ampExtension;
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) AMPExtension(org.jivesoftware.smackx.amp.packet.AMPExtension)

Example 39 with XmlPullParser

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

the class Bookmarks method getConferenceStorage.

private static BookmarkedConference getConferenceStorage(XmlPullParser parser) throws XmlPullParserException, IOException {
    String name = parser.getAttributeValue("", "name");
    boolean autojoin = ParserUtils.getBooleanAttribute(parser, "autojoin", false);
    EntityBareJid jid = ParserUtils.getBareJidAttribute(parser);
    BookmarkedConference conf = new BookmarkedConference(jid);
    conf.setName(name);
    conf.setAutoJoin(autojoin);
    // Check for nickname
    boolean done = false;
    while (!done) {
        XmlPullParser.Event eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT && "nick".equals(parser.getName())) {
            String nickString = parser.nextText();
            conf.setNickname(Resourcepart.from(nickString));
        } else if (eventType == XmlPullParser.Event.START_ELEMENT && "password".equals(parser.getName())) {
            conf.setPassword(parser.nextText());
        } else if (eventType == XmlPullParser.Event.START_ELEMENT && "shared_bookmark".equals(parser.getName())) {
            conf.setShared(true);
        } else if (eventType == XmlPullParser.Event.END_ELEMENT && "conference".equals(parser.getName())) {
            done = true;
        }
    }
    return conf;
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 40 with XmlPullParser

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

the class BytestreamsProvider method parse.

@Override
public Bytestream parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
    boolean done = false;
    Bytestream toReturn = new Bytestream();
    String id = parser.getAttributeValue("", "sid");
    String mode = parser.getAttributeValue("", "mode");
    // streamhost
    Jid JID = null;
    String host = null;
    String port = null;
    XmlPullParser.Event eventType;
    String elementName;
    while (!done) {
        eventType = parser.next();
        if (eventType == XmlPullParser.Event.START_ELEMENT) {
            elementName = parser.getName();
            if (elementName.equals(Bytestream.StreamHost.ELEMENT)) {
                JID = ParserUtils.getJidAttribute(parser);
                host = parser.getAttributeValue("", "host");
                port = parser.getAttributeValue("", "port");
            } else if (elementName.equals(Bytestream.StreamHostUsed.ELEMENT)) {
                toReturn.setUsedHost(ParserUtils.getJidAttribute(parser));
            } else if (elementName.equals(Bytestream.Activate.ELEMENT)) {
                toReturn.setToActivate(ParserUtils.getJidAttribute(parser));
            }
        } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
            elementName = parser.getName();
            if (elementName.equals("streamhost")) {
                if (port == null) {
                    toReturn.addStreamHost(JID, host);
                } else {
                    toReturn.addStreamHost(JID, host, Integer.parseInt(port));
                }
                JID = null;
                host = null;
                port = null;
            } else if (elementName.equals("query")) {
                done = true;
            }
        }
    }
    if (mode == null) {
        toReturn.setMode(Mode.tcp);
    } else {
        toReturn.setMode(Bytestream.Mode.fromName(mode));
    }
    toReturn.setSessionID(id);
    return toReturn;
}
Also used : Bytestream(org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream) Jid(org.jxmpp.jid.Jid) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser)

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