org.jxmpp.jid.parts.Domainpart Java Examples

The following examples show how to use org.jxmpp.jid.parts.Domainpart. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Jid.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
static Jid ofEscaped(CharSequence local, CharSequence domain, CharSequence resource) {
    try {
        if (resource == null) {
            return new WrappedJid(
                    JidCreate.bareFrom(
                            Localpart.from(local.toString()),
                            Domainpart.from(domain.toString())
                    )
            );
        }
        return new WrappedJid(JidCreate.entityFullFrom(
                Localpart.from(local.toString()),
                Domainpart.from(domain.toString()),
                Resourcepart.from(resource.toString())
        ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #2
Source File: GatewayPlugin.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handlePresence(ContactItem item, Presence presence) {
       if (presence.isAvailable()) {
           Domainpart domain = presence.getFrom().getDomain();
           Transport transport = TransportUtils.getTransport(domain.toString());
           if (transport != null) {
               if (presence.getType() == Presence.Type.available) {
                   item.setSpecialIcon(transport.getIcon());
               }
               else {
                   item.setSpecialIcon(transport.getInactiveIcon());
               }
               return false;
           }
       }

       return false;
   }
 
Example #3
Source File: Jid.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
static Jid ofEscaped(CharSequence local, CharSequence domain, CharSequence resource) {
    try {
        if (resource == null) {
            return new WrappedJid(
                    JidCreate.bareFrom(
                            Localpart.from(local.toString()),
                            Domainpart.from(domain.toString())
                    )
            );
        }
        return new WrappedJid(JidCreate.entityFullFrom(
                Localpart.from(local.toString()),
                Domainpart.from(domain.toString()),
                Resourcepart.from(resource.toString())
        ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #4
Source File: Jid.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
static Jid of(CharSequence local, CharSequence domain, CharSequence resource) {
    if (local == null) {
        if (resource == null) {
            return ofDomain(domain);
        } else {
            return ofDomainAndResource(domain, resource);
        }
    }
    if (resource == null) {
        return ofLocalAndDomain(local, domain);
    }
    try {
        return new WrappedJid(JidCreate.entityFullFrom(
                Localpart.fromUnescaped(local.toString()),
                Domainpart.from(domain.toString()),
                Resourcepart.from(resource.toString())
        ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #5
Source File: InvalidJidTestresult.java    From jxmpp with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
	StringBuilder sb = new StringBuilder();
	sb.append(xmppStringPrepper)
	.append(" failed to handle the following invalid JID:\n")
	.append(invalidJid).append('\n')
	.append("as it produced the following JID (when it should have thrown an exception):\n")
	.append(jid).append('\n');
	Localpart localpart = jid.getLocalpartOrNull();
	if (localpart != null) {
		sb.append("- localpart: ").append(localpart).append('\n');
	}
	Domainpart domainpart = jid.getDomain();
	sb.append("- domanipart: ").append(domainpart).append('\n');
	Resourcepart resourcepart = jid.getResourceOrNull();
	if (resourcepart != null) {
		sb.append("- resourcepart: ").append(resourcepart).append('\n');
	}
	return sb.toString();
}
 
Example #6
Source File: Jid.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
static Jid of(CharSequence local, CharSequence domain, CharSequence resource) {
    if (local == null) {
        if (resource == null) {
            return ofDomain(domain);
        } else {
            return ofDomainAndResource(domain, resource);
        }
    }
    if (resource == null) {
        return ofLocalAndDomain(local, domain);
    }
    try {
        return new WrappedJid(JidCreate.entityFullFrom(
                Localpart.fromUnescaped(local.toString()),
                Domainpart.from(domain.toString()),
                Resourcepart.from(resource.toString())
        ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #7
Source File: UserManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Unescapes a complete JID by examing the node itself and unescaping when necessary.
 *
 * @param jid the users jid.
 * @return the unescaped JID.
 */
public static String unescapeJID(BareJid jid) {
    if (jid == null) {
        return null;
    }

    final StringBuilder builder = new StringBuilder();
    Localpart node = jid.getLocalpartOrNull();
    Domainpart restOfJID = jid.getDomain();
    if (node != null) {
        builder.append(XmppStringUtils.unescapeLocalpart(node.toString()));
    }
    builder.append(restOfJID);
    return builder.toString();
}
 
Example #8
Source File: Jid.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
static Jid ofLocalAndDomainEscaped(CharSequence local, CharSequence domain) {
    try {
        return new WrappedJid(
                JidCreate.bareFrom(
                        Localpart.from(local.toString()),
                        Domainpart.from(domain.toString())
                )
        );
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #9
Source File: Jid.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
static Jid ofDomainAndResource(CharSequence domain, CharSequence resource) {
    try {
        return new WrappedJid(
                JidCreate.domainFullFrom(
                        Domainpart.from(domain.toString()),
                        Resourcepart.from(resource.toString())
                ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #10
Source File: Jid.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
static Jid ofLocalAndDomain(CharSequence local, CharSequence domain) {
    try {
        return new WrappedJid(
                JidCreate.bareFrom(
                        Localpart.fromUnescaped(local.toString()),
                        Domainpart.from(domain.toString())
                )
        );
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #11
Source File: Jid.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
static Jid ofLocalAndDomain(CharSequence local, CharSequence domain) {
    try {
        return new WrappedJid(
                JidCreate.bareFrom(
                        Localpart.fromUnescaped(local.toString()),
                        Domainpart.from(domain.toString())
                )
        );
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #12
Source File: Jid.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
static Jid ofDomainAndResource(CharSequence domain, CharSequence resource) {
    try {
        return new WrappedJid(
                JidCreate.domainFullFrom(
                        Domainpart.from(domain.toString()),
                        Resourcepart.from(resource.toString())
                ));
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #13
Source File: JidCreate.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link BareJid} constructed from the optionally given {@link Localpart} and {@link Domainpart}.
 *
 * @param localpart a optional localpart.
 * @param domain a domainpart.
 * @return a bare JID constructed from the given parts.
 */
public static BareJid bareFrom(Localpart localpart, Domainpart domain) {
	if (localpart != null) {
		return new LocalAndDomainpartJid(localpart, domain);
	} else {
		return new DomainpartJid(domain);
	}
}
 
Example #14
Source File: JidCreateTest.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
@Test
public void jidResourcepartWithAtSignTest() throws XmppStringprepException {
	Jid jid = JidCreate.from("a.example.com/[email protected]");

	assertEquals(Domainpart.from("a.example.com"), jid.getDomain());
	assertEquals(Resourcepart.from("[email protected]"), jid.getResourceOrNull());
}
 
Example #15
Source File: JidCreateTest.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
@Test
public void entityFromUnescapedFullTest() throws XmppStringprepException {
	EntityJid entityBareJid = JidCreate.entityFromUnescaped("d'[email protected]/elder");

	Domainpart domainpart = entityBareJid.getDomain();
	assertEquals(Domainpart.from("gascon.fr"), domainpart);

	Resourcepart resourcepart = entityBareJid.getResourceOrThrow();
	assertEquals(Resourcepart.from("elder"), resourcepart);

	Localpart localpart = entityBareJid.getLocalpart();
	assertEquals(Localpart.from("d\\27artagnan"), localpart);
}
 
Example #16
Source File: JidCreateTest.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
@Test
public void entityFromUnescapedBareTest() throws XmppStringprepException {
	EntityJid entityJid = JidCreate.entityFromUnescaped("d'[email protected]");

	Domainpart domainpart = entityJid.getDomain();
	assertEquals(Domainpart.from("musketeers.lit"), domainpart);

	Localpart localpart = entityJid.getLocalpart();
	assertEquals(Localpart.from("d\\27artagnan"), localpart);

	assertEquals(localpart, Localpart.fromUnescaped("d'artagnan"));
}
 
Example #17
Source File: JidCreateTest.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
@Test
public void entityFullFromUnsecapedComplexTest() throws XmppStringprepException {
	EntityFullJid entityFullJid = JidCreate.entityFullFromUnescaped("foo@[email protected]/bar@baz");

	Domainpart domainpart = entityFullJid.getDomain();
	assertEquals(Domainpart.from("[email protected]"), domainpart);

	Localpart localpart = entityFullJid.getLocalpart();
	assertEquals(Localpart.from("foo"), localpart);

	Resourcepart resourcepart = entityFullJid.getResourcepart();
	assertEquals(Resourcepart.from("bar@baz"), resourcepart);
}
 
Example #18
Source File: JidCreateTest.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
@Test
public void entityFullFromComplexTest() throws XmppStringprepException {
	EntityFullJid entityFullJid = JidCreate.entityFullFrom("foo@[email protected]/bar@baz");

	Domainpart domainpart = entityFullJid.getDomain();
	assertEquals(Domainpart.from("[email protected]"), domainpart);

	Localpart localpart = entityFullJid.getLocalpart();
	assertEquals(Localpart.from("foo"), localpart);

	Resourcepart resourcepart = entityFullJid.getResourcepart();
	assertEquals(Resourcepart.from("bar@baz"), resourcepart);
}
 
Example #19
Source File: Jid.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
static Jid ofLocalAndDomainEscaped(CharSequence local, CharSequence domain) {
    try {
        return new WrappedJid(
                JidCreate.bareFrom(
                        Localpart.from(local.toString()),
                        Domainpart.from(domain.toString())
                )
        );
    } catch (XmppStringprepException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #20
Source File: JidCreateTest.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
@Test
public void entityBareFromUnescapedTest() throws XmppStringprepException {
	EntityBareJid entityBareJid = JidCreate.entityBareFromUnescaped("foo@[email protected]/baz");

	// Tricky question. Currently yields '[email protected]'. Domainparts are U-Labels, so this may be correct, even
	// if it is not a valid DNS label/name.
	Domainpart domainpart = entityBareJid.getDomain();
	assertEquals(Domainpart.from("[email protected]"), domainpart);

	Localpart localpart = entityBareJid.getLocalpart();
	assertEquals(Localpart.from("foo"), localpart);
}
 
Example #21
Source File: LocalDomainAndResourcepartJid.java    From jxmpp with Apache License 2.0 4 votes vote down vote up
@Override
public Domainpart getDomain() {
	return bareJid.getDomain();
}
 
Example #22
Source File: DomainpartJid.java    From jxmpp with Apache License 2.0 4 votes vote down vote up
@Override
public Domainpart getDomain() {
	return domain;
}
 
Example #23
Source File: DomainpartJid.java    From jxmpp with Apache License 2.0 4 votes vote down vote up
DomainpartJid(Domainpart domain) {
	this.domain = requireNonNull(domain, "The Domainpart must not be null");
}
 
Example #24
Source File: DomainpartJid.java    From jxmpp with Apache License 2.0 4 votes vote down vote up
DomainpartJid(String domain, JxmppContext context) throws XmppStringprepException {
	this(Domainpart.from(domain, context));
}
 
Example #25
Source File: LocalAndDomainpartJid.java    From jxmpp with Apache License 2.0 4 votes vote down vote up
@Override
public Domainpart getDomain() {
	return domainBareJid.getDomain();
}
 
Example #26
Source File: LocalAndDomainpartJid.java    From jxmpp with Apache License 2.0 4 votes vote down vote up
LocalAndDomainpartJid(Localpart localpart, Domainpart domain) {
	this.localpart = requireNonNull(localpart, "The Localpart must not be null");
	this.domainBareJid = new DomainpartJid(domain);
}
 
Example #27
Source File: DomainAndResourcepartJid.java    From jxmpp with Apache License 2.0 4 votes vote down vote up
@Override
public Domainpart getDomain() {
	return domainBareJid.getDomain();
}
 
Example #28
Source File: JidCreate.java    From jxmpp with Apache License 2.0 2 votes vote down vote up
/**
 * Get a domain full JID.
 *
 * @param domainpart the domainpart.
 * @param resource the resourcepart.
 * @return a domain full JID.
 */
public static DomainFullJid domainFullFrom(Domainpart domainpart, Resourcepart resource) {
	return domainFullFrom(domainBareFrom(domainpart), resource);
}
 
Example #29
Source File: JidCreate.java    From jxmpp with Apache License 2.0 2 votes vote down vote up
/**
 * Get a {@link DomainBareJid} consisting of the given {@link Domainpart}.
 *
 * @param domainpart the domainpart.
 * @return a domain bare JID.
 */
public static DomainBareJid domainBareFrom(Domainpart domainpart) {
	return new DomainpartJid(domainpart);
}
 
Example #30
Source File: JidCreate.java    From jxmpp with Apache License 2.0 2 votes vote down vote up
/**
 * Get a {@link EntityFullJid} constructed from the given parts.
 * 
 * @param localpart the localpart.
 * @param domainpart the domainpart.
 * @param resource the resourcepart.
 * @return a full JID.
 */
public static EntityFullJid entityFullFrom(Localpart localpart, Domainpart domainpart, Resourcepart resource) {
	return entityFullFrom(entityBareFrom(localpart, domainpart), resource);
}