public void testParent() { assertEquals("com", InternetDomainName.from("google.com").parent().toString()); assertEquals("uk", InternetDomainName.from("co.uk").parent().toString()); assertEquals("google.com", InternetDomainName.from("www.google.com").parent().toString()); try { InternetDomainName.from("com").parent(); fail("'com' should throw ISE on .parent() call"); } catch (IllegalStateException expected) { } }
public void testParentChild() { InternetDomainName origin = InternetDomainName.from("foo.com"); InternetDomainName parent = origin.parent(); assertEquals("com", parent.toString()); // These would throw an exception if leniency were not preserved during parent() and child() // calls. InternetDomainName child = parent.child(LOTS_OF_DELTAS); child.child(LOTS_OF_DELTAS); }
/** * Returns a {@link LimitedCookieStoreFacade} whose * {@link LimitedCookieStoreFacade#getCookies()} method returns only cookies * from {@code host} and its parent domains, if applicable. */ 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; }
public void testTopPrivateDomain() { for (String name : TOP_PRIVATE_DOMAIN) { final InternetDomainName domain = InternetDomainName.from(name); assertFalse(name, domain.isPublicSuffix()); assertTrue(name, domain.hasPublicSuffix()); assertTrue(name, domain.isUnderPublicSuffix()); assertTrue(name, domain.isTopPrivateDomain()); assertEquals(domain.parent(), domain.publicSuffix()); } }
public void testTopDomainUnderRegistrySuffix() { for (String name : TOP_UNDER_REGISTRY_SUFFIX) { final InternetDomainName domain = InternetDomainName.from(name); assertFalse(name, domain.isRegistrySuffix()); assertTrue(name, domain.hasRegistrySuffix()); assertTrue(name, domain.isUnderRegistrySuffix()); assertTrue(name, domain.isTopDomainUnderRegistrySuffix()); assertEquals(domain.parent(), domain.registrySuffix()); } }
private static ImmutableList.Builder<String> parentLevels(InternetDomainName internetDomainName) { ImmutableList.Builder<String> levels; if(internetDomainName.hasParent()){ levels = parentLevels(internetDomainName.parent()); } else { levels = ImmutableList.builder(); } levels.add(internetDomainName.toString()); return levels; }
private static ImmutableList.Builder<String> parentLevels(InternetDomainName internetDomainName) { ImmutableList.Builder<String> levels; if(internetDomainName.hasParent()){ levels = parentLevels(internetDomainName.parent()); } else { levels = ImmutableList.builder(); } levels.add(internetDomainName.toString()); return levels; }
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(); }
@Override public GeneralisedWebAddress getGeneralisedHostName(URL url) { String host = url.getHost(); // if (! url.getHost().contains(".")) { // return GeneralisedWebAddress.build(host, GeneralisedWebAddressType.HOST_ADDRESS); // } else InetAddress ip = extractInetAddress(host); if (ip != null) { if (ip instanceof Inet4Address ) { return GeneralisedWebAddress.build(host.replaceFirst("\\d+$", ""), GeneralisedWebAddressType.IPV4_ADDRESS); } else if (ip instanceof Inet6Address) { return GeneralisedWebAddress.build(ip.getHostAddress(), GeneralisedWebAddressType.IPV6_ADDRESS); } } else if (InternetDomainName.isValid(host)) { InternetDomainName domainName = InternetDomainName.from(host); if (domainName.isUnderPublicSuffix()) { return GeneralisedWebAddress.build(domainName.topPrivateDomain().toString(), GeneralisedWebAddressType.DOMAIN_NAME); } else if (domainName.hasParent()) { return GeneralisedWebAddress.build(domainName.parent().toString(), GeneralisedWebAddressType.DOMAIN_NAME); } return GeneralisedWebAddress.build(host, GeneralisedWebAddressType.HOST_ADDRESS); } return null; }
public void testParent() { assertEquals( "com", InternetDomainName.from("google.com").parent().toString()); assertEquals( "uk", InternetDomainName.from("co.uk").parent().toString()); assertEquals( "google.com", InternetDomainName.from("www.google.com").parent().toString()); try { InternetDomainName.from("com").parent(); fail("'com' should throw ISE on .parent() call"); } catch (IllegalStateException expected) { } }
public void testParentChild() { InternetDomainName origin = InternetDomainName.from("foo.com"); InternetDomainName parent = origin.parent(); assertEquals("com", parent.toString()); // These would throw an exception if leniency were not preserved during parent() and child() // calls. InternetDomainName child = parent.child(LOTS_OF_DELTAS); child.child(LOTS_OF_DELTAS); }
/** * Returns a {@link LimitedCookieStoreFacade} whose * {@link LimitedCookieStoreFacade#getCookies()} method returns only cookies * from {@code host} and its parent domains, if applicable. */ 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; }
public void testTopDomainUnderRegistrySuffix() { for (String name : TOP_UNDER_REGISTRY_SUFFIX) { final InternetDomainName domain = InternetDomainName.from(name); assertFalse(name, domain.isRegistrySuffix()); assertTrue(name, domain.hasRegistrySuffix()); assertTrue(name, domain.isUnderRegistrySuffix()); assertTrue(name, domain.isTopDomainUnderRegistrySuffix()); assertEquals(domain.parent(), domain.registrySuffix()); } }
public void testTopPrivateDomain() { for (String name : TOP_PRIVATE_DOMAIN) { final InternetDomainName domain = InternetDomainName.from(name); assertFalse(name, domain.isPublicSuffix()); assertTrue(name, domain.hasPublicSuffix()); assertTrue(name, domain.isUnderPublicSuffix()); assertTrue(name, domain.isTopPrivateDomain()); assertEquals(domain.parent(), domain.publicSuffix()); } }