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 Details

    • Log

      public static final org.slf4j.Logger Log
    • DISABLED

      public static final SystemProperty<Boolean> DISABLED
  • Constructor Details

    • UserAvatarToVCardConvertor

      public UserAvatarToVCardConvertor()
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Module
      Returns the name of the module for display in administration interfaces.
      Specified by:
      getName in interface Module
      Returns:
      The name of the module.
    • initialize

      public void initialize(XMPPServer server)
      Description copied from interface: Module
      Initialize 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:
      initialize in interface Module
      Parameters:
      server - the server hosting this module.
    • start

      public void start()
      Description copied from interface: Module
      Start the module (must return quickly). Any long running operations should spawn a thread and allow the method to return immediately.
      Specified by:
      start in interface Module
    • stop

      public void stop()
      Description copied from interface: Module
      Stop the module. The module should attempt to free up threads and prepare for either another call to initialize (reconfigure the module) or for destruction.
      Specified by:
      stop in interface Module
    • destroy

      public void destroy()
      Description copied from interface: Module
      Module should free all resources and prepare for deallocation.
      Specified by:
      destroy in interface Module
    • itemsPublished

      public void itemsPublished(@Nonnull Node.UniqueIdentifier nodeId, @Nonnull Collection<PublishedItem> items)
      Description copied from interface: PubSubListener
      One or more items were published on a node. All items are published on the same node.
      Specified by:
      itemsPublished in interface PubSubListener
      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: PubSubListener
      One or more items were deleted from a node. All items are deleted from the same node.
      Specified by:
      itemsDeleted in interface PubSubListener
      Parameters:
      nodeId - the identifier of the node on which the items were published.
      items - the deleted items.
    • vCardCreated

      public void vCardCreated(String username, org.dom4j.Element vCard)
      Description copied from interface: VCardListener
      A vCard was created.
      Specified by:
      vCardCreated in interface VCardListener
      Parameters:
      username - the username for which the vCard was created.
      vCard - the vcard created.
    • vCardUpdated

      public void vCardUpdated(String username, org.dom4j.Element vCard)
      Description copied from interface: VCardListener
      A vCard was updated.
      Specified by:
      vCardUpdated in interface VCardListener
      Parameters:
      username - the user for which the vCard was updated.
      vCard - the vcard updated.
    • vCardDeleted

      public void vCardDeleted(String username, org.dom4j.Element vCard)
      Description copied from interface: VCardListener
      A vCard was deleted.
      Specified by:
      vCardDeleted in interface VCardListener
      Parameters:
      username - the user for which the vCard was deleted.
      vCard - the vcard deleted.
    • attemptPepUpdate

      public void attemptPepUpdate(String username, org.dom4j.Element vCard) throws RuntimeException
      Throws:
      RuntimeException
    • decode

      public static byte[] decode(String binVal)
      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.
    • 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 published
      binVal - The hex-encoded binary representation of the avatar that is published
      hash - (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 published
      decodedBinVal - The binary representation of the avatar for which metadata is published
      hash - (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.