Search in sources :

Example 1 with Reason

use of org.jivesoftware.smackx.jingle.element.JingleReason.Reason 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;
}
Also used : Reason(org.jivesoftware.smackx.jingle.element.JingleReason.Reason) JingleReason(org.jivesoftware.smackx.jingle.element.JingleReason) XmlElement(org.jivesoftware.smack.packet.XmlElement)

Aggregations

XmlElement (org.jivesoftware.smack.packet.XmlElement)1 JingleReason (org.jivesoftware.smackx.jingle.element.JingleReason)1 Reason (org.jivesoftware.smackx.jingle.element.JingleReason.Reason)1