commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator UrlValidator.java
Date Sat, 03 May 2003 20:53:59 GMT
dgraham     2003/05/03 13:53:59

  Modified:    validator/src/share/org/apache/commons/validator
                        UrlValidator.java
  Log:
  Simplified logic in isValidAuthority() method.
  
  Revision  Changes    Path
  1.12      +35 -36    jakarta-commons/validator/src/share/org/apache/commons/validator/UrlValidator.java
  
  Index: UrlValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/UrlValidator.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- UrlValidator.java	3 May 2003 20:39:03 -0000	1.11
  +++ UrlValidator.java	3 May 2003 20:53:59 -0000	1.12
  @@ -345,22 +345,17 @@
   	 * of hostname and port.
   	 */
   	protected boolean isValidAuthority(String authority) {
  -		boolean bValid = true;
  -		Perl5Util matchAuthorityPat = new Perl5Util();
  +		Perl5Util authorityMatcher = new Perl5Util();
   		Perl5Util matchIPV4Pat = new Perl5Util();
  -		Perl5Util matchDomainPat = new Perl5Util();
  -		Perl5Util matchAtomPat = new Perl5Util();
  -		Perl5Util matchPortPat = new Perl5Util();
  -		Perl5Util matchAlphaPat = new Perl5Util();
  -        
  -        if (!matchAuthorityPat.match(AUTHORITY_PATTERN, authority)) {
  +		
  +        if (!authorityMatcher.match(AUTHORITY_PATTERN, authority)) {
           	return false;
           }
           
           boolean ipV4Address = false;
           boolean hostname = false;
           // check if authority is IP address or hostname
  -        String hostIP = matchAuthorityPat.group(PARSE_AUTHORITY_HOST_IP);
  +        String hostIP = authorityMatcher.group(PARSE_AUTHORITY_HOST_IP);
           ipV4Address = matchIPV4Pat.match(IP_V4_DOMAIN_PATTERN, hostIP);
           
   		if (ipV4Address) {
  @@ -382,20 +377,22 @@
   			}
           } else {
           	// Domain is hostname name
  -        	hostname = matchDomainPat.match(DOMAIN_PATTERN, hostIP);
  +            Perl5Util domainMatcher = new Perl5Util();
  +        	hostname = domainMatcher.match(DOMAIN_PATTERN, hostIP);
           }
  +        
           //rightmost hostname will never start with a digit.
           if (hostname) {
  -        	// this is a hostname authority so check components
           	String[] domainSegment = new String[10];
           	boolean match = true;
           	int segmentCount = 0;
           	int segmentLength = 0;
  -        
  +            Perl5Util atomMatcher = new Perl5Util();
  +            
           	while (match) {
  -        		match = matchAtomPat.match(ATOM_PATTERN, hostIP);
  +        		match = atomMatcher.match(ATOM_PATTERN, hostIP);
           		if (match) {
  -        			domainSegment[segmentCount] = matchAtomPat.group(1);
  +        			domainSegment[segmentCount] = atomMatcher.group(1);
           			segmentLength = domainSegment[segmentCount].length() + 1;
           			hostIP =
           				(segmentLength >= hostIP.length())
  @@ -411,7 +408,8 @@
           	}
           
           	// First letter of top level must be a alpha
  -        	if (!matchAlphaPat.match(ALPHA_PATTERN, topLevel.substring(0, 1))) {
  +            Perl5Util alphaMatcher = new Perl5Util();
  +        	if (!alphaMatcher.match(ALPHA_PATTERN, topLevel.substring(0, 1))) {
           		return false;
           	}
           
  @@ -420,24 +418,25 @@
           		return false;
           	}
           }
  -        
  -        if (bValid) {
  -        	bValid = (hostname || ipV4Address);
  -        }
  -        
  -        if (bValid) {
  -        	String port = matchAuthorityPat.group(PARSE_AUTHORITY_PORT);
  -        	if (port != null) {
  -        		bValid = matchPortPat.match(PORT_PATTERN, port);
  -        	}
  -        }
  -        
  -        if (bValid) {
  -        	String extra = matchAuthorityPat.group(PARSE_AUTHORITY_EXTRA);
  -        	bValid = ((extra == null) || (extra.length() == 0));
  -        }
  -        
  -        return bValid;
  +
  +		if (!hostname && !ipV4Address) {
  +			return false;
  +		}
  +        
  +		String port = authorityMatcher.group(PARSE_AUTHORITY_PORT);
  +		if (port != null) {
  +			Perl5Util portMatcher = new Perl5Util();
  +			if (!portMatcher.match(PORT_PATTERN, port)) {
  +				return false;
  +			}
  +		}
  +
  +		String extra = authorityMatcher.group(PARSE_AUTHORITY_EXTRA);
  +		if (!GenericValidator.isBlankOrNull(extra)) {
  +			return false;
  +		}
  +
  +		return true;
   	}
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message