Package jabber.roster

Examples of jabber.roster.Jid


  boolean default_flag = false;
  RecordStore rs = null;
  try {
    rs = RecordStore.openRecordStore("MyOptions",true);
  }catch (RecordStoreException ex) {
    jid = new Jid("username@localhost/JabberMix");
           password = "password";
     server_name = "localhost";
    
   
    return;
   
  }
 
  //get record in order
  byte b[] = null;
  byte b1[] = null;
  byte b2[] = null;
  byte b3[] = null;
  byte b4[] = null;
  byte b5[] = null;
  byte b6[] = null;
  byte b7[] = null;
 
  try {
    b = rs.getRecord(1);
    b1 = rs.getRecord(2);
    b2 = rs.getRecord(3);
    b3 = rs.getRecord(4);
    b4 = rs.getRecord(5);
    b5 = rs.getRecord(6);
    b6 = rs.getRecord(7);
    b7 = rs.getRecord(8);
  }catch (RecordStoreNotOpenException e) {
    default_flag = true;
  }catch (InvalidRecordIDException e1) {
    default_flag = true;
  }catch (RecordStoreException e2) {
    default_flag = true;
  }
  if (default_flag) {//default options
    jid = new Jid("username@localhost/JabberMix");
           password = "password";
     server_name = "localhost";
    
   
  }
  else { //the records exist
    jid = new Jid(new String(b, 0, b.length));
   
    password = new String(b1, 0, b1.length);
 
    server_name = new String(b2, 0, b2.length);
   
View Full Code Here


      return roster_vector;
    Enumeration contacts = Datas.roster.elements();
    roster_vector = new Vector();
    while (contacts.hasMoreElements())
    {
      Jid temp = (Jid)contacts.nextElement();
      if (!Presence.getPresence("unavailable").equalsIgnoreCase(temp.getPresence()))
        roster_vector.addElement(temp);
    }

    return roster_vector;
  }
