Class UserNameManager


  • public class UserNameManager
    extends Object
    Main responsibility of this class is to return the correct name of XMPP entities. For local entities (i.e. users) the User name is used. For remote entities the following logic is used:
    1. Check if a UserNameProvider is registered for the entity's domain. If a provider was found then use it to get the entity's name
    2. If no provider was found then retrieve the vCard of the entity and return the name as defined in the vCard. This is not implemented yet.
    3. If no vCard was found then return the string representation of the entity's JID.
    Author:
    Gaston Dombiak
    • Method Detail

      • addUserNameProvider

        public static void addUserNameProvider​(String domain,
                                               UserNameProvider provider)
        Adds the specified UserNameProvider as the provider of users of the specified domain.
        Parameters:
        domain - the domain hosted by the UserNameProvider.
        provider - the provider that will provide the name of users in the specified domain.
      • removeUserNameProvider

        public static void removeUserNameProvider​(String domain)
        Removes any UserNameProvider that was associated with the specified domain.
        Parameters:
        domain - the domain hosted by a UserNameProvider.
      • getUserName

        public static String getUserName​(org.xmpp.packet.JID entity)
                                  throws UserNotFoundException
        Returns the name of the XMPP entity. If the entity is a local user then the User's name will be returned. However, if the user is not a local user then check if there exists a UserNameProvider that provides name for the specified domain. If none was found then the vCard of the entity might be requested and if none was found then a string representation of the entity's JID will be returned.
        Parameters:
        entity - the JID of the entity to get its name.
        Returns:
        the name of the XMPP entity.
        Throws:
        UserNotFoundException - if the jid belongs to the local server but no user was found for that jid.
      • getUserName

        public static String getUserName​(org.xmpp.packet.JID entity,
                                         String defaultName)
                                  throws UserNotFoundException
        Returns the name of the XMPP entity. If the entity is a local user then the User's name will be returned. However, if the user is not a local user then check if there exists a UserNameProvider that provides name for the specified domain. If none was found then the vCard of the entity might be requested and if none was found then a string representation of the entity's JID will be returned.
        Parameters:
        entity - the JID of the entity to get its name.
        defaultName - default name to return when no name was found.
        Returns:
        the name of the XMPP entity.
        Throws:
        UserNotFoundException - if the jid belongs to the local server but no user was found for that jid.