List of usage examples for com.google.common.net InternetDomainName parts
ImmutableList parts
To view the source code for com.google.common.net InternetDomainName parts.
Click Source Link
From source file:google.registry.util.DomainNameUtils.java
/** Checks whether "name" is a strict subdomain of "potentialParent". */ public static boolean isUnder(InternetDomainName name, InternetDomainName potentialParent) { int numNameParts = name.parts().size(); int numParentParts = potentialParent.parts().size(); return numNameParts > numParentParts && name.parts().subList(numNameParts - numParentParts, numNameParts) .equals(potentialParent.parts()); }
From source file:google.registry.model.registry.label.ReservedList.java
/** * Returns true if the given label and TLD is reserved for an anchor tenant, and the given * auth code matches the one set on the reservation. *///from w w w . ja v a 2s.co m public static boolean matchesAnchorTenantReservation(InternetDomainName domainName, String authCode) { ReservedListEntry entry = getReservedListEntry(domainName.parts().get(0), domainName.parent().toString()); return entry != null && entry.reservationType == RESERVED_FOR_ANCHOR_TENANT && Objects.equals(entry.getAuthCode(), authCode); }
From source file:uk.bl.wa.extract.LinkExtractor.java
public static String extractPublicSuffixFromHost(String host) { if (host == null) return null; // Parse out the public suffix: InternetDomainName domainName; try {//from www . jav a2 s.c o m domainName = InternetDomainName.from(host); } catch (Exception e) { return null; } InternetDomainName suffix = null; if (host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if (parts.size() >= 2) { suffix = InternetDomainName.from(parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { suffix = domainName.publicSuffix(); } // Return a value: if (suffix == null) return null; return suffix.toString(); }
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 ww w .j ava 2s .c o 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; }
From source file:google.registry.flows.host.HostFlowUtils.java
/** Return the {@link DomainResource} this host is subordinate to, or null for external hosts. */ static DomainResource lookupSuperordinateDomain(InternetDomainName hostName, DateTime now) throws EppException { Optional<InternetDomainName> tld = findTldForName(hostName); if (!tld.isPresent()) { // This is an host on a TLD we don't run, therefore obviously external, so we are done. return null; }//from w w w . j a v a 2 s .co m // This is a subordinate host String domainName = Joiner.on('.') .join(Iterables.skip(hostName.parts(), hostName.parts().size() - (tld.get().parts().size() + 1))); DomainResource superordinateDomain = loadByForeignKey(DomainResource.class, domainName, now); if (superordinateDomain == null || !isActive(superordinateDomain, now)) { throw new SuperordinateDomainDoesNotExistException(domainName); } return superordinateDomain; }
From source file:uk.bl.wa.extract.LinkExtractor.java
/** * Attempt to parse out the private domain. Fall back on host if things go * awry./*from w w w .j a v a2s. c o m*/ * * @param host * @return */ public static String extractPrivateSuffixFromHost(String host) { if (host == null) return null; // Parse out the public suffix: InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch (Exception e) { return host; } InternetDomainName suffix = null; // It appears the IDN class does not know about the various UK // second-level domains. // If it's a UK host, override the result by assuming three levels: if (host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if (parts.size() >= 3) { suffix = InternetDomainName.from(parts.get(parts.size() - 3) + "." + parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { if (domainName.isTopPrivateDomain() || domainName.isUnderPublicSuffix()) { suffix = domainName.topPrivateDomain(); } else { suffix = domainName; } } // If it all failed for some reason, fall back on the host value: if (suffix == null) suffix = domainName; return suffix.toString(); }
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 ww w . j av a 2s .c o m*/ return provider; }
From source file:org.apache.hadoop.hive.ql.udf.UDFMainDomain.java
public Text evaluate(Text s) { if (s == null) { return result; }/* w ww .j a v a 2 s .com*/ String strMainDomain = s.toString(); try { InternetDomainName domainname = InternetDomainName.from(strMainDomain).topPrivateDomain(); strMainDomain = Joiner.on(".").skipNulls().join(domainname.parts()); } catch (Exception e) { strMainDomain = s.toString(); } result.set(strMainDomain); return result; }
From source file:foo.domaintest.action.RequestModule.java
/** Provides the top level domain name from the request URL. */ @Provides//from w ww . jav a2s. co m @RequestData("tld") String provideTld(@RequestData("domainName") InternetDomainName domainName) { return getLast(domainName.parts()); }
From source file:com.linkedin.pinot.common.response.ServerInstance.java
/** * As per <a href="https://tools.ietf.org/html/rfc952">RFC-952</a> domain names should begin with a letter. * That said, <a href="https://tools.ietf.org/html/rfc1123#page-13">RFC-1123</a> updated it say that it may also begin * with a digit. Indeed, <a href="http://9292.nl/">this</a> is a valid domain name. Only the top-level domain (i.e. the * last portion) has to be non-numeric. More clarification on this matter is in * <a href="https://tools.ietf.org/html/rfc3696#section-2">RFC-3696</a> * * A potentially faster solution is//from w w w . j a v a 2 s. c om * * if (first char is a digit) { * it is probably ipv4; * return name; * } else { * it could be ipv6 (in which case no dots), or a hostname * return substring before the first dot. * } * * It will fail if there are host names starting with a digit, but will work right otherwise. */ private String makeShortHostName(final String name) { try { InternetDomainName domainName = InternetDomainName.from(name); return domainName.parts().get(0); } catch (Exception e) { return name; } }