List of usage examples for com.google.common.net InternetDomainName hasParent
public boolean hasParent()
From source file:google.registry.util.DomainNameUtils.java
/** * Returns the canonicalized TLD part of a valid fully-qualified domain name by stripping off the * leftmost part./* w ww. ja v a 2 s . c o m*/ * * <p>This function is compatible with multi-part TLDs and should not be called with subdomains. * * @throws IllegalArgumentException if there is no TLD */ public static String getTldFromDomainName(InternetDomainName domainName) { checkArgumentNotNull(domainName); checkArgument(domainName.hasParent(), "secondLevelDomainName does not have a TLD"); return domainName.parent().toString(); }
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./*ww w .ja v a 2s.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 {//w w w . jav a2 s. c o m levels = ImmutableList.builder(); } levels.add(internetDomainName.toString()); return levels; }
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./* w ww. j av a2 s .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:org.archive.crawler.prefetch.HostQuotaEnforcer.java
@Override protected boolean shouldProcess(CrawlURI curi) { String uriHostname = serverCache.getHostFor(curi.getUURI()).getHostName(); if (getApplyToSubdomains() && InternetDomainName.isValid(host) && InternetDomainName.isValid(uriHostname)) { InternetDomainName h = InternetDomainName.from(host); InternetDomainName uriHostOrAncestor = InternetDomainName.from(uriHostname); while (true) { if (uriHostOrAncestor.equals(h)) { return true; }//from ww w. j a v a 2s . co m if (uriHostOrAncestor.hasParent()) { uriHostOrAncestor = uriHostOrAncestor.parent(); } else { break; } } return false; } else { return serverCache.getHostFor(curi.getUURI()) == serverCache.getHostFor(host); } }
From source file:org.eel.kitchen.jsonschema.format.HostnameFormatSpecifier.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode value) { final ValidationMessage.Builder msg = newMsg(fmt).setMessage("string is not a valid hostname") .addInfo("value", value); final InternetDomainName hostname; try {/*from www . j a v a2 s.c o m*/ hostname = InternetDomainName.from(value.textValue()); } catch (IllegalArgumentException ignored) { report.addMessage(msg.build()); return; } if (ctx.hasFeature(ValidationFeature.STRICT_RFC_CONFORMANCE)) return; if (!hostname.hasParent()) report.addMessage(msg.build()); }
From source file:org.eel.kitchen.jsonschema.format.HostnameFormatAttribute.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode value) { final Message.Builder msg = newMsg(fmt).setMessage("string is not a valid hostname").addInfo("value", value);/* w ww . ja v a 2s . co m*/ final InternetDomainName hostname; try { hostname = InternetDomainName.from(value.textValue()); } catch (IllegalArgumentException ignored) { report.addMessage(msg.build()); return; } if (ctx.hasFeature(ValidationFeature.STRICT_RFC_CONFORMANCE)) return; if (!hostname.hasParent()) report.addMessage(msg.build()); }
From source file:org.archive.modules.fetcher.BdbCookieStore.java
/** * Returns a {@link LimitedCookieStoreFacade} whose * {@link LimitedCookieStoreFacade#getCookies()} method returns only cookies * from {@code host} and its parent domains, if applicable. *///from w ww .j a v a 2 s . c o m public CookieStore cookieStoreFor(String host) { CompositeCollection cookieCollection = new CompositeCollection(); if (InternetDomainName.isValid(host)) { InternetDomainName domain = InternetDomainName.from(host); while (domain != null) { Collection<Cookie> subset = hostSubset(domain.toString()); cookieCollection.addComposited(subset); if (domain.hasParent()) { domain = domain.parent(); } else { domain = null; } } } else { Collection<Cookie> subset = hostSubset(host.toString()); cookieCollection.addComposited(subset); } @SuppressWarnings("unchecked") List<Cookie> cookieList = new RestrictedCollectionWrappedList<Cookie>(cookieCollection); LimitedCookieStoreFacade store = new LimitedCookieStoreFacade(cookieList); return store; }