Example #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);
 }
Example #2
0
  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;
  }
Example #3
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;
  }