Java Code Examples for com.google.common.net.InternetDomainName#parent()
The following examples show how to use
com.google.common.net.InternetDomainName#parent() .
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: DigitalAssetLinksRepository.java From input-samples with Apache License 2.0 | 5 votes |
public static String getCanonicalDomain(String domain) { InternetDomainName idn = InternetDomainName.from(domain); while (idn != null && !idn.isTopPrivateDomain()) { idn = idn.parent(); } return idn == null ? null : idn.toString(); }
Example 2
Source File: DigitalAssetLinksRepository.java From android-AutofillFramework with Apache License 2.0 | 5 votes |
public static String getCanonicalDomain(String domain) { InternetDomainName idn = InternetDomainName.from(domain); while (idn != null && !idn.isTopPrivateDomain()) { idn = idn.parent(); } return idn == null ? null : idn.toString(); }
Example 3
Source File: Registries.java From nomulus with Apache License 2.0 | 3 votes |
/** * Returns TLD which the domain name or hostname falls under, no matter how many levels of * sublabels there are. * * <p><b>Note:</b> This routine will only work on names under TLDs for which this registry is * authoritative. To extract TLDs from domains (not hosts) that other registries control, use * {@link google.registry.util.DomainNameUtils#getTldFromDomainName(String) * DomainNameUtils#getTldFromDomainName}. * * @param domainName domain name or host name (but not TLD) under an authoritative TLD * @return TLD or absent if {@code domainName} has no labels under an authoritative TLD */ public static Optional<InternetDomainName> findTldForName(InternetDomainName domainName) { ImmutableSet<String> tlds = getTlds(); while (domainName.hasParent()) { domainName = domainName.parent(); if (tlds.contains(domainName.toString())) { return Optional.of(domainName); } } return Optional.empty(); }