Exemplo n.º 1
0
 /**
  * Returns the number of offline messages for the user of the connection.
  *
  * @return the number of offline messages for the user of the connection.
  * @throws XMPPException If the user is not allowed to make this request or the server does not
  *     support offline message retrieval.
  */
 public int getMessageCount() throws XMPPException {
   DiscoverInfo info =
       ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(null, namespace);
   Form extendedInfo = Form.getFormFrom(info);
   if (extendedInfo != null) {
     String value = (String) extendedInfo.getField("number_of_messages").getValues().next();
     return Integer.parseInt(value);
   }
   return 0;
 }
Exemplo n.º 2
0
 RoomInfo(DiscoverInfo info) {
   super();
   this.room = info.getFrom();
   // Get the information based on the discovered features
   this.membersOnly = info.containsFeature("muc_membersonly");
   this.moderated = info.containsFeature("muc_moderated");
   this.nonanonymous = info.containsFeature("muc_nonanonymous");
   this.passwordProtected = info.containsFeature("muc_passwordprotected");
   this.persistent = info.containsFeature("muc_persistent");
   // Get the information based on the discovered extended information
   Form form = Form.getFormFrom(info);
   if (form != null) {
     this.description = form.getField("muc#roominfo_description").getValues().next();
     Iterator<String> values = form.getField("muc#roominfo_subject").getValues();
     if (values.hasNext()) {
       this.subject = values.next();
     } else {
       this.subject = "";
     }
     this.occupantsCount =
         Integer.parseInt(form.getField("muc#roominfo_occupants").getValues().next());
   }
 }
Exemplo n.º 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;
  }