org.publicsuffix
Class PSS

java.lang.Object
  extended by org.publicsuffix.PSS

public class PSS
extends java.lang.Object

This Public Suffix Service (PSS) class reads a file of rules describing TLD-like domain names and makes rulings on passed hostnames/domain-names based of the data file content. For a complete description of the expected file format and parsing rules, see Effective TLD Service and Public Suffix.

This class is a rough port of the c++ file, nsEffectiveTLDService.cpp originally developed by Pamela Greene <pamg.bugs ATGMAILDOTCOM>. The class uses the first effective_tld_names.dat found on the CLASSPATH. The bundled jar has a version of the file taken from Public Suffix on 10/22/2007.

To use this class, instantiate an instance and then call getEffectiveTLDLength(String) passing the hostname to interrogate..

The following description of how the code works is copied from the head of the c++ file.

The list of subdomain rules is stored as a wide tree of SubdomainNodes, primarily to facilitate multiple levels of wildcards. Each node represents one level of a particular rule in the list, and stores meta-information about the rule it represents as well as a list (hash) of all the subdomains beneath it.

For example, if the effective-TLD list contains

foo.com
 *.bar.com
 !baz.bar.com
 
then the subdomain tree will look like this (conceptually; the actual order of the nodes in the hashes is not guaranteed):
 +--------------+
 | com          |
 | exception: 0 |        +--------------+
 | stopOK: 0    |        | foo          |
 | children ----|------> | exception: 0 |
 +--------------+        | stopOK: 1    |
                         | children     |
                         +--------------+
                         | bar          |
                         | exception: 0 |        +--------------+
                         | stopOK: 0    |        | *            |
                         | children ----|------> | exception: 0 |
                         +--------------+        | stopOK: 1    |
                                                 | children     |
                                                 +--------------+
                                                 | baz          |
                                                 | exception: 1 |
                                                 | stopOK: 1    |
                                                 | children     |
                                                 +--------------+

TODO: Add support for IDN (See java6 java.net.IDN).

TODO: Add support for multiple data files

Author:
stack

Field Summary
static java.lang.String DATA_FILENAME
           
 
Constructor Summary
PSS()
          Loads data file and creates a tree of subdomain nodes in memory used finding the effective TLD.
 
Method Summary
 int getEffectiveTLDLength(java.lang.String hostname)
          Finds the length in bytes of the effective TLD for the given hostname
static void main(java.lang.String[] args)
          Dumps the in-memory map of subdomains on STDOUT.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA_FILENAME

public static final java.lang.String DATA_FILENAME
See Also:
Constant Field Values
Constructor Detail

PSS

public PSS()
    throws java.io.UnsupportedEncodingException,
           java.io.IOException
Loads data file and creates a tree of subdomain nodes in memory used finding the effective TLD.

Throws:
java.io.IOException
java.io.UnsupportedEncodingException
Method Detail

getEffectiveTLDLength

public int getEffectiveTLDLength(java.lang.String hostname)
Finds the length in bytes of the effective TLD for the given hostname

Parameters:
hostname - Hostname to check.
Returns:
length of effective-TLD portion in passed hostname

main

public static void main(java.lang.String[] args)
                 throws java.io.UnsupportedEncodingException,
                        java.io.IOException
Dumps the in-memory map of subdomains on STDOUT.

Parameters:
args -
Throws:
java.io.UnsupportedEncodingException
java.io.IOException


Copyright 2007. All Rights Reserved.