java.lang.Object
org.jivesoftware.smack.packet.Stanza
org.jivesoftware.smack.packet.IQ
org.jivesoftware.smackx.vcardtemp.packet.VCard
All Implemented Interfaces:
org.jivesoftware.smack.packet.Element, org.jivesoftware.smack.packet.IqView, org.jivesoftware.smack.packet.NamedElement, org.jivesoftware.smack.packet.StanzaView, org.jivesoftware.smack.packet.TopLevelStreamElement, org.jivesoftware.smack.packet.XmlElement, org.jivesoftware.smack.packet.XmlLangElement

public final class VCard extends org.jivesoftware.smack.packet.IQ
A VCard class for use with the SMACK jabber library.

You should refer to the XEP-54 documentation.

Please note that this class is incomplete but it does provide the most commonly found information in vCards. Also remember that VCard transfer is not a standard, and the protocol may change or be replaced.

Usage:


 // To save VCard:

 VCard vCard = new VCard();
 vCard.setFirstName("kir");
 vCard.setLastName("max");
 vCard.setEmailHome("foo@fee.bar");
 vCard.setJabberId("jabber@id.org");
 vCard.setOrganization("Jetbrains, s.r.o");
 vCard.setNickName("KIR");

 vCard.setField("TITLE", "Mr");
 vCard.setAddressFieldHome("STREET", "Some street");
 vCard.setAddressFieldWork("CTRY", "US");
 vCard.setPhoneWork("FAX", "3443233");

 vCard.save(connection);

 // To load VCard:

 VCard vCard = new VCard();
 vCard.load(conn); // load own VCard
 vCard.load(conn, "joe@foo.bar"); // load someone's VCard
 
  • Field Details

  • Constructor Details

    • VCard

      public VCard()
  • Method Details

    • getField

      public String getField(String field)
      Get the content of a generic VCard field.
      Parameters:
      field - value of field. Possible values: NICKNAME, PHOTO, BDAY, JABBERID, MAILER, TZ, GEO, TITLE, ROLE, LOGO, NOTE, PRODID, REV, SORT-STRING, SOUND, UID, URL, DESC.
      Returns:
      content of field.
    • setField

      public void setField(String field, String value)
      Set generic VCard field.
      Parameters:
      value - value of field
      field - field to set. See getField(String)
      See Also:
    • setField

      public void setField(String field, String value, boolean isUnescapable)
      Set generic, unescapable VCard field. If unescapable is set to true, XML maybe a part of the value.
      Parameters:
      value - value of field
      field - field to set. See getField(String)
      isUnescapable - True if the value should not be escaped, and false if it should.
    • getFirstName

      public String getFirstName()
    • setFirstName

      public void setFirstName(String firstName)
    • getLastName

      public String getLastName()
    • setLastName

      public void setLastName(String lastName)
    • getMiddleName

      public String getMiddleName()
    • setMiddleName

      public void setMiddleName(String middleName)
    • getPrefix

      public String getPrefix()
    • setPrefix

      public void setPrefix(String prefix)
    • getSuffix

      public String getSuffix()
    • setSuffix

      public void setSuffix(String suffix)
    • getNickName

      public String getNickName()
    • setNickName

      public void setNickName(String nickName)
    • getEmailHome

      public String getEmailHome()
    • setEmailHome

      public void setEmailHome(String email)
    • getEmailWork

      public String getEmailWork()
    • setEmailWork

      public void setEmailWork(String emailWork)
    • getJabberId

      public String getJabberId()
    • setJabberId

      public void setJabberId(CharSequence jabberId)
    • getOrganization

      public String getOrganization()
    • setOrganization

      public void setOrganization(String organization)
    • getOrganizationUnit

      public String getOrganizationUnit()
    • setOrganizationUnit

      public void setOrganizationUnit(String organizationUnit)
    • getAddressFieldHome

      public String getAddressFieldHome(String addrField)
      Get home address field.
      Parameters:
      addrField - one of POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET, LOCALITY, REGION, PCODE, CTRY
      Returns:
      content of home address field.
    • setAddressFieldHome

      public void setAddressFieldHome(String addrField, String value)
      Set home address field.
      Parameters:
      addrField - one of POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET, LOCALITY, REGION, PCODE, CTRY
      value - new value for the field.
    • getAddressFieldWork

      public String getAddressFieldWork(String addrField)
      Get work address field.
      Parameters:
      addrField - one of POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET, LOCALITY, REGION, PCODE, CTRY
      Returns:
      content of work address field.
    • setAddressFieldWork

      public void setAddressFieldWork(String addrField, String value)
      Set work address field.
      Parameters:
      addrField - one of POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET, LOCALITY, REGION, PCODE, CTRY
      value - new value for the field.
    • setPhoneHome

      public void setPhoneHome(String phoneType, String phoneNum)
      Set home phone number.
      Parameters:
      phoneType - one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREF
      phoneNum - phone number
    • getPhoneHome

      public String getPhoneHome(String phoneType)
      Get home phone number.
      Parameters:
      phoneType - one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREF
      Returns:
      content of home phone number.
    • setPhoneWork

      public void setPhoneWork(String phoneType, String phoneNum)
      Set work phone number.
      Parameters:
      phoneType - one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREF
      phoneNum - phone number
    • getPhoneWork

      public String getPhoneWork(String phoneType)
      Get work phone number.
      Parameters:
      phoneType - one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREF
      Returns:
      content of work phone number.
    • setAvatar

      public void setAvatar(URL avatarURL)
      Set the avatar for the VCard by specifying the url to the image.
      Parameters:
      avatarURL - the url to the image(png, jpeg, gif, bmp)
    • removeAvatar

      public void removeAvatar()
      Removes the avatar from the vCard. This is done by setting the PHOTO value to the empty string as defined in XEP-0153
    • setAvatar

      public void setAvatar(byte[] bytes)
      Specify the bytes of the JPEG for the avatar to use. If bytes is null, then the avatar will be removed. 'image/jpeg' will be used as MIME type.
      Parameters:
      bytes - the bytes of the avatar, or null to remove the avatar data
    • setAvatar

      public void setAvatar(byte[] bytes, String mimeType)
      Specify the bytes for the avatar to use as well as the mime type.
      Parameters:
      bytes - the bytes of the avatar.
      mimeType - the mime type of the avatar.
    • setAvatar

      public void setAvatar(String encodedImage, String mimeType)
      Specify the Avatar used for this vCard.
      Parameters:
      encodedImage - the Base64 encoded image as String
      mimeType - the MIME type of the image
    • setEncodedImage

      @Deprecated public void setEncodedImage(String encodedAvatar)
      Deprecated.
      Set the encoded avatar string. This is used by the provider.
      Parameters:
      encodedAvatar - the encoded avatar string.
    • getAvatar

      public byte[] getAvatar()
      Return the byte representation of the avatar(if one exists), otherwise returns null if no avatar could be found. Example 1
       // Load Avatar from VCard
       byte[] avatarBytes = vCard.getAvatar();
      
       // To create an ImageIcon for Swing applications
       ImageIcon icon = new ImageIcon(avatar);
      
       // To create just an image object from the bytes
       ByteArrayInputStream bais = new ByteArrayInputStream(avatar);
       try {
         Image image = ImageIO.read(bais);
        }
        catch (IOException e) {
          e.printStackTrace();
       }
       
      Returns:
      byte representation of avatar.
    • getAvatarMimeType

      public String getAvatarMimeType()
      Returns the MIME Type of the avatar or null if none is set.
      Returns:
      the MIME Type of the avatar or null
    • getBytes

      public static byte[] getBytes(URL url) throws IOException
      Common code for getting the bytes of a url.
      Parameters:
      url - the url to read.
      Returns:
      bytes of the file pointed to by URL.
      Throws:
      IOException - if an IOException occurs while reading the file.
    • getAvatarHash

      public String getAvatarHash()
      Returns the SHA-1 Hash of the Avatar image.
      Returns:
      the SHA-1 Hash of the Avatar image.
    • save

      @Deprecated public void save(org.jivesoftware.smack.XMPPConnection connection) throws org.jivesoftware.smack.SmackException.NoResponseException, org.jivesoftware.smack.XMPPException.XMPPErrorException, org.jivesoftware.smack.SmackException.NotConnectedException, InterruptedException
      Deprecated.
      Save this vCard for the user connected by 'connection'. XMPPConnection should be authenticated and not anonymous.
      Parameters:
      connection - the XMPPConnection to use.
      Throws:
      org.jivesoftware.smack.XMPPException.XMPPErrorException - thrown if there was an issue setting the VCard in the server.
      org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the server.
      org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
      InterruptedException - if the calling thread was interrupted.
    • load

      @Deprecated public void load(org.jivesoftware.smack.XMPPConnection connection) throws org.jivesoftware.smack.SmackException.NoResponseException, org.jivesoftware.smack.XMPPException.XMPPErrorException, org.jivesoftware.smack.SmackException.NotConnectedException, InterruptedException
      Deprecated.
      Load VCard information for a connected user. XMPPConnection should be authenticated and not anonymous.
      Parameters:
      connection - connection.
      Throws:
      org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
      org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the remote entity.
      org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
      InterruptedException - if the calling thread was interrupted.
    • load

      @Deprecated public void load(org.jivesoftware.smack.XMPPConnection connection, org.jxmpp.jid.EntityBareJid user) throws org.jivesoftware.smack.SmackException.NoResponseException, org.jivesoftware.smack.XMPPException.XMPPErrorException, org.jivesoftware.smack.SmackException.NotConnectedException, InterruptedException
      Deprecated.
      Load VCard information for a given user. XMPPConnection should be authenticated and not anonymous.
      Parameters:
      connection - connection.
      user - user whose information we want to load.
      Throws:
      org.jivesoftware.smack.XMPPException.XMPPErrorException - if there was an XMPP error returned.
      org.jivesoftware.smack.SmackException.NoResponseException - if there was no response from the server.
      org.jivesoftware.smack.SmackException.NotConnectedException - if the XMPP connection is not connected.
      InterruptedException - if the calling thread was interrupted.
    • getIQChildElementBuilder

      protected org.jivesoftware.smack.packet.IQ.IQChildElementXmlStringBuilder getIQChildElementBuilder(org.jivesoftware.smack.packet.IQ.IQChildElementXmlStringBuilder xml)
      Specified by:
      getIQChildElementBuilder in class org.jivesoftware.smack.packet.IQ
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object