portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/util/parser ValidationParameterParser.java
Date Mon, 31 Mar 2003 00:30:32 GMT
taylor      2003/03/30 16:30:32

  Modified:    src/java/org/apache/jetspeed/util TestValidation.java
                        TestValidationParameterParser.java
                        ValidationHelper.java
               src/java/org/apache/jetspeed/util/parser
                        ValidationParameterParser.java
  Log:
  Enhanced Validation Helper to except 'required' parameter, and added a second signature
for checking maxLength of field
  
  Revision  Changes    Path
  1.3       +15 -15    jakarta-jetspeed/src/java/org/apache/jetspeed/util/TestValidation.java
  
  Index: TestValidation.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/TestValidation.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestValidation.java	4 Mar 2003 00:05:15 -0000	1.2
  +++ TestValidation.java	31 Mar 2003 00:30:32 -0000	1.3
  @@ -105,8 +105,8 @@
           String goodString = "The quick brown fox jumped over the lazy dog 0123456789";
           String badString = "><$$!&.*";
   
  -        assertTrue(ValidationHelper.isAlphaNumeric(goodString));        
  -        assertTrue(!ValidationHelper.isAlphaNumeric(badString));        
  +        assertTrue(ValidationHelper.isAlphaNumeric(goodString, false));        
  +        assertTrue(!ValidationHelper.isAlphaNumeric(badString, false));        
       }
       
       public void testLooseAlphaNumeric() throws Exception
  @@ -121,14 +121,14 @@
           
           for (int ia=0; ia < goodString.length; ia++)
           {
  -            assertTrue(ValidationHelper.isLooseAlphaNumeric(goodString[ia]));
  -            System.out.println(goodString[ia]+" is Good: "+ValidationHelper.isLooseAlphaNumeric(goodString[ia]));
  +            assertTrue(ValidationHelper.isLooseAlphaNumeric(goodString[ia], false));
  +            System.out.println(goodString[ia]+" is Good: "+ValidationHelper.isLooseAlphaNumeric(goodString[ia],
false));
           }
           
           for (int ib=0; ib < badString.length; ib++)
           {
  -            assertTrue(!ValidationHelper.isLooseAlphaNumeric(badString[ib]));
  -            System.out.println(badString[ib]+" is Bad: "+!ValidationHelper.isLooseAlphaNumeric(badString[ib]));
  +            assertTrue(!ValidationHelper.isLooseAlphaNumeric(badString[ib], false));
  +            System.out.println(badString[ib]+" is Bad: "+!ValidationHelper.isLooseAlphaNumeric(badString[ib],
false));
           }      
       }
       
  @@ -140,12 +140,12 @@
           
           for (int ia=0; ia < goodString.length; ia++)
           {
  -            assertTrue(ValidationHelper.isDecimal(goodString[ia]));
  +            assertTrue(ValidationHelper.isDecimal(goodString[ia], false));
           }
   
           for (int ib=0; ib < badString.length; ib++)
           {
  -            assertTrue(!ValidationHelper.isDecimal(badString[ib]));
  +            assertTrue(!ValidationHelper.isDecimal(badString[ib], false));
           }
       }
       
  @@ -157,12 +157,12 @@
   
           for (int ia=0; ia < goodString.length; ia++)
           {
  -            assertTrue(ValidationHelper.isInteger(goodString[ia]));
  +            assertTrue(ValidationHelper.isInteger(goodString[ia], false));
           }
   
           for (int ib=0; ib < badString.length; ib++)
           {
  -            assertTrue(!ValidationHelper.isInteger(badString[ib]));
  +            assertTrue(!ValidationHelper.isInteger(badString[ib], false));
           }
       }
       
  @@ -175,12 +175,12 @@
   
           for (int ia=0; ia < goodString.length; ia++)
           {
  -            assertTrue(ValidationHelper.isEmailAddress(goodString[ia]));
  +            assertTrue(ValidationHelper.isEmailAddress(goodString[ia], false));
           }
   
           for (int ib=0; ib < badString.length; ib++)
           {
  -            assertTrue(!ValidationHelper.isEmailAddress(badString[ib]));
  +            assertTrue(!ValidationHelper.isEmailAddress(badString[ib], false));
           }
       }
       
  @@ -189,8 +189,8 @@
           String goodString = "http://www.apache.org";
           String badString = "me.";
           
  -        assertTrue(ValidationHelper.isURL(goodString));        
  -        assertTrue(!ValidationHelper.isURL(badString));        
  +        assertTrue(ValidationHelper.isURL(goodString, false));        
  +        assertTrue(!ValidationHelper.isURL(badString, false));        
       }
   
   
  
  
  
  1.4       +3 -3      jakarta-jetspeed/src/java/org/apache/jetspeed/util/TestValidationParameterParser.java
  
  Index: TestValidationParameterParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/TestValidationParameterParser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestValidationParameterParser.java	4 Mar 2003 00:05:15 -0000	1.3
  +++ TestValidationParameterParser.java	31 Mar 2003 00:30:32 -0000	1.4
  @@ -184,12 +184,12 @@
   
           public boolean validateEmail(String email)
           {
  -            return ValidationHelper.isEmailAddress(email);
  +            return ValidationHelper.isEmailAddress(email, false);
           }            
   
           public boolean validateName(String name)
           {
  -            return ValidationHelper.isLooseAlphaNumeric(name);
  +            return ValidationHelper.isLooseAlphaNumeric(name, false);
           }            
   
       }
  
  
  
  1.2       +102 -13   jakarta-jetspeed/src/java/org/apache/jetspeed/util/ValidationHelper.java
  
  Index: ValidationHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/ValidationHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ValidationHelper.java	12 Feb 2003 05:57:48 -0000	1.1
  +++ ValidationHelper.java	31 Mar 2003 00:30:32 -0000	1.2
  @@ -59,6 +59,7 @@
   import javax.mail.internet.*;
   import java.net.*;
   import java.util.Properties;
  +import org.apache.commons.lang.StringUtils;
   
   /**
    * <P>Data Validation functions using Regex</P>
  @@ -75,27 +76,54 @@
        * Tests that the input string contains only alpha numeric or white spaces
        * <P>
        * @param evalString The string that is to be evaluated
  +     * @param required indicates whether the field is required or not
        * @return True if the input is alpha numeric, false otherwise.
        **/
  -    public static boolean isAlphaNumeric(String evalString)
  +    public static boolean isAlphaNumeric(String evalString, boolean required)
       {
  -        if ((evalString == null) || evalString.equals(""))
  +        if (StringUtils.isEmpty(evalString))
           {
  +            if (true == required)
  +            {
  +                return false;
  +            }
               return true;
           }
           Perl5Util util = new Perl5Util();
           return util.match("/^[\\w\\s]+$/", evalString);
       }
   
  -    public static boolean isLooseAlphaNumeric(String evalString)
  +    public static boolean isAlphaNumeric(String evalString, boolean required, int maxLength)
       {
  -        if ((evalString == null) || evalString.equals(""))
  +        if (isTooLong(evalString, maxLength))
           {
  +            return false;
  +        }
  +        return isAlphaNumeric(evalString, required);
  +    }
  +
  +    public static boolean isLooseAlphaNumeric(String evalString, boolean required)
  +    {
  +        if (StringUtils.isEmpty(evalString))
  +        {
  +            if (true == required)
  +            {
  +                return false;
  +            }
               return true;
           }
           Perl5Util util = new Perl5Util();
           return util.match("/^[\\w\\s\\.\\,\\/\\-\\(\\)\\+]+$/", evalString);
       }
  +
  +    public static boolean isLooseAlphaNumeric(String evalString, boolean required, int
maxLength)
  +    {
  +        if (isTooLong(evalString, maxLength))
  +        {
  +            return false;
  +        }
  +        return isLooseAlphaNumeric(evalString, required);
  +    }
           
       /**
        * Tests that the input string contains only numeric
  @@ -103,48 +131,86 @@
        * @param evalString The string that is to be evaluated
        * @return True if the input is numeric, false otherwise.
        **/
  -    public static boolean isDecimal(String evalString)
  +    public static boolean isDecimal(String evalString, boolean required)
       {
  -        if ((evalString == null) || evalString.equals(""))
  +        if (StringUtils.isEmpty(evalString))
           {
  +            if (true == required)
  +            {
  +                return false;
  +            }
               return true;
           }
           Perl5Util util = new Perl5Util();
           return util.match("/^(\\d+\\.)?\\d+$/", evalString);
       }
       
  +    public static boolean isDecimal(String evalString, boolean required, int maxLength)
  +    {
  +        if (isTooLong(evalString, maxLength))
  +        {
  +            return false;
  +        }
  +        return isDecimal(evalString, required);
  +    }
  +
       /**
        * Tests that the input string contains only an integer
        * <P>
        * @param evalString The string that is to be evaluated
        * @return True if the input is numeric, false otherwise.
        **/
  -    public static boolean isInteger (String evalString)
  +    public static boolean isInteger (String evalString, boolean required)
       {
  -        if ((evalString == null) || evalString.equals(""))
  +        if (StringUtils.isEmpty(evalString))
           {
  +            if (true == required)
  +            {
  +                return false;
  +            }
               return true;
           }
           Perl5Util util = new Perl5Util();
           return util.match("/^\\d+$/", evalString);
       }
       
  +    public static boolean isInteger(String evalString, boolean required, int maxLength)
  +    {
  +        if (isTooLong(evalString, maxLength))
  +        {
  +            return false;
  +        }
  +        return isInteger(evalString, required);
  +    }
  +
       /**
        * Tests that the input string contains a valid email addess
        * <P>
        * @param evalString The string that is to be evaluated
        * @return True if the input is a valid email address.
        **/
  -    public static boolean isEmailAddress(String evalString)
  +    public static boolean isEmailAddress(String evalString, boolean required)
       {
  -        if ((evalString == null) || evalString.equals(""))
  +        if (StringUtils.isEmpty(evalString))
           {
  +            if (true == required)
  +            {
  +                return false;
  +            }
               return true;
           }
           Perl5Util util = new Perl5Util();
           return util.match("/^(?:\\w[\\w-]*\\.)*\\w[\\w-]*@(?:\\w[\\w-]*\\.)+\\w[\\w-]*$/",
evalString);
       }
       
  +    public static boolean isEmailAddress(String evalString, boolean required, int maxLength)
  +    {
  +        if (isTooLong(evalString, maxLength))
  +        {
  +            return false;
  +        }
  +        return isEmailAddress(evalString, required);
  +    }
       
       /**
        * Tests that the input string contains a valid URL
  @@ -152,12 +218,16 @@
        * @param evalString The string that is to be evaluated
        * @return True if the input is a valid URL.
        **/
  -    public static boolean isURL(String evalString)
  +    public static boolean isURL(String evalString, boolean required)
       {
           try
           {
  -            if ((evalString == null) || evalString.equals(""))
  +            if (StringUtils.isEmpty(evalString))
               {
  +                if (true == required)
  +                {
  +                    return false;
  +                }
                   return true;
               }
               
  @@ -179,6 +249,15 @@
           }
       }
   
  +    public static boolean isURL(String evalString, boolean required, int maxLength)
  +    {
  +        if (isTooLong(evalString, maxLength))
  +        {
  +            return false;
  +        }
  +        return isURL(evalString, required);
  +    }
  +
       public static boolean isValidIdentifier(String folderName)
       {
           boolean valid = true;
  @@ -194,5 +273,15 @@
           }
           return valid;
       }
  +
  +    public static boolean isTooLong(String evalString, int maxLength)
  +    {
  +        if (null != evalString)
  +        {
  +            return (evalString.length() > maxLength);
  +        }
  +        return false;
  +    }
  +
   }
   
  
  
  
  1.3       +11 -11    jakarta-jetspeed/src/java/org/apache/jetspeed/util/parser/ValidationParameterParser.java
  
  Index: ValidationParameterParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/parser/ValidationParameterParser.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ValidationParameterParser.java	4 Mar 2003 00:05:15 -0000	1.2
  +++ ValidationParameterParser.java	31 Mar 2003 00:30:32 -0000	1.3
  @@ -297,15 +297,15 @@
       
           if (propclass == String.class)
           {
  -            return ValidationHelper.isAlphaNumeric(getString(prop.getName()));
  +            return ValidationHelper.isAlphaNumeric(getString(prop.getName()), false);
           }
           else if (propclass == Integer.class || propclass == Integer.TYPE)
           {
  -             return ValidationHelper.isInteger(getString(prop.getName()));
  +             return ValidationHelper.isInteger(getString(prop.getName()), false);
           }
           else if (propclass == Long.class    || propclass == Long.TYPE)
           {
  -            return ValidationHelper.isDecimal(getString(prop.getName()));
  +            return ValidationHelper.isDecimal(getString(prop.getName()), false);
           }
           else if (propclass == Boolean.class || propclass == Boolean.TYPE)
           {
  @@ -314,15 +314,15 @@
           }
           else if (propclass == Double.class  || propclass == Double.TYPE)
           {
  -            return ValidationHelper.isDecimal(getString(prop.getName()));
  +            return ValidationHelper.isDecimal(getString(prop.getName()), false);
           }
           else if (propclass == BigDecimal.class)
           {
  -            return ValidationHelper.isDecimal(getString(prop.getName()));
  +            return ValidationHelper.isDecimal(getString(prop.getName()), false);
           }
           else if (propclass == String[].class)
           {
  -            return ValidationHelper.isAlphaNumeric(getString(prop.getName()));
  +            return ValidationHelper.isAlphaNumeric(getString(prop.getName()), false);
           }
           else if (propclass == Object.class)
           {
  @@ -331,11 +331,11 @@
           }
           else if (propclass == int[].class)
           {
  -            return ValidationHelper.isInteger(getString(prop.getName()));
  +            return ValidationHelper.isInteger(getString(prop.getName()), false);
           }
           else if (propclass == Integer[].class)
           {
  -            return ValidationHelper.isInteger(getString(prop.getName()));
  +            return ValidationHelper.isInteger(getString(prop.getName()), false);
           }
           else if (propclass == Date.class)
           {
  @@ -344,11 +344,11 @@
           }
           else if (propclass == NumberKey.class)
           {
  -            return ValidationHelper.isInteger(getString(prop.getName()));
  +            return ValidationHelper.isInteger(getString(prop.getName()), false);
           }
           else if (propclass == StringKey.class)
           {
  -            return ValidationHelper.isInteger(getString(prop.getName()));
  +            return ValidationHelper.isInteger(getString(prop.getName()), false);
           }
           else
           {
  
  
  

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


Mime
View raw message