Public Suffix List

Public Suffix List API

License

License

GroupId

GroupId

de.malkusch.whois-server-list
ArtifactId

ArtifactId

public-suffix-list
Last Version

Last Version

2.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Public Suffix List
Public Suffix List API
Project URL

Project URL

https://github.com/whois-server-list/public-suffix-list
Source Code Management

Source Code Management

https://github.com/whois-server-list/public-suffix-list

Download public-suffix-list

How to add to project

<!-- https://jarcasting.com/artifacts/de.malkusch.whois-server-list/public-suffix-list/ -->
<dependency>
    <groupId>de.malkusch.whois-server-list</groupId>
    <artifactId>public-suffix-list</artifactId>
    <version>2.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/de.malkusch.whois-server-list/public-suffix-list/
implementation 'de.malkusch.whois-server-list:public-suffix-list:2.2.0'
// https://jarcasting.com/artifacts/de.malkusch.whois-server-list/public-suffix-list/
implementation ("de.malkusch.whois-server-list:public-suffix-list:2.2.0")
'de.malkusch.whois-server-list:public-suffix-list:jar:2.2.0'
<dependency org="de.malkusch.whois-server-list" name="public-suffix-list" rev="2.2.0">
  <artifact name="public-suffix-list" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.malkusch.whois-server-list', module='public-suffix-list', version='2.2.0')
)
libraryDependencies += "de.malkusch.whois-server-list" % "public-suffix-list" % "2.2.0"
[de.malkusch.whois-server-list/public-suffix-list "2.2.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.apache.commons : commons-lang3 jar 3.4
com.google.code.findbugs : jsr305 jar 3.0.0

test (2)

Group / Artifact Type Version
com.carrotsearch : junit-benchmarks jar 0.7.2
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Public Suffix List API

This is a thread-safe Java API for Mozilla's Public Suffix List:

A "public suffix" is one under which Internet users can directly register names. Some examples of public suffixes are .com, .co.uk and pvt.k12.ma.us.

Installation

This package is available in Maven central:

<dependency>
	<groupId>de.malkusch.whois-server-list</groupId>
	<artifactId>public-suffix-list</artifactId>
	<version>2.2.0</version>
</dependency>

Usage

Create a PublicSuffixList with a PublicSuffixListFactory:

  • PublicSuffixList.getRegistrableDomain(): Gets the registrable domain or null. E.g. "www.example.net" and "example.net" will return "example.net". Null, an empty string or domains with a leading dot will return null.

  • PublicSuffixList.isRegistrable(): Returns whether a domain is registrable. E.g. "example.net" is registrable, "www.example.net" and "net" are not.

  • PublicSuffixList.isPublicSuffix(): Returns whether a domain is a public suffix or not. E.g. "com" is a public suffix, "example.com" isn't.

  • PublicSuffixList.getPublicSuffix(): Returns the public suffix from a domain or null. If the domain is already a public suffix, it will be returned unchanged. E.g. "www.example.net" will return "net".

All methods are case insensitive.

IDN

You can use the API's methods with UTF-8 domain names or Punycode encoded ASCII domain names. The API will return the results in the same format as the input was. I.e. if you use an UTF-8 string the result will be an UTF-8 String as well. Same for Punycode.

Example

PublicSuffixListFactory factory = new PublicSuffixListFactory();
PublicSuffixList suffixList = factory.build();

assertTrue(suffixList.isPublicSuffix("net"));
assertFalse(suffixList.isPublicSuffix("example.net"));

assertEquals("net", suffixList.getPublicSuffix("www.example.net"));
assertEquals("net", suffixList.getPublicSuffix("net"));

assertTrue(suffixList.isRegistrable("example.net"));
assertFalse(suffixList.isRegistrable("www.example.net"));
assertFalse(suffixList.isRegistrable("net"));

assertNull(suffixList.getRegistrableDomain("net"));
assertEquals("example.net", suffixList.getRegistrableDomain("example.net"));
assertEquals("example.net", suffixList.getRegistrableDomain("www.example.net"));
assertEquals("example.co.uk", suffixList.getRegistrableDomain("example.co.uk"));
assertEquals("example.co.uk", suffixList.getRegistrableDomain("www.example.co.uk"));

assertEquals("食狮.com.cn", suffixList.getRegistrableDomain("食狮.com.cn"));
assertEquals("xn--85x722f.com.cn", suffixList.getRegistrableDomain("xn--85x722f.com.cn"));

Public Suffix List update

This library comes with a bundled list which is most likely out dated. You are encouraged to follow Mozilla's Atom change feed and use the latest effective_tld_names.dat. You can specify a custom path to your latest list by setting the property PROPERTY_LIST_FILE:

PublicSuffixListFactory factory = new PublicSuffixListFactory();

Properties properties = factory.getDefaults();
properties.setProperty(
        PublicSuffixListFactory.PROPERTY_LIST_FILE, "/effective_tld_names.dat");

PublicSuffixList suffixList = factory.build(properties);

Download Public Suffix List with Maven

You can integrate the download of the latest list in your maven build process:

<build>
    <plugins>
        <plugin>
            <groupId>com.googlecode.maven-download-plugin</groupId>
            <artifactId>download-maven-plugin</artifactId>
            <version>1.2.0</version>
            <executions>
                <execution>
                    <id>package-psl</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>wget</goal>
                    </goals>
                    <configuration>
                        <url>https://publicsuffix.org/list/effective_tld_names.dat</url>
                        <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                        <outputFileName>effective_tld_names.dat</outputFileName>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

License and author

Markus Malkusch [email protected] is the author of this project. This project is free and under the WTFPL.

Donations

If you like this project and feel generous donate a few Bitcoins here: 1335STSwu9hST4vcMRppEPgENMHD2r1REK

Build Status

de.malkusch.whois-server-list

Versions

Version
2.2.0
2.1.0
2.0.1
2.0.0
1.0.0