Class PublicSuffixes
java.lang.Object
org.archive.net.PublicSuffixes
Utility class for making use of the information about 'public suffixes' at
http://publicsuffix.org.
The public suffix list (once known as 'effective TLDs') was motivated by the
need to decide on which broader domains a subdomain was allowed to set
cookies. For example, a server at 'www.example.com' can set cookies for
'www.example.com' or 'example.com' but not 'com'. 'www.example.co.uk' can set
cookies for 'www.example.co.uk' or 'example.co.uk' but not 'co.uk' or 'uk'.
The number of rules for all top-level-domains and 2nd- or 3rd- level domains
has become quite long; essentially the broadest domain a subdomain may assign
to is the one that was sold/registered to a specific name registrant.
This concept should be useful in other contexts, too. Grouping URIs (or
queues of URIs to crawl) together with others sharing the same registered
suffix may be useful for applying the same rules to all, such as assigning
them to the same queue or crawler in a multi- machine setup.
As of Heritrix3, we prefer the term 'Assignment Level Domain' (ALD)
for such domains, by analogy to 'Top Level Domain' (TLD) or '2nd Level
Domain' (2LD), etc.
- Author:
- Gojomo this version of PublicSuffixes uses suffix-tree data structure for generating less redundant regular expression. It may be even possible to write a light-weight, thread-safe matcher based on this class., Kenji Nagahashi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprefix tree node. each Node represents sequence of letters (prefix) and alternative sequences following it (list of Node's). -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidbuildRegex(PublicSuffixes.Node alt, StringBuilder sb) bulids regular expression from prefix-treealtinto buffersb.static voiddump(PublicSuffixes.Node alt, int lv, PrintWriter out) utility function for dumping prefix tree structure. intended for debug use.static Patternstatic Stringstatic Stringstatic voidUtility method for dumping a regex String, based on a published public suffix list, which matches any SURT-form hostname up through the broadest 'private' (assigned/sold) domain-segment.protected static PublicSuffixes.NodeReads a file of the format promulgated by publicsuffix.org, ignoring comments and '!'static StringTruncate SURT to its topmost assigned domain segment; that is, the public suffix plus one segment, but as a SURT-ordered prefix.
-
Field Details
-
topmostAssignedSurtPrefixPattern
-
topmostAssignedSurtPrefixRegex
-
-
Constructor Details
-
PublicSuffixes
public PublicSuffixes()
-
-
Method Details
-
main
Utility method for dumping a regex String, based on a published public suffix list, which matches any SURT-form hostname up through the broadest 'private' (assigned/sold) domain-segment. That is, for any of the SURT-form hostnames... com,example, com,example,www, com,example,california,www ...the regex will match 'com,example,'.- Parameters:
args-- Throws:
IOException
-
readPublishedFileToSurtTrie
protected static PublicSuffixes.Node readPublishedFileToSurtTrie(BufferedReader reader) throws IOException Reads a file of the format promulgated by publicsuffix.org, ignoring comments and '!' exceptions/notations, converting domain segments to SURT-ordering. Leaves glob-style '*' wildcarding in place. Returns root node of SURT-ordered prefix tree.- Parameters:
reader-- Returns:
- root of prefix tree node.
- Throws:
IOException
-
dump
utility function for dumping prefix tree structure. intended for debug use.- Parameters:
alt- root of prefix tree.lv- indent level. 0 for root (no indent).out- writer to send output to.
-
buildRegex
bulids regular expression from prefix-treealtinto buffersb.- Parameters:
alt- prefix tree root.sb- StringBuffer to store regular expression.
-
getTopmostAssignedSurtPrefixPattern
-
getTopmostAssignedSurtPrefixRegex
-
getTopmostAssignedSurtPrefixRegex
-
reduceSurtToAssignmentLevel
Truncate SURT to its topmost assigned domain segment; that is, the public suffix plus one segment, but as a SURT-ordered prefix. if the pattern doesn't match, the passed-in SURT is returned.- Parameters:
surt- SURT to truncate- Returns:
- truncated-to-topmost-assigned SURT prefix
-