public final class Jid extends Object implements Comparable<Jid>, Serializable, CharSequence
A JID consists of three parts:
[ localpart "@" ] domainpart [ "/" resourcepart ]
The easiest way to create a JID is to use theof(CharSequence) method:
Jid jid = Jid.of("juliet@capulet.lit/balcony");
You can then get the parts from it via the respective methods:
String local = jid.getLocal(); // juliet
String domain = jid.getDomain(); // capulet.lit
String resource = jid.getResource(); // balcony
This class overrides equals() and hashCode(), so that different instances with the same value are equal:
Jid.of("romeo@capulet.lit/balcony").equals(Jid.of("romeo@capulet.lit/balcony")); // true
This class also supports XEP-0106: JID Escaping, i.e.
Jid.of("d'artagnan@musketeers.lit")
is escaped as d\\27artagnan@musketeers.lit.| Modifier and Type | Field and Description |
|---|---|
static String |
ESCAPING_FEATURE
The service discovery feature used for determining support of JID escaping (
jid\20escaping). |
| Constructor and Description |
|---|
Jid(CharSequence local,
CharSequence domain,
CharSequence resource)
Deprecated.
|
Jid(String domain)
Deprecated.
|
Jid(String local,
String domain)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
Jid |
asBareJid()
Converts this JID into a bare JID, i.e. removes the resource.
|
Jid |
atSubdomain(CharSequence subdomain)
Returns a new JID at a subdomain and at the same domain as this JID.
|
char |
charAt(int index) |
int |
compareTo(Jid o)
Compares this JID with another JID.
|
boolean |
equals(Object o) |
String |
getDomain()
Gets the domain part.
|
String |
getLocal()
Gets the local part of the JID, also known as the name or node.
|
String |
getResource()
Gets the resource part.
|
int |
hashCode() |
boolean |
isBareJid()
Checks if the JID is a bare JID.
|
boolean |
isFullJid()
Checks if the JID is a full JID.
|
int |
length() |
static Jid |
of(CharSequence jid)
Returns a JID from a string.
|
static Jid |
of(CharSequence local,
CharSequence domain,
CharSequence resource)
Returns a full JID with a domain and resource part, e.g.
|
static Jid |
ofDomain(CharSequence domain)
Returns a bare JID with only the domain part, e.g.
|
static Jid |
ofDomainAndResource(CharSequence domain,
CharSequence resource)
Returns a full JID with a domain and resource part, e.g.
|
static Jid |
ofEscaped(CharSequence jid)
Creates a JID from a escaped JID string.
|
static Jid |
ofLocalAndDomain(CharSequence local,
CharSequence domain)
Returns a bare JID with a local and domain part, e.g.
|
CharSequence |
subSequence(int start,
int end) |
String |
toEscapedString()
Gets the JID in escaped form as described in XEP-0106: JID Escaping.
|
String |
toString()
Converts the JID into its string representation, i.e. [ localpart "@" ] domainpart [ "/" resourcepart ].
|
static Jid |
valueOf(String jid)
Deprecated.
Use
of(CharSequence) |
static Jid |
valueOf(String jid,
boolean doUnescape)
Deprecated.
|
Jid |
withLocal(CharSequence local)
Returns a new JID with a new local part and the same domain and resource part of the current JID.
|
Jid |
withResource(CharSequence resource)
Returns a new full JID with a resource and the same local and domain part of the current JID.
|
chars, codePointspublic static final String ESCAPING_FEATURE
jid\20escaping).@Deprecated public Jid(String domain)
ofDomain(CharSequence)domain - The domain.@Deprecated public Jid(String local, String domain)
ofLocalAndDomain(CharSequence, CharSequence)local - The local part.domain - The domain part.@Deprecated public Jid(CharSequence local, CharSequence domain, CharSequence resource)
of(CharSequence, CharSequence, CharSequence)}local - The local part.domain - The domain part.resource - The resource part.@Deprecated public static Jid valueOf(String jid)
of(CharSequence). The input string will be escaped.[ localpart "@" ] domainpart [ "/" resourcepart ]
jid - The JID.@Deprecated public static Jid valueOf(String jid, boolean doUnescape)
of(CharSequence) or ofEscaped(CharSequence)}[ localpart "@" ] domainpart [ "/" resourcepart ]
jid - The JID.doUnescape - If the jid parameter will be unescaped.public static Jid of(CharSequence local, CharSequence domain, CharSequence resource)
capulet.com/balconylocal - The local part.domain - The domain.resource - The resource part.public static Jid ofDomain(CharSequence domain)
capulet.comdomain - The domain.public static Jid ofLocalAndDomain(CharSequence local, CharSequence domain)
juliet@capulet.comlocal - The local part.domain - The domain.public static Jid ofDomainAndResource(CharSequence domain, CharSequence resource)
capulet.com/balconydomain - The domain.resource - The resource part.public static Jid of(CharSequence jid)
. The input string will be escaped.[ localpart "@" ] domainpart [ "/" resourcepart ]
jid - The JID.public static Jid ofEscaped(CharSequence jid)
[ localpart "@" ] domainpart [ "/" resourcepart ]
jid - The JID.public final boolean isFullJid()
The term "full JID" refers to an XMPP address of the form <localpart@domainpart/resourcepart> (for a particular authorized client or device associated with an account) or of the form <domainpart/resourcepart> (for a particular resource or script associated with a server).
public final boolean isBareJid()
The term "bare JID" refers to an XMPP address of the form <localpart@domainpart> (for an account at a server) or of the form <domainpart> (for a server).
public final Jid asBareJid()
The term "bare JID" refers to an XMPP address of the form <localpart@domainpart> (for an account at a server) or of the form <domainpart> (for a server).
withResource(CharSequence)public final Jid withLocal(CharSequence local)
local - The local part.public final Jid withResource(CharSequence resource)
resource - The resource.asBareJid()public final Jid atSubdomain(CharSequence subdomain)
subdomain - The subdomain.public final String getLocal()
The localpart of a JID is an optional identifier placed before the domainpart and separated from the latter by the '@' character. Typically a localpart uniquely identifies the entity requesting and using network access provided by a server (i.e., a local account), although it can also represent other kinds of entities (e.g., a chat room associated with a multi-user chat service). The entity represented by an XMPP localpart is addressed within the context of a specific domain (i.e.,
<localpart@domainpart>).
public final String getDomain()
The domainpart of a JID is that portion after the '@' character (if any) and before the '/' character (if any); it is the primary identifier and is the only REQUIRED element of a JID (a mere domainpart is a valid JID).
public final String getResource()
The resourcepart of a JID is an optional identifier placed after the domainpart and separated from the latter by the '/' character. A resourcepart can modify either a
<localpart@domainpart>address or a mere<domainpart>address. Typically a resourcepart uniquely identifies a specific connection (e.g., a device or location) or object (e.g., an occupant in a multi-user chat room) belonging to the entity associated with an XMPP localpart at a domain (i.e.,<localpart@domainpart/resourcepart>).
public final String toEscapedString()
toString()public final int length()
length in interface CharSequencepublic final char charAt(int index)
charAt in interface CharSequencepublic final CharSequence subSequence(int start, int end)
subSequence in interface CharSequencepublic final String toString()
toString in interface CharSequencetoString in class ObjecttoEscapedString()public final int compareTo(Jid o)
compareTo in interface Comparable<Jid>o - The other JID.Copyright © 2014–2015 XMPP.rocks. All rights reserved.