/** * Returns true if the specified <code>String</code> matches any * widely used "local" domains (localhost or localdomain). Leading dots are * ignored if present. The search is case-insensitive. * @param lTld the parameter to check for local TLD status, not null * @return true if the parameter is an local TLD */ public boolean isValidLocalTld(String lTld) { final String key = chompLeadingDot(unicodeToASCII(lTld).toLowerCase(Locale.ENGLISH)); return arrayContains(LOCAL_TLDS, key); }
/** * Returns true if the specified <code>String</code> matches any * IANA-defined infrastructure top-level domain. Leading dots are * ignored if present. The search is case-insensitive. * @param iTld the parameter to check for infrastructure TLD status, not null * @return true if the parameter is an infrastructure TLD */ public boolean isValidInfrastructureTld(String iTld) { final String key = chompLeadingDot(unicodeToASCII(iTld).toLowerCase(Locale.ENGLISH)); return arrayContains(INFRASTRUCTURE_TLDS, key); }
final boolean isValidDomainSyntax(String domain) { if (domain == null) { return false; } domain = unicodeToASCII(domain); // hosts must be equally reachable via punycode and Unicode; // Unicode is never shorter than punycode, so check punycode // if domain did not convert, then it will be caught by ASCII // checks in the regexes below if (domain.length() > MAX_DOMAIN_LENGTH) { return false; } String[] groups = domainRegex.match(domain); return (groups != null && groups.length > 0) || hostnameRegex.isValid(domain); }
/** * Returns true if the specified <code>String</code> matches any * IANA-defined generic top-level domain. Leading dots are ignored * if present. The search is case-insensitive. * @param gTld the parameter to check for generic TLD status, not null * @return true if the parameter is a generic TLD */ public boolean isValidGenericTld(String gTld) { final String key = chompLeadingDot(unicodeToASCII(gTld).toLowerCase(Locale.ENGLISH)); return (arrayContains(GENERIC_TLDS, key) || arrayContains(genericTLDsPlus, key)) && !arrayContains(genericTLDsMinus, key); }
/** * Returns true if the specified <code>String</code> matches any * IANA-defined country code top-level domain. Leading dots are * ignored if present. The search is case-insensitive. * @param ccTld the parameter to check for country code TLD status, not null * @return true if the parameter is a country code TLD */ public boolean isValidCountryCodeTld(String ccTld) { final String key = chompLeadingDot(unicodeToASCII(ccTld).toLowerCase(Locale.ENGLISH)); return (arrayContains(COUNTRY_CODE_TLDS, key) || arrayContains(countryCodeTLDsPlus, key)) && !arrayContains(countryCodeTLDsMinus, key); }
/** * Returns true if the specified <code>String</code> parses * as a valid domain name with a recognized top-level domain. * The parsing is case-insensitive. * @param domain the parameter to check for domain name syntax * @return true if the parameter is a valid domain name */ public boolean isValid(String domain) { if (domain == null) { return false; } domain = unicodeToASCII(domain); // hosts must be equally reachable via punycode and Unicode; // Unicode is never shorter than punycode, so check punycode // if domain did not convert, then it will be caught by ASCII // checks in the regexes below if (domain.length() > MAX_DOMAIN_LENGTH) { return false; } String[] groups = domainRegex.match(domain); if (groups != null && groups.length > 0) { return isValidTld(groups[0]); } return allowLocal && hostnameRegex.isValid(domain); }
final String authorityASCII = DomainValidator.unicodeToASCII(authority);
/** * Returns true if the specified <code>String</code> matches any * IANA-defined top-level domain. Leading dots are ignored if present. * The search is case-insensitive. * @param tld the parameter to check for TLD status, not null * @return true if the parameter is a TLD */ public boolean isValidTld(String tld) { tld = unicodeToASCII(tld); if(allowLocal && isValidLocalTld(tld)) { return true; } return isValidInfrastructureTld(tld) || isValidGenericTld(tld) || isValidCountryCodeTld(tld); }
}; for(String s : asciidots) { assertEquals(s,DomainValidator.unicodeToASCII(s)); }; for(String s[] : otherDots) { assertEquals(s[1],DomainValidator.unicodeToASCII(s[0]));
/** * Returns true if the specified <code>String</code> matches any * IANA-defined infrastructure top-level domain. Leading dots are * ignored if present. The search is case-insensitive. * @param iTld the parameter to check for infrastructure TLD status, not null * @return true if the parameter is an infrastructure TLD */ public boolean isValidInfrastructureTld(String iTld) { final String key = chompLeadingDot(unicodeToASCII(iTld).toLowerCase(Locale.ENGLISH)); return arrayContains(INFRASTRUCTURE_TLDS, key); }
/** * Returns true if the specified <code>String</code> matches any * widely used "local" domains (localhost or localdomain). Leading dots are * ignored if present. The search is case-insensitive. * @param lTld the parameter to check for local TLD status, not null * @return true if the parameter is an local TLD */ public boolean isValidLocalTld(String lTld) { final String key = chompLeadingDot(unicodeToASCII(lTld).toLowerCase(Locale.ENGLISH)); return arrayContains(LOCAL_TLDS, key); }
/** * Returns true if the specified <code>String</code> matches any * IANA-defined country code top-level domain. Leading dots are * ignored if present. The search is case-insensitive. * @param ccTld the parameter to check for country code TLD status, not null * @return true if the parameter is a country code TLD */ public boolean isValidCountryCodeTld(String ccTld) { final String key = chompLeadingDot(unicodeToASCII(ccTld).toLowerCase(Locale.ENGLISH)); return (arrayContains(COUNTRY_CODE_TLDS, key) || arrayContains(countryCodeTLDsPlus, key)) && !arrayContains(countryCodeTLDsMinus, key); }
final boolean isValidDomainSyntax(String domain) { if (domain == null) { return false; } domain = unicodeToASCII(domain); // hosts must be equally reachable via punycode and Unicode; // Unicode is never shorter than punycode, so check punycode // if domain did not convert, then it will be caught by ASCII // checks in the regexes below if (domain.length() > MAX_DOMAIN_LENGTH) { return false; } String[] groups = domainRegex.match(domain); return (groups != null && groups.length > 0 && completeDomainRegex.match(domain) != null) || hostnameRegex.isValid(domain); }
/** * Returns true if the specified <code>String</code> matches any * IANA-defined generic top-level domain. Leading dots are ignored * if present. The search is case-insensitive. * @param gTld the parameter to check for generic TLD status, not null * @return true if the parameter is a generic TLD */ public boolean isValidGenericTld(String gTld) { final String key = chompLeadingDot(unicodeToASCII(gTld).toLowerCase(Locale.ENGLISH)); return (arrayContains(GENERIC_TLDS, key) || arrayContains(genericTLDsPlus, key)) && !arrayContains(genericTLDsMinus, key); }
/** * Returns true if the specified <code>String</code> parses * as a valid domain name with a recognized top-level domain. * The parsing is case-insensitive. * @param domain the parameter to check for domain name syntax * @return true if the parameter is a valid domain name */ public boolean isValid(String domain) { if (domain == null) { return false; } domain = unicodeToASCII(domain); // hosts must be equally reachable via punycode and Unicode; // Unicode is never shorter than punycode, so check punycode // if domain did not convert, then it will be caught by ASCII // checks in the regexes below if (domain.length() > MAX_DOMAIN_LENGTH) { return false; } String[] groups = domainRegex.match(domain); if (groups != null && groups.length > 0 && completeDomainRegex.match(domain) != null) { return isValidTld(groups[0]); } return allowLocal && hostnameRegex.isValid(domain); }
/** * Returns true if the specified <code>String</code> matches any * IANA-defined top-level domain. Leading dots are ignored if present. * The search is case-insensitive. * @param tld the parameter to check for TLD status, not null * @return true if the parameter is a TLD */ public boolean isValidTld(String tld) { tld = unicodeToASCII(tld); if(allowLocal && isValidLocalTld(tld)) { return true; } return isValidInfrastructureTld(tld) || isValidGenericTld(tld) || isValidCountryCodeTld(tld); }
final String authorityASCII = DomainValidator.unicodeToASCII(authority);