APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.security.util

pack-priv Class DomainName

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .File, .FileInputStream, .FileNotFoundException, .InputStream, .InputStreamReader, .IOException, java.util.Arrays, .HashSet, .Iterator, .LinkedList, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, java.util.zip.ZipEntry, .ZipInputStream, sun.security.ssl.SSLLogger

Allows public suffixes and registered domains to be determined from a string that represents a target domain name. A database of known registered suffixes is used to perform the determination. A public suffix is defined as the rightmost part of a domain name that is not owned by an individual registrant. Examples of public suffixes are: com edu co.uk k12.ak.us com.tw 網路.tw Public suffixes effectively denote registration authorities. A registered domain is a public suffix preceded by one domain label and a ".". Examples are: oracle.com mit.edu The internal database is derived from the information maintained at http://publicsuffix.org. The information is fixed for a particular JDK installation, but may be updated in future releases or updates. Because of the large number of top-level domains (TLDs) and public suffix rules, we only load the rules on demand -- from a Zip file containing an entry for each TLD. As each entry is loaded, its data is stored permanently in a cache. The containment hierarchy for the data is shown below: Rules --> contains all the rules for a particular TLD RuleSet --> contains all the rules that match 1 label RuleSet --> contains all the rules that match 2 labels RuleSet --> contains all the rules that match 3 labels : RuleSet --> contains all the rules that match N labels HashSet of rules, where each rule is an exception rule, a "normal" rule, a wildcard rule (rules that contain a wildcard prefix only), or a LinkedList of "other" rules The general matching algorithm tries to find the longest match. So, the search begins at the RuleSet with the most labels, and works backwards. Exceptions take priority over all other rules, and if a Rule contains any exceptions, then even if we find a "normal" match, we search all other RuleSets for exceptions. It is assumed that all other rules don't intersect/overlap. If this happens, a match will be returned, but not necessarily the expected one. For a further explanation of the rules, see http://publicsuffix.org/list/. The "other" rules are for the (possible future) case where wildcards are located in a rule any place other than the beginning.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DomainName.CommonMatch

Represents a match against a standard rule in the public suffix list.

private static interface
DomainName.Match

Represents a string's match with a rule in the public suffix list.

private static class
DomainName.OtherMatch

Represents a non-match with NO_MATCH or a match against a non-standard rule in the public suffix list.

private static class
private static class
private static class
private static class
DomainName.Rules

A Rules object contains a list of rules for a particular TLD.

Field Summary

Modifier and TypeField and Description
private static final Map<String, DomainName.Rules>
cache

For efficiency, the set of rules for each TLD is kept in text files and only loaded if needed.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static DomainName.Match
getMatch(String domain)

public static RegisteredDomain

Returns:

the registered domain, or null if not known or not registerable
registeredDomain
(String
the domain name
domain
)

Returns the registered domain of the specified domain.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
private static final Map<String, DomainName.Rules> cache

For efficiency, the set of rules for each TLD is kept in text files and only loaded if needed.

Constructor Detail

DomainNameback to summary
private DomainName()

Method Detail

getMatchback to summary
private static DomainName.Match getMatch(String domain)
registeredDomainback to summary
public static RegisteredDomain registeredDomain(String domain)

Returns the registered domain of the specified domain.

Parameters
domain:String

the domain name

Returns:RegisteredDomain

the registered domain, or null if not known or not registerable

Exceptions
NullPointerException:
if domain is null
sun.security.util back to summary

private Class DomainName.CommonMatch

extends Object
implements Match
Class Inheritance
All Implemented Interfaces
sun.security.util.DomainName.Match

Represents a match against a standard rule in the public suffix list. A standard rule is an explicit name, a wildcard rule with a wildcard only in the leading label, or an exception rule.

Field Summary

Modifier and TypeField and Description
private final String
private final int
private int
private final DomainName.Rule

Constructor Summary

AccessConstructor and Description
pack-priv
CommonMatch(String domain, DomainName.Rule rule, int publicSuffix)

Method Summary

Modifier and TypeMethod and Description
public RegisteredDomain
public DomainName.Rule.Type
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

domainback to summary
private final String domain
publicSuffixback to summary
private final int publicSuffix
registeredDomainback to summary
private int registeredDomain
ruleback to summary
private final DomainName.Rule rule

Constructor Detail

CommonMatchback to summary
pack-priv CommonMatch(String domain, DomainName.Rule rule, int publicSuffix)

Method Detail

registeredDomainback to summary
public RegisteredDomain registeredDomain()

Implements sun.security.util.DomainName.Match.registeredDomain.

Annotations
@Override
typeback to summary
public DomainName.Rule.Type type()

Implements sun.security.util.DomainName.Match.type.

Annotations
@Override
sun.security.util back to summary

private Interface DomainName.Match

Known Direct Implementers
sun.security.util.DomainName.CommonMatch, sun.security.util.DomainName.OtherMatch

Represents a string's match with a rule in the public suffix list.

Method Summary

