Class VCard

  • All Implemented Interfaces:
    Element, FullyQualifiedElement, IqView, NamedElement, StanzaView, TopLevelStreamElement, XmlLangElement

    public final class VCard
    extends 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
     
    • Constructor Detail

    • Method Detail

      • getField

        public java.lang.String getField​(java.lang.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​(java.lang.String field,
                             java.lang.String value)
        Set generic VCard field.
        Parameters:
        value - value of field
        field - field to set. See getField(String)
        See Also:
        getField(String)
      • setField

        public void setField​(java.lang.String field,
                             java.lang.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.
      • setFirstName

        public void setFirstName​(java.lang.String firstName)
      • setLastName

        public void setLastName​(java.lang.String lastName)
      • setMiddleName

        public void setMiddleName​(java.lang.String middleName)
      • getPrefix

        public java.lang.String getPrefix()
      • setPrefix

        public void setPrefix​(java.lang.String prefix)
      • getSuffix

        public java.lang.String getSuffix()
      • setSuffix

        public void setSuffix​(java.lang.String suffix)
      • setNickName

        public void setNickName​(java.lang.String nickName)
      • setEmailHome

        public void setEmailHome​(java.lang.String email)
      • setEmailWork

        public void setEmailWork​(java.lang.String emailWork)
      • setJabberId

        public void setJabberId​(java.lang.CharSequence jabberId)
      • setOrganization

        public void setOrganization​(java.lang.String organization)
      • getAddressFieldHome

        public java.lang.String getAddressFieldHome​(java.lang.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​(java.lang.String addrField,
                                        java.lang.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 java.lang.String getAddressFieldWork​(java.lang.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​(java.lang.String addrField,
                                        java.lang.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​(java.lang.String phoneType,
                                 java.lang.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 java.lang.String getPhoneHome​(java.lang.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​(java.lang.String phoneType,
                                 java.lang.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 java.lang.String getPhoneWork​(java.lang.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​(java.net.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,
                              java.lang.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​(java.lang.String encodedImage,
                              java.lang.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​(java.lang.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 java.lang.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​(java.net.URL url)
                               throws java.io.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:
        java.io.IOException - if an IOException occurs while reading the file.
      • getAvatarHash

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

        protected IQ.IQChildElementXmlStringBuilder getIQChildElementBuilder​(IQ.IQChildElementXmlStringBuilder xml)
        Description copied from class: IQ
        This method must be overwritten by IQ subclasses to create their child content. It is important you don't use the builder to add the final end tag. This will be done automatically by IQ.IQChildElementXmlStringBuilder after eventual existing ExtensionElements have been added.

        For example to create an IQ with a extra attribute and an additional child element

         
         <iq to='foo@example.org' id='123'>
           <bar xmlns='example:bar' extraAttribute='blaz'>
              <extraElement>elementText</extraElement>
           </bar>
         </iq>
         
         
        the body of the getIQChildElementBuilder looks like
         
         // The builder 'xml' will already have the child element and the 'xmlns' attribute added
         // So the current builder state is "<bar xmlns='example:bar'"
         xml.attribute("extraAttribute", "blaz");
         xml.rightAngleBracket();
         xml.element("extraElement", "elementText");
         // Do not close the 'bar' attribute by calling xml.closeElement('bar')
         
         
        If your IQ only contains attributes and no child elements, i.e. it can be represented as empty element, then you can mark it as such.
         xml.attribute("myAttribute", "myAttributeValue");
         xml.setEmptyElement();
         
        If your IQ does not contain any attributes or child elements (besides ExtensionElements), consider sub-classing SimpleIQ instead.
        Specified by:
        getIQChildElementBuilder in class IQ
        Parameters:
        xml - a pre-created builder which already has the child element and the 'xmlns' attribute set.
        Returns:
        the build to create the IQ child content.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object