public static String validateDomainName(String domain) {
        if (domain == null || domain.trim().isEmpty()) {
            throw new IllegalArgumentException("Domain name cannot be null or empty");
        }
        String result = IDN.toASCII(domain);
        if (result.equals(domain)) {
            // no conversion; validate again via USE_STD3_ASCII_RULES
            IDN.toASCII(domain, IDN.USE_STD3_ASCII_RULES);
        } else {
            Log.info("Converted domain name: from '{}' to '{}'", domain, result);
        }
        return result;
    }
Returns a valid domain name, possibly as an ACE-encoded IDN 
(per <a href="http://www.ietf.org/rfc/rfc3490.txt">RFC 3490</a>).

@param domain Proposed domain name
@return The validated domain name, possibly ACE-encoded
@throws IllegalArgumentException The given domain name is not valid
xmppserver/src/main/java/org/jivesoftware/util/StringUtils.java