List of usage examples for com.google.common.net InternetDomainName from
public static InternetDomainName from(String domain)
From source file:uk.bl.wa.extract.LinkExtractor.java
/** * Returns a list of each level of the given host address. E.g. 'bbc.co.uk' would return: * [uk],[co.uk],[bbc.co.uk]/*from w w w . j av a 2 s .com*/ * * @param host The full host address * @return An ImmutableList of Strings, one element per host level */ public static ImmutableList<String> allLevels(String host) { // Default to empty list Builder<String> result = ImmutableList.builder(); try { InternetDomainName domainName = InternetDomainName.from(host); result = parentLevels(domainName); } catch (NullPointerException e) { // ignore errors of this nature } catch (IllegalArgumentException e) { // This happens for IP-based hosts, see // https://github.com/ukwa/webarchive-discovery/issues/90 } return result.build(); }
From source file:org.artifactory.repo.remote.browse.HtmlRepositoryBrowser.java
private boolean isBintray(String url) { try {/*from ww w . j a v a 2 s . c om*/ return bintrayDomain.equals(InternetDomainName.from(url).topPrivateDomain()); } catch (Exception e) { log.debug("url : " + url + " is not under public domain"); } return false; }
From source file:google.registry.flows.domain.DomainPricingLogic.java
/** Returns a new transfer price for the pricer. */ public FeesAndCredits getTransferPrice(Registry registry, String domainName, DateTime transferDate, int years) throws EppException { Money renewCost = getDomainRenewCost(domainName, transferDate, years); return customLogic.customizeTransferPrice(TransferPriceParameters.newBuilder() .setFeesAndCredits(new FeesAndCredits.Builder().setCurrency(registry.getCurrency()) .addFeeOrCredit(Fee.create(renewCost.getAmount(), FeeType.RENEW)).build()) .setRegistry(registry).setDomainName(InternetDomainName.from(domainName)).setAsOfDate(transferDate) .setYears(years).build());/* w w w .j av a 2 s. c o m*/ }
From source file:org.artifactory.repo.remote.browse.HtmlRepositoryBrowser.java
private InternetDomainName getBintrayDomain() { String bintrayHost;//w w w . j a v a2s. co m try { bintrayHost = new URL(ConstantValues.bintrayUrl.getString()).getHost(); } catch (MalformedURLException e) { log.error(String.format("Failed to parse bintray URL '%s' falling back to bintray.com", ConstantValues.bintrayUrl.getString())); bintrayHost = "bintray.com"; } return InternetDomainName.from(bintrayHost); }
From source file:google.registry.dns.writer.dnsupdate.DnsUpdateWriter.java
@Override public void publishHost(String hostName) { // Get the superordinate domain name of the host. InternetDomainName host = InternetDomainName.from(hostName); ImmutableList<String> hostParts = host.parts(); Optional<InternetDomainName> tld = Registries.findTldForName(host); // host not managed by our registry, no need to update DNS. if (!tld.isPresent()) { return;//from ww w.j ava2 s . c om } ImmutableList<String> tldParts = tld.get().parts(); ImmutableList<String> domainParts = hostParts.subList(hostParts.size() - tldParts.size() - 1, hostParts.size()); String domain = Joiner.on(".").join(domainParts); // Refresh the superordinate domain, always delete the host first to ensure idempotency, // and only publish the host if it is a glue record. publishDomain(domain, hostName); }
From source file:com.crosstreelabs.cognitio.conductor.Conductor.java
protected void saveWork(final WorkCompleted complete) { CatalogueEntry entry = complete.getWork(); entry.status = Status.INDEXED;//w w w. j av a 2 s. c om if (entry.lastVisit == null) { entry.lastVisit = new DateTime(); } cs.save(entry); Resource resource = complete.getResult(); communicator.toLibrarian(new IndexRequest(resource)); // 1) Create catalogue entries for unknown links Collection<String> links = new HashSet<>(complete.getLinks()); List<CatalogueEntry> entries = cs.findAllLocations(links.toArray(new String[0])); // 1a) Don't duplicate catalogue entries that we already know about for (CatalogueEntry e : entries) { links.remove(e.location); } // 1b) Create the remaining catalogue entries for (String str : links) { try { URL url; try { url = URL.parse(str); } catch (GalimatiasParseException ex) { continue; } String tld = InternetDomainName.from(url.host().toString()).topPrivateDomain().toString(); Host host = hs.findByDomain(tld); if (host == null) { host = new Host(); host.host = tld; } CatalogueEntry e = createChild(entry, str); e.host = host; cs.save(e); } catch (Exception e) { } } entries = cs.findAllLocations(complete.getLinks().toArray(new String[0])); // 2) Find existing references Collection<Reference> knownReferences = rs.findReferencesFrom(entry); Collection<Reference> defunctReferences = new HashSet<>(knownReferences); // 2a) Ignore references we'd otherwise duplicate Iterator<Reference> referenceIterator = defunctReferences.iterator(); outer: while (referenceIterator.hasNext()) { Reference ref = referenceIterator.next(); Iterator<CatalogueEntry> entryIterator = entries.iterator(); while (entryIterator.hasNext()) { CatalogueEntry e = entryIterator.next(); if (ref.linkee.equals(e.id)) { referenceIterator.remove(); entryIterator.remove(); break outer; } } ref.defunct = new DateTime(); } // 2b) Invalidate defunct references rs.saveAll(defunctReferences); // 3) Create references for all remaining catalogue entries Collection<Reference> newReferences = new HashSet<>(); for (CatalogueEntry e : entries) { Reference ref = new Reference(); ref.linker = entry.id; ref.linkee = e.id; ref.discovered = new DateTime(); newReferences.add(ref); } rs.saveAll(newReferences); }
From source file:google.registry.flows.domain.DomainPricingLogic.java
/** Returns a new update price for the pricer. */ public FeesAndCredits getUpdatePrice(Registry registry, String domainName, DateTime date) throws EppException { CurrencyUnit currency = registry.getCurrency(); BaseFee feeOrCredit = Fee.create(Money.zero(registry.getCurrency()).getAmount(), FeeType.UPDATE); return customLogic.customizeUpdatePrice(UpdatePriceParameters.newBuilder() .setFeesAndCredits(/*from w w w .j a v a 2s .c o m*/ new FeesAndCredits.Builder().setCurrency(currency).addFeeOrCredit(feeOrCredit).build()) .setRegistry(registry).setDomainName(InternetDomainName.from(domainName)).setAsOfDate(date) .build()); }
From source file:google.registry.rdap.RdapActionBase.java
void validateDomainName(String name) { try {//from w w w.jav a 2 s. c o m Optional<InternetDomainName> tld = findTldForName(InternetDomainName.from(name)); if (!tld.isPresent() || !getTlds().contains(tld.get().toString())) { throw new NotFoundException(name + " not found"); } } catch (IllegalArgumentException e) { throw new BadRequestException(name + " is not a valid " + getHumanReadableObjectTypeName()); } }
From source file:org.apache.metron.common.dsl.functions.NetworkFunctions.java
private static InternetDomainName toDomainName(Object dnObj) { if (dnObj != null) { if (dnObj instanceof String) { String dn = dnObj.toString(); try { return InternetDomainName.from(dn); } catch (IllegalArgumentException iae) { return null; }/* w w w .j a v a2s .com*/ } else { throw new IllegalArgumentException(dnObj + " is not a string and therefore also not a domain."); } } return null; }
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. *///w w w. j a va 2 s .c om 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; }