List of usage examples for com.google.common.net InternetDomainName isValid
public static boolean isValid(String name)
From source file:org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdDomainName.java
public static MdId asMdId(String mdName) { if (mdName == null || !InternetDomainName.isValid(mdName)) { throw new IllegalArgumentException( "MD Name must follow internet domain name pattern " + " Rejecting: " + mdName); }//from w ww. j a v a 2 s. c o m return asMdId(InternetDomainName.from(mdName)); }
From source file:com.francetelecom.clara.cloud.commons.FqdnHelper.java
/** * Takes a candidate fqdn and removes all invalid parts. if this becomes empty, it returns the default. * When too long, trims by removing chars at beginning * @param candidateFqdn//w ww. ja v a 2 s . c o m * @param defaultOnEmpty a valid default domain name, otherwise an exception is thrown. * @return */ public static String truncateUnsupportedCharsToValidHost(String candidateFqdn, String defaultOnEmpty) { if (defaultOnEmpty == null || defaultOnEmpty.isEmpty() || !InternetDomainName.isValid(defaultOnEmpty)) { throw new IllegalArgumentException("invalid default (" + defaultOnEmpty + ")"); } String trimmed; if (candidateFqdn == null || candidateFqdn.isEmpty()) { return defaultOnEmpty; } trimmed = InternetDomainNameCleaner.from(candidateFqdn).name(); if (trimmed.isEmpty()) { return defaultOnEmpty; } return trimmed; }
From source file:org.adaway.util.RegexUtils.java
/** * I could not find any android class that provides checking of an hostnames, thus I am using * regex// ww w . jav a2 s .co m * * @param input * @return return true if input is valid hostname */ public static boolean isValidHostname(String input) { return InternetDomainName.isValid(input); }
From source file:io.fluo.commoncrawl.data.util.LinkUtil.java
public static URL createURL(String url) throws ParseException { String cleanUrl = DataUtil.cleanUrl(url); try {/*from w w w . j a v a 2s . co m*/ URL u = new URL(cleanUrl); if (!u.getProtocol().equalsIgnoreCase("http") && !u.getProtocol().equalsIgnoreCase("https")) { throw new ParseException("Bad protocol: " + u.toString(), 0); } if (u.getUserInfo() != null) { throw new ParseException("No user info: " + u.toString(), 0); } if (!HostSpecifier.isValid(u.getHost())) { throw new ParseException("Invalid host: " + u.getHost(), 0); } if (InternetDomainName.isValid(u.getHost())) { if (!InternetDomainName.from(u.getHost()).isUnderPublicSuffix()) { throw new ParseException("Bad domain: " + u.getHost(), 0); } } String uri = DataUtil.toUri(cleanUrl); String reformUrl = DataUtil.toUrl(uri); if (!reformUrl.equals(cleanUrl)) { String msg = String.format("Url %s creates url %s when reformed from uri %s", cleanUrl, reformUrl, uri); log.info(msg); throw new ParseException(msg, 0); } return u; } catch (MalformedURLException e) { throw new ParseException(e.getMessage(), 0); } }
From source file:com.forerunnergames.tools.net.NetworkTools.java
public static boolean isValidDomainName(@Nullable final String address) { return address != null && InternetDomainName.isValid(address); }
From source file:com.google.api.tools.framework.aspects.naming.ServiceNameRule.java
@Override public void run(Model model) { String serviceName = model.getServiceConfig().getName(); if (!Strings.isNullOrEmpty(serviceName) && (!InternetDomainName.isValid(serviceName) // InternetDomainName.isValid does a lenient validation and allows underscores (which we // do not want to permit as DNS names). Therefore explicitly checking for underscores. || INVALID_CHARACTER_PATTERN.matcher(serviceName).find())) { warning(getLocationInConfig(model.getServiceConfig(), Service.NAME_FIELD_NUMBER), "Invalid DNS name '%s'.", serviceName); }// w ww. j a v a 2 s . c o m }
From source file:org.jclouds.openstack.keystone.v1_1.functions.RegionFirstPartOfDNSNameOrProvider.java
@Override public String apply(Endpoint input) { if (input.getRegion() != null) return input.getRegion(); String host = input.getPublicURL().getHost(); if (InternetDomainName.isValid(host)) { InternetDomainName domain = InternetDomainName.from(host); return domain.parts().get(0); }/*from w w w.j av a 2 s. co m*/ return provider; }
From source file:org.eel.kitchen.jsonschema.keyword.common.format.HostnameValidator.java
@Override public ValidationReport validate(final ValidationContext context, final JsonNode instance) throws JsonValidationFailureException { final ValidationReport report = context.createReport(); final String value = instance.getTextValue(); if (!InternetDomainName.isValid(value)) report.fail("string is not a valid hostname"); return report; }
From source file:webindex.core.models.URL.java
public static boolean isValidHost(String host) { return HostSpecifier.isValid(host) && InternetDomainName.isValid(host) && InternetDomainName.from(host).isUnderPublicSuffix(); }
From source file:org.sindice.core.analytics.commons.util.URIUtil.java
/** * Return the second-level domain name. Returns null if the domain is not valid. * This method normalises domain names by removing the leading www sub-domain, * if present./*from w w w. j av a 2s. co m*/ * @param domain * @return */ public static String getSndDomain(String domain) { if (domain == null) { return null; } // Remove www subdomain if it exists if (domain.startsWith("www.")) { domain = domain.substring(4); } if (InternetDomainName.isValid(domain)) { // the domain is valid according to the RFC3490 final InternetDomainName idn = InternetDomainName.from(domain); if (idn.hasPublicSuffix()) { // the domain has a public suffix if (idn.isUnderPublicSuffix()) { return idn.topPrivateDomain().name(); } else if (idn.hasParent()) { final List<String> parts = idn.parts(); return parts.get(parts.size() - 2).concat(".").concat(parts.get(parts.size() - 1)); } } } return null; }