Search in sources :

Example 1 with DefaultBehavior

use of org.jivesoftware.smackx.mam.element.MamPrefsIQ.DefaultBehavior in project Smack by igniterealtime.

the class MamPrefsIQProvider method parse.

@Override
public MamPrefsIQ parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
    String iqType = parser.getAttributeValue("", "type");
    String defaultBehaviorString = parser.getAttributeValue("", "default");
    DefaultBehavior defaultBehavior = null;
    if (defaultBehaviorString != null) {
        defaultBehavior = DefaultBehavior.valueOf(defaultBehaviorString);
    }
    if (iqType == null) {
        iqType = "result";
    }
    List<Jid> alwaysJids = null;
    List<Jid> neverJids = null;
    outerloop: while (true) {
        final int eventType = parser.next();
        final String name = parser.getName();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                switch(name) {
                    case "always":
                        alwaysJids = iterateJids(parser);
                        break;
                    case "never":
                        neverJids = iterateJids(parser);
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new MamPrefsIQ(alwaysJids, neverJids, defaultBehavior);
}
Also used : MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ) Jid(org.jxmpp.jid.Jid) DefaultBehavior(org.jivesoftware.smackx.mam.element.MamPrefsIQ.DefaultBehavior)

Example 2 with DefaultBehavior

use of org.jivesoftware.smackx.mam.element.MamPrefsIQ.DefaultBehavior in project Smack by igniterealtime.

the class MamPrefsIQProvider method parse.

@Override
public MamPrefsIQ parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
    MamElementFactory elementFactory = MamElementFactory.forParser(parser);
    String defaultBehaviorString = parser.getAttributeValue("", "default");
    DefaultBehavior defaultBehavior = null;
    if (defaultBehaviorString != null) {
        defaultBehavior = DefaultBehavior.valueOf(defaultBehaviorString);
    }
    List<Jid> alwaysJids = null;
    List<Jid> neverJids = null;
    outerloop: while (true) {
        final XmlPullParser.Event eventType = parser.next();
        switch(eventType) {
            case START_ELEMENT:
                final String name = parser.getName();
                switch(name) {
                    case "always":
                        alwaysJids = iterateJids(parser);
                        break;
                    case "never":
                        neverJids = iterateJids(parser);
                        break;
                }
                break;
            case END_ELEMENT:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
            default:
                // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
                break;
        }
    }
    return elementFactory.newPrefsIQ(alwaysJids, neverJids, defaultBehavior);
}
Also used : Jid(org.jxmpp.jid.Jid) DefaultBehavior(org.jivesoftware.smackx.mam.element.MamPrefsIQ.DefaultBehavior) MamElementFactory(org.jivesoftware.smackx.mam.element.MamElementFactory)

Aggregations

DefaultBehavior (org.jivesoftware.smackx.mam.element.MamPrefsIQ.DefaultBehavior)2 Jid (org.jxmpp.jid.Jid)2 MamElementFactory (org.jivesoftware.smackx.mam.element.MamElementFactory)1 MamPrefsIQ (org.jivesoftware.smackx.mam.element.MamPrefsIQ)1