Search in sources :

Example 1 with MUCRole

use of org.jivesoftware.smackx.muc.MUCRole in project Smack by igniterealtime.

the class MUCParserUtils method parseItem.

public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
    int initialDepth = parser.getDepth();
    MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
    Resourcepart nick = ParserUtils.getResourcepartAttribute(parser, "nick");
    MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role"));
    Jid jid = ParserUtils.getJidAttribute(parser);
    Jid actor = null;
    Resourcepart actorNick = null;
    String reason = null;
    outerloop: while (true) {
        int eventType = parser.next();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                String name = parser.getName();
                switch(name) {
                    case "actor":
                        actor = ParserUtils.getJidAttribute(parser);
                        // TODO change to
                        // actorNick = Resourcepart.from(parser.getAttributeValue("", "nick"));
                        // once a newer version of JXMPP is used that supports from(null).
                        String actorNickString = parser.getAttributeValue("", "nick");
                        if (actorNickString != null) {
                            actorNick = Resourcepart.from(actorNickString);
                        }
                        break;
                    case "reason":
                        reason = parser.nextText();
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new MUCItem(affiliation, role, actor, reason, jid, nick, actorNick);
}
Also used : MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) MUCAffiliation(org.jivesoftware.smackx.muc.MUCAffiliation) MUCRole(org.jivesoftware.smackx.muc.MUCRole) Jid(org.jxmpp.jid.Jid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Aggregations

MUCAffiliation (org.jivesoftware.smackx.muc.MUCAffiliation)1 MUCRole (org.jivesoftware.smackx.muc.MUCRole)1 MUCItem (org.jivesoftware.smackx.muc.packet.MUCItem)1 EntityBareJid (org.jxmpp.jid.EntityBareJid)1 Jid (org.jxmpp.jid.Jid)1 Resourcepart (org.jxmpp.jid.parts.Resourcepart)1