View Full Code Here

        {
          return;
        }
        n = (Node)n.getChildren().firstElement();
        String jid = n.getValue("user");
        Jid j = (Jid)Datas.roster.get(Jid.getLittleJid(jid));
        if (j == null)
          return;
        j.phone = n.text;
        //Datas.roster.put(Jid.getLittleJid(jid), j);
      }
      return;
    }
    else if (stanzaId.equals("setNum"))
    {
      System.out.println("Phone number saved");
      return;
    }
    else if (stanzaId.equals("roster_2"))
    {
      System.out.println("Contact deleted");
      return;
    }
    else if (stanzaId.equals("vc1")) {
      //AVATAR set
       
      return;
    }
    else if (stanzaId.equals("vc2")) {
      System.out.print("getting vcard");
      Node vcard =_node.getChild("vCard");
      Jid user  = (Jid)Datas.roster.get(Jid.getLittleJid(stanzaFrom));
      if (user != null && vcard != null && vcard.getChild("PHOTO") != null) {
        Node binval = vcard.getChild("PHOTO").getChild("BINVAL");
        try {
          if (binval != null && binval.text != null) {
           
            byte[] img = Base64.decode(binval.text);
            if (img != null) {
              user.setAvatar(img);
              //System.out.println("AVATAR settato");
            }
          }
        }catch(Exception e) {System.out.println("AVATAR error:"+e.getMessage());}
         
View Full Code Here

      else if ((x = _node.getChild("x", "xmlns","vcard-temp:x:update")) != null) {
        try {
          Node hash = x.getChild("photo"); //AVATAR
          if (hash != null && hash.text != null && !hash.text.equals("")) {
            //byte[] image = hash.text.getBytes();
            Jid rost = (Jid)Datas.roster.get(Jid.getLittleJid(stanzaFrom));
            if (rost != null) {
              if (rost.avatarHash == null) {//No avatar yet
                rost.avatarHash = hash.text;
                //ask for avatar
                Presence.getVCard(rost.getLittleJid());
              }
              else if (!rost.avatarHash.equals(hash.text))
                Presence.getVCard(rost.getLittleJid());//update avatar
            }
           
          }
        }catch (Exception e) {
          System.out.println(e.getMessage());
        }
      }

      Jid rost = new Jid(stanzaFrom);
      if (_node.getChild("status") != null)
      {
        status = _node.getChild("status");
        rost.setPresence(Presence.getPresence(stanzaType), status.text);
      }
      else
        rost.setPresence(Presence.getPresence(stanzaType));

      jabberListener.notifyPresence(rost, stanzaType);
     
    } else if (stanzaType.equals("subscribe")) {
       // roster wants to subscribe for my presence events
         Jid rost = new Jid(stanzaFrom);
         if (stanzaFrom.indexOf("@") == -1 || Datas.isGateway(rost.getServername())) //service subscription
         {
           Subscribe.acceptSubscription(rost);
           return;
         }


         jabberListener.notifyPresence(rost, stanzaType);
      
     } else if (stanzaType.equals("subscribed")) {
       // roster granted my "subscribe wish"
       Jid rost = new Jid(stanzaFrom);
      jabberListener.notifyPresence(rost, stanzaType);
     } else if (stanzaType.equals("unsubscribe")) {
       // roster wants to unsubscribe for my presence events
     } else if (stanzaType.equals("unsubscribed")) {
       // roster unsubscribed me for his presence events
       // or my "subscribe wish" was declined
       Jid rost = new Jid(stanzaFrom);
      jabberListener.notifyPresence(rost, stanzaType);
     } else if (stanzaType.equals("probe")) {
       // roster/server probes my presence
     }
   
View Full Code Here

    for (int i=0; i<children.size();i++) {
      Node child = (Node)children.elementAt(i);
     
     
     
      Jid newjid = new Jid(child.getValue("jid"));
      if (child.getValue("name") != null) {//nick
        newjid.setNickname(child.getValue("name"));
      }
      //check group
      if (child.getChild("group") != null)
        newjid.group = child.getChild("group").text;
      if (newjid.getUsername() == newjid.getServername())
        continue;
      String subs = child.getValue("subscription");
      if (Datas.roster.get(newjid.getLittleJid()) != null &&  subs != null) {
       
        if (subs.equals("none") || subs.equals("from")){
          ((Jid)Datas.roster.get(newjid.getLittleJid())).setPresence(Presence.getPresence("unsubscribed"));
        }
        else if (subs.equals("remove"))
        {
          Datas.roster.remove(newjid.getLittleJid());
          Vector conversations = Datas.conversations;
          for (int k=0; k<conversations.size(); k++) {
            Conversation c = (Conversation) conversations.elementAt(k);
            if (c.name.equals(newjid.getUsername())) {
              conversations.removeElementAt(k);
              break;
            }
          }
         
        }
      /*  else if (subs.equals("to") && child.getValue("ask") == null && Datas.isGateway(newjid.getServername())) {
          //TODO: AUTO SUBSCRIPTION FOR TRANSPORTS DA TESTARE
          System.out.println("is gateway:"+newjid.getServername());
          Subscribe.acceptSubscription(newjid);
         
        }*/
        return;
      }
      else {
        Datas.registerRoster(newjid);
        if (subs != null && (subs.equals("none") || subs.equals("from"))){
          newjid.setPresence(Presence.getPresence("unsubscribed"));
        }
      /*  else if (subs != null && subs.equals("to") && child.getValue("ask") == null && Datas.isGateway(newjid.getServername())) {
          //TODO: AUTO SUBSCRIPTION FOR TRANSPORTS DA TESTARE
          //System.out.println("is gateway:"+newjid.getServername());
          Subscribe.acceptSubscription(newjid);
View Full Code Here

    else
      roster = Datas.createRosterVector(true);
    if (roster.size() > 0) {
      //contacts_list = new ChoiceGroup("Contacts", ChoiceGroup.EXCLUSIVE);
      for (int i=0;i< roster.size(); i++) {       
        Jid temp = (Jid)roster.elementAt(i);
        /*String username = temp.getUsername().replace('%', '@');
        contacts_list.append(username, Datas.images.displayImage(temp.getPresence()));*/
        contacts_list.addItem(temp);
      }
     
 
View Full Code Here

        Subscribe.setPhoneNumber(currentjid, currentjid.phone);
        Datas.roster.put(currentjid.getLittleJid(), currentjid);
 
      }
      else if (changes) {
        Jid newjid = new Jid(jid);
        newjid.group = group;
        newjid.phone = phone;
       
        //notify to the server
        Subscribe.setNewRosterItem(newjid, isNew);
View Full Code Here

        else
        {
          Datas.hostname = server;
          Datas.subdomain = null;
        }
        Datas.jid = new Jid(jid + "@" + Datas.hostname);
        if (Datas.jid.getResource() == null)
          Datas.jid.setResource("JabberMix");
        Datas.setPassword(password);
        Datas.server_name = server;
       
View Full Code Here

   
  }
  public void commandActionInvite(Command id) {

    if (id == Contents.accept) {
      Jid room = new Jid((String)infopool.remove("invit_room"));
      infopool.remove("invit_from");
      ChatHelper.groupChatJoin(Datas.jid.getUsername(), room.getUsername(), room.getServername());
     
    }
    else {
      internal_state = ((Integer)infopool.remove("invit_internal_state")).intValue();
      infopool.remove("invit_from");
View Full Code Here

    //System.out.println("+readMESSAGE+");
   
    Message message = new Message(_node); // takes the subject&body of the message
    String threadId = "";
    Conversation conversation = null; // conversation corresponding to the message
    Jid rosterFrom;
   
   
   
    if (_node.getChild("thread") != null) {
      threadId = _node.getChild("thread").text;
    } else {
      // _node has no "thread" child: server message?
      if (message.from.equalsIgnoreCase(Datas.hostname) ||  Datas.isGateway(message.from))
      {
        System.out.println("server message");
        conversation = new Conversation(message.from);
        conversation.appendToMe(message);
        jabberListener.newMessageEvent(conversation, -1);
        return;
      }
     
    }   
    //groupchat invitation management
    if ((stanzaType == null || stanzaType.equals("normal")) && _node.getChild("x", "xmlns", "jabber:x:conference") != null) {
      String jidfrom;
      String room;
      //check if server uses new MUC protocol
      if (_node.getChild("x", "xmlns", "http://jabber.org/protocol/muc#user") != null) {
        Node invite = _node.getChild("x", "xmlns", "http://jabber.org/protocol/muc#user");
        if (invite.getChild("invite") != null) {
          jidfrom = invite.getChild("invite").getValue("from");
          room = stanzaFrom;
          jabberListener.newInvitationEvent(jidfrom, room);
          return;
        }
      }//check if server uses old protocol
      else if (_node.getChild("body") != null && _node.getChild("body").text.startsWith("You have been invited")) {

        Node invite = _node.getChild("x", "xmlns", "jabber:x:conference");
        jidfrom = stanzaFrom;
        room = invite.getValue("jid");
        jabberListener.newInvitationEvent(jidfrom, room);
        return;
      }     
    }
    //Composing management
    else if (stanzaType.equals("chat") && _node.getChild("composing", "xmlns", "http://jabber.org/protocol/chatstates") != null) {
     
      Vector conversations = Datas.conversations;
      Conversation convers = null;
      // finds out the conversation, if already exists
     
      for(int i=0; i<conversations.size(); i++) {
        convers = (Conversation) conversations.elementAt(i);
        if (convers.match(_node)) {
          convers.composing = Jid.getUsername(convers.name) + Contents.composing;
          jabberListener.newComposingEvent(convers);
          break;
        }
       
      }
       
     
       
      
      return;
    }
    else if (stanzaType.equals("chat") && _node.getChild("inactive", "xmlns", "http://jabber.org/protocol/chatstates") != null) {
      Vector conversations = Datas.conversations;
      Conversation convers = null;
      // finds out the conversation, if already exists
     
      for(int i=0; i<conversations.size(); i++) {
        convers = (Conversation) conversations.elementAt(i);
        if (convers.match(_node)) {
          convers.composing = Jid.getUsername(convers.name) + Contents.inactive;
          jabberListener.newComposingEvent(convers);
          break;
        }
       
      }
     
      return;
    }
    else if (stanzaType.equals("chat") && _node.getChild("x", "xmlns", "jabber:x:event") != null &&  _node.getChild("body") == null) {
      Node x = _node.getChild("x", "xmlns", "jabber:x:event");
      if (x.getChild("composing") != null) {
        Vector conversations = Datas.conversations;
        Conversation convers = null;
     
        for(int i=0; i<conversations.size(); i++) {
          convers = (Conversation) conversations.elementAt(i);
          if (convers.match(_node)) {
            convers.composing = Jid.getUsername(convers.name) + Contents.composing;
            jabberListener.newComposingEvent(convers);
            break;
          }
         
        }
       
       
        return;
      }
    }
   
    Vector conversations = Datas.conversations;
   
    // finds out the conversation, if already exists
    int i=0;
    boolean found=false;
    while ((i<conversations.size()) && !found) {
      conversation = (Conversation) conversations.elementAt(i);
      found = conversation.match(_node);
      i++;
    }
   
    // default stanza type if not specified.
    if (stanzaType == null) {
      stanzaType = "normal";
    }
   
    if (found == false) { // no conversation with this roster is running

      if (stanzaType.equals("error")) {
        message.addError(_node.getChild("error").text);
        jabberListener.notifyError(null, message);
      }
      else if (stanzaType.equals("normal")
          || stanzaType.equals("chat") ) {
        rosterFrom = (Jid) Datas.roster.get(Jid.getLittleJid(stanzaFrom));

        if (rosterFrom == null) {
          // the roster is not known
          Jid newjid = new Jid(stanzaFrom, "online");
          rosterFrom = newjid;
          Datas.registerRoster(newjid);
         
        }
        // normal: default message type. reply expected. no history.
        // chat: peer to peer communication. with history.

        SingleChat chat = new SingleChat(rosterFrom, stanzaType, threadId);

        chat.appendToMe(message);
        // registers this new conversation
        conversations.addElement(chat);

        jabberListener.newConversationEvent(chat);
      }
      else if (stanzaType.equals("groupchat") && (stanzaFrom.indexOf("/") == -1)) {
        System.out.println("My message");
          return;
        /*Conversation conversation = ChatHelper.createChat(partners, littleFrom, nick);
        conversation.appendToMe(new Message("", "Added to this room"));
        conversation.isMulti = true;
        Datas.conversations.addElement(conversation);
        jabberListener.newConversationEvent(conversation);
        return;*/
      }
      else if (stanzaType.equals("headline")) {
        rosterFrom = (Jid) Datas.roster.get(stanzaFrom);
        if (rosterFrom == null) {
          // the roster is not known
          Jid newjid = new Jid(stanzaFrom);
          rosterFrom = newjid;
          if (stanzaFrom.indexOf("@") != -1) //is user
          {
           
            Datas.registerRoster(newjid);
View Full Code Here

TOP

Related Classes of jabber.roster.Jid

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.