@Override protected ItemsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content) { return new ItemsExtension(ItemsExtension.ItemsElementType.items, attributeMap.get("node"), content); }
@Override public CharSequence toXML(String enclosingNamespace) { if ((items == null) || (items.size() == 0)) { return super.toXML(enclosingNamespace); } else { StringBuilder builder = new StringBuilder("<"); builder.append(getElementName()); builder.append(" node='"); builder.append(getNode()); if (notify != null) { builder.append("' "); builder.append(type.getElementAttribute()); builder.append("='"); builder.append(notify.equals(Boolean.TRUE) ? 1 : 0); builder.append("'>"); } else { builder.append("'>"); for (NamedElement item : items) { builder.append(item.toXML(null)); } } builder.append("</"); builder.append(getElementName()); builder.append('>'); return builder.toString(); } }
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public void processStanza(Stanza packet) { EventElement event = packet.getExtension("event", PubSubNamespace.event.getXmlns()); ItemsExtension itemsElem = (ItemsExtension) event.getEvent(); ItemPublishEvent eventItems = new ItemPublishEvent(itemsElem.getNode(), itemsElem.getItems(), getSubscriptionIds(packet), DelayInformationManager.getDelayTimestamp(packet)); // TODO: Use AsyncButOrdered (with Node as Key?) listener.handlePublishedItems(eventItems); } }
@Override @SuppressWarnings("unchecked") public List<ExtensionElement> getExtensions() { return (List<ExtensionElement>) getItems(); }
/** * Get the items specified from the node. This would typically be * used when the server does not return the payload due to size * constraints. The user would be required to retrieve the payload * after the items have been retrieved via {@link #getItems()} or an * event, that did not include the payload. * * @param ids Item ids of the items to retrieve * * @return The list of {@link Item} with payload * * @throws XMPPException */ public <T extends Item> List<T> getItems(Collection<String> ids) throws XMPPException { List<Item> itemList = new ArrayList<Item>(ids.size()); for (String id : ids) { itemList.add(new Item(id)); } PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); PubSub result = (PubSub)SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS); return (List<T>)itemsElem.getItems(); }
@Override public String toString() { return getClass().getName() + "Content [" + toXML(null) + "]"; }
for (ExtensionElement item : ((ItemsExtension) items).getExtensions()) { if (!(item instanceof PayloadItem<?>)) { continue;
@SuppressWarnings("unchecked") private <T extends Item> List<T> getItems(PubSub request, List<ExtensionElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { PubSub result = pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow(); ItemsExtension itemsElem = result.getExtension(PubSubElementType.ITEMS); if (returnedExtensions != null) { returnedExtensions.addAll(result.getExtensions()); } return (List<T>) itemsElem.getItems(); }
/** * Get the items specified from the node. This would typically be * used when the server does not return the payload due to size * constraints. The user would be required to retrieve the payload * after the items have been retrieved via {@link #getItems()} or an * event, that did not include the payload. * * @param ids Item ids of the items to retrieve * * @return The list of {@link Item} with payload * * @throws XMPPException */ public <T extends Item> List<T> getItems(Collection<String> ids) throws XMPPException { List<Item> itemList = new ArrayList<Item>(ids.size()); for (String id : ids) { itemList.add(new Item(id)); } PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); PubSub result = (PubSub)SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS); return (List<T>)itemsElem.getItems(); }
@Override public String toString() { return getClass().getName() + "Content [" + toXML() + "]"; }
@Override public void processStanza(Stanza packet) { // CHECKSTYLE:OFF EventElement event = 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<>(pubItems.size()); for (RetractItem item : pubItems) { items.add(item.getId()); } ItemDeleteEvent eventItems = new ItemDeleteEvent(itemsElem.getNode(), items, getSubscriptionIds(packet)); listener.handleDeletedItems(eventItems); } // CHECKSTYLE:ON } }
public List<PacketExtension> getExtensions() { return (List<PacketExtension>)getItems(); }
builder.append(getElementName()); builder.append(" node='"); builder.append(getNode()); builder.append(getElementName()); builder.append(">"); return builder.toString();
/** * Get the items specified from the node. This would typically be * used when the server does not return the payload due to size * constraints. The user would be required to retrieve the payload * after the items have been retrieved via {@link #getItems()} or an * event, that did not include the payload. * * @param ids Item ids of the items to retrieve * * @return The list of {@link Item} with payload * * @throws XMPPException */ public <T extends Item> List<T> getItems(Collection<String> ids) throws XMPPException { List<Item> itemList = new ArrayList<Item>(ids.size()); for (String id : ids) { itemList.add(new Item(id)); } PubSub request = createPubsubPacket(Type.GET, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); PubSub result = (PubSub)SyncPacketSend.getReply(con, request); ItemsExtension itemsElem = (ItemsExtension)result.getExtension(PubSubElementType.ITEMS); return (List<T>)itemsElem.getItems(); }
/** * Get the items specified from the node. This would typically be * used when the server does not return the payload due to size * constraints. The user would be required to retrieve the payload * after the items have been retrieved via {@link #getItems()} or an * event, that did not include the payload. * * @param ids Item ids of the items to retrieve * @param <T> type of the items. * * @return The list of {@link Item} with payload * @throws XMPPErrorException * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @throws InterruptedException */ public <T extends Item> List<T> getItems(Collection<String> ids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { List<Item> itemList = new ArrayList<>(ids.size()); for (String id : ids) { itemList.add(new Item(id)); } PubSub request = createPubsubPacket(Type.get, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList)); return getItems(request); }
@Override public String toString() { return getClass().getName() + "Content [" + toXML() + "]"; }
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 List<PacketExtension> getExtensions() { return (List<PacketExtension>)getItems(); }
builder.append(getElementName()); builder.append(" node='"); builder.append(getNode()); builder.append(getElementName()); builder.append(">"); return builder.toString();
/** * Delete the items with the specified id's from the node. * * @param itemIds The list of id's of items to delete * @throws XMPPErrorException * @throws NoResponseException if there was no response from the server. * @throws NotConnectedException * @throws InterruptedException */ public void deleteItem(Collection<String> itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { List<Item> items = new ArrayList<>(itemIds.size()); for (String id : itemIds) { items.add(new Item(id)); } PubSub request = createPubsubPacket(Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items)); pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow(); } }