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

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

Introduction

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

Prototype

public static InternetDomainName from(String domain) 

Source Link

Document

Returns an instance of InternetDomainName after lenient validation.

Usage

From source file:org.archive.porky.ExtractTopPrivateDomainFromHostNameUDF.java

public String exec(Tuple input) throws IOException {
    if (input == null || input.size() == 0)
        return null;
    String str = null;/*from  www  .  j  a  v a2s  .  c  om*/
    try {
        str = (String) input.get(0);
        InternetDomainName domainName = InternetDomainName.from(str);
        return (domainName.topPrivateDomain().name());
    } catch (Exception e) {
        return "other";
    }
}

From source file:com.francetelecom.clara.cloud.techmodel.cf.RouteUri.java

public String getHost() {
    return InternetDomainName.from(value).parts().get(0);
}

From source file:org.xacml4j.v30.DNSName.java

public DNSName(String domainName, PortRange range) {
    Preconditions.checkNotNull(domainName);
    Preconditions.checkNotNull(range);//from  w  ww .j  a va  2s  . c  o m
    this.name = InternetDomainName.from(domainName);
    this.portRange = range;
}

From source file:webindex.core.models.URL.java

public static String domainFromHost(String host) {
    return InternetDomainName.from(host).topPrivateDomain().name();
}

From source file:io.ssc.trackthetrackers.util.TopPrivateDomainExtractor.java

public static String extract(String url) throws URISyntaxException {

    String urlToInspect = url.replaceAll("\\[", "").replaceAll("\\]", "").replaceAll("\\{", "")
            .replaceAll("}", "").replaceAll("_", "").replaceAll("<", "").replaceAll(">", "")
            .replaceAll("\\|", "").replaceAll("\\^", "").replaceAll("\\\\", "").replaceAll("%", "");

    String domainToInspect = urlToInspect;

    if (domainToInspect.startsWith("http://")) {
        domainToInspect = new URI(urlToInspect).getHost();

        domainToInspect.replaceAll("http://", "");

        if (domainToInspect.endsWith("/")) {
            domainToInspect = domainToInspect.substring(0, domainToInspect.length() - 1);
        }//from ww w. j a  v  a 2 s . co m
    }

    if (domainToInspect.endsWith(".amazonaws.com")) {
        return "amazonaws.com";
    }

    if (domainToInspect.endsWith(".cloudfront.net") || domainToInspect.equalsIgnoreCase("cloudfront.net")) {
        return "cloudfront.net";
    }

    if (domainToInspect.endsWith(".googlecode.com")) {
        return "googlecode.com";
    }

    if (domainToInspect.endsWith(".blogspot.com") || domainToInspect.equalsIgnoreCase("blogspot.com")) {
        return "blogspot.com";
    }

    if (domainToInspect.endsWith(".googleapis.com")) {
        return "googleapis.com";
    }

    if (domainToInspect.endsWith(".appspot.com")) {
        return "appspot.com";
    }

    return InternetDomainName.from(domainToInspect).topPrivateDomain().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 a  va  2 s . c o  m*/
    return provider;
}

From source file:com.jaeksoft.searchlib.analysis.filter.domain.TldTokenFilter.java

@Override
public final boolean incrementToken() throws IOException {
    if (!input.incrementToken())
        return false;
    try {//  ww  w  .  j  a v  a 2  s.  co  m
        URL url = LinkUtils.newEncodedURL(termAtt.toString());
        InternetDomainName domainName = InternetDomainName.from(url.getHost());
        termAtt.setEmpty();
        termAtt.append(domainName.publicSuffix().name());
    } catch (MalformedURLException e) {
        if (silent)
            return false;
        throw e;
    } catch (IllegalArgumentException e) {
        if (silent)
            return false;
        throw e;
    } catch (URISyntaxException e) {
        if (silent)
            return false;
        throw new IOException(e);
    }
    return true;
}

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.j a  v  a 2 s .c o m*/
    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:com.jaeksoft.searchlib.analysis.filter.domain.DomainTldTokenFilter.java

@Override
public final boolean incrementToken() throws IOException {
    if (!input.incrementToken())
        return false;
    try {//from  w w  w. ja va2 s  . c o  m
        URL url = LinkUtils.newEncodedURL(termAtt.toString());
        InternetDomainName domainName = InternetDomainName.from(url.getHost());
        termAtt.setEmpty();
        termAtt.append(domainName.topPrivateDomain().toString());
    } catch (MalformedURLException e) {
        if (silent)
            return false;
        throw e;
    } catch (IllegalArgumentException e) {
        if (silent)
            return false;
        throw e;
    } catch (URISyntaxException e) {
        if (silent)
            return false;
        throw new IOException(e);
    }
    return true;
}

From source file:org.apache.hadoop.hive.ql.udf.UDFMainDomain.java

public Text evaluate(Text s) {
    if (s == null) {
        return result;
    }//w w w  .  j a v  a2  s  .c o m
    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;
}