Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B34D817BBD for ; Tue, 13 Jan 2015 20:07:58 +0000 (UTC) Received: (qmail 44574 invoked by uid 500); 13 Jan 2015 20:07:50 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 43862 invoked by uid 500); 13 Jan 2015 20:07:50 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 42430 invoked by uid 99); 13 Jan 2015 20:07:49 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Jan 2015 20:07:49 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id B713EAC09EC for ; Tue, 13 Jan 2015 20:07:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r936080 [16/44] - in /websites/production/commons/content/proper/commons-validator: ./ apidocs/ apidocs/org/apache/commons/validator/ apidocs/org/apache/commons/validator/class-use/ apidocs/org/apache/commons/validator/routines/ apidocs/org... Date: Tue, 13 Jan 2015 20:07:39 -0000 To: commits@commons.apache.org From: britter@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150113200748.B713EAC09EC@hades.apache.org> Modified: websites/production/commons/content/proper/commons-validator/cobertura/org.apache.commons.validator.routines.DomainValidator.html ============================================================================== --- websites/production/commons/content/proper/commons-validator/cobertura/org.apache.commons.validator.routines.DomainValidator.html (original) +++ websites/production/commons/content/proper/commons-validator/cobertura/org.apache.commons.validator.routines.DomainValidator.html Tue Jan 13 20:07:34 2015 @@ -12,7 +12,8 @@
 
- + +
Classes in this File Line Coverage Branch Coverage Complexity
DomainValidator
100%
36/36
93%
28/30
2,3
DomainValidator
90%
65/72
85%
48/56
3,867
DomainValidator$IDNHolder
66%
4/6
50%
2/4
3,867
 
@@ -56,1733 +57,2202 @@  19  
 import java.io.Serializable;
 20   -
 import java.util.Arrays;
+
 import java.lang.reflect.InvocationTargetException;
 21   -
 
+
 import java.lang.reflect.Method;
 22   -
 /**
+
 import java.util.Arrays;
 23   -
  * <p><b>Domain name</b> validation routines.</p>
+
 import java.util.Locale;
 24   -
  *
+
 
 25   -
  * <p>
+
 /**
 26   -
  * This validator provides methods for validating Internet domain names
+
  * <p><b>Domain name</b> validation routines.</p>
 27   -
  * and top-level domains.
+
  *
 28   -
  * </p>
+
  * <p>
 29   -
  *
+
  * This validator provides methods for validating Internet domain names
 30   -
  * <p>Domain names are evaluated according
+
  * and top-level domains.
 31   -
  * to the standards <a href="http://www.ietf.org/rfc/rfc1034.txt">RFC1034</a>,
+
  * </p>
 32   -
  * section 3, and <a href="http://www.ietf.org/rfc/rfc1123.txt">RFC1123</a>,
+
  *
 33   -
  * section 2.1. No accomodation is provided for the specialized needs of
+
  * <p>Domain names are evaluated according
 34   -
  * other applications; if the domain name has been URL-encoded, for example,
+
  * to the standards <a href="http://www.ietf.org/rfc/rfc1034.txt">RFC1034</a>,
 35   -
  * validation will fail even though the equivalent plaintext version of the
+
  * section 3, and <a href="http://www.ietf.org/rfc/rfc1123.txt">RFC1123</a>,
 36   -
  * same name would have passed.
+
  * section 2.1. No accommodation is provided for the specialized needs of
 37   -
  * </p>
+
  * other applications; if the domain name has been URL-encoded, for example,
 38   -
  *
+
  * validation will fail even though the equivalent plaintext version of the
 39   -
  * <p>
+
  * same name would have passed.
 40   -
  * Validation is also provided for top-level domains (TLDs) as defined and
+
  * </p>
 41   -
  * maintained by the Internet Assigned Numbers Authority (IANA):
+
  *
 42   -
  * </p>
+
  * <p>
 43   -
  *
+
  * Validation is also provided for top-level domains (TLDs) as defined and
 44   -
  *   <ul>
+
  * maintained by the Internet Assigned Numbers Authority (IANA):
 45   -
  *     <li>{@link #isValidInfrastructureTld} - validates infrastructure TLDs
+
  * </p>
 46   -
  *         (<code>.arpa</code>, etc.)</li>
+
  *
 47   -
  *     <li>{@link #isValidGenericTld} - validates generic TLDs
+
  *   <ul>
 48   -
  *         (<code>.com, .org</code>, etc.)</li>
+
  *     <li>{@link #isValidInfrastructureTld} - validates infrastructure TLDs
 49   -
  *     <li>{@link #isValidCountryCodeTld} - validates country code TLDs
+
  *         (<code>.arpa</code>, etc.)</li>
 50   -
  *         (<code>.us, .uk, .cn</code>, etc.)</li>
+
  *     <li>{@link #isValidGenericTld} - validates generic TLDs
 51   -
  *   </ul>
+
  *         (<code>.com, .org</code>, etc.)</li>
 52   -
  *
+
  *     <li>{@link #isValidCountryCodeTld} - validates country code TLDs
 53   -
  * <p>
+
  *         (<code>.us, .uk, .cn</code>, etc.)</li>
 54   -
  * (<b>NOTE</b>: This class does not provide IP address lookup for domain names or
+
  *   </ul>
 55   -
  * methods to ensure that a given domain name matches a specific IP; see
+
  *
 56   -
  * {@link java.net.InetAddress} for that functionality.)
+
  * <p>
 57   -
  * </p>
+
  * (<b>NOTE</b>: This class does not provide IP address lookup for domain names or
 58   -
  *
+
  * methods to ensure that a given domain name matches a specific IP; see
 59   -
  * @version $Revision: 1647964 $ $Date: 2014-12-26 13:33:35 +0100 (Fr, 26 Dez 2014) $
+
  * {@link java.net.InetAddress} for that functionality.)
 60   -
  * @since Validator 1.4
+
  * </p>
 61   -
  */