Modifier and TypeMethod and Description
public RegisteredDomain
public DomainName.Rule.Type
type()

Method Detail

registeredDomainback to summary
public RegisteredDomain registeredDomain()
typeback to summary
public DomainName.Rule.Type type()
sun.security.util back to summary

private Class DomainName.OtherMatch

extends Object
implements Match
Class Inheritance
All Implemented Interfaces
sun.security.util.DomainName.Match

Represents a non-match with NO_MATCH or a match against a non-standard rule in the public suffix list. A non-standard rule is a wildcard rule that includes wildcards in a label other than the leading label. The public suffix list doesn't currently have such rules.

Field Summary

Modifier and TypeField and Description
private final int
private final DomainName.Rule
private final LinkedList<String>

Constructor Summary

AccessConstructor and Description
pack-priv
OtherMatch(DomainName.Rule rule, int numLabels, LinkedList<String> target)

Method Summary

Modifier and TypeMethod and Description
private String
getSuffixes(int n)

public RegisteredDomain
public DomainName.Rule.Type
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

numLabelsback to summary
private final int numLabels
ruleback to summary
private final DomainName.Rule rule
targetback to summary
private final LinkedList<String> target

Constructor Detail

OtherMatchback to summary
pack-priv OtherMatch(DomainName.Rule rule, int numLabels, LinkedList<String> target)

Method Detail

getSuffixesback to summary
private String getSuffixes(int n)
registeredDomainback to summary
public RegisteredDomain registeredDomain()

Implements sun.security.util.DomainName.Match.registeredDomain.

Annotations
@Override
typeback to summary
public DomainName.Rule.Type type()

Implements sun.security.util.DomainName.Match.type.

Annotations
@Override
sun.security.util back to summary

private Class DomainName.OtherRule

extends Rule
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv List<String>
Inherited from sun.security.util.DomainName.Rule:
authdomaintype

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

labelsback to summary
pack-priv List<String> labels

Constructor Detail

OtherRuleback to summary
pack-priv OtherRule(String domain, RegisteredDomain.Type auth, List<String> labels)
sun.security.util back to summary

private Class DomainName.RegisteredDomainImpl

extends Object
implements RegisteredDomain
Class Inheritance
All Implemented Interfaces
sun.security.util.RegisteredDomain

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final RegisteredDomain.Type

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String
name()

Implements sun.security.util.RegisteredDomain.name.

Returns the name of the registered domain.

public String
publicSuffix()

Implements sun.security.util.RegisteredDomain.publicSuffix.

Returns the public suffix of the registered domain.

public RegisteredDomain.Type
type()

Implements sun.security.util.RegisteredDomain.type.

Returns the type of the registered domain.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nameback to summary
private final String name
publicSuffixback to summary
private final String publicSuffix
typeback to summary
private final RegisteredDomain.Type type

Constructor Detail

RegisteredDomainImplback to summary
pack-priv RegisteredDomainImpl(String name, RegisteredDomain.Type type, String publicSuffix)

Method Detail

nameback to summary
public String name()

Implements sun.security.util.RegisteredDomain.name.

Doc from sun.security.util.RegisteredDomain.name.

Returns the name of the registered domain.

Annotations
@Override
publicSuffixback to summary
public String publicSuffix()

Implements sun.security.util.RegisteredDomain.publicSuffix.

Doc from sun.security.util.RegisteredDomain.publicSuffix.

Returns the public suffix of the registered domain.

Annotations
@Override
typeback to summary
public RegisteredDomain.Type type()

Implements sun.security.util.RegisteredDomain.type.

Doc from sun.security.util.RegisteredDomain.type.

Returns the type of the registered domain.

Annotations
@Override
sun.security.util back to summary

private Class DomainName.Rule

extends Object
Class Inheritance
Known Direct Subclasses
sun.security.util.DomainName.OtherRule

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum

Field Summary

Modifier and TypeField and Description
pack-priv RegisteredDomain.Type
pack-priv String
pack-priv DomainName.Rule.Type

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

authback to summary
pack-priv RegisteredDomain.Type auth
domainback to summary
pack-priv String domain
typeback to summary
pack-priv DomainName.Rule.Type type

Constructor Detail

Ruleback to summary
pack-priv Rule(String domain, DomainName.Rule.Type type, RegisteredDomain.Type auth)
sun.security.util back to summary

pack-priv final Enum DomainName.Rule.Type

extends Enum<DomainName.Rule.Type>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final DomainName.Rule.Type
public static final DomainName.Rule.Type
public static final DomainName.Rule.Type
public static final DomainName.Rule.Type

Constructor Summary

AccessConstructor and Description
private
Type()

Method Summary

