use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class MessageEventProvider method parse.
/**
* Parses a MessageEvent 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 MessageEvent parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
MessageEvent messageEvent = new MessageEvent();
boolean done = false;
while (!done) {
XmlPullParser.Event eventType = parser.next();
if (eventType == XmlPullParser.Event.START_ELEMENT) {
if (parser.getName().equals("id"))
messageEvent.setStanzaId(parser.nextText());
if (parser.getName().equals(MessageEvent.COMPOSING))
messageEvent.setComposing(true);
if (parser.getName().equals(MessageEvent.DELIVERED))
messageEvent.setDelivered(true);
if (parser.getName().equals(MessageEvent.DISPLAYED))
messageEvent.setDisplayed(true);
if (parser.getName().equals(MessageEvent.OFFLINE))
messageEvent.setOffline(true);
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
if (parser.getName().equals("x")) {
done = true;
}
}
}
return messageEvent;
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class OfferRevokeProvider method parse.
@Override
public OfferRevokePacket parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
// The parser will be positioned on the opening IQ tag, so get the JID attribute.
Jid userJID = ParserUtils.getJidAttribute(parser);
// Default the userID to the JID.
Jid userID = userJID;
String reason = null;
String sessionID = null;
boolean done = false;
while (!done) {
XmlPullParser.Event eventType = parser.next();
if ((eventType == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals("reason")) {
reason = parser.nextText();
} else if ((eventType == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals(SessionID.ELEMENT_NAME)) {
sessionID = parser.getAttributeValue("", "id");
} else if ((eventType == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals(UserID.ELEMENT_NAME)) {
userID = ParserUtils.getJidAttribute(parser, "id");
} else if ((eventType == XmlPullParser.Event.END_ELEMENT) && parser.getName().equals("offer-revoke")) {
done = true;
}
}
return new OfferRevokePacket(userJID, userID, reason, sessionID);
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class OmemoDeviceListVAxolotlElementTest method serializationTest.
@Test
public void serializationTest() throws Exception {
HashSet<Integer> ids = new HashSet<>();
ids.add(1234);
ids.add(9876);
OmemoDeviceListElement_VAxolotl element = new OmemoDeviceListElement_VAxolotl(ids);
String xml = element.toXML().toString();
XmlPullParser parser = TestUtils.getParser(xml);
OmemoDeviceListElement_VAxolotl parsed = new OmemoDeviceListVAxolotlProvider().parse(parser);
assertTrue("Parsed element must equal the original.", parsed.getDeviceIds().equals(element.getDeviceIds()));
assertEquals("Generated XML must match.", "<list xmlns='eu.siacs.conversations.axolotl'>" + "<device id='1234'/>" + "<device id='9876'/>" + "</list>", xml);
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class OmemoBundleVAxolotlElementTest method emptyPreKeysShouldFailTest.
@Test(expected = IllegalArgumentException.class)
public void emptyPreKeysShouldFailTest() throws Exception {
String s = "<bundle xmlns='eu.siacs.conversations.axolotl'><signedPreKeyPublic signedPreKeyId='1'>BU4bJ18+rqbSnBblZU8pR/s+impyhoL9AJssJIE59fZb</signedPreKeyPublic><signedPreKeySignature>MaQtv7ySqHpPr0gkVtMp4KmWC61Hnfs5a7/cKEhrX8n12evGdkg4fNf3Q/ufgmJu5dnup9pkTA1pj00dTbtXjw==</signedPreKeySignature><identityKey>BWO0QOem1YXIJuT61cxXpG/mKlvISDwZxQJHW2/7eVki</identityKey><prekeys></prekeys></bundle>";
XmlPullParser parser = TestUtils.getParser(s);
new OmemoBundleVAxolotlProvider().parse(parser);
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class PubkeyElementTest method providerTest.
@SuppressWarnings("UndefinedEquals")
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void providerTest(SmackTestUtil.XmlPullParserKind parserKind) throws ParseException, XmlPullParserException, IOException, SmackParsingException {
String base64EncodedOpenPgpPublicKey = "VGhpcyBpcyBqdXN0IGEgdGVzdA==";
String pubkeyElement = "<pubkey xmlns='urn:xmpp:openpgp:0' date='2018-01-21T10:46:21.000+00:00'>" + "<data>" + base64EncodedOpenPgpPublicKey + "</data>" + "</pubkey>";
Date date = XmppDateTime.parseXEP0082Date("2018-01-21T10:46:21.000+00:00");
PubkeyElement element = new PubkeyElement(new PubkeyElement.PubkeyDataElement(base64EncodedOpenPgpPublicKey), date);
assertXmlSimilar(pubkeyElement, element.toXML().toString());
XmlPullParser parser = SmackTestUtil.getParserFor(pubkeyElement, parserKind);
PubkeyElement parsed = PubkeyElementProvider.INSTANCE.parse(parser);
assertEquals(element.getDate(), parsed.getDate());
assertEquals(element.getDataElement().getB64Data(), parsed.getDataElement().getB64Data());
}
Aggregations