Search in sources :

Example 1 with ItemNamespace

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

the class ItemProvider method parse.

@Override
public Item parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
    String id = parser.getAttributeValue(null, "id");
    String node = parser.getAttributeValue(null, "node");
    String xmlns = parser.getNamespace();
    ItemNamespace itemNamespace = ItemNamespace.fromXmlns(xmlns);
    XmlPullParser.TagEvent event = parser.nextTag();
    switch(event) {
        case START_ELEMENT:
            String payloadElemName = parser.getName();
            String payloadNS = parser.getNamespace();
            final ExtensionElementProvider<ExtensionElement> extensionProvider = ProviderManager.getExtensionProvider(payloadElemName, payloadNS);
            if (extensionProvider == null) {
                // TODO: Should we use StandardExtensionElement in this case? And probably remove SimplePayload all together.
                CharSequence payloadText = PacketParserUtils.parseElement(parser, true);
                return new PayloadItem<>(itemNamespace, id, node, new SimplePayload(payloadText.toString()));
            } else {
                return new PayloadItem<>(itemNamespace, id, node, extensionProvider.parse(parser));
            }
        case END_ELEMENT:
            return new Item(itemNamespace, id, node);
        default:
            throw new AssertionError("unknown: " + event);
    }
}
Also used : PayloadItem(org.jivesoftware.smackx.pubsub.PayloadItem) PayloadItem(org.jivesoftware.smackx.pubsub.PayloadItem) Item(org.jivesoftware.smackx.pubsub.Item) ItemNamespace(org.jivesoftware.smackx.pubsub.Item.ItemNamespace) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) SimplePayload(org.jivesoftware.smackx.pubsub.SimplePayload)

Aggregations

ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)1 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1 Item (org.jivesoftware.smackx.pubsub.Item)1 ItemNamespace (org.jivesoftware.smackx.pubsub.Item.ItemNamespace)1 PayloadItem (org.jivesoftware.smackx.pubsub.PayloadItem)1 SimplePayload (org.jivesoftware.smackx.pubsub.SimplePayload)1