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
IQ.IQChildElementXmlStringBuilder, IQ.Type
Modifier and Type | Field and Description |
---|---|
static String |
ELEMENT |
static String |
NAMESPACE |
IQ_ELEMENT, QUERY_ELEMENT
DEFAULT_LANGUAGE, ITEM, language, TEXT
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 |
getEmailHome() |
String |
getEmailWork() |
String |
getField(String field)
Set generic VCard field.
|
String |
getFirstName() |
protected IQ.IQChildElementXmlStringBuilder |
getIQChildElementBuilder(IQ.IQChildElementXmlStringBuilder xml)
This method must be overwritten by IQ subclasses to create their child content.
|
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
|
String |
getPrefix() |
String |
getSuffix() |
int |
hashCode() |
void |
load(XMPPConnection connection)
Deprecated.
use
VCardManager.loadVCard() instead. |
void |
load(XMPPConnection connection,
String user)
Deprecated.
use
VCardManager.loadVCard(String) instead. |
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)
Deprecated.
use
VCardManager.saveVCard(VCard) instead. |
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
|
void |
setPrefix(String prefix) |
void |
setSuffix(String suffix) |
createErrorResponse, createResultIQ, getChildElementName, getChildElementNamespace, getChildElementXML, getType, isRequestIQ, setType, toXML
addCommonAttributes, addExtension, addExtensions, appendErrorIfExists, getDefaultLanguage, getError, getExtension, getExtension, getExtensions, getExtensions, getExtensionsXML, getFrom, getLanguage, getPacketID, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, overrideExtension, removeExtension, removeExtension, setError, setFrom, setLanguage, setPacketID, setStanzaId, setTo, toString
public static final String ELEMENT
public static final String NAMESPACE
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 image@Deprecated public 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()
@Deprecated public void save(XMPPConnection connection) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException
VCardManager.saveVCard(VCard)
instead.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
@Deprecated public void load(XMPPConnection connection) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException
VCardManager.loadVCard()
instead.@Deprecated public void load(XMPPConnection connection, String user) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException
VCardManager.loadVCard(String)
instead.XMPPException.XMPPErrorException
SmackException.NoResponseException
- if there was no response from the server.SmackException.NotConnectedException
protected IQ.IQChildElementXmlStringBuilder getIQChildElementBuilder(IQ.IQChildElementXmlStringBuilder xml)
IQ
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 stanza(/packet) extensions), consider sub-classing
SimpleIQ
instead.getIQChildElementBuilder
in class IQ
xml
- a pre-created builder which already has the child element and the 'xmlns' attribute set.