Example usage for com.google.common.net InternetDomainName toString

List of usage examples for com.google.common.net InternetDomainName toString

Introduction

In this page you can find the example usage for com.google.common.net InternetDomainName toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns the domain name, normalized to all lower case.

Usage

From source file:org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdIdDomainName.java

public static MdId asMdId(InternetDomainName mdName) {
    if (mdName == null || mdName.toString().length() < MD_NAME_MIN_LEN
            || mdName.toString().length() > MD_NAME_MAX_LEN) {
        throw new IllegalArgumentException("MD Domain Name must be between " + MD_NAME_MIN_LEN + " and "
                + MD_NAME_MAX_LEN + " chars long" + " Rejecting: " + mdName);
    }//from w w w.j  a  v  a 2s.  co  m
    return new MdIdDomainName(mdName);
}

From source file:google.registry.tools.EppToolCommand.java

/**
 * Helper function for grouping sets of domain names into respective TLDs. Useful for batched
 * EPP calls when invoking commands (i.e. domain check) with sets of domains across multiple TLDs.
 *///from w  ww.java  2s .  c om
protected static Multimap<String, String> validateAndGroupDomainNamesByTld(List<String> names) {
    ImmutableMultimap.Builder<String, String> builder = new ImmutableMultimap.Builder<>();
    for (String name : names) {
        InternetDomainName tld = findTldForNameOrThrow(InternetDomainName.from(name));
        builder.put(tld.toString(), name);
    }
    return builder.build();
}

From source file:google.registry.model.registry.Registries.java

/**
 * Returns the registered TLD which this domain name falls under, or throws an exception if no
 * match exists.// w w  w .  j  av  a  2  s.  c  om
 */
public static InternetDomainName findTldForNameOrThrow(InternetDomainName domainName) {
    return checkArgumentNotNull(findTldForName(domainName).orNull(),
            "Domain name is not under a recognized TLD: %s", domainName.toString());
}

From source file:google.registry.flows.host.HostFlowUtils.java

/** Checks that a host name is valid. */
static InternetDomainName validateHostName(String name) throws EppException {
    checkArgumentNotNull(name, "Must specify host name to validate");
    if (name.length() > 253) {
        throw new HostNameTooLongException();
    }//w w  w  . jav a  2s  . com
    String hostNameLowerCase = Ascii.toLowerCase(name);
    if (!name.equals(hostNameLowerCase)) {
        throw new HostNameNotLowerCaseException(hostNameLowerCase);
    }
    try {
        String hostNamePunyCoded = Idn.toASCII(name);
        if (!name.equals(hostNamePunyCoded)) {
            throw new HostNameNotPunyCodedException(hostNamePunyCoded);
        }
        InternetDomainName hostName = InternetDomainName.from(name);
        if (!name.equals(hostName.toString())) {
            throw new HostNameNotNormalizedException(hostName.toString());
        }
        // Checks whether a hostname is deep enough. Technically a host can be just one under a
        // public suffix (e.g. example.com) but we require by policy that it has to be at least one
        // part beyond that (e.g. ns1.example.com). The public suffix list includes all current
        // ccTlds, so this check requires 4+ parts if it's a ccTld that doesn't delegate second
        // level domains, such as .co.uk. But the list does not include new tlds, so in that case
        // we just ensure 3+ parts. In the particular case where our own tld has a '.' in it, we know
        // that there need to be 4 parts as well.
        if (hostName.isUnderPublicSuffix()) {
            if (hostName.parent().isUnderPublicSuffix()) {
                return hostName;
            }
        } else {
            // We need to know how many parts the hostname has beyond the public suffix, but we don't
            // know what the public suffix is. If the host is in bailiwick and we are hosting a
            // multipart "tld" like .co.uk the publix suffix might be 2 parts. Otherwise it's an
            // unrecognized tld that's not on the public suffix list, so assume the tld alone is the
            // public suffix.
            Optional<InternetDomainName> tldParsed = findTldForName(hostName);
            int suffixSize = tldParsed.isPresent() ? tldParsed.get().parts().size() : 1;
            if (hostName.parts().size() >= suffixSize + 2) {
                return hostName;
            }
        }
        throw new HostNameTooShallowException();
    } catch (IllegalArgumentException e) {
        throw new InvalidHostNameException();
    }
}

From source file:google.registry.model.registry.Registries.java

/**
 * Returns TLD which the domain name or hostname falls under, no matter how many levels of
 * sublabels there are./*from   w  ww . j a v a2 s  . co  m*/
 *
 * <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.absent();
}

From source file:uk.bl.wa.extract.LinkExtractor.java

private static ImmutableList.Builder<String> parentLevels(InternetDomainName internetDomainName) {
    ImmutableList.Builder<String> levels;

    if (internetDomainName.hasParent()) {
        levels = parentLevels(internetDomainName.parent());
    } else {/*from   w  ww.  j av a 2s  . c  om*/
        levels = ImmutableList.builder();
    }

    levels.add(internetDomainName.toString());
    return levels;
}

From source file:google.registry.flows.domain.DomainPricingLogic.java

/**
 * Checks whether an LRP token String maps to a valid {@link LrpTokenEntity} for the domain name's
 * TLD, and return that entity (wrapped in an {@link Optional}) if one exists.
 *
 * <p>This method has no knowledge of whether or not an auth code (interpreted here as an LRP
 * token) has already been checked against the reserved list for QLP (anchor tenant), as auth
 * codes are used for both types of registrations.
 *//*from  w ww  .jav a  2s.com*/
public static Optional<LrpTokenEntity> getMatchingLrpToken(String lrpToken, InternetDomainName domainName) {
    // Note that until the actual per-TLD logic is built out, what's being done here is a basic
    // domain-name-to-assignee match.
    if (!lrpToken.isEmpty()) {
        LrpTokenEntity token = ofy().load().key(Key.create(LrpTokenEntity.class, lrpToken)).now();
        if (token != null && token.getAssignee().equalsIgnoreCase(domainName.toString())
                && token.getRedemptionHistoryEntry() == null
                && token.getValidTlds().contains(domainName.parent().toString())) {
            return Optional.of(token);
        }
    }
    return Optional.<LrpTokenEntity>absent();
}

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;/*  www . jav a2  s. co  m*/
    try {
        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:uk.bl.wa.extract.LinkExtractor.java

/**
 * Attempt to parse out the private domain. Fall back on host if things go
 * awry./* w w  w  . j  a  v a 2 s  .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:google.registry.tools.GetApplicationIdsCommand.java

@Override
public void run() {
    for (String domainName : mainParameters) {
        InternetDomainName tld = findTldForNameOrThrow(InternetDomainName.from(domainName));
        assertTldExists(tld.toString());
        System.out.printf("%s:%n", domainName);

        // Sample output:
        // example.tld:
        //    1 (NewRegistrar)
        //    2 (OtherRegistrar)
        // example2.tld:
        //    No applications exist for 'example2.tld'.
        ImmutableList<DomainApplication> applications = ImmutableList
                .copyOf(loadActiveApplicationsByDomainName(domainName, DateTime.now(UTC)));
        if (applications.isEmpty()) {
            System.out.printf("    No applications exist for \'%s\'.%n", domainName);
        } else {//from   w  w w .  j a va2 s . co m
            for (DomainApplication application : applications) {
                System.out.printf("    %s (%s)%n", application.getForeignKey(),
                        application.getCurrentSponsorClientId());
            }
        }
    }
}