public void processPacket(Packet packet) { EventElement event = (EventElement) packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); ConfigurationEvent config = (ConfigurationEvent) event.getEvent(); listener.handleNodeConfiguration(config); }
public boolean accept(Packet packet) { if (!(packet instanceof Message)) return false; EventElement event = (EventElement) packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); if (event == null) return false; NodeExtension embedEvent = event.getEvent(); if (embedEvent == null) return false; if (embedEvent.getElementName().equals(firstElement)) { if (!embedEvent.getNode().equals(getId())) return false; if (secondElement == null) return true; if (embedEvent instanceof EmbeddedPacketExtension) { List<PacketExtension> secondLevelList = ((EmbeddedPacketExtension) embedEvent).getExtensions(); if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement)) return true; } } return false; }
@Test public void parseBasicItem() throws Exception { XmlPullParser parser = PacketParserUtils.getParserFor( "<message from='pubsub.myserver.com' to='*****@*****.**' 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()); }
@Test public void parseEmptyTag() throws Exception { String itemContent = "<foo xmlns='smack:test'><bar/></foo>"; XmlPullParser parser = PacketParserUtils.getParserFor( "<message from='pubsub.myserver.com' to='*****@*****.**' 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()); 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 PayloadItem<?>); PayloadItem<?> item = (PayloadItem<?>) itemExt; assertEquals("testid1", item.getId()); assertTrue(item.getPayload() instanceof SimplePayload); assertXMLEqual(itemContent, ((SimplePayload) item.getPayload()).toXML().toString()); }
@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='*****@*****.**' 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()); }
@SuppressWarnings({"rawtypes", "unchecked"}) public void processPacket(Packet packet) { EventElement event = (EventElement) packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); ItemsExtension itemsElem = (ItemsExtension) event.getEvent(); DelayInformation delay = (DelayInformation) packet.getExtension("delay", "urn:xmpp:delay"); // If there was no delay based on XEP-0203, then try XEP-0091 for backward compatibility if (delay == null) { delay = (DelayInformation) packet.getExtension("x", "jabber:x:delay"); } ItemPublishEvent eventItems = new ItemPublishEvent( itemsElem.getNode(), (List<Item>) itemsElem.getItems(), getSubscriptionIds(packet), (delay == null ? null : delay.getStamp())); listener.handlePublishedItems(eventItems); }
public void processPacket(Packet packet) { EventElement event = (EventElement) packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); List<PacketExtension> extList = event.getExtensions(); if (extList.get(0).getElementName().equals(PubSubElementType.PURGE_EVENT.getElementName())) { listener.handlePurge(); } else { ItemsExtension itemsElem = (ItemsExtension) event.getEvent(); @SuppressWarnings("unchecked") Collection<RetractItem> pubItems = (Collection<RetractItem>) itemsElem.getItems(); List<String> items = new ArrayList<String>(pubItems.size()); for (RetractItem item : pubItems) { items.add(item.getId()); } ItemDeleteEvent eventItems = new ItemDeleteEvent(itemsElem.getNode(), items, getSubscriptionIds(packet)); listener.handleDeletedItems(eventItems); } }