Esempio n. 1
0
 /**
  * The user subscribes to the node using the supplied jid and subscription options. The bare jid
  * portion of this one must match the jid for the connection.
  *
  * <p>Please note that the {@link Subscription.State} should be checked on return since more
  * actions may be required by the caller. {@link Subscription.State#pending} - The owner must
  * approve the subscription request before messages will be received. {@link
  * Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true, the
  * caller must configure the subscription before messages will be received. If it is false the
  * caller can configure it but is not required to do so.
  *
  * @param jid The jid to subscribe as.
  * @return The subscription
  * @throws XMPPErrorException
  * @throws NoResponseException
  * @throws NotConnectedException
  */
 public Subscription subscribe(String jid, SubscribeForm subForm)
     throws NoResponseException, XMPPErrorException, NotConnectedException {
   PubSub request = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
   request.addExtension(new FormNode(FormNodeType.OPTIONS, subForm));
   PubSub reply = (PubSub) PubSubManager.sendPubsubPacket(con, jid, Type.set, request);
   return (Subscription) reply.getExtension(PubSubElementType.SUBSCRIPTION);
 }
Esempio n. 2
0
 /**
  * Delete the specified node
  *
  * @param nodeId
  * @throws XMPPException
  */
 public void deleteNode(String nodeId) throws XMPPException {
   sendPubsubPacket(
       Type.SET,
       new NodeExtension(PubSubElementType.DELETE, nodeId),
       PubSubElementType.DELETE.getNamespace());
   nodeMap.remove(nodeId);
 }
Esempio n. 3
0
  /**
   * Creates a node with specified configuration.
   *
   * @param name 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
   * @exception XMPPException
   */
  public Node createNode(String name, Form config) throws XMPPException {
    PubSub request =
        createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name));

    if (config != null) request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));

    // Errors will cause exceptions in getReply, so it only returns
    // on success.
    sendPubsubPacket(con, to, Type.SET, request);
    Node newNode = new Node(con, name);
    newNode.setTo(to);
    nodeMap.put(newNode.getId(), newNode);

    return newNode;
  }
Esempio n. 4
0
  /**
   * Creates a node with specified configuration.
   *
   * <p>Note: This is the only way to create a collection node.
   *
   * @param name 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
   * @exception XMPPException
   */
  public Node createNode(String name, Form config) throws XMPPException {
    PubSub request =
        createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name));
    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().next().equals(NodeType.leaf.toString());
    }

    // Errors will cause exceptions in getReply, so it only returns
    // on success.
    sendPubsubPacket(con, to, Type.SET, request);
    Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name);
    newNode.setTo(to);
    nodeMap.put(newNode.getId(), newNode);

    return newNode;
  }
Esempio n. 5
0
 protected Packet sendPubsubPacket(Type type, NodeExtension ext, PubSubNamespace ns)
     throws NoResponseException, XMPPErrorException, NotConnectedException {
   return PubSubManager.sendPubsubPacket(con, to, type, ext, ns);
 }