use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class PubSubManager method createNode.
/**
* Creates a node with specified configuration.
*
* Note: This is the only way to create a collection node.
*
* @param nodeId The name of the node, which must be unique within the
* pubsub service
* @param config The configuration for the node
* @return The node that was created
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public Node createNode(String nodeId, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub request = PubSub.createPubsubPacket(pubSubService, Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId), null);
boolean isLeafNode = true;
if (config != null) {
request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());
if (nodeTypeField != null)
isLeafNode = nodeTypeField.getValues().get(0).equals(NodeType.leaf.toString());
}
// Errors will cause exceptions in getReply, so it only returns
// on success.
sendPubsubPacket(request);
Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId);
nodeMap.put(newNode.getId(), newNode);
return newNode;
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class LeafNode method getItems.
/**
* Get items persisted on the node.
* <p>
* {@code additionalExtensions} can be used e.g. to add a "Result Set Management" extension.
* {@code returnedExtensions} will be filled with the stanza(/packet) extensions found in the answer.
* </p>
*
* @param additionalExtensions additional {@code PacketExtensions} to be added to the request.
* This is an optional argument, if provided as null no extensions will be added.
* @param returnedExtensions a collection that will be filled with the returned packet
* extensions. This is an optional argument, if provided as null it won't be populated.
* @return List of {@link Item}
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(List<ExtensionElement> additionalExtensions, List<ExtensionElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId()));
request.addExtensions(additionalExtensions);
return getItems(request, returnedExtensions);
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class LeafNode method getItems.
@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();
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class LeafNode method send.
/**
* Publishes an event to the node. This is an empty event
* with no item.
*
* This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false
* and {@link ConfigureForm#isDeliverPayloads()}=false.
*
* This is a synchronous call which will throw an exception
* on failure.
*
* For asynchronous calls, use {@link #publish() publish()}.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public void send() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId()));
pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
use of org.jivesoftware.smackx.pubsub.packet.PubSub in project Smack by igniterealtime.
the class PubSubProvider method parse.
@Override
public PubSub parse(XmlPullParser parser, int initialDepth) throws Exception {
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;
}
Aggregations