Class UserAvatarToVCardConvertor
java.lang.Object
org.jivesoftware.openfire.vcard.xep0398.UserAvatarToVCardConvertor
- All Implemented Interfaces:
Module,PubSubListener,VCardListener
public class UserAvatarToVCardConvertor
extends Object
implements VCardListener, PubSubListener, Module
Utility methods that help convert various User Avatar representations into each-other.
- Author:
- Guus der Kinderen, guus@goodbytes.nl
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SystemProperty<Boolean>static final org.slf4j.Logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidattemptPepUpdate(String username, org.dom4j.Element vCard) static byte[]Decodes a base64-encoded binary value.voiddestroy()Module should free all resources and prepare for deallocation.static org.xmpp.packet.IQgeneratePublishDataRequest(org.xmpp.packet.JID owner, String binVal, String hash) Creates an IQ stanza that is appropriate to publish an item to the avatar data node of the PEP service of a particular user.static org.xmpp.packet.IQgeneratePublishMetadataRequest(org.xmpp.packet.JID owner, byte[] decodedBinVal, String hash, String type) Creates an IQ stanza that is appropriate to publish an item to the avatar metadata node of the PEP service of a particular user.static int[]getDimensions(byte[] bytes) Finds the width and height (in pixels) of an image.getName()Returns the name of the module for display in administration interfaces.static StringCalculated the SHA-1 hash of Base64-encoded datavoidinitialize(XMPPServer server) Initialize the module with the container.voiditemsDeleted(Node.UniqueIdentifier nodeId, Collection<PublishedItem> items) One or more items were deleted from a node.voiditemsPublished(Node.UniqueIdentifier nodeId, Collection<PublishedItem> items) One or more items were published on a node.voidstart()Start the module (must return quickly).voidstop()Stop the module.voidvCardCreated(String username, org.dom4j.Element vCard) A vCard was created.voidvCardDeleted(String username, org.dom4j.Element vCard) A vCard was deleted.voidvCardUpdated(String username, org.dom4j.Element vCard) A vCard was updated.
-
Field Details
-
Log
public static final org.slf4j.Logger Log -
DISABLED
-
-
Constructor Details
-
UserAvatarToVCardConvertor
public UserAvatarToVCardConvertor()
-
-
Method Details
-
getName
Description copied from interface:ModuleReturns the name of the module for display in administration interfaces. -
initialize
Description copied from interface:ModuleInitialize the module with the container. Modules may be initialized and never started, so modules should be prepared for a call to destroy() to follow initialize().- Specified by:
initializein interfaceModule- Parameters:
server- the server hosting this module.
-
start
public void start()Description copied from interface:ModuleStart the module (must return quickly). Any long running operations should spawn a thread and allow the method to return immediately. -
stop
public void stop()Description copied from interface:ModuleStop the module. The module should attempt to free up threads and prepare for either another call to initialize (reconfigure the module) or for destruction. -
destroy
public void destroy()Description copied from interface:ModuleModule should free all resources and prepare for deallocation. -
itemsPublished
public void itemsPublished(@Nonnull Node.UniqueIdentifier nodeId, @Nonnull Collection<PublishedItem> items) Description copied from interface:PubSubListenerOne or more items were published on a node. All items are published on the same node.- Specified by:
itemsPublishedin interfacePubSubListener- Parameters:
nodeId- the identifier of the node on which the items were published.items- the published items.
-
itemsDeleted
public void itemsDeleted(@Nonnull Node.UniqueIdentifier nodeId, @Nonnull Collection<PublishedItem> items) Description copied from interface:PubSubListenerOne or more items were deleted from a node. All items are deleted from the same node.- Specified by:
itemsDeletedin interfacePubSubListener- Parameters:
nodeId- the identifier of the node on which the items were published.items- the deleted items.
-
vCardCreated
Description copied from interface:VCardListenerA vCard was created.- Specified by:
vCardCreatedin interfaceVCardListener- Parameters:
username- the username for which the vCard was created.vCard- the vcard created.
-
vCardUpdated
Description copied from interface:VCardListenerA vCard was updated.- Specified by:
vCardUpdatedin interfaceVCardListener- Parameters:
username- the user for which the vCard was updated.vCard- the vcard updated.
-
vCardDeleted
Description copied from interface:VCardListenerA vCard was deleted.- Specified by:
vCardDeletedin interfaceVCardListener- Parameters:
username- the user for which the vCard was deleted.vCard- the vcard deleted.
-
attemptPepUpdate
- Throws:
RuntimeException
-
decode
Decodes a base64-encoded binary value. This method can decode both Mime-encoded as well as non-Mime-encoded values.- Parameters:
binVal- The value to decode- Returns:
- the decoded value.
-
hash
Calculated the SHA-1 hash of Base64-encoded data- Parameters:
base64EncodedData- The data for which to return a hash- Returns:
- the hash
-
generatePublishDataRequest
public static org.xmpp.packet.IQ generatePublishDataRequest(@Nonnull org.xmpp.packet.JID owner, @Nonnull String binVal, @Nullable String hash) Creates an IQ stanza that is appropriate to publish an item to the avatar data node of the PEP service of a particular user.- Parameters:
owner- The owner of the PEP service on which data is to be publishedbinVal- The hex-encoded binary representation of the avatar that is publishedhash- (optional) The SHA-1 hash of the binary data (will be calculated from decodedBinVal if not provided)- Returns:
- An IQ stanza
-
generatePublishMetadataRequest
public static org.xmpp.packet.IQ generatePublishMetadataRequest(@Nonnull org.xmpp.packet.JID owner, @Nonnull byte[] decodedBinVal, @Nullable String hash, @Nonnull String type) Creates an IQ stanza that is appropriate to publish an item to the avatar metadata node of the PEP service of a particular user.- Parameters:
owner- The owner of the PEP service on which data is to be publisheddecodedBinVal- The binary representation of the avatar for which metadata is publishedhash- (optional) The SHA-1 hash of the binary data (will be calculated from decodedBinVal if not provided)type- The media type of the image- Returns:
- An IQ stanza
-
getDimensions
public static int[] getDimensions(byte[] bytes) Finds the width and height (in pixels) of an image. This method returns an array of size 2. The first element is the width, the second element the height of the image. When the provided data could not be processed, this method returns null.- Parameters:
bytes- the raw bytes of an image.- Returns:
- an array containing the width and height of the image, or null if the dimensions could not be determined.
-