Java Code Examples for org.jxmpp.util.XmppStringUtils#parseDomain()

The following examples show how to use org.jxmpp.util.XmppStringUtils#parseDomain() . 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: JidUtil.java    From jxmpp with Apache License 2.0 6 votes vote down vote up
/**
 * Check if the given CharSequence is a valid entity bare JID. That
 * is, it must consists exactly of a local- and a domainpart
 * (<localpart@domainpart>).
 * <p>
 * This is a convenience method meant to validate user entered bare JIDs. If
 * the given {@code jid} is not a valid bare JID, then this method will
 * throw either {@link NotAEntityBareJidStringException} or
 * {@link XmppStringprepException}. The NotABareJidStringException will
 * contain a meaningful message explaining why the given CharSequence is not a
 * valid bare JID (e.g. "does not contain a '@' character").
 * </p>
 * 
 * @param jidcs the JID CharSequence
 * @return a BareJid instance representing the given JID CharSequence
 * @throws NotAEntityBareJidStringException if the given CharSequence is not a bare JID.
 * @throws XmppStringprepException if an error happens.
 */
public static EntityBareJid validateEntityBareJid(CharSequence jidcs) throws NotAEntityBareJidStringException, XmppStringprepException {
	String jid = jidcs.toString();
	final int atIndex = jid.indexOf('@');
	if (atIndex == -1) {
		throw new NotAEntityBareJidStringException("'" + jid + "' does not contain a '@' character");
	} else if (jid.indexOf('@', atIndex + 1) != -1) {
		throw new NotAEntityBareJidStringException("'" + jid + "' contains multiple '@' characters");
	}
	final String localpart = XmppStringUtils.parseLocalpart(jid);
	if (localpart.length() == 0) {
		throw new NotAEntityBareJidStringException("'" + jid + "' has empty localpart");
	}
	final String domainpart = XmppStringUtils.parseDomain(jid);
	if (domainpart.length() == 0) {
		throw new NotAEntityBareJidStringException("'" + jid + "' has empty domainpart");
	}
	return JidCreate.entityBareFromUnescaped(jid);
}
 
Example 2
Source File: JidCreate.java    From jxmpp with Apache License 2.0 6 votes vote down vote up
/**
 * Get a {@link FullJid} representing the given String.
 *
 * @param jid the JID's String.
 * @return a full JID representing the input String.
 * @throws XmppStringprepException if an error occurs.
 */
public static FullJid fullFrom(String jid) throws XmppStringprepException {
	FullJid fullJid = FULLJID_CACHE.lookup(jid);
	if (fullJid != null) {
		return fullJid;
	}

	String localpart = XmppStringUtils.parseLocalpart(jid);
	String domainpart = XmppStringUtils.parseDomain(jid);
	String resource = XmppStringUtils.parseResource(jid);
	try {
		fullJid = fullFrom(localpart, domainpart, resource);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(jid, e);
	}
	FULLJID_CACHE.put(jid, fullJid);
	return fullJid;
}
 
Example 3
Source File: JidCreate.java    From jxmpp with Apache License 2.0 6 votes vote down vote up
/**
 * Get a {@link EntityBareJid} representing the given String.
 *
 * @param jid the input String.
 * @param context the JXMPP context.
 * @return a bare JID representing the given String.
 * @throws XmppStringprepException if an error occurs.
 */
public static EntityBareJid entityBareFrom(String jid, JxmppContext context) throws XmppStringprepException {
	EntityBareJid bareJid;
	if (context.isCachingEnabled()) {
		bareJid = ENTITY_BAREJID_CACHE.lookup(jid);
		if (bareJid != null) {
			return bareJid;
		}
	}

	String localpart = XmppStringUtils.parseLocalpart(jid);
	String domainpart = XmppStringUtils.parseDomain(jid);
	try {
		bareJid = new LocalAndDomainpartJid(localpart, domainpart, context);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(jid, e);
	}

	if (context.isCachingEnabled()) {
		ENTITY_BAREJID_CACHE.put(jid, bareJid);
	}
	return bareJid;
}
 
Example 4
Source File: JidCreate.java    From jxmpp with Apache License 2.0 6 votes vote down vote up
/**
 * Get a {@link EntityBareJid} representing the given unescaped String.
 *
 * @param unescapedJidString the input String.
 * @param context the JXMPP context.
 * @return a bare JID representing the given String.
 * @throws XmppStringprepException if an error occurs.
 */
