/** * Get a {@link Jid} from a given {@link CharSequence} or {@code null} if the input does not represent a JID. * * @param cs the input {@link CharSequence} * @return a JID or {@code null} */ public static Jid fromUnescapedOrNull(CharSequence cs) { try { return fromUnescaped(cs); } catch (XmppStringprepException e) { return null; } }
/** * Get a {@link Jid} from the given unescaped CharSequence. * * @param unescapedJid an unescaped CharSequence representing a JID. * @return a JID. * @throws XmppStringprepException if an error occurs. */ public static Jid fromUnescaped(CharSequence unescapedJid) throws XmppStringprepException { return fromUnescaped(unescapedJid.toString()); }
/** * Like {@link #fromUnescaped(CharSequence)} but does throw an unchecked {@link IllegalArgumentException} instead of a * {@link XmppStringprepException}. * * @param cs the character sequence which should be transformed to a {@link Jid} * @return the {@link Jid} if no exception occurs * @throws IllegalArgumentException if the given input is not a valid JID * @see #fromUnescaped(CharSequence) * @since 0.6.2 */ public static Jid fromUnescapedOrThrowUnchecked(CharSequence cs) { try { return fromUnescaped(cs); } catch (XmppStringprepException e) { throw new IllegalArgumentException(e); } }
String jidString = icon.getDescription(); try { Jid jid = JidCreate.fromUnescaped(jidString); chat.grantMembership(jid);