+
  *
 62   -
 public class DomainValidator implements Serializable {
+
  * @version $Revision: 1650777 $
 63   -
 
+
  * @since Validator 1.4
 64   -
     private static final long serialVersionUID = -4407125112880174009L;
+
  */
 65   -
 
+
 public class DomainValidator implements Serializable {
 66   -
     // Regular expression strings for hostnames (derived from RFC2396 and RFC 1123)
+
 
 67   -
     private static final String DOMAIN_LABEL_REGEX = "\\p{Alnum}(?>[\\p{Alnum}-]*\\p{Alnum})*";
+
     private static final long serialVersionUID = -4407125112880174009L;
 68   -
     private static final String TOP_LABEL_REGEX = "\\p{Alpha}{2,}";
+
 
 69   -
     private static final String DOMAIN_NAME_REGEX =
+
     // Regular expression strings for hostnames (derived from RFC2396 and RFC 1123)
 70   -
             "^(?:" + DOMAIN_LABEL_REGEX + "\\.)+" + "(" + TOP_LABEL_REGEX + ")$";
-  71  
 
+  71   +
     // RFC2396: domainlabel   = alphanum | alphanum *( alphanum | "-" ) alphanum
 72   -
     private final boolean allowLocal;
+
     // Max 63 characters
 73   -
 
+
     private static final String DOMAIN_LABEL_REGEX = "\\p{Alnum}(?>[\\p{Alnum}-]{0,61}\\p{Alnum})?";
 74   -
     /**
+
 
 75   -
      * Singleton instance of this validator, which
+
     // RFC2396 toplabel = alpha | alpha *( alphanum | "-" ) alphanum
 76   -
      *  doesn't consider local addresses as valid.
+
     // Max 63 characters
 77   -
      */
-  78  1
     private static final DomainValidator DOMAIN_VALIDATOR = new DomainValidator(false);
-  79   +
     private static final String TOP_LABEL_REGEX = "\\p{Alpha}(?>[\\p{Alnum}-]{0,61}\\p{Alnum})?";
+  78  
 
+  79   +
     // RFC2396 hostname = *( domainlabel "." ) toplabel [ "." ]
 80   -
     /**
+
     // Note that the regex currently requires both a domain label and a top level label, whereas
 81   -
      * Singleton instance of this validator, which does
+
     // the RFC does not. This is because the regex is used to detect if a TLD is present.
 82   -
      *  consider local addresses valid.
+
     // If the match fails, input is checked against DOMAIN_LABEL_REGEX (hostnameRegex)
 83   -
      */
-  84  1
     private static final DomainValidator DOMAIN_VALIDATOR_WITH_LOCAL = new DomainValidator(true);
+
     // RFC1123 sec 2.1 allows hostnames to start with a digit
+  84   +
     private static final String DOMAIN_NAME_REGEX =
 85   -
 
+
             "^(?:" + DOMAIN_LABEL_REGEX + "\\.)+" + "(" + TOP_LABEL_REGEX + ")\\.?$";
 86   -
     /**
+
 
 87   -
      * RegexValidator for matching domains.
+
     private final boolean allowLocal;
 88   -
      */
-  89  2
     private final RegexValidator domainRegex =
+
 
+  89   +
     /**
 90   -
             new RegexValidator(DOMAIN_NAME_REGEX);
+
      * Singleton instance of this validator, which
 91   -
     /**
+
      *  doesn't consider local addresses as valid.
 92   -
      * RegexValidator for matching the a local hostname
-  93  
      */
-  94  2
     private final RegexValidator hostnameRegex =
+  93  1
     private static final DomainValidator DOMAIN_VALIDATOR = new DomainValidator(false);
+  94   +
 
 95   -
             new RegexValidator(DOMAIN_LABEL_REGEX);
+
     /**
 96   -
 
+
      * Singleton instance of this validator, which does
 97   -
     /**
+
      *  consider local addresses valid.
 98   -
      * Returns the singleton instance of this validator. It
-  99   -
      *  will not consider local addresses as valid.
+
      */
+  99  1
     private static final DomainValidator DOMAIN_VALIDATOR_WITH_LOCAL = new DomainValidator(true);
 100   -
      * @return the singleton instance of this validator
+
 
 101   -
      */
+
     /**
 102   -
     public static DomainValidator getInstance() {
-  103  5
         return DOMAIN_VALIDATOR;
-  104   -
     }
+
      * RegexValidator for matching domains.
+  103   +
      */
+  104  2
     private final RegexValidator domainRegex =
 105   -
 
+
             new RegexValidator(DOMAIN_NAME_REGEX);
 106  
     /**
 107   -
      * Returns the singleton instance of this validator,
+
      * RegexValidator for matching a local hostname
 108   -
      *  with local validation as required.
+
      */
 109   -
      * @param allowLocal Should local addresses be considered valid?
-  110   -
      * @return the singleton instance of this validator
+
     // RFC1123 sec 2.1 allows hostnames to start with a digit
+  110  2
     private final RegexValidator hostnameRegex =
 111   -
      */
+
             new RegexValidator(DOMAIN_LABEL_REGEX);
 112   -
     public static DomainValidator getInstance(boolean allowLocal) {
-  113  30131
        if(allowLocal) {
-  114  17
           return DOMAIN_VALIDATOR_WITH_LOCAL;
+
 
+  113   +
     /**
+  114   +
      * Returns the singleton instance of this validator. It
 115   -
        }
-  116  30114
        return DOMAIN_VALIDATOR;
+
      *  will not consider local addresses as valid.
+  116   +
      * @return the singleton instance of this validator
 117   -
     }
+
      */
 118   +
     public static DomainValidator getInstance() {
+  119  15
         return DOMAIN_VALIDATOR;
+  120   +
     }
+  121  
 
-  119   -
     /** Private constructor. */
-  120  2
     private DomainValidator(boolean allowLocal) {
-  121  2
        this.allowLocal = allowLocal;
-  122  2
     }
+  122   +
     /**
 123   -
 
+
      * Returns the singleton instance of this validator,
 124   -
     /**
+
      *  with local validation as required.
 125   -
      * Returns true if the specified <code>String</code> parses
+
      * @param allowLocal Should local addresses be considered valid?
 126   -
      * as a valid domain name with a recognized top-level domain.
+
      * @return the singleton instance of this validator
 127   -
      * The parsing is case-sensitive.
-  128   -
      * @param domain the parameter to check for domain name syntax
-  129   -
      * @return true if the parameter is a valid domain name
-  130  
      */
+  128   +
     public static DomainValidator getInstance(boolean allowLocal) {
+  129  30194
        if(allowLocal) {
+  130  17
           return DOMAIN_VALIDATOR_WITH_LOCAL;
 131   -
     public boolean isValid(String domain) {
-  132  30161
         String[] groups = domainRegex.match(domain);
-  133  30161
         if (groups != null && groups.length > 0) {
-  134  7979
             return isValidTld(groups[0]);
-  135   -
         } else {
-  136  22182
             return allowLocal && hostnameRegex.isValid(domain);
-  137   -
         }
-  138   +
        }
+  132  30177
        return DOMAIN_VALIDATOR;
+  133  
     }
+  134   +
 
+  135   +
     /** Private constructor. */
+  136  2
     private DomainValidator(boolean allowLocal) {
+  137  2
        this.allowLocal = allowLocal;
+  138  2
     }
 139  
 
 140  
     /**
 141   -
      * Returns true if the specified <code>String</code> matches any
+
      * Returns true if the specified <code>String</code> parses
 142   -
      * IANA-defined top-level domain. Leading dots are ignored if present.
+
      * as a valid domain name with a recognized top-level domain.
 143   -
      * The search is case-sensitive.
+
      * The parsing is case-insensitive.
 144   -
      * @param tld the parameter to check for TLD status
+
      * @param domain the parameter to check for domain name syntax
 145   -
      * @return true if the parameter is a TLD
+
      * @return true if the parameter is a valid domain name
 146  
      */
 147   -
     public boolean isValidTld(String tld) {
-  148  8014
         if(allowLocal && isValidLocalTld(tld)) {
-  149  2
            return true;
+
     public boolean isValid(String domain) {
+  148  30236
         if (domain == null) {
+  149  2
             return false;
 150  
         }
-  151  8012
         return isValidInfrastructureTld(tld)
-  152  8012
                 || isValidGenericTld(tld)
-  153  3190
                 || isValidCountryCodeTld(tld);
+  151  30234
         domain = unicodeToASCII(domain);
+  152   +
         // hosts must be equally reachable via punycode and Unicode;
+  153   +
         // Unicode is never shorter than punycode, so check punycode
 154   -
     }
+
         // if domain did not convert, then it will be caught by ASCII
 155   -
 
-  156   -
     /**
-  157   -
      * Returns true if the specified <code>String</code> matches any
+
         // checks in the regexes below
+  156  30234
         if (domain.length() > 253) {
+  157  0
             return false;
 158   -
      * IANA-defined infrastructure top-level domain. Leading dots are
-  159   -
      * ignored if present. The search is case-sensitive.
-  160   -
      * @param iTld the parameter to check for infrastructure TLD status
-  161   -
      * @return true if the parameter is an infrastructure TLD
+
         }
+  159  30234
         String[] groups = domainRegex.match(domain);
+  160  30234
         if (groups != null && groups.length > 0) {
+  161  11201
             return isValidTld(groups[0]);
 162   -
      */
-  163   -
     public boolean isValidInfrastructureTld(String iTld) {
-  164  8014
         return Arrays.binarySearch(INFRASTRUCTURE_TLDS, (chompLeadingDot(iTld.toLowerCase()))) >= 0;
-  165   +
         }
+  163  19033
         return allowLocal && hostnameRegex.isValid(domain);
+  164  
     }
-  166   +  165  
 
+  166   +
     // package protected for unit test access
 167   -
     /**
+
     // must agree with isValid() above
 168   -
      * Returns true if the specified <code>String</code> matches any
-  169   -
      * IANA-defined generic top-level domain. Leading dots are ignored
-  170   -
      * if present. The search is case-sensitive.
+
     final boolean isValidDomainSyntax(String domain) {
+  169  21
         if (domain == null) {
+  170  0
             return false;
 171   -
      * @param gTld the parameter to check for generic TLD status
-  172   -
      * @return true if the parameter is a generic TLD
+
         }
+  172  21
         domain = unicodeToASCII(domain);
 173   -
      */
+
         // hosts must be equally reachable via punycode and Unicode;
 174   -
     public boolean isValidGenericTld(String gTld) {
-  175  8014
         return Arrays.binarySearch(GENERIC_TLDS, chompLeadingDot(gTld.toLowerCase())) >= 0;
+
         // Unicode is never shorter than punycode, so check punycode
+  175   +
         // if domain did not convert, then it will be caught by ASCII
 176   -
     }
-  177   -
 
-  178   -
     /**
+
         // checks in the regexes below
+  177  21
         if (domain.length() > 253) {
+  178  1
             return false;
 179   -
      * Returns true if the specified <code>String</code> matches any
-  180   -
      * IANA-defined country code top-level domain. Leading dots are
-  181   -
      * ignored if present. The search is case-sensitive.
-  182   -
      * @param ccTld the parameter to check for country code TLD status
+
         }
+  180  20
         String[] groups = domainRegex.match(domain);
+  181  20
         return (groups != null && groups.length > 0)
+  182  12
                 || hostnameRegex.isValid(domain);
 183   -
      * @return true if the parameter is a country code TLD
+
     }
 184   -
      */
+
 
 185   -
     public boolean isValidCountryCodeTld(String ccTld) {
-  186  3192
         return Arrays.binarySearch(COUNTRY_CODE_TLDS, chompLeadingDot(ccTld.toLowerCase())) >= 0;
+
     /**
+  186   +
      * Returns true if the specified <code>String</code> matches any
 187   -
     }
+
      * IANA-defined top-level domain. Leading dots are ignored if present.
 188   -
 
+
      * The search is case-insensitive.
 189   -
     /**
+
      * @param tld the parameter to check for TLD status, not null
 190   -
      * Returns true if the specified <code>String</code> matches any
+
      * @return true if the parameter is a TLD
 191   -
      * widely used "local" domains (localhost or localdomain). Leading dots are
-  192   -
      *  ignored if present. The search is case-sensitive.
-  193   -
      * @param iTld the parameter to check for local TLD status
-  194   -
      * @return true if the parameter is an local TLD
-  195  
      */
+  192   +
     public boolean isValidTld(String tld) {
+  193  11243
         tld = unicodeToASCII(tld);
+  194  11243
         if(allowLocal && isValidLocalTld(tld)) {
+  195  2
            return true;
 196   -
     public boolean isValidLocalTld(String iTld) {
-  197  7
         return Arrays.binarySearch(LOCAL_TLDS, chompLeadingDot(iTld.toLowerCase())) >= 0;
-  198   +
         }
+  197  11241
         return isValidInfrastructureTld(tld)
+  198  11241
                 || isValidGenericTld(tld)
+  199  6407
                 || isValidCountryCodeTld(tld);
+  200  
     }
-  199   +  201  
 
-  200   -
     private String chompLeadingDot(String str) {
-  201  19227
         if (str.startsWith(".")) {
-  202  10
             return str.substring(1);
+  202   +
     /**
 203   -
         } else {
-  204  19217
             return str;
+
      * Returns true if the specified <code>String</code> matches any
+  204   +
      * IANA-defined infrastructure top-level domain. Leading dots are
 205   -
         }
+
      * ignored if present. The search is case-insensitive.
 206   -
     }
+
      * @param iTld the parameter to check for infrastructure TLD status, not null
 207   -
 
+
      * @return true if the parameter is an infrastructure TLD
 208   -
     // ---------------------------------------------
+
      */
 209   -
     // ----- TLDs defined by IANA
-  210   -
     // ----- Authoritative and comprehensive list at:
-  211   -
     // ----- http://data.iana.org/TLD/tlds-alpha-by-domain.txt
+
     public boolean isValidInfrastructureTld(String iTld) {
+  210  11243
         iTld = unicodeToASCII(iTld);
+  211  11243
         return Arrays.binarySearch(INFRASTRUCTURE_TLDS, (chompLeadingDot(iTld.toLowerCase(Locale.ENGLISH)))) >= 0;
 212   +
     }
+  213  
 
-  213  1
     private static final String[] INFRASTRUCTURE_TLDS = new String[] {
 214   -
         "arpa",               // internet infrastructure
+
     /**
 215   -
         "root"                // diagnostic marker for non-truncated root zone
+
      * Returns true if the specified <code>String</code> matches any
 216   -
     };
+
      * IANA-defined generic top-level domain. Leading dots are ignored
 217   -
 
-  218  1
     private static final String[] GENERIC_TLDS = new String[] {
+
      * if present. The search is case-insensitive.
+  218   +
      * @param gTld the parameter to check for generic TLD status, not null
 219   -
         "abogado",
+
      * @return true if the parameter is a generic TLD
 220   -
         "academy",
+
      */
 221   -
         "accountants",
-  222   -
         "active",
-  223   -
         "actor",
+
     public boolean isValidGenericTld(String gTld) {
+  222  11243
         gTld = unicodeToASCII(gTld);
+  223  11243
         return Arrays.binarySearch(GENERIC_TLDS, chompLeadingDot(gTld.toLowerCase(Locale.ENGLISH))) >= 0;
 224   -
         "aero",
+
     }
 225   -
         "agency",
+
 
 226   -
         "airforce",
+
     /**
 227   -
         "allfinanz",
+
      * Returns true if the specified <code>String</code> matches any
 228   -
         "alsace",
+
      * IANA-defined country code top-level domain. Leading dots are
 229   -
         "archi",
+
      * ignored if present. The search is case-insensitive.
 230   -
         "army",
+
      * @param ccTld the parameter to check for country code TLD status, not null
 231   -
         "arpa",
+
      * @return true if the parameter is a country code TLD
 232   -
         "asia",
+
      */
 233   -
         "associates",
-  234   -
         "attorney",
-  235   -
         "auction",
+
     public boolean isValidCountryCodeTld(String ccTld) {
+  234  6409
         ccTld = unicodeToASCII(ccTld);
+  235  6409
         return Arrays.binarySearch(COUNTRY_CODE_TLDS, chompLeadingDot(ccTld.toLowerCase(Locale.ENGLISH))) >= 0;
 236   -
         "audio",
+
     }
 237   -
         "autos",
+
 
 238   -
         "axa",
+
     /**
 239   -
         "band",
+
      * Returns true if the specified <code>String</code> matches any
 240   -
         "bar",
+
      * widely used "local" domains (localhost or localdomain). Leading dots are
 241   -
         "bargains",
+
      * ignored if present. The search is case-insensitive.
 242   -
         "bayern",
+
      * @param lTld the parameter to check for local TLD status, not null
 243   -
         "beer",
+
      * @return true if the parameter is an local TLD
 244   -
         "berlin",
+
      */
 245   -
         "best",
-  246   -
         "bid",
-  247   -
         "bike",
+
     public boolean isValidLocalTld(String lTld) {
+  246  8
         lTld = unicodeToASCII(lTld);
+  247  8
         return Arrays.binarySearch(LOCAL_TLDS, chompLeadingDot(lTld.toLowerCase(Locale.ENGLISH))) >= 0;
 248   -
         "bio",
+
     }
 249   -
         "biz",
+
 
 250   -
         "black",
-  251   -
         "blackfriday",
-  252   -
         "blue",
+
     private String chompLeadingDot(String str) {
+  251  28903
         if (str.startsWith(".")) {
+  252  10
             return str.substring(1);
 253   -
         "bmw",
-  254   -
         "bnpparibas",
+
         }
+  254  28893
         return str;
 255   -
         "boo",
+
     }
 256   -
         "boutique",
[... 2428 lines stripped ...]