public class XmppStringUtils extends Object
Constructor and Description |
---|
XmppStringUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
completeJidFrom(CharSequence localpart,
CharSequence domainpart)
Construct a JID String from the given parts.
|
static String |
completeJidFrom(CharSequence localpart,
CharSequence domainpart,
CharSequence resource)
Construct a JID String from the given parts.
|
static String |
completeJidFrom(String localpart,
String domainpart)
Construct a JID String from the given parts.
|
static String |
completeJidFrom(String localpart,
String domainpart,
String resource)
Construct a JID String from the given parts.
|
static String |
escapeLocalpart(String localpart)
Escapes the localpart of a JID according to "JID Escaping" (XEP-0106).
|
static String |
generateKey(String element,
String namespace)
Generate a unique key from a element name and namespace.
|
static boolean |
isBareJid(String jid)
Returns true if
jid is a bare JID ("foo@bar.com"). |
static boolean |
isFullJID(String jid)
Returns true if jid is a full JID (i.e.
|
static String |
parseBareAddress(String jid)
Deprecated.
use
parseBareJid(String) instead |
static String |
parseBareJid(String jid)
Returns the JID with any resource information removed.
|
static String |
parseDomain(String jid)
Returns the domain of an XMPP address (JID).
|
static String |
parseLocalpart(String jid)
Returns the localpart of an XMPP address (JID).
|
static String |
parseResource(String jid)
Returns the resource portion of an XMPP address (JID).
|
static String |
unescapeLocalpart(String localpart)
Un-escapes the localpart of a JID according to "JID Escaping" (XEP-0106).
|
public XmppStringUtils()
public static String parseLocalpart(String jid)
jid
is null
, then this method returns also null
. If
the input String is no valid JID or has no localpart, then this method will return the empty String.jid
- the XMPP address to parse.null
.public static String parseDomain(String jid)
jid
is null
, then this method returns also null
. If
the input String is no valid JID or has no domainpart, then this method will return the empty String.jid
- the XMPP address to parse.null
.public static String parseResource(String jid)
jid
is null
, then this method returns also
null
. If the input String is no valid JID or has no resourcepart, then this method will return the
empty String.jid
- the XMPP address to parse.@Deprecated public static String parseBareAddress(String jid)
parseBareJid(String)
insteadjid
- the XMPP JID.public static String parseBareJid(String jid)
jid
- the XMPP JID.public static boolean isFullJID(String jid)
jid
- the String to check.public static boolean isBareJid(String jid)
jid
is a bare JID ("foo@bar.com").
This method may return true for Strings that are not valid JIDs (e.g. because of Stringprep violations). Consider
using org.jxmpp.jid.util.JidUtil.validateBareJid(String)
from jxmpp-jid instead of this method as it
exceptions provide a meaningful message string why the JID is not a bare JID and will also check for Stringprep
errors.
jid
- the String to check.public static String escapeLocalpart(String localpart)
Unescaped Character | Encoded Sequence |
<space> | \20 |
" | \22 |
& | \26 |
' | \27 |
/ | \2f |
: | \3a |
< | \3c |
> | \3e |
@ | \40 |
\ | \5c |
This process is useful when the localpart 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 localpart, 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 localpart escaping and un-escaping must be performed manually at the appropriate time; the JID class will not escape or un-escape automatically.localpart
- the localpart.public static String unescapeLocalpart(String localpart)
Unescaped Character | Encoded Sequence |
<space> | \20 |
" | \22 |
& | \26 |
' | \27 |
/ | \2f |
: | \3a |
< | \3c |
> | \3e |
@ | \40 |
\ | \5c |
This process is useful when the localpart 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 localpart, 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 localpart escaping and un-escaping must be performed manually at the appropriate time; the JID class will not escape or un-escape automatically.localpart
- the escaped version of the localpart.public static String completeJidFrom(CharSequence localpart, CharSequence domainpart)
localpart
- the localpart.domainpart
- the domainpart.public static String completeJidFrom(String localpart, String domainpart)
localpart
- the localpart.domainpart
- the domainpart.public static String completeJidFrom(CharSequence localpart, CharSequence domainpart, CharSequence resource)
localpart
- the localpart.domainpart
- the domainpart.resource
- the resourcepart.public static String completeJidFrom(String localpart, String domainpart, String resource)
localpart
- the localpart.domainpart
- the domainpart.resource
- the resourcepart.public static String generateKey(String element, String namespace)
element + '\t' + namespace
.
The tab character (\t) was chosen because it will be normalized, i.e. replace by space, in attribute values. It
therefore should never appear in element
or namespace
. For more information about the
normalization, see the XML specification ยง 3.3.3
Attribute-Value Normalization.
element
- the element.namespace
- the namespace.