public static EntityBareJid entityBareFromUnescaped(String unescapedJidString, JxmppContext context) throws XmppStringprepException {
	EntityBareJid bareJid;
	if (context.isCachingEnabled()) {
		bareJid = ENTITY_BAREJID_CACHE.lookup(unescapedJidString);
		if (bareJid != null) {
			return bareJid;
		}
	}

	String localpart = XmppStringUtils.parseLocalpart(unescapedJidString);
	// Some as from(String), but we escape the localpart
	localpart = XmppStringUtils.escapeLocalpart(localpart);

	String domainpart = XmppStringUtils.parseDomain(unescapedJidString);
	try {
		bareJid = new LocalAndDomainpartJid(localpart, domainpart, context);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(unescapedJidString, e);
	}

	if (context.isCachingEnabled()) {
		ENTITY_BAREJID_CACHE.put(unescapedJidString, bareJid);
	}
	return bareJid;
}
 
Example 5
Source File: JidCreate.java    From jxmpp with Apache License 2.0 6 votes vote down vote up
/**
 * Get a {@link EntityFullJid} representing the given String.
 *
 * @param jid the JID's String.
 * @return a full JID representing the input String.
 * @throws XmppStringprepException if an error occurs.
 */
public static EntityFullJid entityFullFrom(String jid) throws XmppStringprepException {
	EntityFullJid fullJid = ENTITY_FULLJID_CACHE.lookup(jid);
	if (fullJid != null) {
		return fullJid;
	}

	String localpart = XmppStringUtils.parseLocalpart(jid);
	String domainpart = XmppStringUtils.parseDomain(jid);
	String resource = XmppStringUtils.parseResource(jid);
	try {
		fullJid = entityFullFrom(localpart, domainpart, resource);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(jid, e);
	}
	ENTITY_FULLJID_CACHE.put(jid, fullJid);
	return fullJid;
}
 
Example 6
Source File: JidCreate.java    From jxmpp with Apache License 2.0 6 votes vote down vote up
/**
 * Get a domain bare JID.
 *
 * @param jid the JID String.
 * @param context the JXMPP context.
 * @return a domain bare JID.
 * @throws XmppStringprepException if an error occurs.
 */
public static DomainBareJid domainBareFrom(String jid, JxmppContext context) throws XmppStringprepException {
	DomainBareJid domainJid;
	if (context.isCachingEnabled()) {
		domainJid = DOMAINJID_CACHE.lookup(jid);
		if (domainJid != null) {
			return domainJid;
		}
	}

	String domain = XmppStringUtils.parseDomain(jid);
	try {
		domainJid = new DomainpartJid(domain, context);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(jid, e);
	}

	if (context.isCachingEnabled()) {
		DOMAINJID_CACHE.put(jid, domainJid);
	}
	return domainJid;
}
 
Example 7
Source File: JidCreate.java    From jxmpp with Apache License 2.0 6 votes vote down vote up
/**
 * Get a domain full JID from the given String.
 *
 * @param jid the JID.
 * @param context the JXMPP context.
 * @return a DomainFullJid.
 * @throws XmppStringprepException if an error happens.
 */
public static DomainFullJid domainFullFrom(String jid, JxmppContext context) throws XmppStringprepException {
	DomainFullJid domainResourceJid;
	if (context.isCachingEnabled()) {
		domainResourceJid = DOMAINRESOURCEJID_CACHE.lookup(jid);
		if (domainResourceJid != null) {
			return domainResourceJid;
		}
	}

	String domain = XmppStringUtils.parseDomain(jid);
	String resource = XmppStringUtils.parseResource(jid);
	try {
		domainResourceJid = new DomainAndResourcepartJid(domain, resource, context);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(jid, e);
	}

	if (context.isCachingEnabled()) {
		DOMAINRESOURCEJID_CACHE.put(jid, domainResourceJid);
	}
	return domainResourceJid;
}
 
Example 8
Source File: JidCreate.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link Jid} from the given String.
 *
 * @param jidString the input String.
 * @param context the JXMPP context.
 * @return the Jid represented by the input String.
 * @throws XmppStringprepException if an error occurs.
 * @see #from(CharSequence)
 */
public static Jid from(String jidString, JxmppContext context) throws XmppStringprepException {
	String localpart = XmppStringUtils.parseLocalpart(jidString);
	String domainpart = XmppStringUtils.parseDomain(jidString);
	String resource = XmppStringUtils.parseResource(jidString);
	try {
		return from(localpart, domainpart, resource, context);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(jidString, e);
	}
}
 
Example 9
Source File: JidCreate.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link Jid} from the given unescaped String.
 *
 * @param unescapedJidString a unescaped String representing a JID.
 * @return a JID.
 * @throws XmppStringprepException if an error occurs.
 */
