Author: sebb
Date: Thu Jan 7 22:18:08 2016
New Revision: 1723634
URL: http://svn.apache.org/viewvc?rev=1723634&view=rev
Log:
VALIDATOR-351 DomainValidator - allow access to internal arrays
Modified:
commons/proper/validator/trunk/src/changes/changes.xml
commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
commons/proper/validator/trunk/src/test/java/org/apache/commons/validator/routines/DomainValidatorTest.java
Modified: commons/proper/validator/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/changes/changes.xml?rev=1723634&r1=1723633&r2=1723634&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/changes/changes.xml (original)
+++ commons/proper/validator/trunk/src/changes/changes.xml Thu Jan 7 22:18:08
2016
@@ -96,9 +96,12 @@ http://commons.apache.org/validator/depe
<action issue="VALIDATOR-359" type="fix" dev="sebb" due-to="Dora Kinghorn">
EmailValidator does not catch invalid email address like [email protected]
</action>
- <action issue="VALIDATOR-384" type="fix" dev="sebb" due-to=" Kris Babic">
+ <action issue="VALIDATOR-384" type="fix" dev="sebb" due-to="Kris Babic">
EmailValidator does not support escaped quotes in a quoted string
</action>
+ <action issue="VALIDATOR-351" type="add" dev="sebb">
+ DomainValidator - allow access to internal arrays
+ </action>
<action type="update" dev="sebb">
Updated to TLD list Version 2016010600, Last Updated Wed Jan 6 07:07:02
2016 UTC
</action>
Modified:
commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
URL:
http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java?rev=1723634&r1=1723633&r2=1723634&view=diff
==============================================================================
---
commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
(original)
+++
commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/DomainValidator.java
Thu Jan 7 22:18:08 2016
@@ -1512,19 +1512,28 @@ public class DomainValidator implements
/**
* enum used by {@link DomainValidator#updateTLDOverride(ArrayType,
String[])}
- * to determine which override array to update.
+ * to determine which override array to update / fetch
* @since 1.5.0
- * @since 1.5.1 made public
+ * @since 1.5.1 made public and added read-only array references
*/
public enum ArrayType {
- /** Update the GENERIC_TLDS_PLUS table containing additonal generic
TLDs */
+ /** Update (or get a copy of) the GENERIC_TLDS_PLUS table containing
additonal generic TLDs */
GENERIC_PLUS,
- /** Update the GENERIC_TLDS_MINUS table containing deleted generic
TLDs */
+ /** Update (or get a copy of) the GENERIC_TLDS_MINUS table containing
deleted generic TLDs */
GENERIC_MINUS,
- /** Update the COUNTRY_CODE_TLDS_PLUS table containing additonal
country code TLDs */
+ /** Update (or get a copy of) the COUNTRY_CODE_TLDS_PLUS table
containing additonal country code TLDs */
COUNTRY_CODE_PLUS,
- /** Update the COUNTRY_CODE_TLDS_MINUS table containing deleted
country code TLDs */
- COUNTRY_CODE_MINUS;
+ /** Update (or get a copy of) the COUNTRY_CODE_TLDS_MINUS table
containing deleted country code TLDs */
+ COUNTRY_CODE_MINUS,
+ /** Get a copy of the generic TLDS table */
+ GENERIC_RO,
+ /** Get a copy of the country code table */
+ COUNTRY_CODE_RO,
+ /** Get a copy of the infrastructure table */
+ INFRASTRUCTURE_RO,
+ /** Get a copy of the local table */
+ LOCAL_RO
+ ;
};
// For use by unit test code only
@@ -1546,8 +1555,16 @@ public class DomainValidator implements
* To clear an override array, provide an empty array.
*
* @param table the table to update, see {@link DomainValidator.ArrayType}
+ * Must be one of the following
+ * <ul>
+ * <li>COUNTRY_CODE_MINUS</li>
+ * <li>COUNTRY_CODE_PLUS</li>
+ * <li>GENERIC_MINUS</li>
+ * <li>GENERIC_PLUS</li>
+ * </ul>
* @param tlds the array of TLDs, must not be null
* @throws IllegalStateException if the method is called after getInstance
+ * @throws InvalidArgumentException if one of the read-only tables is
requested
* @since 1.5.0
*/
public static synchronized void updateTLDOverride(ArrayType table, String
[] tlds) {
@@ -1573,10 +1590,57 @@ public class DomainValidator implements
case GENERIC_PLUS:
genericTLDsPlus = copy;
break;
+ case COUNTRY_CODE_RO:
+ case GENERIC_RO:
+ case INFRASTRUCTURE_RO:
+ case LOCAL_RO:
+ throw new IllegalArgumentException("Cannot update the table: " +
table);
+ default:
+ throw new IllegalArgumentException("Unexpected enum value: " +
table);
}
}
/**
+ * Get a copy of the internal array.
+ * @param table the array type (any of the enum values)
+ * @return a copy of the array
+ * @throws IllegalArgumentException if the table type is unexpected
(should not happen)
+ * @since 1.5.1
+ */
+ public static String [] getTLDEntries(ArrayType table) {
+ final String array[];
+ switch(table) {
+ case COUNTRY_CODE_MINUS:
+ array = countryCodeTLDsMinus;
+ break;
+ case COUNTRY_CODE_PLUS:
+ array = countryCodeTLDsPlus;
+ break;
+ case GENERIC_MINUS:
+ array = genericTLDsMinus;
+ break;
+ case GENERIC_PLUS:
+ array = genericTLDsPlus;
+ break;
+ case GENERIC_RO:
+ array = GENERIC_TLDS;
+ break;
+ case COUNTRY_CODE_RO:
+ array = COUNTRY_CODE_TLDS;
+ break;
+ case INFRASTRUCTURE_RO:
+ array = INFRASTRUCTURE_TLDS;
+ break;
+ case LOCAL_RO:
+ array = LOCAL_TLDS;
+ break;
+ default:
+ throw new IllegalArgumentException("Unexpected enum value: " +
table);
+ }
+ return Arrays.copyOf(array, array.length); // clone the array
+ }
+
+ /**
* Converts potentially Unicode input to punycode.
* If conversion fails, returns the original input.
*
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=1723634&r1=1723633&r2=1723634&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
Thu Jan 7 22:18:08 2016
@@ -303,6 +303,44 @@ public class DomainValidatorTest extends
assertTrue(Modifier.isPublic(DomainValidator.ArrayType.class.getModifiers()));
}
+ public void testUpdateBaseArrays() {
+ try {
+ DomainValidator.updateTLDOverride(ArrayType.COUNTRY_CODE_RO, new
String[]{"com"});
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ try {
+ DomainValidator.updateTLDOverride(ArrayType.GENERIC_RO, new
String[]{"com"});
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ try {
+ DomainValidator.updateTLDOverride(ArrayType.INFRASTRUCTURE_RO, new
String[]{"com"});
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ try {
+ DomainValidator.updateTLDOverride(ArrayType.LOCAL_RO, new
String[]{"com"});
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ }
+
+ public void testGetArray() {
+
assertNotNull(DomainValidator.getTLDEntries(ArrayType.COUNTRY_CODE_MINUS));
+
assertNotNull(DomainValidator.getTLDEntries(ArrayType.COUNTRY_CODE_PLUS));
+ assertNotNull(DomainValidator.getTLDEntries(ArrayType.GENERIC_MINUS));
+ assertNotNull(DomainValidator.getTLDEntries(ArrayType.GENERIC_PLUS));
+
assertNotNull(DomainValidator.getTLDEntries(ArrayType.COUNTRY_CODE_RO));
+ assertNotNull(DomainValidator.getTLDEntries(ArrayType.GENERIC_RO));
+
assertNotNull(DomainValidator.getTLDEntries(ArrayType.INFRASTRUCTURE_RO));
+ assertNotNull(DomainValidator.getTLDEntries(ArrayType.LOCAL_RO));
+ }
+
public void testUpdateCountryCode() {
assertFalse(validator.isValidCountryCodeTld("com")); // cannot be valid
DomainValidator.updateTLDOverride(ArrayType.COUNTRY_CODE_PLUS, new
String[]{"com"});