On 31 December 2014 at 04:42, Adrian Crum <adrian.c...@sandglass-software.com> wrote: > Be aware that the file contains encoded Chinese TLDs (XN--*). So, it needs > additional parsing.
Oops. These entries use PunyCode. This is available in Java 6 onwards (java.net.IDN) There are other possible implementations but that is out of scope for the 1.4.1 release. I'll exclude these entries for now. > Adrian Crum > Sandglass Software > www.sandglass-software.com > > On 12/30/2014 5:23 PM, s...@apache.org wrote: >> >> Author: sebb >> Date: Wed Dec 31 01:23:26 2014 >> New Revision: 1648642 >> >> URL: http://svn.apache.org/r1648642 >> Log: >> Add code for developers to check inbuilt list against iana tld >> >> Modified: >> >> commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java >> >> Modified: >> commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java >> URL: >> http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java?rev=1648642&r1=1648641&r2=1648642&view=diff >> >> ============================================================================== >> --- >> commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java >> (original) >> +++ >> commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java >> Wed Dec 31 01:23:26 2014 >> @@ -16,6 +16,15 @@ >> */ >> package org.apache.commons.validator.routines; >> >> +import java.io.BufferedReader; >> +import java.io.File; >> +import java.io.FileOutputStream; >> +import java.io.FileReader; >> +import java.io.InputStream; >> +import java.net.HttpURLConnection; >> +import java.net.URL; >> +import java.util.Locale; >> + >> import junit.framework.TestCase; >> >> /** >> @@ -110,4 +119,37 @@ public class DomainValidatorTest extends >> public void testIDN() { >> assertTrue("b\u00fccher.ch in IDN should validate", >> validator.isValid("www.xn--bcher-kva.ch")); >> } >> + >> + // Download and process local copy of >> http://data.iana.org/TLD/tlds-alpha-by-domain.txt >> + // Check if the internal TLD table is up to date >> + public static void main(String a[]) throws Exception { >> + DomainValidator dv = DomainValidator.getInstance();; >> + File f = new File("target/tlds-alpha-by-domain.txt"); >> + if (!f.canRead()) { >> + String >> tldurl="http://data.iana.org/TLD/tlds-alpha-by-domain.txt"; >> + System.out.println("Downloading " + tldurl); >> + byte buff[] = new byte[1024]; >> + HttpURLConnection hc = (HttpURLConnection) new >> URL(tldurl).openConnection(); >> + InputStream is = hc.getInputStream(); >> + FileOutputStream fos = new FileOutputStream(f); >> + while(is.read(buff) != -1) { >> + fos.write(buff); >> + } >> + fos.close(); >> + is.close(); >> + System.out.println("Done"); >> + } >> + BufferedReader br = new BufferedReader(new FileReader(f)); >> + System.out.println("Entries missing from TLD List"); >> + String line; >> + while((line = br.readLine()) != null) { >> + if (!line.startsWith("#")) { >> + if (!dv.isValidTld(line)) { >> + System.out.println(line.toLowerCase(Locale.ENGLISH)); >> + } >> + } >> + } >> + br.close(); >> + System.out.println("Done"); >> + } >> } >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org