Class JidCreate


  • public class JidCreate
    extends java.lang.Object
    API to create JIDs (XMPP addresses) from Strings and CharSequences.

    If the input was user generated, e.g. captured from some sort of user interface, fromUnescaped(String) should be used instead. This allows the user to enter unescaped JID values. You can use JidUtil.isValidEntityBareJid(CharSequence) to query, e.g. while the user it entering it, if a given CharSequence is a valid bare JID.

    JIDs created from input received from an XMPP source should use from(String).

    JidCreate uses caches for efficient Jid construction, But it's not guaranteed that the same String or CharSequence will yield the same Jid instance.

    See Also:
    Jid
    • Constructor Detail

      • JidCreate

        public JidCreate()
    • Method Detail

      • from

        public static Jid from​(java.lang.CharSequence localpart,
                               java.lang.CharSequence domainpart,
                               java.lang.CharSequence resource)
                        throws XmppStringprepException
        Get a Jid from the given parts.

        Only the domainpart is required.

        Parameters:
        localpart - a optional localpart.
        domainpart - a required domainpart.
        resource - a optional resourcepart.
        Returns:
        a JID which consists of the given parts.
        Throws:
        XmppStringprepException - if an error occurs.
      • from

        public static Jid from​(java.lang.String localpart,
                               java.lang.String domainpart,
                               java.lang.String resource)
                        throws XmppStringprepException
        Get a Jid from the given parts.

        Only the domainpart is required.

        Parameters:
        localpart - a optional localpart.
        domainpart - a required domainpart.
        resource - a optional resourcepart.
        Returns:
        a JID which consists of the given parts.
        Throws:
        XmppStringprepException - if an error occurs.
      • from

        public static Jid from​(java.lang.String localpart,
                               java.lang.String domainpart,
                               java.lang.String resource,
                               JxmppContext context)
                        throws XmppStringprepException
        Get a Jid from the given parts.

        Only the domainpart is required.

        Parameters:
        localpart - a optional localpart.
        domainpart - a required domainpart.
        resource - a optional resourcepart.
        context - the JXMPP context.
        Returns:
        a JID which consists of the given parts.
        Throws:
        XmppStringprepException - if an error occurs.
      • fromOrThrowUnchecked

        public static Jid fromOrThrowUnchecked​(java.lang.CharSequence cs)
        Like from(CharSequence) but does throw an unchecked IllegalArgumentException instead of a XmppStringprepException.
        Parameters:
        cs - the character sequence which should be transformed to a Jid
        Returns:
        the Jid if no exception occurs
        Throws:
        java.lang.IllegalArgumentException - if the given input is not a valid JID
        Since:
        0.6.2
        See Also:
        from(String)
      • fromOrNull

        public static Jid fromOrNull​(java.lang.CharSequence cs)
        Get a Jid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • fromUnescapedOrThrowUnchecked

        public static Jid fromUnescapedOrThrowUnchecked​(java.lang.CharSequence cs)
        Like fromUnescaped(CharSequence) but does throw an unchecked IllegalArgumentException instead of a XmppStringprepException.
        Parameters:
        cs - the character sequence which should be transformed to a Jid
        Returns:
        the Jid if no exception occurs
        Throws:
        java.lang.IllegalArgumentException - if the given input is not a valid JID
        Since:
        0.6.2
        See Also:
        fromUnescaped(CharSequence)
      • fromUnescaped

        public static Jid fromUnescaped​(java.lang.CharSequence unescapedJid)
                                 throws XmppStringprepException
        Get a Jid from the given unescaped CharSequence.
        Parameters:
        unescapedJid - an unescaped CharSequence representing a JID.
        Returns:
        a JID.
        Throws:
        XmppStringprepException - if an error occurs.
      • fromUnescaped

        public static Jid fromUnescaped​(java.lang.String unescapedJidString)
                                 throws XmppStringprepException
        Get a Jid from the given unescaped String.
        Parameters:
        unescapedJidString - a unescaped String representing a JID.
        Returns:
        a JID.
        Throws:
        XmppStringprepException - if an error occurs.
      • fromUnescapedOrNull

        public static Jid fromUnescapedOrNull​(java.lang.CharSequence cs)
        Get a Jid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • fromUrlEncoded

        public static Jid fromUrlEncoded​(java.lang.CharSequence cs)
                                  throws XmppStringprepException
        Get a Jid from an URL encoded CharSequence.
        Parameters:
        cs - a CharSequence representing an URL encoded JID.
        Returns:
        a JID
        Throws:
        XmppStringprepException - if an error occurs.
        See Also:
        URLDecoder
      • bareFromOrThrowUnchecked

        public static BareJid bareFromOrThrowUnchecked​(java.lang.CharSequence cs)
        Like bareFrom(CharSequence) but does throw an unchecked IllegalArgumentException instead of a XmppStringprepException.
        Parameters:
        cs - the character sequence which should be transformed to a BareJid
        Returns:
        the BareJid if no exception occurs
        Throws:
        java.lang.IllegalArgumentException - if the given input is not a valid JID
        Since:
        0.6.2
        See Also:
        bareFrom(CharSequence)
      • bareFrom

        public static BareJid bareFrom​(java.lang.CharSequence jid)
                                throws XmppStringprepException
        Get a BareJid representing the given CharSequence.
        Parameters:
        jid - the input CharSequence.
        Returns:
        a bare JID representing the given CharSequence.
        Throws:
        XmppStringprepException - if an error occurs.
      • bareFrom

        public static BareJid bareFrom​(Localpart localpart,
                                       DomainBareJid domainBareJid)
        Get a BareJid constructed from the optionally given Localpart and {link DomainBareJid}.
        Parameters:
        localpart - a optional localpart.
        domainBareJid - a domain bare JID.
        Returns:
        a bare JID.
      • bareFrom

        public static BareJid bareFrom​(Localpart localpart,
                                       Domainpart domain)
        Get a BareJid constructed from the optionally given Localpart and Domainpart.
        Parameters:
        localpart - a optional localpart.
        domain - a domainpart.
        Returns:
        a bare JID constructed from the given parts.
      • bareFromOrNull

        public static BareJid bareFromOrNull​(java.lang.CharSequence cs)
        Get a BareJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • bareFromUrlEncoded

        public static BareJid bareFromUrlEncoded​(java.lang.CharSequence cs)
                                          throws XmppStringprepException
        Get a BareJid from an URL encoded CharSequence.
        Parameters:
        cs - a CharSequence representing an URL encoded bare JID.
        Returns:
        a bare JID
        Throws:
        XmppStringprepException - if an error occurs.
        See Also:
        URLDecoder
      • fullFromOrThrowUnchecked

        public static FullJid fullFromOrThrowUnchecked​(java.lang.CharSequence cs)
        Like fullFrom(CharSequence) but does throw an unchecked IllegalArgumentException instead of a XmppStringprepException.
        Parameters:
        cs - the character sequence which should be transformed to a FullJid
        Returns:
        the FullJid if no exception occurs
        Throws:
        java.lang.IllegalArgumentException - if the given input is not a valid JID
        Since:
        0.6.2
        See Also:
        fullFrom(CharSequence)
      • fullFrom

        public static FullJid fullFrom​(java.lang.CharSequence jid)
                                throws XmppStringprepException
        Get a FullJid representing the given CharSequence.
        Parameters:
        jid - a CharSequence representing a JID.
        Returns:
        a full JID representing the given CharSequence.
        Throws:
        XmppStringprepException - if an error occurs.
      • fullFrom

        public static FullJid fullFrom​(java.lang.String localpart,
                                       java.lang.String domainpart,
                                       java.lang.String resource)
                                throws XmppStringprepException
        Get a FullJid constructed from the given parts.
        Parameters:
        localpart - a optional localpart.
        domainpart - a domainpart.
        resource - a resourcepart.
        Returns:
        a full JID.
        Throws:
        XmppStringprepException - if an error occurs.
      • fullFrom

        public static FullJid fullFrom​(java.lang.String localpart,
                                       java.lang.String domainpart,
                                       java.lang.String resource,
                                       JxmppContext context)
                                throws XmppStringprepException
        Get a FullJid constructed from the given parts.
        Parameters:
        localpart - a optional localpart.
        domainpart - a domainpart.
        resource - a resourcepart.
        context - the JXMPP context.
        Returns:
        a full JID.
        Throws:
        XmppStringprepException - if an error occurs.
      • fullFrom

        public static FullJid fullFrom​(Localpart localpart,
                                       DomainBareJid domainBareJid,
                                       Resourcepart resource)
        Get a FullJid constructed from the given parts.
        Parameters:
        localpart - a optional localpart.
        domainBareJid - a domain bare JID.
        resource - a resourcepart
        Returns:
        a full JID.
      • fullFrom

        public static FullJid fullFrom​(Localpart localpart,
                                       Domainpart domainpart,
                                       Resourcepart resource)
        Get a FullJid constructed from the given parts.
        Parameters:
        localpart - the optional localpart.
        domainpart - the domainpart.
        resource - the resourcepart.
        Returns:
        a full JID.
      • fullFromOrNull

        public static FullJid fullFromOrNull​(java.lang.CharSequence cs)
        Get a FullJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • fullFromUrlEncoded

        public static FullJid fullFromUrlEncoded​(java.lang.CharSequence cs)
                                          throws XmppStringprepException
        Get a FullJid from an URL encoded CharSequence.
        Parameters:
        cs - a CharSequence representing an URL encoded full JID.
        Returns:
        a full JID
        Throws:
        XmppStringprepException - if an error occurs.
        See Also:
        URLDecoder
      • entityFromOrThrowUnchecked

        public static EntityJid entityFromOrThrowUnchecked​(java.lang.CharSequence cs)
        Like entityFrom(CharSequence) but does throw an unchecked IllegalArgumentException instead of a XmppStringprepException.
        Parameters:
        cs - the character sequence which should be transformed to a EntityJid
        Returns:
        the EntityJid if no exception occurs
        Throws:
        java.lang.IllegalArgumentException - if the given input is not a valid JID
        Since:
        0.6.2
        See Also:
        entityFrom(CharSequence)
      • entityFromUnescaped

        public static EntityJid entityFromUnescaped​(java.lang.String jidString)
                                             throws XmppStringprepException
        Get a EntityJid representing the given String.
        Parameters:
        jidString - the JID's string.
        Returns:
        an entity JID representing the given String.
        Throws:
        XmppStringprepException - if an error occurs.
      • entityFromUnesacpedOrNull

        @Deprecated
        public static EntityJid entityFromUnesacpedOrNull​(java.lang.CharSequence cs)
        Deprecated.
        Get a EntityJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • entityFromUnescapedOrNull

        public static EntityJid entityFromUnescapedOrNull​(java.lang.CharSequence cs)
        Get a EntityJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • entityFromOrNull

        public static EntityJid entityFromOrNull​(java.lang.CharSequence cs)
        Get a EntityJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • entityFromUrlEncoded

        public static EntityJid entityFromUrlEncoded​(java.lang.CharSequence cs)
                                              throws XmppStringprepException
        Get a EntityJid from an URL encoded CharSequence.
        Parameters:
        cs - a CharSequence representing an URL encoded entity JID.
        Returns:
        an entity JID
        Throws:
        XmppStringprepException - if an error occurs.
        See Also:
        URLDecoder
      • entityBareFromUnescaped

        public static EntityBareJid entityBareFromUnescaped​(java.lang.CharSequence unescapedJid)
                                                     throws XmppStringprepException
        Get a EntityBareJid representing the given unescaped CharSequence.
        Parameters:
        unescapedJid - the input CharSequence.
        Returns:
        a bare JID representing the given CharSequence.
        Throws:
        XmppStringprepException - if an error occurs.
      • entityBareFromUnescaped

        public static EntityBareJid entityBareFromUnescaped​(java.lang.String unescapedJidString)
                                                     throws XmppStringprepException
        Get a EntityBareJid representing the given unescaped String.
        Parameters:
        unescapedJidString - the input String.
        Returns:
        a bare JID representing the given String.
        Throws:
        XmppStringprepException - if an error occurs.
      • entityBareFromUnescaped

        public static EntityBareJid entityBareFromUnescaped​(java.lang.String unescapedJidString,
                                                            JxmppContext context)
                                                     throws XmppStringprepException
        Get a EntityBareJid representing the given unescaped String.
        Parameters:
        unescapedJidString - the input String.
        context - the JXMPP context.
        Returns:
        a bare JID representing the given String.
        Throws:
        XmppStringprepException - if an error occurs.
      • entityBareFromUnescapedOrNull

        public static EntityBareJid entityBareFromUnescapedOrNull​(java.lang.CharSequence cs)
        Get a EntityBareJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • entityBareFrom

        public static EntityBareJid entityBareFrom​(Localpart localpart,
                                                   DomainBareJid domainBareJid)
        Get a EntityBareJid constructed from the given Localpart and {link DomainBareJid}.
        Parameters:
        localpart - a localpart.
        domainBareJid - a domain bare JID.
        Returns:
        a bare JID.
      • entityBareFromOrNull

        public static EntityBareJid entityBareFromOrNull​(java.lang.CharSequence cs)
        Get a EntityBareJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • entityBareFromUrlEncoded

        public static EntityBareJid entityBareFromUrlEncoded​(java.lang.CharSequence cs)
                                                      throws XmppStringprepException
        Get a EntityBareJid from an URL encoded CharSequence.
        Parameters:
        cs - a CharSequence representing an URL encoded entity bare JID.
        Returns:
        an entity bare JID
        Throws:
        XmppStringprepException - if an error occurs.
        See Also:
        URLDecoder
      • entityFullFromOrNull

        public static EntityFullJid entityFullFromOrNull​(java.lang.CharSequence cs)
        Get a EntityFullJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • entityFullFromUnescaped

        public static EntityFullJid entityFullFromUnescaped​(java.lang.CharSequence unescapedJid)
                                                     throws XmppStringprepException
        Get a EntityFullJid representing the given unescaped CharSequence.
        Parameters:
        unescapedJid - a CharSequence representing a JID.
        Returns:
        a full JID representing the given CharSequence.
        Throws:
        XmppStringprepException - if an error occurs.
      • entityFullFromUnescaped

        public static EntityFullJid entityFullFromUnescaped​(java.lang.String unescapedJidString)
                                                     throws XmppStringprepException
        Get a EntityFullJid representing the given unescaped String.
        Parameters:
        unescapedJidString - the JID's String.
        Returns:
        a full JID representing the input String.
        Throws:
        XmppStringprepException - if an error occurs.
      • entityFullFromUnescaped

        public static EntityFullJid entityFullFromUnescaped​(java.lang.String unescapedJidString,
                                                            JxmppContext context)
                                                     throws XmppStringprepException
        Get a EntityFullJid representing the given unescaped String.
        Parameters:
        unescapedJidString - the JID's String.
        context - the JXMPP context.
        Returns:
        a full JID representing the input String.
        Throws:
        XmppStringprepException - if an error occurs.
      • entityFullFromUnescapedOrNull

        public static EntityFullJid entityFullFromUnescapedOrNull​(java.lang.CharSequence cs)
        Get a EntityFullJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • entityFullFrom

        public static EntityFullJid entityFullFrom​(java.lang.String localpart,
                                                   java.lang.String domainpart,
                                                   java.lang.String resource)
                                            throws XmppStringprepException
        Get a EntityFullJid constructed from the given parts.
        Parameters:
        localpart - a localpart.
        domainpart - a domainpart.
        resource - a resourcepart.
        Returns:
        a full JID.
        Throws:
        XmppStringprepException - if an error occurs.
      • entityFullFrom

        public static EntityFullJid entityFullFrom​(java.lang.String localpart,
                                                   java.lang.String domainpart,
                                                   java.lang.String resource,
                                                   JxmppContext context)
                                            throws XmppStringprepException
        Get a EntityFullJid constructed from the given parts.
        Parameters:
        localpart - a localpart.
        domainpart - a domainpart.
        resource - a resourcepart.
        context - the JXMPP context.
        Returns:
        a full JID.
        Throws:
        XmppStringprepException - if an error occurs.
      • entityFullFrom

        public static EntityFullJid entityFullFrom​(Localpart localpart,
                                                   DomainBareJid domainBareJid,
                                                   Resourcepart resource)
        Get a EntityFullJid constructed from the given parts.
        Parameters:
        localpart - a localpart.
        domainBareJid - a domain bare JID..
        resource - a resourcepart
        Returns:
        a full JID.
      • entityFullFrom

        public static EntityFullJid entityFullFrom​(Localpart localpart,
                                                   Domainpart domainpart,
                                                   Resourcepart resource)
        Get a EntityFullJid constructed from the given parts.
        Parameters:
        localpart - the localpart.
        domainpart - the domainpart.
        resource - the resourcepart.
        Returns:
        a full JID.
      • entityFullFrom

        public static EntityFullJid entityFullFrom​(java.lang.CharSequence localpart,
                                                   Domainpart domainpart,
                                                   java.lang.CharSequence resource)
                                            throws XmppStringprepException
        Get a EntityFullJid constructed from the given parts.
        Parameters:
        localpart - the localpart.
        domainpart - the domainpart.
        resource - the resourcepart.
        Returns:
        a full JID.
        Throws:
        XmppStringprepException - if an error occurs.
      • entityFullFromUrlEncoded

        public static EntityFullJid entityFullFromUrlEncoded​(java.lang.CharSequence cs)
                                                      throws XmppStringprepException
        Get a EntityFullJid from an URL encoded CharSequence.
        Parameters:
        cs - a CharSequence representing an URL encoded entity full JID.
        Returns:
        an entity full JID
        Throws:
        XmppStringprepException - if an error occurs.
        See Also:
        URLDecoder
      • domainBareFromOrNull

        public static DomainBareJid domainBareFromOrNull​(java.lang.CharSequence cs)
        Get a DomainBareJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • domainBareFromUrlEncoded

        public static DomainBareJid domainBareFromUrlEncoded​(java.lang.CharSequence cs)
                                                      throws XmppStringprepException
        Get a DomainBareJid from an URL encoded CharSequence.
        Parameters:
        cs - a CharSequence representing an URL encoded domain bare JID.
        Returns:
        a domain bare JID
        Throws:
        XmppStringprepException - if an error occurs.
        See Also:
        URLDecoder
      • domainFullFrom

        public static DomainFullJid domainFullFrom​(Domainpart domainpart,
                                                   Resourcepart resource)
        Get a domain full JID.
        Parameters:
        domainpart - the domainpart.
        resource - the resourcepart.
        Returns:
        a domain full JID.
      • domainFullFrom

        public static DomainFullJid domainFullFrom​(DomainBareJid domainBareJid,
                                                   Resourcepart resource)
        Get a domain full JID.
        Parameters:
        domainBareJid - a domain bare JID.
        resource - a resourcepart.
        Returns:
        a domain full JID.
      • domainFullFromOrNull

        public static DomainFullJid domainFullFromOrNull​(java.lang.CharSequence cs)
        Get a DomainFullJid from a given CharSequence or null if the input does not represent a JID.
        Parameters:
        cs - the input CharSequence
        Returns:
        a JID or null
      • domainFullFromUrlEncoded

        public static DomainFullJid domainFullFromUrlEncoded​(java.lang.CharSequence cs)
                                                      throws XmppStringprepException
        Get a DomainFullJid from an URL encoded CharSequence.
        Parameters:
        cs - a CharSequence representing an URL encoded domain full JID.
        Returns:
        a domain full JID
        Throws:
        XmppStringprepException - if an error occurs.
        See Also:
        URLDecoder