use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class AbstractDelayInformationProvider method parse.
@Override
public final DelayInformation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, ParseException {
String stampString = parser.getAttributeValue("", "stamp");
String from = parser.getAttributeValue("", "from");
final String reason;
XmlPullParser.Event event = parser.next();
switch(event) {
case TEXT_CHARACTERS:
reason = parser.getText();
parser.next();
break;
case END_ELEMENT:
reason = null;
break;
default:
// TODO: Should be SmackParseException.
throw new IOException("Unexpected event: " + event);
}
Date stamp = parseDate(stampString);
return new DelayInformation(stamp, from, reason);
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class OpenIQProviderTest method shouldCorrectlyParseIQStanzaAttribute.
@Test
public void shouldCorrectlyParseIQStanzaAttribute() throws Exception {
String control = XMLBuilder.create("open").a("xmlns", "http://jabber.org/protocol/ibb").a("block-size", "4096").a("sid", "i781hf64").a("stanza", "iq").asString(outputProperties);
OpenIQProvider oip = new OpenIQProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(control);
Open open = oip.parse(parser);
assertEquals(StanzaType.IQ, open.getStanza());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class OpenIQProviderTest method shouldCorrectlyParseMessageStanzaAttribute.
@Test
public void shouldCorrectlyParseMessageStanzaAttribute() throws Exception {
String control = XMLBuilder.create("open").a("xmlns", "http://jabber.org/protocol/ibb").a("block-size", "4096").a("sid", "i781hf64").a("stanza", "message").asString(outputProperties);
OpenIQProvider oip = new OpenIQProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(control);
Open open = oip.parse(parser);
assertEquals(StanzaType.MESSAGE, open.getStanza());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class MoodConcretisationTest method concretisationTest.
@Test
public void concretisationTest() throws Exception {
ProviderManager.addExtensionProvider(EcstaticMoodConcretisation.ELEMENT, EcstaticMoodConcretisation.NAMESPACE, EcstaticMoodConcretisationProvider.INSTANCE);
String xml = "<mood xmlns='http://jabber.org/protocol/mood'>" + "<happy>" + "<ecstatic xmlns='https://example.org/'/>" + "</happy>" + "<text>Yay, the mood spec has been approved!</text>" + "</mood>";
MoodElement element = new MoodElement(new MoodElement.MoodSubjectElement(Mood.happy, new EcstaticMoodConcretisation()), "Yay, the mood spec has been approved!");
assertXmlSimilar(xml, element.toXML().toString());
XmlPullParser parser = TestUtils.getParser(xml);
MoodElement parsed = MoodProvider.INSTANCE.parse(parser);
assertXmlSimilar(xml, parsed.toXML().toString());
assertTrue(parsed.hasConcretisation());
assertTrue(parsed.hasText());
assertEquals(EcstaticMoodConcretisation.ELEMENT, parsed.getMoodConcretisation().getMood());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class DelayInformationTest method delayInformationTest.
@Test
public void delayInformationTest() throws Exception {
DelayInformationProvider p = new DelayInformationProvider();
DelayInformation delayInfo;
XmlPullParser parser;
String control;
GregorianCalendar calendar = new GregorianCalendar(2002, 9 - 1, 10, 23, 8, 25);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = calendar.getTime();
control = XMLBuilder.create("x").a("xmlns", "jabber:x:delay").a("from", "capulet.com").a("stamp", "2002-09-10T23:08:25Z").t("Offline Storage").asString(outputProperties);
parser = PacketParserUtils.getParserFor(control);
delayInfo = p.parse(parser);
assertEquals("capulet.com", delayInfo.getFrom());
assertEquals(date, delayInfo.getStamp());
assertEquals("Offline Storage", delayInfo.getReason());
assertEquals(XmlPullParser.Event.END_ELEMENT, parser.getEventType());
assertEquals("x", parser.getName());
control = XMLBuilder.create("x").a("xmlns", "jabber:x:delay").a("from", "capulet.com").a("stamp", "2002-09-10T23:08:25Z").asString(outputProperties);
parser = PacketParserUtils.getParserFor(control);
delayInfo = p.parse(parser);
assertEquals("capulet.com", delayInfo.getFrom());
assertEquals(date, delayInfo.getStamp());
assertNull(delayInfo.getReason());
assertEquals(XmlPullParser.Event.END_ELEMENT, parser.getEventType());
assertEquals("x", parser.getName());
}
Aggregations