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;
}
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;
}
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);
}
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());
}
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);
});
}
Aggregations