use of org.jivesoftware.smackx.jingle.element.JingleReason in project Smack by igniterealtime.
the class JingleProvider method parse.
@Override
public Jingle parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
Jingle.Builder builder = Jingle.builder(iqData);
String actionString = parser.getAttributeValue("", Jingle.ACTION_ATTRIBUTE_NAME);
if (actionString != null) {
JingleAction action = JingleAction.fromString(actionString);
builder.setAction(action);
}
FullJid initiator = ParserUtils.getFullJidAttribute(parser, Jingle.INITIATOR_ATTRIBUTE_NAME);
builder.setInitiator(initiator);
FullJid responder = ParserUtils.getFullJidAttribute(parser, Jingle.RESPONDER_ATTRIBUTE_NAME);
builder.setResponder(responder);
String sessionId = parser.getAttributeValue("", Jingle.SESSION_ID_ATTRIBUTE_NAME);
builder.setSessionId(sessionId);
outerloop: while (true) {
XmlPullParser.Event eventType = parser.next();
switch(eventType) {
case START_ELEMENT:
String tagName = parser.getName();
switch(tagName) {
case JingleContent.ELEMENT:
JingleContent content = parseJingleContent(parser, parser.getDepth());
builder.addJingleContent(content);
break;
case JingleReason.ELEMENT:
JingleReason reason = parseJingleReason(parser);
builder.setReason(reason);
break;
default:
LOGGER.severe("Unknown Jingle element: " + tagName);
break;
}
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}
return builder.build();
}
use of org.jivesoftware.smackx.jingle.element.JingleReason in project Smack by igniterealtime.
the class JingleProviderTest method testReasonElementWithExtraElement.
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testReasonElementWithExtraElement(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
String xml = "<iq from='juliet@capulet.lit/balcony'" + " id='le71fa63'" + " to='romeo@montague.lit/orchard'" + " type='set'>" + "<jingle xmlns='urn:xmpp:jingle:1'" + " action='session-terminate'" + " sid='a73sjjvkla37jfea'>" + "<reason>" + "<success/>" + "<my-element xmlns='https://example.org' foo='bar'/>" + "</reason>" + "</jingle>" + "</iq>";
Jingle jingle = SmackTestUtil.parse(xml, JingleProvider.class, parserKind);
JingleReason jingleReason = jingle.getReason();
assertEquals(JingleReason.Reason.success, jingleReason.asEnum());
XmlElement element = jingleReason.getElement();
// TODO: Use JUnit 5.8's assertInstanceOf when possible
// assertInstanceOf(StandardExtesionElement.class, extraElement);
assertTrue(element instanceof StandardExtensionElement);
StandardExtensionElement extraElement = (StandardExtensionElement) element;
assertEquals("https://example.org", extraElement.getNamespace());
assertEquals("bar", extraElement.getAttributes().get("foo"));
}
use of org.jivesoftware.smackx.jingle.element.JingleReason in project Smack by igniterealtime.
the class JingleProvider method parseJingleReason.
public static JingleReason parseJingleReason(XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException {
ParserUtils.assertAtStartTag(parser);
final int initialDepth = parser.getDepth();
final String jingleNamespace = parser.getNamespace();
JingleReason.Reason reason = null;
XmlElement element = null;
String text = null;
// 'sid' is only set if the reason is 'alternative-session'.
String sid = null;
outerloop: while (true) {
XmlPullParser.TagEvent event = parser.nextTag();
switch(event) {
case START_ELEMENT:
String elementName = parser.getName();
String namespace = parser.getNamespace();
if (namespace.equals(jingleNamespace)) {
switch(elementName) {
case "text":
text = parser.nextText();
break;
case "alternative-session":
parser.next();
sid = parser.nextText();
break;
default:
reason = Reason.fromString(elementName);
break;
}
} else {
element = PacketParserUtils.parseExtensionElement(elementName, namespace, parser, null);
}
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
}
}
JingleReason res;
if (sid != null) {
res = new JingleReason.AlternativeSession(sid, text, element);
} else {
res = new JingleReason(reason, text, element);
}
return res;
}
Aggregations