Package org.xmpp.packet
Class JID
java.lang.Object
org.xmpp.packet.JID
- All Implemented Interfaces:
Serializable,Comparable<JID>
An XMPP address (JID). A JID is made up of a node (generally a username), a
domain, and a resource. The node and resource are optional; domain is
required. In simple ABNF form:
- jid = [ node "@" ] domain [ "/" resource ]
user@example.comuser@example.com/homeexample.com
- Author:
- Matt Tucker, Guus der Kinderen, guus.der.kinderen@gmail.com
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.github.benmanes.caffeine.cache.Cache<String,ValueWrapper<String>> static final com.github.benmanes.caffeine.cache.Cache<String,ValueWrapper<String>> static final com.github.benmanes.caffeine.cache.Cache<String,ValueWrapper<String>> -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a JID from it's String representation.Constructs a JID from it's String representation.Constructs a JID given a node, domain, and resource.Constructs a JID given a node, domain, and resource being able to specify if stringprep should be applied or not. -
Method Summary
Modifier and TypeMethodDescriptionReturns the bare JID representation of this JID, which is the JID with resource information removed.intstatic Stringdomainprep(String domain) Returns a valid representation of a JID domain part, based on the provided input.booleanstatic booleanReturns true if two JID's are equivalent.static StringescapeNode(String node) Escapes the node portion of a JID according to "JID Escaping" (XEP-0106).Returns the domain.getNode()Returns the node, ornullif this JID does not contain node information.Returns the resource, ornullif this JID does not contain resource information.inthashCode()static StringReturns a valid representation of a JID node, based on the provided input.static Stringresourceprep(String resource) Returns a valid representation of a JID resource, based on the provided input.Returns the String representation of the bare JID, which is the JID with resource information removed.Returns the String representation of the full JID, for example:username@domain.com/mobile.toString()Returns a String representation of the JID.static StringunescapeNode(String node) Un-escapes the node portion of a JID according to "JID Escaping" (XEP-0106).
-
Field Details
-
NODEPREP_CACHE
public static final com.github.benmanes.caffeine.cache.Cache<String,ValueWrapper<String>> NODEPREP_CACHE -
DOMAINPREP_CACHE
public static final com.github.benmanes.caffeine.cache.Cache<String,ValueWrapper<String>> DOMAINPREP_CACHE -
RESOURCEPREP_CACHE
public static final com.github.benmanes.caffeine.cache.Cache<String,ValueWrapper<String>> RESOURCEPREP_CACHE
-
-
Constructor Details
-
JID
Constructs a JID from it's String representation.- Parameters:
jid- a valid JID.- Throws:
IllegalArgumentException- if the JID is not valid.
-
JID
Constructs a JID from it's String representation. This construction allows the caller to specify if stringprep should be applied or not.- Parameters:
jid- a valid JID.skipStringPrep-trueif stringprep should not be applied.- Throws:
IllegalArgumentException- if the JID is not valid.
-
JID
Constructs a JID given a node, domain, and resource.- Parameters:
node- the node.domain- the domain, which must not benull.resource- the resource.- Throws:
NullPointerException- if domain isnull.IllegalArgumentException- if the JID is not valid.
-
JID
Constructs a JID given a node, domain, and resource being able to specify if stringprep should be applied or not.- Parameters:
node- the node.domain- the domain, which must not benull.resource- the resource.skipStringprep-trueif stringprep should not be applied.- Throws:
NullPointerException- if domain isnull.IllegalArgumentException- if the JID is not valid.
-
-
Method Details
-
escapeNode
Escapes the node portion of a JID according to "JID Escaping" (XEP-0106). Escaping replaces characters prohibited by node-prep with escape sequences, as follows:
This process is useful when the node comes from an external source that doesn't conform to nodeprep. For example, a username in LDAP may be "Joe Smith". Because the <space> character isn't a valid part of a node, the username should be escaped to "Joe\20Smith" before being made into a JID (e.g. "joe\20smith@example.com" after case-folding, etc. has been applied). All node escaping and un-escaping must be performed manually at the appropriate time; the JID class will not escape or un-escape automatically.Unescaped Character Encoded Sequence <space> \20 " \22 & \26 ' \27 / \2f : \3a < \3c > \3e @ \40 \ \5c - Parameters:
node- the node.- Returns:
- the escaped version of the node.
- See Also:
-
unescapeNode
Un-escapes the node portion of a JID according to "JID Escaping" (XEP-0106). Escaping replaces characters prohibited by node-prep with escape sequences, as follows:
This process is useful when the node comes from an external source that doesn't conform to nodeprep. For example, a username in LDAP may be "Joe Smith". Because the <space> character isn't a valid part of a node, the username should be escaped to "Joe\20Smith" before being made into a JID (e.g. "joe\20smith@example.com" after case-folding, etc. has been applied). All node escaping and un-escaping must be performed manually at the appropriate time; the JID class will not escape or un-escape automatically.Unescaped Character Encoded Sequence <space> \20 " \22 & \26 ' \27 / \2f : \3a < \3c > \3e @ \40 \ \5c - Parameters:
node- the escaped version of the node.- Returns:
- the un-escaped version of the node.
- See Also:
-
nodeprep
Returns a valid representation of a JID node, based on the provided input. This method throws anIllegalArgumentExceptionif the provided argument cannot be represented as a valid JID node (e.g. if StringPrepping fails).- Parameters:
node- The raw node value.- Returns:
- A String based JID node representation
- Throws:
IllegalArgumentException- ifnodeis not a valid JID node.
-
domainprep
Returns a valid representation of a JID domain part, based on the provided input. This method throws anIllegalArgumentExceptionif the provided argument cannot be represented as a valid JID domain part (e.g. if Stringprepping fails).- Parameters:
domain- The raw domain value.- Returns:
- A String based JID domain part representation
- Throws:
IllegalArgumentException- ifdomainis not a valid JID domain part.
-
resourceprep
Returns a valid representation of a JID resource, based on the provided input. This method throws anIllegalArgumentExceptionif the provided argument cannot be represented as a valid JID resource (e.g. if StringPrepping fails).- Parameters:
resource- The raw resource value.- Returns:
- A String based JID resource representation
- Throws:
IllegalArgumentException- ifresourceis not a valid JID resource.
-
getNode
Returns the node, ornullif this JID does not contain node information.- Returns:
- the node.
-
getDomain
Returns the domain.- Returns:
- the domain.
-
getResource
Returns the resource, ornullif this JID does not contain resource information.- Returns:
- the resource.
-
toBareJID
Returns the String representation of the bare JID, which is the JID with resource information removed. For example:username@domain.com- Returns:
- the bare JID.
-
asBareJID
Returns the bare JID representation of this JID, which is the JID with resource information removed. For example:username@domain.com- Returns:
- the bare JID.
- See Also:
-
toFullJID
Returns the String representation of the full JID, for example:username@domain.com/mobile. If no resource has been provided in the constructor of this object, an IllegalStateException is thrown.- Returns:
- the full JID.
- Throws:
IllegalStateException- If no resource was provided in the constructor used to create this instance.
-
toString
Returns a String representation of the JID. -
hashCode
public int hashCode() -
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<JID>
-
equals
Returns true if two JID's are equivalent. The JID components are compared using the following rules:- Nodes are normalized using nodeprep (case insensitive).
- Domains are normalized using IDNA and then nameprep (case insensitive).
- Resources are normalized using resourceprep (case sensitive).
User@EXAMPLE.com/homeis considered equal touser@example.com/home.- Parameters:
jid1- a JID.jid2- a JID.- Returns:
- true if the JIDs are equivalent; false otherwise.
- Throws:
IllegalArgumentException- if either JID is not valid.
-