Search in sources :

Example 1 with Affiliation

use of org.jivesoftware.smackx.pubsub.Affiliation in project Smack by igniterealtime.

the class AffiliationProvider method parse.

@Override
public Affiliation parse(XmlPullParser parser, int initialDepth) throws Exception {
    String node = parser.getAttributeValue(null, "node");
    BareJid jid = ParserUtils.getBareJidAttribute(parser);
    String affiliationString = parser.getAttributeValue(null, "affiliation");
    Affiliation.Type affiliationType = null;
    if (affiliationString != null) {
        affiliationType = Affiliation.Type.valueOf(affiliationString);
    }
    Affiliation affiliation;
    if (node != null && jid == null) {
        // affiliationType may be empty
        affiliation = new Affiliation(node, affiliationType);
    } else if (node == null && jid != null) {
        // TODO
        PubSubNamespace namespace = null;
        affiliation = new Affiliation(jid, affiliationType, namespace);
    } else {
        throw new SmackException("Invalid affililation. Either one of 'node' or 'jid' must be set" + ". Node: " + node + ". Jid: " + jid + '.');
    }
    return affiliation;
}
Also used : BareJid(org.jxmpp.jid.BareJid) SmackException(org.jivesoftware.smack.SmackException) Affiliation(org.jivesoftware.smackx.pubsub.Affiliation) PubSubNamespace(org.jivesoftware.smackx.pubsub.packet.PubSubNamespace)

Example 2 with Affiliation

use of org.jivesoftware.smackx.pubsub.Affiliation in project Smack by igniterealtime.

the class AffiliationProvider method parse.

@Override
public Affiliation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws IOException {
    String node = parser.getAttributeValue(null, "node");
    BareJid jid = ParserUtils.getBareJidAttribute(parser);
    String namespaceString = parser.getNamespace();
    AffiliationNamespace namespace = AffiliationNamespace.fromXmlns(namespaceString);
    String affiliationString = parser.getAttributeValue(null, "affiliation");
    Affiliation.Type affiliationType = null;
    if (affiliationString != null) {
        affiliationType = Affiliation.Type.valueOf(affiliationString);
    }
    Affiliation affiliation;
    if (node != null && jid == null) {
        // affiliationType may be empty
        affiliation = new Affiliation(node, affiliationType, namespace);
    } else if (node == null && jid != null) {
        affiliation = new Affiliation(jid, affiliationType, namespace);
    } else {
        // TODO: Should be SmackParsingException.
        throw new IOException("Invalid affililation. Either one of 'node' or 'jid' must be set" + ". Node: " + node + ". Jid: " + jid + '.');
    }
    return affiliation;
}
Also used : BareJid(org.jxmpp.jid.BareJid) AffiliationNamespace(org.jivesoftware.smackx.pubsub.Affiliation.AffiliationNamespace) IOException(java.io.IOException) Affiliation(org.jivesoftware.smackx.pubsub.Affiliation)

Aggregations

Affiliation (org.jivesoftware.smackx.pubsub.Affiliation)2 BareJid (org.jxmpp.jid.BareJid)2 IOException (java.io.IOException)1 SmackException (org.jivesoftware.smack.SmackException)1 AffiliationNamespace (org.jivesoftware.smackx.pubsub.Affiliation.AffiliationNamespace)1 PubSubNamespace (org.jivesoftware.smackx.pubsub.packet.PubSubNamespace)1