use of org.jivesoftware.smackx.jingle.element.JingleContentDescription in project Smack by igniterealtime.
the class JingleProvider method parseJingleContent.
public static JingleContent parseJingleContent(XmlPullParser parser, final int initialDepth) throws XmlPullParserException, IOException, SmackParsingException {
JingleContent.Builder builder = JingleContent.getBuilder();
String creatorString = parser.getAttributeValue("", JingleContent.CREATOR_ATTRIBUTE_NAME);
JingleContent.Creator creator = JingleContent.Creator.valueOf(creatorString);
builder.setCreator(creator);
String disposition = parser.getAttributeValue("", JingleContent.DISPOSITION_ATTRIBUTE_NAME);
builder.setDisposition(disposition);
String name = parser.getAttributeValue("", JingleContent.NAME_ATTRIBUTE_NAME);
builder.setName(name);
String sendersString = parser.getAttributeValue("", JingleContent.SENDERS_ATTRIBUTE_NAME);
if (sendersString != null) {
JingleContent.Senders senders = JingleContent.Senders.valueOf(sendersString);
builder.setSenders(senders);
}
outerloop: while (true) {
XmlPullParser.Event eventType = parser.next();
switch(eventType) {
case START_ELEMENT:
String tagName = parser.getName();
String namespace = parser.getNamespace();
switch(tagName) {
case JingleContentDescription.ELEMENT:
{
JingleContentDescription description;
JingleContentDescriptionProvider<?> provider = JingleContentProviderManager.getJingleContentDescriptionProvider(namespace);
if (provider == null) {
StandardExtensionElement standardExtensionElement = StandardExtensionElementProvider.INSTANCE.parse(parser);
description = new UnknownJingleContentDescription(standardExtensionElement);
} else {
description = provider.parse(parser);
}
builder.setDescription(description);
break;
}
case JingleContentTransport.ELEMENT:
{
JingleContentTransport transport;
JingleContentTransportProvider<?> provider = JingleContentProviderManager.getJingleContentTransportProvider(namespace);
if (provider == null) {
StandardExtensionElement standardExtensionElement = StandardExtensionElementProvider.INSTANCE.parse(parser);
transport = new UnknownJingleContentTransport(standardExtensionElement);
} else {
transport = provider.parse(parser);
}
builder.setTransport(transport);
break;
}
default:
LOGGER.severe("Unknown Jingle content 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.JingleContentDescription in project Smack by igniterealtime.
the class JingleProviderTest method testParseUnknownJingleContentDescrption.
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testParseUnknownJingleContentDescrption(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
final String unknownJingleContentDescriptionNamespace = "urn:xmpp:jingle:unknown-description:5";
final String unknownJingleContentDescription = // @formatter:off
"<description xmlns='" + unknownJingleContentDescriptionNamespace + "'>" + "<file>" + "<date>1969-07-21T02:56:15Z</date>" + "<desc>This is a test. If this were a real file...</desc>" + "<media-type>text/plain</media-type>" + "<name>test.txt</name>" + "<range/>" + "<size>6144</size>" + "<hash xmlns='urn:xmpp:hashes:2'" + " algo='sha-1'>w0mcJylzCn+AfvuGdqkty2+KP48=</hash>" + "</file>" + "</description>";
// @formatter:on
CharSequence xml = createTestJingle(unknownJingleContentDescription);
Jingle jingle = SmackTestUtil.parse(xml, JingleProvider.class, parserKind);
JingleContentDescription jingleContentDescription = jingle.getSoleContentOrThrow().getDescription();
String parsedUnknownJingleContentDescriptionNamespace = jingleContentDescription.getNamespace();
assertEquals(unknownJingleContentDescriptionNamespace, parsedUnknownJingleContentDescriptionNamespace);
}
Aggregations