public static Jid fromUnescaped(String unescapedJidString) throws XmppStringprepException {
	String localpart = XmppStringUtils.parseLocalpart(unescapedJidString);
	// Some as from(String), but we escape the localpart
	localpart = XmppStringUtils.escapeLocalpart(localpart);

	String domainpart = XmppStringUtils.parseDomain(unescapedJidString);
	String resource = XmppStringUtils.parseResource(unescapedJidString);
	try {
		return from(localpart, domainpart, resource);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(unescapedJidString, e);
	}
}
 
Example 10
Source File: JidCreate.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link BareJid} representing the given String.
 *
 * @param jid the input String.
 * @param context the JXMPP context.
 * @return a bare JID representing the given String.
 * @throws XmppStringprepException if an error occurs.
 */
public static BareJid bareFrom(String jid, JxmppContext context) throws XmppStringprepException {
	BareJid bareJid;
	if (context.isCachingEnabled()) {
		bareJid = BAREJID_CACHE.lookup(jid);
		if (bareJid != null) {
			return bareJid;
		}
	}

	String localpart = XmppStringUtils.parseLocalpart(jid);
	String domainpart = XmppStringUtils.parseDomain(jid);
	try {
		if (localpart.length() != 0) {
			bareJid = new LocalAndDomainpartJid(localpart, domainpart, context);
		} else {
			bareJid = new DomainpartJid(domainpart, context);
		}
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(jid, e);
	}

	if (context.isCachingEnabled()) {
		BAREJID_CACHE.put(jid, bareJid);
	}
	return bareJid;
}
 
Example 11
Source File: JidCreate.java    From jxmpp with Apache License 2.0 5 votes vote down vote up
/**
 * Get a {@link EntityFullJid} representing the given unescaped String.
 *
 * @param unescapedJidString the JID's String.
 * @param context the JXMPP context.
 * @return a full JID representing the input String.
 * @throws XmppStringprepException if an error occurs.
 */
public static EntityFullJid entityFullFromUnescaped(String unescapedJidString, JxmppContext context) throws XmppStringprepException {
	EntityFullJid fullJid;
	if (context.isCachingEnabled()) {
		fullJid = ENTITY_FULLJID_CACHE.lookup(unescapedJidString);
		if (fullJid != null) {
			return fullJid;
		}
	}

	String localpart = XmppStringUtils.parseLocalpart(unescapedJidString);
	// Some as from(String), but we escape the localpart
	localpart = XmppStringUtils.escapeLocalpart(localpart);

	String domainpart = XmppStringUtils.parseDomain(unescapedJidString);
	String resource = XmppStringUtils.parseResource(unescapedJidString);
	try {
		fullJid = new LocalDomainAndResourcepartJid(localpart, domainpart, resource, context);
	} catch (XmppStringprepException e) {
		throw new XmppStringprepException(unescapedJidString, e);
	}

	if (context.isCachingEnabled()) {
		ENTITY_FULLJID_CACHE.put(unescapedJidString, fullJid);
	}
	return fullJid;
}
 
Example 12
Source File: FastpathPlugin.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void leaveWorkgroup() {
    workgroupLabel.setText(FpRes.getString("workgroup") + ":");
    logoutButton.setVisible(false);
    joinButton.setVisible(true);
    comboBox.setVisible(true);

    comboBox.removeAllItems();
    // Log into workgroup
    DomainBareJid workgroupService = JidCreate.domainBareFromOrThrowUnchecked("workgroup." + SparkManager.getSessionManager().getServerAddress());
    EntityFullJid jid = SparkManager.getSessionManager().getJID();

    try {
        Collection<String> col = Agent.getWorkgroups(workgroupService, jid, SparkManager.getConnection());
        // Add workgroups to combobox
        Iterator<String> workgroups = col.iterator();
        while (workgroups.hasNext()) {
            String workgroup = workgroups.next();
            String componentAddress = XmppStringUtils.parseDomain(workgroup);
            setComponentAddress(componentAddress);
            comboBox.addItem(XmppStringUtils.parseLocalpart(workgroup));
        }
    }
    catch (XMPPException | SmackException | InterruptedException ee) {
        // If the user does not belong to a workgroup, then don't initialize the rest of the plugin.
        return;
    }

    try {
        agentSession.setOnline(false);
    }
    catch (XMPPException | SmackException | InterruptedException e1) {
        Log.error(e1);
    }
    litWorkspace.unload();
    wgroup = null;

    // UnRegister tab handler
    SparkManager.getChatManager().removeSparkTabHandler(fastpathTabHandler);
}