com or foo.co.uk. Only
syntactic analysis is performed; no DNS lookups or other network interactions take place. Thus
there is no guarantee that the domain actually exists on the internet.
One common use of this class is to determine whether a given string is likely to represent an
addressable domain on the web -- that is, for a candidate string "xxx", might browsing to
"http://xxx/" result in a webpage being displayed? In the past, this test was frequently
done by determining whether the domain ended with a public suffix
but was not itself a public suffix. However, this test is no longer accurate. There are many
domains which are both public suffixes and addressable as hosts; "uk.com" is one example.
Using the subset of public suffixes that are registry suffixes,
one can get a better result, as only a few registry suffixes are addressable. However, the most
useful test to determine if a domain is a plausible web host is hasPublicSuffix(). This
will return true for many domains which (currently) are not hosts, such as "com",
but given that any public suffix may become a host without warning, it is better to err on the
side of permissiveness and thus avoid spurious rejection of valid sites. Of course, to actually
determine addressability of any host, clients of this class will need to perform their own DNS
lookups.
During construction, names are normalized in two ways:
'.') are converted to the ASCII
period.
The normalized values will be returned from toString() and parts(), and will
be reflected in the result of equals(Object).
Internationalized domain
names such as 网络.cn are supported, as are the equivalent IDNA Punycode-encoded
versions.
| Modifier and Type | Field and Description |
|---|---|
| private static final CharMatcher | |
| private static final CharMatcher | |
| private static final Joiner | |
| private static final Splitter | |
| private static final CharMatcher | |
| private static final CharMatcher | |
| private static final int | MAX_DOMAIN_PART_LENGTH
Maximum size of a single part of a domain name. |
| private static final int | MAX_LENGTH
Maximum length of a full domain name, including separators, and leaving room for the root label. |
| private static final int | MAX_PARTS
Maximum parts (labels) in a domain name. |
| private final String | name
The full domain name, converted to lower case. |
| private static final int | NO_SUFFIX_FOUND
Value of |
| private static final CharMatcher | |
| private final ImmutableList | parts
The parts of the domain name, converted to lower case. |
| private int | publicSuffixIndexCache
Cached value of #publicSuffixIndex(). |
| private int | registrySuffixIndexCache
Cached value of #registrySuffixIndex(). |
| private static final int | SUFFIX_NOT_INITIALIZED
Value of |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| private InternetDomainName | ancestor(int levels)
Returns the ancestor of the current domain at the given number of levels "higher" (rightward) in the subdomain list. |
| public InternetDomainName | |
| public boolean | equals(Object
the reference object with which to compare. object)Overrides java. |
| private int | findSuffixOfType(Optional<PublicSuffixType> desiredType)
Returns the index of the leftmost part of the suffix, or -1 if not found. |
| public static InternetDomainName | from(String
A domain name (not IP address) domain)Returns an instance of |
| public int | |
| public boolean | |
| public boolean | hasPublicSuffix()
Indicates whether this domain name ends in a public suffix, including if it is a public suffix itself. |
| public boolean | hasRegistrySuffix()
Indicates whether this domain name ends in a registry suffix, including if it is a registry suffix itself. |
| public boolean | Returns: true if this domain name appears exactly on the public suffix listIndicates whether this domain name represents a public suffix, as defined by the Mozilla Foundation's Public Suffix List (PSL). |
| public boolean | Returns: true if this domain name appears exactly on the public suffix list as part of
the registry suffix section (labelled "ICANN").Indicates whether this domain name represents a registry suffix, as defined by a subset of the Mozilla Foundation's Public Suffix List (PSL). |
| public boolean | isTopDomainUnderRegistrySuffix()
Indicates whether this domain name is composed of exactly one subdomain component followed by a registry suffix. |
| public boolean | isTopPrivateDomain()
Indicates whether this domain name is composed of exactly one subdomain component followed by a public suffix. |
| public boolean | isUnderPublicSuffix()
Indicates whether this domain name ends in a public suffix, while not being a public suffix itself. |
| public boolean | isUnderRegistrySuffix()
Indicates whether this domain name ends in a registry suffix, while not being a registry suffix itself. |
| public static boolean | |
| private static boolean | matchesType(Optional<PublicSuffixType> desiredType, Optional<PublicSuffixType> actualType)
If a |
| public InternetDomainName | parent()
Returns an |
| public ImmutableList | |
| public InternetDomainName | publicSuffix()
Returns the public suffix portion of the domain name, or |
| private int | |
| public InternetDomainName | registrySuffix()
Returns the registry suffix portion of the domain name, or
|
| private int | |
| public InternetDomainName | topDomainUnderRegistrySuffix()
Returns the portion of this domain name that is one level beneath the registry suffix. |
| public InternetDomainName | topPrivateDomain()
Returns the portion of this domain name that is one level beneath the public suffix. |
| public String | toString()
Overrides java. |
| private static boolean | Returns: Whether the part is validThe domain name part to be validated part, boolean Is this the final (rightmost) domain part? isFinalPart)Helper method for |
| private static boolean | Returns: Is the domain name syntactically valid?Validation method used by |
| DASH_MATCHER | back to summary |
|---|---|
| private static final CharMatcher DASH_MATCHER | |
| DIGIT_MATCHER | back to summary |
|---|---|
| private static final CharMatcher DIGIT_MATCHER | |
| DOT_JOINER | back to summary |
|---|---|
| private static final Joiner DOT_JOINER | |
| DOT_SPLITTER | back to summary |
|---|---|
| private static final Splitter DOT_SPLITTER | |
| DOTS_MATCHER | back to summary |
|---|---|
| private static final CharMatcher DOTS_MATCHER | |
| LETTER_MATCHER | back to summary |
|---|---|
| private static final CharMatcher LETTER_MATCHER | |
| MAX_DOMAIN_PART_LENGTH | back to summary |
|---|---|
| private static final int MAX_DOMAIN_PART_LENGTH Maximum size of a single part of a domain name. See RFC 2181 part 11. | |
| MAX_LENGTH | back to summary |
|---|---|
| private static final int MAX_LENGTH Maximum length of a full domain name, including separators, and leaving room for the root label. See RFC 2181 part 11. | |
| MAX_PARTS | back to summary |
|---|---|
| private static final int MAX_PARTS Maximum parts (labels) in a domain name. This value arises from the 255-octet limit described in RFC 2181 part 11 with the fact that the encoding of each part occupies at least two bytes (dot plus label externally, length byte plus label internally). Thus, if all labels have the minimum size of one byte, 127 of them will fit. | |
| name | back to summary |
|---|---|
| private final String name The full domain name, converted to lower case. | |
| NO_SUFFIX_FOUND | back to summary |
|---|---|
| private static final int NO_SUFFIX_FOUND Value of | |
| PART_CHAR_MATCHER | back to summary |
|---|---|
| private static final CharMatcher PART_CHAR_MATCHER | |
| parts | back to summary |
|---|---|
| private final ImmutableList<String> parts The parts of the domain name, converted to lower case. | |
| publicSuffixIndexCache | back to summary |
|---|---|
| private int publicSuffixIndexCache Cached value of #publicSuffixIndex(). Do not use directly. Since this field isn't
| |
| registrySuffixIndexCache | back to summary |
|---|---|
| private int registrySuffixIndexCache Cached value of #registrySuffixIndex(). Do not use directly. Since this field isn't
| |
| SUFFIX_NOT_INITIALIZED | back to summary |
|---|---|
| private static final int SUFFIX_NOT_INITIALIZED Value of | |
| InternetDomainName | back to summary |
|---|---|
| pack-priv InternetDomainName(String name) Constructor used to implement | |
| ancestor | back to summary |
|---|---|
| private InternetDomainName ancestor(int levels) Returns the ancestor of the current domain at the given number of levels "higher" (rightward)
in the subdomain list. The number of levels must be non-negative, and less than TODO: Reasonable candidate for addition to public API. | |
| child | back to summary |
|---|---|
| public InternetDomainName child(String leftParts) Creates and returns a new
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object object) Overrides java. Equality testing is based on the text supplied by the caller, after normalization as described in the class documentation. For example, a non-ASCII Unicode domain name and the Punycode version of the same domain name would not be considered equal.
| |
| findSuffixOfType | back to summary |
|---|---|
| private int findSuffixOfType(Optional<PublicSuffixType> desiredType) Returns the index of the leftmost part of the suffix, or -1 if not found. Note that the value
defined as a suffix may not produce If a | |
| from | back to summary |
|---|---|
| public static InternetDomainName from(String domain) Returns an instance of
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| hasParent | back to summary |
|---|---|
| public boolean hasParent() Indicates whether this domain is composed of two or more parts. | |
| hasPublicSuffix | back to summary |
|---|---|
| public boolean hasPublicSuffix() Indicates whether this domain name ends in a public suffix,
including if it is a public suffix itself. For example, returns Note that this method is equivalent to
| |
| hasRegistrySuffix | back to summary |
|---|---|
| public boolean hasRegistrySuffix() Indicates whether this domain name ends in a registry suffix,
including if it is a registry suffix itself. For example, returns Note that this method is equivalent to
| |
| isPublicSuffix | back to summary |
|---|---|
| public boolean isPublicSuffix() Indicates whether this domain name represents a public suffix, as defined by the Mozilla
Foundation's Public Suffix List (PSL). A public suffix
is one under which Internet users can directly register names, such as Public suffixes are a proper superset of registry suffixes.
The list of public suffixes additionally contains privately owned domain names under which
Internet users can register subdomains. An example of a public suffix that is not a registry
suffix is For considerations on whether the public suffix or registry suffix designation is more suitable for your application, see this article.
| |
| isRegistrySuffix | back to summary |
|---|---|
| public boolean isRegistrySuffix() Indicates whether this domain name represents a registry suffix, as defined by a subset
of the Mozilla Foundation's Public Suffix List (PSL). A
registry suffix is one under which Internet users can directly register names via a domain name
registrar, and have such registrations lawfully protected by internet-governing bodies such as
ICANN. Examples of registry suffixes include Registry suffixes are a proper subset of public suffixes. The
list of public suffixes additionally contains privately owned domain names under which Internet
users can register subdomains. An example of a public suffix that is not a registry suffix is
For considerations on whether the public suffix or registry suffix designation is more suitable for your application, see this article.
| |
| isTopDomainUnderRegistrySuffix | back to summary |
|---|---|
| public boolean isTopDomainUnderRegistrySuffix() Indicates whether this domain name is composed of exactly one subdomain component followed by a
registry suffix. For example, returns Warning This method should not be used to determine the probable highest level
parent domain for which cookies may be set. Use
| |
| isTopPrivateDomain | back to summary |
|---|---|
| public boolean isTopPrivateDomain() Indicates whether this domain name is composed of exactly one subdomain component followed by a
public suffix. For example, returns This method can be used to determine whether a domain is probably the highest level for which cookies may be set, though even that depends on individual browsers' implementations of cookie controls. See RFC 2109 for details.
| |
| isUnderPublicSuffix | back to summary |
|---|---|
| public boolean isUnderPublicSuffix() Indicates whether this domain name ends in a public suffix,
while not being a public suffix itself. For example, returns This method can be used to determine whether it will probably be possible to set cookies on the domain, though even that depends on individual browsers' implementations of cookie controls. See RFC 2109 for details.
| |
| isUnderRegistrySuffix | back to summary |
|---|---|
| public boolean isUnderRegistrySuffix() Indicates whether this domain name ends in a registry suffix,
while not being a registry suffix itself. For example, returns
| |
| isValid | back to summary |
|---|---|
| public static boolean isValid(String name) Indicates whether the argument is a syntactically valid domain name using lenient validation. Specifically, validation against RFC 3490 ("Internationalizing Domain Names in Applications") is skipped. The following two code snippets are equivalent:
| |
| matchesType | back to summary |
|---|---|
| private static boolean matchesType(Optional<PublicSuffixType> desiredType, Optional<PublicSuffixType> actualType) If a | |
| parent | back to summary |
|---|---|
| public InternetDomainName parent() Returns an
| |
| parts | back to summary |
|---|---|
| public ImmutableList Returns the individual components of this domain name, normalized to all lower case. For
example, for the domain name | |
| publicSuffix | back to summary |
|---|---|
| public InternetDomainName publicSuffix() Returns the public suffix portion of the domain name, or
| |
| publicSuffixIndex | back to summary |
|---|---|
| private int publicSuffixIndex() The index in the | |
| registrySuffix | back to summary |
|---|---|
| public InternetDomainName registrySuffix() Returns the registry suffix portion of the domain name, or
| |
| registrySuffixIndex | back to summary |
|---|---|
| private int registrySuffixIndex() The index in the | |
| topDomainUnderRegistrySuffix | back to summary |
|---|---|
| public InternetDomainName topDomainUnderRegistrySuffix() Returns the portion of this domain name that is one level beneath the registry suffix. For example, for If Warning This method should not be used to determine whether a domain is probably the
highest level for which cookies may be set. Use
| |
| topPrivateDomain | back to summary |
|---|---|
| public InternetDomainName topPrivateDomain() Returns the portion of this domain name that is one level beneath the public suffix. For example, for If This method can be used to determine the probable highest level parent domain for which cookies may be set, though even that depends on individual browsers' implementations of cookie controls.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns the domain name, normalized to all lower case.
| |
| validatePart | back to summary |
|---|---|
| private static boolean validatePart(String part, boolean isFinalPart) Helper method for
| |
| validateSyntax | back to summary |
|---|---|
| private static boolean validateSyntax(List<String> parts) Validation method used by
| |