Modifier and TypeMethod and Description
public static DomainName.Rule.Type
public static DomainName.Rule.Type[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

EXCEPTIONback to summary
public static final DomainName.Rule.Type EXCEPTION
NORMALback to summary
public static final DomainName.Rule.Type NORMAL
OTHERback to summary
public static final DomainName.Rule.Type OTHER
WILDCARDback to summary
public static final DomainName.Rule.Type WILDCARD

Constructor Detail

Typeback to summary
private Type()

Method Detail

valueOfback to summary
public static DomainName.Rule.Type valueOf(String name)
valuesback to summary
public static DomainName.Rule.Type[] values()
sun.security.util back to summary

private Class DomainName.Rules

extends Object
Class Inheritance

A Rules object contains a list of rules for a particular TLD. Rules are stored in a linked list of RuleSet objects. The list is indexed according to the number of labels in the name (minus one) such that all rules with the same number of labels are stored in the same RuleSet. Doing this means we can find the longest match first, and also we can stop comparing as soon as we find a match.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DomainName.Rules.RuleSet

Represents a set of rules with the same number of labels and for a particular TLD.

Field Summary

Modifier and TypeField and Description
private final boolean
private final LinkedList<DomainName.Rules.RuleSet>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static DomainName.Rules
private static InputStream
pack-priv static DomainName.Rules
getRules(String domain)

private static DomainName.Rules
private DomainName.Rules.RuleSet
getRuleSet(int index)

Return the requested RuleSet.

private static String
pack-priv DomainName.Match
match(String domain)

Find a match for the target string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hasExceptionsback to summary
private final boolean hasExceptions
ruleSetsback to summary
private final LinkedList<DomainName.Rules.RuleSet> ruleSets

Constructor Detail

Rulesback to summary
private Rules(InputStream is) throws IOException

Method Detail

createRulesback to summary
private static DomainName.Rules createRules(String tld)
getPubSuffixStreamback to summary
private static InputStream getPubSuffixStream()
getRulesback to summary
pack-priv static DomainName.Rules getRules(String domain)
getRulesback to summary
private static DomainName.Rules getRules(String tld, ZipInputStream zis) throws IOException
getRuleSetback to summary
private DomainName.Rules.RuleSet getRuleSet(int index)

Return the requested RuleSet. If it hasn't been created yet, create it and any RuleSets leading up to it.

getTopLevelDomainback to summary
private static String getTopLevelDomain(String domain)
matchback to summary
pack-priv DomainName.Match match(String domain)

Find a match for the target string.

sun.security.util back to summary

private Class DomainName.Rules.RuleSet

extends Object
Class Inheritance

Represents a set of rules with the same number of labels and for a particular TLD. Examples: numLabels = 2 names: co.uk, ac.uk wildcards *.de (only "de" stored in HashSet) exceptions: !foo.de (stored as "foo.de")

Field Summary

Modifier and TypeField and Description
private static final RegisteredDomain.Type[]
pack-priv boolean
private final int
private final Set<DomainName.Rule>

Constructor Summary

AccessConstructor and Description
pack-priv
RuleSet(int n)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addRule(int auth, String rule)

private static int
labels(String s, int n)

Returns a substring (index) with the n right-most labels from s.

pack-priv DomainName.Match
match(String domain)

private DomainName.Match
matchException(String domain, DomainName.Rule rule)

Check for a match with an exception rule.

private DomainName.Match
matchNormal(String domain, DomainName.Rule rule)

Check for a match with an explicit name rule or a wildcard rule (i.e., a non-exception rule).

private DomainName.Match
matchOther(String domain, DomainName.Rule rule)

A left-to-right comparison of labels.

private DomainName.Match
private static int
private static LinkedList<String>
split(String rule)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AUTHSback to summary
private static final RegisteredDomain.Type[] AUTHS
hasExceptionsback to summary
pack-priv boolean hasExceptions
numLabelsback to summary
private final int numLabels
rulesback to summary
private final Set<DomainName.Rule> rules

Constructor Detail

RuleSetback to summary
pack-priv RuleSet(int n)

Method Detail

addRuleback to summary
pack-priv void addRule(int auth, String rule)
labelsback to summary
private static int labels(String s, int n)

Returns a substring (index) with the n right-most labels from s. Returns -1 if s does not have at least n labels, 0, if the substring is s.

matchback to summary
pack-priv DomainName.Match match(String domain)
matchExceptionback to summary
private DomainName.Match matchException(String domain, DomainName.Rule rule)

Check for a match with an exception rule.

matchNormalback to summary
private DomainName.Match matchNormal(String domain, DomainName.Rule rule)

Check for a match with an explicit name rule or a wildcard rule (i.e., a non-exception rule).

matchOtherback to summary
private DomainName.Match matchOther(String domain, DomainName.Rule rule)

A left-to-right comparison of labels. The simplest approach to doing match() would be to use a descending iterator giving a right-to-left comparison. But, it's more efficient to do left-to-right compares because the left most labels are the ones most likely to be different. We just have to figure out which label to start at.

matchWildcardback to summary
private DomainName.Match matchWildcard(String domain, DomainName.Rule rule)
numLabelsback to summary
private static int numLabels(String rule)
splitback to summary
private static LinkedList<String> split(String rule)