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,IqView,NamedElement,StanzaView,TopLevelStreamElement,XmlElement,XmlLangElement
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
FieldsFields inherited from class org.jivesoftware.smack.packet.IQ
IQ_ELEMENT, QUERY_ELEMENTFields inherited from class org.jivesoftware.smack.packet.Stanza
DEFAULT_LANGUAGE, ITEM, language, TEXT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleangetAddressFieldHome(String addrField) Get home address field.getAddressFieldWork(String addrField) Get work address field.byte[]Return the byte representation of the avatar(if one exists), otherwise returns null if no avatar could be found.Returns the SHA-1 Hash of the Avatar image.Returns the MIME Type of the avatar or null if none is set.static byte[]Common code for getting the bytes of a url.Get the content of a generic VCard field.protected IQ.IQChildElementXmlStringBuilderThis method must be overwritten by IQ subclasses to create their child content.getPhoneHome(String phoneType) Get home phone number.getPhoneWork(String phoneType) Get work phone number.inthashCode()voidload(XMPPConnection connection) Deprecated.voidload(XMPPConnection connection, EntityBareJid user) Deprecated.useVCardManager.loadVCard(EntityBareJid)instead.voidRemoves the avatar from the vCard.voidsave(XMPPConnection connection) Deprecated.useVCardManager.saveVCard(VCard)instead.voidsetAddressFieldHome(String addrField, String value) Set home address field.voidsetAddressFieldWork(String addrField, String value) Set work address field.voidsetAvatar(byte[] bytes) Specify the bytes of the JPEG for the avatar to use.voidSpecify the bytes for the avatar to use as well as the mime type.voidSpecify the Avatar used for this vCard.voidSet the avatar for the VCard by specifying the url to the image.voidsetEmailHome(String email) voidsetEmailWork(String emailWork) voidsetEncodedImage(String encodedAvatar) Deprecated.UsesetAvatar(String, String)instead.voidSet generic VCard field.voidSet generic, unescapable VCard field.voidsetFirstName(String firstName) voidsetJabberId(CharSequence jabberId) voidsetLastName(String lastName) voidsetMiddleName(String middleName) voidsetNickName(String nickName) voidsetOrganization(String organization) voidsetOrganizationUnit(String organizationUnit) voidsetPhoneHome(String phoneType, String phoneNum) Set home phone number.voidsetPhoneWork(String phoneType, String phoneNum) Set work phone number.voidvoidMethods inherited from class org.jivesoftware.smack.packet.IQ
createErrorResponse, createErrorResponse, createResultIQ, getChildElementName, getChildElementNamespace, getChildElementQName, getChildElementXML, getElementName, getType, setType, toString, toXMLMethods inherited from class org.jivesoftware.smack.packet.Stanza
addCommonAttributes, addExtension, addExtensions, appendErrorIfExists, getDefaultLanguage, getError, getExtension, getExtension, getExtensionElement, getExtensions, getExtensions, getExtensions, getExtensions, getExtensionsMap, getFrom, getLanguage, getNamespace, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, logCommonAttributes, overrideExtension, removeExtension, setError, setFrom, setNewStanzaId, setStanzaId, setTo, throwIfNoStanzaIdMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jivesoftware.smack.packet.IqView
isRequestIQ, isResponseIQMethods inherited from interface org.jivesoftware.smack.packet.StanzaView
getError, getExtension, getExtension, getExtensions, getExtensions, getExtensions, getFrom, getStanzaId, getTo, hasExtension, hasExtension, hasExtensionMethods inherited from interface org.jivesoftware.smack.packet.XmlElement
getQName
-
Field Details
-
ELEMENT
- See Also:
-
NAMESPACE
- See Also:
-
-
Constructor Details
-
VCard
public VCard()
-
-
Method Details
-
getField
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
Set generic VCard field.- Parameters:
value- value of fieldfield- field to set. SeegetField(String)- See Also:
-
setField
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
-
setFirstName
-
getLastName
-
setLastName
-
getMiddleName
-
setMiddleName
-
getPrefix
-
setPrefix
-
getSuffix
-
setSuffix
-
getNickName
-
setNickName
-
getEmailHome
-
setEmailHome
-
getEmailWork
-
setEmailWork
-
getJabberId
-
setJabberId
-
getOrganization
-
setOrganization
-
getOrganizationUnit
-
setOrganizationUnit
-
getAddressFieldHome
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
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
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
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
Set home phone number.- Parameters:
phoneType- one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREFphoneNum- phone number
-
getPhoneHome
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
Set work phone number.- Parameters:
phoneType- one of VOICE, FAX, PAGER, MSG, CELL, VIDEO, BBS, MODEM, ISDN, PCS, PREFphoneNum- phone number
-
getPhoneWork
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
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
Removes the avatar from the vCard. This is done by setting the PHOTO value to the empty string as defined in XEP-0153 -
setAvatar
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
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
Specify the Avatar used for this vCard.- Parameters:
encodedImage- the Base64 encoded image as StringmimeType- the MIME type of the image
-
setEncodedImage
Deprecated.UsesetAvatar(String, String)instead.Set the encoded avatar string. This is used by the provider.- Parameters:
encodedAvatar- the encoded avatar string.
-
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
Returns the MIME Type of the avatar or null if none is set.- Returns:
- the MIME Type of the avatar or null
-
getBytes
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
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, 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.InterruptedException- if the calling thread was interrupted.
-
load
@Deprecated public void load(XMPPConnection connection) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, 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.InterruptedException- if the calling thread was interrupted.
-
load
@Deprecated public void load(XMPPConnection connection, EntityBareJid user) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, 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 whose 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.InterruptedException- if the calling thread was interrupted.
-
getIQChildElementBuilder
protected IQ.IQChildElementXmlStringBuilder getIQChildElementBuilder(IQ.IQChildElementXmlStringBuilder xml) Description copied from class:IQThis 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.IQChildElementXmlStringBuilderafter eventual existingExtensionElements have been added.For example to create an IQ with a extra attribute and an additional child element
the body of the<iq to='foo@example.org' id='123'> <bar xmlns='example:bar' extraAttribute='blaz'> <extraElement>elementText</extraElement> </bar> </iq>getIQChildElementBuilderlooks like
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.// 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 (besidesExtensionElements), consider sub-classingSimpleIQinstead.- Specified by:
getIQChildElementBuilderin 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
-
hashCode
-
VCardManager.loadVCard()instead.