Search in sources :

Example 1 with ExtensionElement

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

the class XHTMLExtensionProviderTest method parsesWell.

@Test
public void parsesWell() throws IOException, XmlPullParserException {
    XmlPullParser parser = PacketParserUtils.newXmppParser();
    parser.setInput(getClass().getResourceAsStream(XHTML_EXTENSION_SAMPLE_RESOURCE_NAME), "UTF-8");
    parser.next();
    XHTMLExtensionProvider provider = new XHTMLExtensionProvider();
    ExtensionElement extension = provider.parse(parser, parser.getDepth());
    assertThat(extension, instanceOf(XHTMLExtension.class));
    XHTMLExtension attachmentsInfo = (XHTMLExtension) extension;
    assertThat(sampleXhtml(), equalsCharSequence(attachmentsInfo.getBodies().get(0)));
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) XHTMLExtension(org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension) Test(org.junit.Test)

Example 2 with ExtensionElement

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

the class ItemValidationTest method parseSimplePayloadItem.

@Test
public void parseSimplePayloadItem() throws Exception {
    String itemContent = "<foo xmlns='smack:test'>Some text</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);
    ExtensionElement eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
    EventElement event = (EventElement) eventExt;
    ExtensionElement 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);
    SimplePayload payload = (SimplePayload) item.getPayload();
    assertEquals("foo", payload.getElementName());
    assertEquals("smack:test", payload.getNamespace());
    assertXMLEqual(itemContent, payload.toXML().toString());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) XmlPullParser(org.xmlpull.v1.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Test(org.junit.Test)

Example 3 with ExtensionElement

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

the class ItemValidationTest method parseBasicItem.

@Test
public void parseBasicItem() throws Exception {
    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' />" + "</items>" + "</event>" + "</message>");
    Stanza message = PacketParserUtils.parseMessage(parser);
    ExtensionElement 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());
    ExtensionElement itemExt = ((ItemsExtension) event.getExtensions().get(0)).items.get(0);
    assertTrue(itemExt instanceof Item);
    assertEquals("testid1", ((Item) itemExt).getId());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) XmlPullParser(org.xmlpull.v1.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Test(org.junit.Test)

Example 4 with ExtensionElement

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

the class ItemValidationTest method parseComplexItem.

@Test
public void parseComplexItem() throws Exception {
    String itemContent = "<entry xmlns='http://www.w3.org/2005/Atom'>" + "<title>Soliloquy</title>" + "<summary>" + "To be, or not to be: that is the question:" + "Whether 'tis nobler in the mind to suffer" + "The slings and arrows of outrageous fortune," + "Or to take arms against a sea of troubles," + "And by opposing end them?" + "</summary>" + "<link rel='alternate' type='text/html' href='http://denmark.lit/2003/12/13/atom03'/>" + "<id>tag:denmark.lit,2003:entry-32397</id>" + "<published>2003-12-13T18:30:02Z</published>" + "<updated>2003-12-13T18:30:02Z</updated>" + "</entry>";
    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);
    ExtensionElement eventExt = message.getExtension(PubSubNamespace.EVENT.getXmlns());
    EventElement event = (EventElement) eventExt;
    ExtensionElement 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);
    SimplePayload payload = (SimplePayload) item.getPayload();
    assertEquals("entry", payload.getElementName());
    assertEquals("http://www.w3.org/2005/Atom", payload.getNamespace());
    assertXMLEqual(itemContent, payload.toXML().toString());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) XmlPullParser(org.xmlpull.v1.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Test(org.junit.Test)

Example 5 with ExtensionElement

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

the class AccountManager method isSupported.

public boolean isSupported() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    ExtensionElement extensionElement = connection.getFeature(Registration.Feature.ELEMENT, Registration.Feature.NAMESPACE);
    if (extensionElement != null) {
        return true;
    }
    // won't be able to do IQs.
    if (connection.isAuthenticated()) {
        return ServiceDiscoveryManager.getInstanceFor(connection).serverSupportsFeature(Registration.NAMESPACE);
    }
    return false;
}
Also used : ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Aggregations

ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)32 Test (org.junit.Test)9 XmlPullParser (org.xmlpull.v1.XmlPullParser)9 AccountItem (com.xabber.android.data.account.AccountItem)7 Message (org.jivesoftware.smack.packet.Message)7 Stanza (org.jivesoftware.smack.packet.Stanza)4 LinkedList (java.util.LinkedList)3 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)3 TreeSet (java.util.TreeSet)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 Presence (org.jivesoftware.smack.packet.Presence)2 AMPExtension (org.jivesoftware.smackx.amp.packet.AMPExtension)2 AMPExtensionProvider (org.jivesoftware.smackx.amp.provider.AMPExtensionProvider)2 Base64BinaryChunk (org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk)2 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)2 PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)2 RSMSet (org.jivesoftware.smackx.rsm.packet.RSMSet)2 FormField (org.jivesoftware.smackx.xdata.FormField)2 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)2 NetworkException (com.xabber.android.data.NetworkException)1