Search in sources :

Example 26 with XmlElement

use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.

the class ItemValidationTest method parseEmptyTag.

@Test
public void parseEmptyTag() throws Exception {
    String itemContent = "<foo xmlns='smack:test'><bar/></foo>";
    XmlPullParser parser = PacketParserUtils.getParserFor("<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" + "<event xmlns='http://jabber.org/protocol/pubsub#event'>" + "<items node='testNode'>" + "<item id='testid1' >" + itemContent + "</item>" + "</items>" + "</event>" + "</message>");
    Stanza message = PacketParserUtils.parseMessage(parser);
    XmlElement eventExt = message.getExtension(PubSubNamespace.event.getXmlns());
    assertTrue(eventExt instanceof EventElement);
    EventElement event = (EventElement) eventExt;
    assertEquals(EventElementType.items, event.getEventType());
    assertEquals(1, event.getExtensions().size());
    assertTrue(event.getExtensions().get(0) instanceof ItemsExtension);
    assertEquals(1, ((ItemsExtension) event.getExtensions().get(0)).items.size());
    NamedElement itemExt = ((ItemsExtension) event.getExtensions().get(0)).items.get(0);
    assertTrue(itemExt instanceof PayloadItem<?>);
    PayloadItem<?> item = (PayloadItem<?>) itemExt;
    assertEquals("testid1", item.getId());
    assertTrue(item.getPayload() instanceof SimplePayload);
    assertXmlSimilar(itemContent, item.getPayload().toXML().toString());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) XmlElement(org.jivesoftware.smack.packet.XmlElement) NamedElement(org.jivesoftware.smack.packet.NamedElement) Test(org.junit.jupiter.api.Test)

Example 27 with XmlElement

use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.

the class Node method getAffiliations.

private List<Affiliation> getAffiliations(AffiliationNamespace affiliationsNamespace, List<XmlElement> additionalExtensions, Collection<XmlElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSubElementType pubSubElementType = affiliationsNamespace.type;
    PubSub pubSub = createPubsubPacket(IQ.Type.get, new NodeExtension(pubSubElementType, getId()));
    if (additionalExtensions != null) {
        for (XmlElement pe : additionalExtensions) {
            pubSub.addExtension(pe);
        }
    }
    PubSub reply = sendPubsubPacket(pubSub);
    if (returnedExtensions != null) {
        returnedExtensions.addAll(reply.getExtensions());
    }
    AffiliationsExtension affilElem = reply.getExtension(pubSubElementType);
    return affilElem.getAffiliations();
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) XmlElement(org.jivesoftware.smack.packet.XmlElement)

Example 28 with XmlElement

use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.

the class OpenPgpContentElement method getExtension.

/**
 * Returns the first extension that matches the specified element name and
 * namespace, or <code>null</code> if it doesn't exist. If the provided elementName is null,
 * only the namespace is matched. Extensions are
 * are arbitrary XML elements in standard XMPP stanzas.
 *
 * @param elementName the XML element name of the extension. (May be null)
 * @param namespace the XML element namespace of the extension.
 * @param <PE> type of the ExtensionElement.
 * @return the extension, or <code>null</code> if it doesn't exist.
 */
@SuppressWarnings("unchecked")
public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
    if (namespace == null) {
        return null;
    }
    QName key = new QName(namespace, elementName);
    XmlElement packetExtension;
    synchronized (payload) {
        packetExtension = payload.getFirst(key);
    }
    if (packetExtension == null) {
        return null;
    }
    return (PE) packetExtension;
}
Also used : QName(javax.xml.namespace.QName) XmlElement(org.jivesoftware.smack.packet.XmlElement)

Aggregations

XmlElement (org.jivesoftware.smack.packet.XmlElement)28 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)6 Test (org.junit.jupiter.api.Test)5 NamedElement (org.jivesoftware.smack.packet.NamedElement)4 Stanza (org.jivesoftware.smack.packet.Stanza)4 XmlEnvironment (org.jivesoftware.smack.packet.XmlEnvironment)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 QName (javax.xml.namespace.QName)2 Message (org.jivesoftware.smack.packet.Message)2 MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)2 JingleReason (org.jivesoftware.smackx.jingle.element.JingleReason)2 PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)1 Mechanisms (org.jivesoftware.smack.packet.Mechanisms)1