You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bs...@apache.org on 2007/10/30 07:34:01 UTC
svn commit: r589974 -
/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
Author: bspeakmon
Date: Mon Oct 29 23:33:59 2007
New Revision: 589974
URL: http://svn.apache.org/viewvc?rev=589974&view=rev
Log:
- VALIDATOR-203: refactoring UrlValidator to use DomainValidator, replacing
the rather ugly domain checking code that caused VALIDATOR-202
Modified:
commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
Modified: commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java
URL: http://svn.apache.org/viewvc/commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java?rev=589974&r1=589973&r2=589974&view=diff
==============================================================================
--- commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java (original)
+++ commons/proper/validator/trunk/src/main/java/org/apache/commons/validator/routines/UrlValidator.java Mon Oct 29 23:33:59 2007
@@ -339,55 +339,8 @@
if (!ipV4Address) {
// Domain is hostname name
- Perl5Util domainMatcher = new Perl5Util();
- hostname = domainMatcher.match(DOMAIN_PATTERN, hostIP);
- }
-
- //rightmost hostname will never start with a digit.
- if (hostname) {
- // LOW-TECH FIX FOR VALIDATOR-202
- // TODO: Rewrite to use ArrayList and .add semantics: see VALIDATOR-203
- char[] chars = hostIP.toCharArray();
- int size = 1;
- for(int i=0; i<chars.length; i++) {
- if(chars[i] == '.') {
- size++;
- }
- }
- String[] domainSegment = new String[size];
- boolean match = true;
- int segmentCount = 0;
- int segmentLength = 0;
- Perl5Util atomMatcher = new Perl5Util();
-
- while (match) {
- match = atomMatcher.match(ATOM_PATTERN, hostIP);
- if (match) {
- domainSegment[segmentCount] = atomMatcher.group(1);
- segmentLength = domainSegment[segmentCount].length() + 1;
- hostIP =
- (segmentLength >= hostIP.length())
- ? ""
- : hostIP.substring(segmentLength);
-
- segmentCount++;
- }
- }
- String topLevel = domainSegment[segmentCount - 1];
- if (topLevel.length() < 2 || topLevel.length() > 4) {
- return false;
- }
-
- // First letter of top level must be a alpha
- Perl5Util alphaMatcher = new Perl5Util();
- if (!alphaMatcher.match(ALPHA_PATTERN, topLevel.substring(0, 1))) {
- return false;
- }
-
- // Make sure there's a host name preceding the authority.
- if (segmentCount < 2) {
- return false;
- }
+ DomainValidator validator = DomainValidator.getInstance();
+ hostname = validator.isValid(hostIP);
}
if (!hostname && !ipV4Address) {