public class VCard extends IQ
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
DEFAULT_LANGUAGE, ID_NOT_AVAILABLE
Constructor and Description |
---|
VCard() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
String |
getAddressFieldHome(String addrField)
Get home address field
|
String |
getAddressFieldWork(String addrField)
Get work address field
|
byte[] |
getAvatar()
Return the byte representation of the avatar(if one exists), otherwise returns null if
no avatar could be found.
|
String |
getAvatarHash()
Returns the SHA-1 Hash of the Avatar image.
|
String |
getAvatarMimeType()
Returns the MIME Type of the avatar or null if none is set
|
static byte[] |
getBytes(URL url)
Common code for getting the bytes of a url.
|
String |
getChildElementXML()
Returns the sub-element XML section of the IQ packet, or null if there
isn't one.
|
String |
getEmailHome() |
String |
getEmailWork() |
String |
getField(String field)
Set generic VCard field.
|
String |
getFirstName() |
String |
getJabberId() |
String |
getLastName() |
String |
getMiddleName() |
String |
getNickName() |
String |
getOrganization() |
String |
getOrganizationUnit() |
String |
getPhoneHome(String phoneType)
Get home phone number
|
String |
getPhoneWork(String phoneType)
Get work phone number
|
int |
hashCode() |
void |
load(XMPPConnection connection)
Load VCard information for a connected user.
|
void |
load(XMPPConnection connection,
String user)
Load VCard information for a given user.
|
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
|
void |
save(XMPPConnection connection)
Save this vCard for the user connected by 'connection'.
|
void |
setAddressFieldHome(String addrField,
String value)
Set home address field
|
void |
setAddressFieldWork(String addrField,
String value)
Set work address field
|
void |
setAvatar(byte[] bytes)
Specify the bytes of the JPEG for the avatar to use.
|
void |
setAvatar(byte[] bytes,
String mimeType)
Specify the bytes for the avatar to use as well as the mime type.
|
void |
setAvatar(String encodedImage,
String mimeType)
Specify the Avatar used for this vCard.
|
void |
setAvatar(URL avatarURL)
Set the avatar for the VCard by specifying the url to the image.
|
void |
setEmailHome(String email) |
void |
setEmailWork(String emailWork) |
void |
setEncodedImage(String encodedAvatar)
Deprecated.
Use
setAvatar(String, String) instead. |
void |
setField(String field,
String value)
Set generic VCard field.
|
void |
setField(String field,
String value,
boolean isUnescapable)
Set generic, unescapable VCard field.
|
void |
setFirstName(String firstName) |
void |
setJabberId(String jabberId) |
void |
setLastName(String lastName) |
void |
setMiddleName(String middleName) |
void |
setNickName(String nickName) |
void |
setOrganization(String organization) |
void |
setOrganizationUnit(String organizationUnit) |
void |
setPhoneHome(String phoneType,
String phoneNum)
Set home phone number
|
void |
setPhoneWork(String phoneType,
String phoneNum)
Set work phone number
|
String |
toString() |
createErrorResponse, createResultIQ, getType, setType, toXML
addCommonAttributes, addExtension, addExtensions, getDefaultLanguage, getError, getExtension, getExtension, getExtensions, getExtensionsXML, getFrom, getPacketID, getTo, getXmlns, nextID, removeExtension, setDefaultXmlns, setError, setFrom, setPacketID, setTo
public VCard()
public String getField(String field)
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.public void setField(String field, String value)
value
- value of fieldfield
- field to set. See getField(String)
getField(String)
public void setField(String field, String value, boolean isUnescapable)
value
- value of fieldfield
- field to set. See getField(String)
isUnescapable
- True if the value should not be escaped, and false if it should.public String getFirstName()
public void setFirstName(String firstName)
public String getLastName()
public void setLastName(String lastName)
public String getMiddleName()
public void setMiddleName(String middleName)
public String getNickName()
public void setNickName(String nickName)
public String getEmailHome()
public void setEmailHome(String email)
public String getEmailWork()
public void setEmailWork(String emailWork)
public String getJabberId()
public void setJabberId(String jabberId)
public String getOrganization()
public void setOrganization(String organization)
public String getOrganizationUnit()
public void setOrganizationUnit(String organizationUnit)
public String getAddressFieldHome(String addrField)
addrField
- one of POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET,
LOCALITY, REGION, PCODE, CTRYpublic void setAddressFieldHome(String addrField, String value)
addrField
- one of POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET,
LOCALITY, REGION, PCODE, CTRYpublic String getAddressFieldWork(String addrField)
addrField
- one of POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET,
LOCALITY, REGION, PCODE, CTRYpublic void setAddressFieldWork(String addrField, String value)
addrField
- one of POSTAL, PARCEL, (DOM | INTL), PREF, POBOX, EXTADR, STREET,
LOCALITY, REGION, PCODE, CTRYpublic void setPhoneHome(String phoneType, String phoneNum)
phoneType
- one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREFphoneNum
- phone numberpublic String getPhoneHome(String phoneType)
phoneType
- one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREFpublic void setPhoneWork(String phoneType, String phoneNum)
phoneType
- one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREFphoneNum
- phone numberpublic String getPhoneWork(String phoneType)
phoneType
- one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREFpublic void setAvatar(URL avatarURL)
avatarURL
- the url to the image(png,jpeg,gif,bmp)public void removeAvatar()
public void setAvatar(byte[] bytes)
bytes
- the bytes of the avatar, or null to remove the avatar datapublic void setAvatar(byte[] bytes, String mimeType)
bytes
- the bytes of the avatar.mimeType
- the mime type of the avatar.public void setAvatar(String encodedImage, String mimeType)
encodedImage
- the Base64 encoded image as StringmimeType
- the MIME type of the imagepublic void setEncodedImage(String encodedAvatar)
setAvatar(String, String)
instead.encodedAvatar
- the encoded avatar string.public byte[] getAvatar()
// 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(); }
public String getAvatarMimeType()
public static byte[] getBytes(URL url) throws IOException
url
- the url to read.IOException
public String getAvatarHash()
public void save(XMPPConnection connection) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException
NOTE: the method is asynchronous and does not wait for the returned value.
connection
- the XMPPConnection to use.XMPPException.XMPPErrorException
- thrown if there was an issue setting the VCard in the server.SmackException.NoResponseException
- if there was no response from the server.SmackException.NotConnectedException
public void load(XMPPConnection connection) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException
public void load(XMPPConnection connection, String user) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException
XMPPException.XMPPErrorException
SmackException.NoResponseException
- if there was no response from the server.SmackException.NotConnectedException
public String getChildElementXML()
IQ
Extensions of this class must override this method.
getChildElementXML
in class IQ