private List<Subscription> getSubscriptions(List<ExtensionElement> additionalExtensions, Collection<ExtensionElement> returnedExtensions, PubSubNamespace pubSubNamespace) throws NoResponseException, XMPPErrorException, NotConnectedException { PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId()), pubSubNamespace); if (additionalExtensions != null) { for (ExtensionElement pe : additionalExtensions) { pubSub.addExtension(pe); } } PubSub reply = sendPubsubPacket(pubSub); if (returnedExtensions != null) { returnedExtensions.addAll(reply.getExtensions()); } SubscriptionsExtension subElem = (SubscriptionsExtension) reply.getExtension(PubSubElementType.SUBSCRIPTIONS); return subElem.getSubscriptions(); }
public void processPacket(Stanza packet) { EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); List<ExtensionElement> 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); } }
@Override public PubSub parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException { String namespace = parser.getNamespace(); PubSubNamespace pubSubNamespace = PubSubNamespace.valueOfFromXmlns(namespace); PubSub pubsub = new PubSub(pubSubNamespace); outerloop: while (true) { int eventType = parser.next(); switch (eventType) { case XmlPullParser.START_TAG: PacketParserUtils.addExtensionElement(pubsub, parser); break; case XmlPullParser.END_TAG: if (parser.getDepth() == initialDepth) { break outerloop; } break; } } return pubsub; }
public IQ parseIQ(XmlPullParser parser) throws Exception { PubSub pubsub = new PubSub(); String namespace = parser.getNamespace(); pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace)); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { PacketExtension ext = PacketParserUtils.parsePacketExtension( parser.getName(), namespace, parser); if (ext != null) { pubsub.addExtension(ext); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("pubsub")) { done = true; } } } return pubsub; }
public String toXML() { StringBuilder builder = new StringBuilder("<event xmlns='" + PubSubNamespace.EVENT.getXmlns() + "'>"); builder.append(ext.toXML()); builder.append("</event>"); return builder.toString(); }
/** * Creates an instant node, if supported. * * @return The node that was created * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException */ public LeafNode createNode() throws NoResponseException, XMPPErrorException, NotConnectedException { PubSub reply = sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.CREATE), null); NodeExtension elem = reply.getExtension("create", PubSubNamespace.BASIC.getXmlns()); LeafNode newNode = new LeafNode(con, elem.getNode()); newNode.setTo(to); nodeMap.put(newNode.getId(), newNode); return newNode; }
static PubSub sendPubsubPacket(XMPPConnection con, String to, Type type, List<ExtensionElement> extList, PubSubNamespace ns) throws NoResponseException, XMPPErrorException, NotConnectedException { PubSub pubSub = new PubSub(to, type, ns); for (ExtensionElement pe : extList) { pubSub.addExtension(pe); } return sendPubsubPacket(con ,pubSub); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public void processPacket(Stanza packet) { EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); ItemsExtension itemsElem = (ItemsExtension)event.getEvent(); ItemPublishEvent eventItems = new ItemPublishEvent(itemsElem.getNode(), (List<Item>)itemsElem.getItems(), getSubscriptionIds(packet), DelayInformationManager.getDelayTimestamp(packet)); listener.handlePublishedItems(eventItems); }
public void processPacket(Stanza packet) { EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns()); ConfigurationEvent config = (ConfigurationEvent)event.getEvent(); listener.handleNodeConfiguration(config); }
public boolean accept(Stanza 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<ExtensionElement> secondLevelList = ((EmbeddedPacketExtension)embedEvent).getExtensions(); if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement)) return true; } } return false; }
/** * Creates an instant node, if supported. * * @return The node that was created * @exception XMPPException */ public LeafNode createNode() throws XMPPException { PubSub reply = (PubSub)sendPubsubPacket(Type.SET, new NodeExtension(PubSubElementType.CREATE)); NodeExtension elem = (NodeExtension)reply.getExtension("create", PubSubNamespace.BASIC.getXmlns()); LeafNode newNode = new LeafNode(con, elem.getNode()); newNode.setTo(to); nodeMap.put(newNode.getId(), newNode); return newNode; }
static PubSub createPubsubPacket(String to, Type type, PacketExtension ext, PubSubNamespace ns) { PubSub request = new PubSub(); request.setTo(to); request.setType(type); if (ns != null) { request.setPubSubNamespace(ns); } request.addExtension(ext); return request; }
/** * Returns a configuration form, from which you can create an answer form to be submitted * via the {@link #sendConfigurationForm(Form)}. * * @return the configuration form */ public ConfigureForm getNodeConfiguration() throws XMPPException { Packet reply = sendPubsubPacket(Type.GET, new NodeExtension(PubSubElementType.CONFIGURE_OWNER, getId()), PubSubNamespace.OWNER); return NodeUtils.getFormFromPacket(reply, PubSubElementType.CONFIGURE_OWNER); }
/** * Update the configuration with the contents of the new {@link Form} * * @param submitForm */ public void sendConfigurationForm(Form submitForm) throws XMPPException { PubSub packet = createPubsubPacket(Type.SET, new FormNode(FormNodeType.CONFIGURE_OWNER, getId(), submitForm), PubSubNamespace.OWNER); SyncPacketSend.getReply(con, packet); }
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(); Collection<? extends PacketExtension> pubItems = itemsElem.getItems(); Iterator<RetractItem> it = (Iterator<RetractItem>)pubItems.iterator(); List<String> items = new ArrayList<String>(pubItems.size()); while (it.hasNext()) { RetractItem item = it.next(); items.add(item.getId()); } ItemDeleteEvent eventItems = new ItemDeleteEvent(itemsElem.getNode(), items, getSubscriptionIds(packet)); listener.handleDeletedItems(eventItems); } }
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; }
public IQ parseIQ(XmlPullParser parser) throws Exception { PubSub pubsub = new PubSub(); String namespace = parser.getNamespace(); pubsub.setPubSubNamespace(PubSubNamespace.valueOfFromXmlns(namespace)); boolean done = false; while (!done) { int eventType = parser.next(); if (eventType == XmlPullParser.START_TAG) { PacketExtension ext = PacketParserUtils.parsePacketExtension(parser.getName(), namespace, parser); if (ext != null) { pubsub.addExtension(ext); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals("pubsub")) { done = true; } } } return pubsub; }
/** * Creates an instant node, if supported. * * @return The node that was created * @exception XMPPException */ public LeafNode createNode() throws XMPPException { PubSub reply = (PubSub) sendPubsubPacket(Type.SET, new NodeExtension( PubSubElementType.CREATE)); NodeExtension elem = (NodeExtension) reply.getExtension("create", PubSubNamespace.BASIC.getXmlns()); LeafNode newNode = new LeafNode(con, elem.getNode()); newNode.setTo(to); nodeMap.put(newNode.getId(), newNode); return newNode; }
/** * Returns a configuration form, from which you can create an answer form to * be submitted via the {@link #sendConfigurationForm(Form)}. * * @return the configuration form */ public ConfigureForm getNodeConfiguration() throws XMPPException { Packet reply = sendPubsubPacket(Type.GET, new NodeExtension( PubSubElementType.CONFIGURE_OWNER, getId()), PubSubNamespace.OWNER); return NodeUtils.getFormFromPacket(reply, PubSubElementType.CONFIGURE_OWNER); }
/** * Update the configuration with the contents of the new {@link Form} * * @param submitForm */ public void sendConfigurationForm(Form submitForm) throws XMPPException { PubSub packet = createPubsubPacket(Type.SET, new FormNode( FormNodeType.CONFIGURE_OWNER, getId(), submitForm), PubSubNamespace.OWNER); SyncPacketSend.getReply(con, packet); }
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(); Collection<? extends PacketExtension> pubItems = itemsElem .getItems(); Iterator<RetractItem> it = (Iterator<RetractItem>) pubItems .iterator(); List<String> items = new ArrayList<String>(pubItems.size()); while (it.hasNext()) { RetractItem item = it.next(); items.add(item.getId()); } ItemDeleteEvent eventItems = new ItemDeleteEvent( itemsElem.getNode(), items, getSubscriptionIds(packet)); listener.handleDeletedItems(eventItems); } }
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; }