Class VCard
- java.lang.Object
-
- org.jivesoftware.smack.packet.Stanza
-
- org.jivesoftware.smack.packet.IQ
-
- org.jivesoftware.smackx.vcardtemp.packet.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jivesoftware.smack.packet.IQ
IQ.IQChildElementXmlStringBuilder, IQ.ResponseType, IQ.Type
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ELEMENT
static java.lang.String
NAMESPACE
-
Fields inherited from class org.jivesoftware.smack.packet.IQ
IQ_ELEMENT, QUERY_ELEMENT
-
Fields inherited from class org.jivesoftware.smack.packet.Stanza
DEFAULT_LANGUAGE, ITEM, language, TEXT
-
-
Constructor Summary
Constructors Constructor Description VCard()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
java.lang.String
getAddressFieldHome(java.lang.String addrField)
Get home address field.java.lang.String
getAddressFieldWork(java.lang.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.java.lang.String
getAvatarHash()
Returns the SHA-1 Hash of the Avatar image.java.lang.String
getAvatarMimeType()
Returns the MIME Type of the avatar or null if none is set.static byte[]
getBytes(java.net.URL url)
Common code for getting the bytes of a url.java.lang.String
getEmailHome()
java.lang.String
getEmailWork()
java.lang.String
getField(java.lang.String field)
Get the content of a generic VCard field.java.lang.String
getFirstName()
protected IQ.IQChildElementXmlStringBuilder
getIQChildElementBuilder(IQ.IQChildElementXmlStringBuilder xml)
This method must be overwritten by IQ subclasses to create their child content.java.lang.String
getJabberId()
java.lang.String
getLastName()
java.lang.String
getMiddleName()
java.lang.String
getNickName()
java.lang.String
getOrganization()
java.lang.String
getOrganizationUnit()
java.lang.String
getPhoneHome(java.lang.String phoneType)
Get home phone number.java.lang.String
getPhoneWork(java.lang.String phoneType)
Get work phone number.java.lang.String
getPrefix()
java.lang.String
getSuffix()
int
hashCode()
void
load(XMPPConnection connection)
Deprecated.useVCardManager.loadVCard()
instead.void
load(XMPPConnection connection, EntityBareJid user)
Deprecated.useVCardManager.loadVCard(EntityBareJid)
instead.void
removeAvatar()
Removes the avatar from the vCard.void
save(XMPPConnection connection)
Deprecated.useVCardManager.saveVCard(VCard)
instead.void
setAddressFieldHome(java.lang.String addrField, java.lang.String value)
Set home address field.void
setAddressFieldWork(java.lang.String addrField, java.lang.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, java.lang.String mimeType)
Specify the bytes for the avatar to use as well as the mime type.void
setAvatar(java.lang.String encodedImage, java.lang.String mimeType)
Specify the Avatar used for this vCard.void
setAvatar(java.net.URL avatarURL)
Set the avatar for the VCard by specifying the url to the image.void
setEmailHome(java.lang.String email)
void
setEmailWork(java.lang.String emailWork)
void
setEncodedImage(java.lang.String encodedAvatar)
Deprecated.UsesetAvatar(String, String)
instead.void
setField(java.lang.String field, java.lang.String value)
Set generic VCard field.void
setField(java.lang.String field, java.lang.String value, boolean isUnescapable)
Set generic, unescapable VCard field.void
setFirstName(java.lang.String firstName)
void
setJabberId(java.lang.CharSequence jabberId)
void
setLastName(java.lang.String lastName)
void
setMiddleName(java.lang.String middleName)
void
setNickName(java.lang.String nickName)
void
setOrganization(java.lang.String organization)
void
setOrganizationUnit(java.lang.String organizationUnit)
void
setPhoneHome(java.lang.String phoneType, java.lang.String phoneNum)
Set home phone number.void
setPhoneWork(java.lang.String phoneType, java.lang.String phoneNum)
Set work phone number.void
setPrefix(java.lang.String prefix)
void
setSuffix(java.lang.String suffix)
-
Methods inherited from class org.jivesoftware.smack.packet.IQ
createErrorResponse, createErrorResponse, createErrorResponse, createResultIQ, getChildElementName, getChildElementNamespace, getChildElementQName, getChildElementXML, getElementName, getType, setType, toString, toXML
-
Methods inherited from class org.jivesoftware.smack.packet.Stanza
addCommonAttributes, addExtension, addExtensions, appendErrorIfExists, getDefaultLanguage, getError, getExtension, getExtension, getExtension, getExtensionElement, getExtensions, getExtensions, getExtensions, getExtensions, getExtensionsMap, getFrom, getLanguage, getNamespace, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, logCommonAttributes, overrideExtension, removeExtension, removeExtension, setError, setError, setFrom, setLanguage, setNewStanzaId, setStanzaId, setStanzaId, setTo, throwIfNoStanzaId
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.packet.FullyQualifiedElement
getQName
-
Methods inherited from interface org.jivesoftware.smack.packet.IqView
isRequestIQ, isResponseIQ
-
Methods inherited from interface org.jivesoftware.smack.packet.StanzaView
getError, getExtension, getExtension, getExtensions, getExtensions, getExtensions, getFrom, getStanzaId, getTo, hasExtension, hasExtension, hasExtension
-
-
-
-
Field Detail
-
ELEMENT
public static final java.lang.String ELEMENT
- See Also:
- Constant Field Values
-
NAMESPACE
public static final java.lang.String NAMESPACE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
VCard
public VCard()
-
-
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 fieldfield
- field to set. SeegetField(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 fieldfield
- field to set. SeegetField(String)
isUnescapable
- True if the value should not be escaped, and false if it should.
-
getFirstName
public java.lang.String getFirstName()
-
setFirstName
public void setFirstName(java.lang.String firstName)
-
getLastName
public java.lang.String getLastName()
-
setLastName
public void setLastName(java.lang.String lastName)
-
getMiddleName
public java.lang.String getMiddleName()
-
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)
-
getNickName
public java.lang.String getNickName()
-
setNickName
public void setNickName(java.lang.String nickName)
-
getEmailHome
public java.lang.String getEmailHome()
-
setEmailHome
public void setEmailHome(java.lang.String email)
-
getEmailWork
public java.lang.String getEmailWork()
-
setEmailWork
public void setEmailWork(java.lang.String emailWork)
-
getJabberId
public java.lang.String getJabberId()
-
setJabberId
public void setJabberId(java.lang.CharSequence jabberId)
-
getOrganization
public java.lang.String getOrganization()
-
setOrganization
public void setOrganization(java.lang.String organization)
-
getOrganizationUnit
public java.lang.String getOrganizationUnit()
-
setOrganizationUnit
public void setOrganizationUnit(java.lang.String organizationUnit)
-
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, CTRYvalue
- 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, CTRYvalue
- 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, PREFphoneNum
- 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, PREFphoneNum
- 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 StringmimeType
- the MIME type of the image
-
setEncodedImage
@Deprecated public void setEncodedImage(java.lang.String encodedAvatar)
Deprecated.UsesetAvatar(String, String)
instead.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.
-
save
@Deprecated public void save(XMPPConnection connection) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Deprecated.useVCardManager.saveVCard(VCard)
instead.Save this vCard for the user connected by 'connection'. XMPPConnection should be authenticated and not anonymous.- Parameters:
connection
- the XMPPConnection to use.- Throws:
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
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.
-
load
@Deprecated public void load(XMPPConnection connection) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Deprecated.useVCardManager.loadVCard()
instead.Load VCard information for a connected user. XMPPConnection should be authenticated and not anonymous.- Parameters:
connection
- connection.- Throws:
XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NoResponseException
- if there was no response from the remote entity.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.
-
load
@Deprecated public void load(XMPPConnection connection, EntityBareJid user) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
Deprecated.useVCardManager.loadVCard(EntityBareJid)
instead.Load VCard information for a given user. XMPPConnection should be authenticated and not anonymous.- Parameters:
connection
- connection.user
- user whos information we want to load.- Throws:
XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NoResponseException
- if there was no response from the server.SmackException.NotConnectedException
- if the XMPP connection is not connected.java.lang.InterruptedException
- if the calling thread was interrupted.
-
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 byIQ.IQChildElementXmlStringBuilder
after eventual existingExtensionElement
s 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>
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')
xml.attribute("myAttribute", "myAttributeValue"); xml.setEmptyElement();
If your IQ does not contain any attributes or child elements (besidesExtensionElement
s), consider sub-classingSimpleIQ
instead.- Specified by:
getIQChildElementBuilder
in classIQ
- 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 classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-