cvs commit: jakarta-struts/src/share/org/apache/struts/util StrutsValidator.java

2003-07-01 Thread dgraham
dgraham 2003/07/01 19:44:31

  Removed: src/share/org/apache/struts/util StrutsValidator.java
  Log:
  Changed processRoles() to send a 403 Forbidden response if the role check
  fails for PR# 17276.  Also removed deprecated methods.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-struts/src/share/org/apache/struts/util StrutsValidator.java

2002-10-16 Thread rleland

rleland 2002/10/16 11:44:30

  Modified:conf/share validator-rules.xml
   doc/userGuide dev_validator.xml
   src/share/org/apache/struts/util StrutsValidator.java
  Log:
  Bug#:13528 Apply patch to allow validator to conditionally
  require fields. supplied by James Turner [EMAIL PROTECTED]
  Also turn his comments into userguide material.
  
  Revision  ChangesPath
  1.10  +15 -29jakarta-struts/conf/share/validator-rules.xml
  
  Index: validator-rules.xml
  ===
  RCS file: /home/cvs/jakarta-struts/conf/share/validator-rules.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- validator-rules.xml   11 Oct 2002 19:12:26 -  1.9
  +++ validator-rules.xml   16 Oct 2002 18:44:30 -  1.10
  @@ -81,6 +81,17 @@
   
 /validator
   
  +  validator name=requiredif
  + classname=org.apache.struts.util.StrutsValidator
  + method=validateRequiredIf
  + methodParams=java.lang.Object,
  +   org.apache.commons.validator.ValidatorAction,
  +   org.apache.commons.validator.Field,
  +   org.apache.struts.action.ActionErrors,
  +   org.apache.commons.validator.Validator,
  +   javax.servlet.http.HttpServletRequest
  + msg=errors.required
  +  /validator
   
 validator name=minlength
   classname=org.apache.struts.util.StrutsValidator
  @@ -586,10 +597,10 @@
   
 /validator
   
  -
  +!-- range is deprecated use rangeInt instead --
 validator name=range
   classname=org.apache.struts.util.StrutsValidator
  -   method=validateRange
  +   method=validateIntRange
methodParams=java.lang.Object,
  org.apache.commons.validator.ValidatorAction,
  org.apache.commons.validator.Field,
  @@ -599,33 +610,8 @@
 msg=errors.range
   
javascript![CDATA[
  -function validateRange(form) {
  -var bValid = true;
  -var focusField = null;
  -var i = 0;
  -var fields = new Array();
  -oRange = new range();
  -for (x in oRange) {
  -if ((form[oRange[x][0]].type == 'text' ||
  - form[oRange[x][0]].type == 'textarea') 
  -(form[oRange[x][0]].value.length  0)) {
  -var iMin = parseInt(oRange[x][2](min));
  -var iMax = parseInt(oRange[x][2](max));
  -var iValue = parseInt(form[oRange[x][0]].value);
  -if (!(iValue = iMin  iValue = iMax)) {
  -if (i == 0) {
  -focusField = form[oRange[x][0]];
  -}
  -fields[i++] = oRange[x][1];
  -bValid = false;
  -}
  -}
  -}
  -if (fields.length  0) {
  -focusField.focus();
  -alert(fields.join('\n'));
  -}
  -return bValid;
  +function validateRange(form) {   
  +return validIntRange(form);
   }]]
/javascript
   
  
  
  
  1.5   +99 -1 jakarta-struts/doc/userGuide/dev_validator.xml
  
  Index: dev_validator.xml
  ===
  RCS file: /home/cvs/jakarta-struts/doc/userGuide/dev_validator.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- dev_validator.xml 31 Aug 2002 13:15:02 -  1.4
  +++ dev_validator.xml 16 Oct 2002 18:44:30 -  1.5
  @@ -2,15 +2,113 @@
   document url=./resources.xml
   properties
 authorDavid Winterfeldt/author 
  +  authorJames Turner/author 
  +  authorRob Leland/author 
   titleThe Struts User's Guide - Validator Guide/title
   /properties
   body 
   chapter name=Struts Validator Guide 
   
   section href=validator name=Struts Validator
  -p
  +
   [:TODO:]
  +pCover basic functionality as documented on David's web site.
  +a href=http://home.earthlink.net/~dwinterfeldt/;Validation Framework for Struts 
/a 
   /p
  +
  +p Struts 1.1 has added additional functionality over the original validator
  +contributed by David Winterfeldt/p
  +ul
  +li Conditionally required fields/li
  +li intRange() amp; floatRange() methods in both JavaScript and Java/li
  +li deprecation of range() methods in both JavaScript and Java/li
  +/ul
  +
  +p
  +The most fundamental change is the ability to conditionally
  +require validator 

cvs commit: jakarta-struts/src/share/org/apache/struts/util StrutsValidator.java

2002-10-14 Thread rleland

rleland 2002/10/14 09:35:25

  Modified:src/share/org/apache/struts/util StrutsValidator.java
  Log:
  Deprecated validateRange() now
  calls validatIntRange()
  ValidateRange() will be removed before
  Struts 1.1 final.
  
  Revision  ChangesPath
  1.10  +2 -31 
jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java
  
  Index: StrutsValidator.java
  ===
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- StrutsValidator.java  11 Oct 2002 19:22:58 -  1.9
  +++ StrutsValidator.java  14 Oct 2002 16:35:25 -  1.10
  @@ -461,14 +461,12 @@
   return result;
   }
   
  -
  -
   /**
*  p
*
*  Checks if a fields value is within a range (min amp; max specified in the
*  vars attribute)./p
  - *@deprecated  As of Struts 1.1, replaced by {@link 
#validateIntRange(Object,ValidatorAction,Field,ActionErrors,HttpServletRequest)}
  + *@deprecated  As of Struts 1.1b3, replaced by {@link 
#validateIntRange(Object,ValidatorAction,Field,ActionErrors,HttpServletRequest)}
*@param  bean The bean validation is being performed on.
*@param  va   The codeValidatorAction/code that is currently being 
performed.
*@param  fieldThe codeField/code object associated with the current
  @@ -482,34 +480,7 @@
   ValidatorAction va, Field field,
   ActionErrors errors,
   HttpServletRequest request) {
  -
  -String value = null;
  -if (isString(bean)) {
  -value = (String) bean;
  -} else {
  -value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  -}
  -String sMin = field.getVarValue(min);
  -String sMax = field.getVarValue(max);
  -
  -if (!GenericValidator.isBlankOrNull(value)) {
  -try {
  -int iValue = Integer.parseInt(value);
  -int min = Integer.parseInt(sMin);
  -int max = Integer.parseInt(sMax);
  -
  -if (!GenericValidator.isInRange(iValue, min, max)) {
  -errors.add(field.getKey(), 
StrutsValidatorUtil.getActionError(request, va, field));
  -
  -return false;
  -}
  -} catch (Exception e) {
  -errors.add(field.getKey(), 
StrutsValidatorUtil.getActionError(request, va, field));
  -return false;
  -}
  -}
  -
  -return true;
  +return validateIntRange(bean,va,field,errors,request);
   }
   
  /**
  
  
  

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




cvs commit: jakarta-struts/src/share/org/apache/struts/util StrutsValidator.java

2002-10-10 Thread rleland

rleland 2002/10/10 10:51:20

  Modified:src/share/org/apache/struts/util StrutsValidator.java
  Log:
  Add validateIntRange()  validateDoubleRange()
  and depreciate validateRange().
  
  Revision  ChangesPath
  1.8   +100 -3
jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java
  
  Index: StrutsValidator.java
  ===
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StrutsValidator.java  25 Aug 2002 04:31:15 -  1.7
  +++ StrutsValidator.java  10 Oct 2002 17:51:20 -  1.8
  @@ -57,7 +57,6 @@
   import java.io.Serializable;
   import java.util.Date;
   import java.util.Locale;
  -import javax.servlet.ServletContext;
   import javax.servlet.http.HttpServletRequest;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -80,7 +79,7 @@
*
*@author David Winterfeldt
*@author James Turner
  - *@createdMarch 18, 2002
  + *@author Rob Leland
*@since  Struts 1.1
*/
   public class StrutsValidator implements Serializable {
  @@ -469,7 +468,7 @@
*
*  Checks if a fields value is within a range (min amp; max specified in the
*  vars attribute)./p
  - *
  + *@deprecated  As of Struts 1.1, replaced by {@link 
#validateIntRange(Object,ValidatorAction,Field,ActionErrors,HttpServletRequest)}
*@param  bean The bean validation is being performed on.
*@param  va   The codeValidatorAction/code that is currently being 
performed.
*@param  fieldThe codeField/code object associated with the current
  @@ -512,6 +511,104 @@
   
   return true;
   }
  +
  +   /**
  +*  p
  +*
  +*  Checks if a fields value is within a range (min amp; max specified in the
  +*  vars attribute)./p
  +*
  +*@param  bean The bean validation is being performed on.
  +*@param  va   The codeValidatorAction/code that is currently being 
performed.
  +*@param  fieldThe codeField/code object associated with the current
  +*  field being validated.
  +*@param  errors   The codeActionErrors/code object to add errors to if any
  +*  validation errors occur.
  +*@param  request  Current request object.
  +*@return  True if in range, false otherwise.
  +*/
  +   public static boolean validateIntRange(Object bean,
  +   ValidatorAction va, Field field,
  +   ActionErrors errors,
  +   HttpServletRequest request) {
  +
  +   String value = null;
  +   if (isString(bean)) {
  +   value = (String) bean;
  +   } else {
  +   value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +   }
  +   String sMin = field.getVarValue(min);
  +   String sMax = field.getVarValue(max);
  +
  +   if (!GenericValidator.isBlankOrNull(value)) {
  +   try {
  +   int iValue = Integer.parseInt(value);
  +   int min = Integer.parseInt(sMin);
  +   int max = Integer.parseInt(sMax);
  +
  +   if (!GenericValidator.isInRange(iValue, min, max)) {
  +   errors.add(field.getKey(), 
StrutsValidatorUtil.getActionError(request, va, field));
  +
  +   return false;
  +   }
  +   } catch (Exception e) {
  +   errors.add(field.getKey(), 
StrutsValidatorUtil.getActionError(request, va, field));
  +   return false;
  +   }
  +   }
  +
  +   return true;
  +   }
  +
  +   /**
  +*  p
  +*
  +*  Checks if a fields value is within a range (min amp; max specified in the
  +*  vars attribute)./p
  +*
  +*@param  bean The bean validation is being performed on.
  +*@param  va   The codeValidatorAction/code that is currently being 
performed.
  +*@param  fieldThe codeField/code object associated with the current
  +*  field being validated.
  +*@param  errors   The codeActionErrors/code object to add errors to if any
  +*  validation errors occur.
  +*@param  request  Current request object.
  +*@return  True if in range, false otherwise.
  +*/
  +   public static boolean validateDoubleRange(Object bean,
  +   ValidatorAction va, Field field,
  +   ActionErrors errors,
  +   HttpServletRequest request) {
  +
  +   String value = null;
  +   if (isString(bean)) {
  +   value = (String) bean;
  +   } else {
  +   value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +   }
  +   String sMin = field.getVarValue(min);
  +   String sMax = field.getVarValue(max);
  +
  +   if (!GenericValidator.isBlankOrNull(value)) {
  +   try {
  + 

cvs commit: jakarta-struts/src/share/org/apache/struts/util StrutsValidator.java

2002-07-18 Thread craigmcc

craigmcc2002/07/18 21:02:06

  Modified:.STATUS
   src/share/org/apache/struts/util StrutsValidator.java
  Log:
  Make StrutsValidator validators work with indexed string values.
  
  PR: Bugzilla #10919
  Submitted by: James Turner turner at blackbear.com
  Thanks for the patch!
  
  Revision  ChangesPath
  1.31  +2 -3  jakarta-struts/STATUS
  
  Index: STATUS
  ===
  RCS file: /home/cvs/jakarta-struts/STATUS,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- STATUS19 Jul 2002 03:30:19 -  1.30
  +++ STATUS19 Jul 2002 04:02:05 -  1.31
  @@ -6,7 +6,7 @@
   OUTSTANDING BUGS IN STRUTS 1.1-b1 AND NIGHTLY BUILDS
   
   
  -   20 open bugs to swat!!
  +   18 open bugs to swat!!
   
   
   Controller:
  @@ -65,7 +65,6 @@
   10584 Not all validation files are read in Validation PlugIn
   10782 If two fields are required, and one has a mask, the mask is not checked if 
the other field is blank
   10868 Validator  does not support non-default resource bundles
  -10919 PATCH: ValidatorUtils can't handle StringArrays
   
   
   Web Site:
  
  
  
  1.5   +126 -39   
jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java
  
  Index: StrutsValidator.java
  ===
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StrutsValidator.java  30 Jun 2002 03:28:46 -  1.4
  +++ StrutsValidator.java  19 Jul 2002 04:02:06 -  1.5
  @@ -101,19 +101,24 @@
  ActionErrors errors,
  HttpServletRequest request) {
   
  -   String value = null;
  -   if (field.getProperty() != null  field.getProperty().length()  0)
  -  value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  -
  -   if (GenericValidator.isBlankOrNull(value)) {
  -  errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, 
va, field));
  +String value = null;
  +if (isString(bean)) {
  +value = (String) bean;
  +} else {
  +value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +}
  +if (GenericValidator.isBlankOrNull(value)) {
  +errors.add(field.getKey(),
  +   StrutsValidatorUtil.getActionError(request, va, field));
  +
  +return false;
  +} else {
  +return true;
  +}
   
  -  return false;
  -   } else {
  -  return true;
  -   }
   }
   
  +
   /**
* pChecks if the field matches the regular expression in the field's mask 
attribute./p
*
  @@ -130,25 +135,30 @@
  ActionErrors errors,
  HttpServletRequest request) {
   
  - String mask = field.getVarValue(mask);
  -
  - if (field.getProperty() != null  field.getProperty().length()  0) {
  -String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  -
  -try {
  -   if (!GenericValidator.isBlankOrNull(value)  
!GenericValidator.matchRegexp(value, mask)) {
  -  errors.add(field.getKey(), 
StrutsValidatorUtil.getActionError(request, va, field));
  -
  -  return false;
  -   } else {
  -  return true;
  -   }
  +String mask = field.getVarValue(mask);
  +String value = null;
  +if (isString(bean)) {
  +value = (String) bean;
  +} else {
  +value = ValidatorUtil.getValueAsString(bean,
  +   field.getProperty());
  +}
  +try {
  +if (!GenericValidator.isBlankOrNull(value) 
  +!GenericValidator.matchRegexp(value, mask)) {
  +errors.add(field.getKey(),
  +   StrutsValidatorUtil.getActionError(request, va,
  +  field));
  +
  +return false;
  +} else {
  +return true;
  +}
   } catch (Exception e) {
  -   LOG.error(e.getMessage(), e);
  +LOG.error(e.getMessage(), e);
   }
  - }
  +return true;
   
  - return true;
   }
   
   
  @@ -169,7 +179,12 @@
   HttpServletRequest request) {
   
  Byte result = null;
  -   String value = 

cvs commit: jakarta-struts/src/share/org/apache/struts/util StrutsValidator.java

2002-04-01 Thread dwinterfeldt

dwinterfeldt02/04/01 20:06:21

  Modified:src/share/org/apache/struts/util StrutsValidator.java
  Log:
  Changing interface to some methods to return correctly typed objects which are 
available in a Map using the property of the field as the key.  This Map can be 
accessed from the ValidatorForm.  The change should be transparent through the 
framework, but any direct method calls to these methods will need to be changed.  The 
change in the interface is to reduce duplication for Struts 1.1.
  
  Revision  ChangesPath
  1.2   +111 -89   
jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java
  
  Index: StrutsValidator.java
  ===
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StrutsValidator.java  18 Mar 2002 01:42:51 -  1.1
  +++ StrutsValidator.java  2 Apr 2002 04:06:21 -   1.2
  @@ -56,16 +56,17 @@
   package org.apache.struts.util;
   
   import java.io.Serializable;
  +import java.util.Date;
   import java.util.Locale;
   import javax.servlet.ServletContext;
   import javax.servlet.http.HttpServletRequest;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogSource;
   import org.apache.commons.validator.Field;
  +import org.apache.commons.validator.GenericTypeValidator;
   import org.apache.commons.validator.GenericValidator;
   import org.apache.commons.validator.ValidatorAction;
   import org.apache.commons.validator.ValidatorUtil;
  -import org.apache.regexp.RESyntaxException;
   import org.apache.struts.action.ActionErrors;
   
   
  @@ -142,8 +143,6 @@
  } else {
 return true;   
  }
  - } catch (RESyntaxException e) {
  -LOG.error(e.getMessage(), e);
} catch (Exception e) {
   LOG.error(e.getMessage(), e);
}
  @@ -164,19 +163,23 @@
*  validation errors occur.
* @paramrequest Current request object.
   */
  -public static boolean validateByte(Object bean, 
  -  ValidatorAction va, Field field, 
  -  ActionErrors errors, 
  - HttpServletRequest request) {
  +public static Byte validateByte(Object bean, 
  + ValidatorAction va, Field field, 
  + ActionErrors errors, 
  +HttpServletRequest request) {
  
  +   Byte result = null;
  String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
   
  -   if (!GenericValidator.isBlankOrNull(value)  
!GenericValidator.isByte(value)) {
  -  errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, 
va, field));
  -  return false;
  -   } else {
  -  return true;   
  +   if (!GenericValidator.isBlankOrNull(value)) {
  +   result = GenericTypeValidator.formatByte(value);
  +   
  +   if (result == null) {
  + errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, 
va, field));
  +  }
  }
  +   
  +   return result;
   }
   
   /**
  @@ -190,18 +193,22 @@
*  validation errors occur.
* @paramrequest Current request object.
   */
  -public static boolean validateShort(Object bean, 
  -   ValidatorAction va, Field field, 
  -   ActionErrors errors, 
  -  HttpServletRequest request) {
  +public static Short validateShort(Object bean, 
  +   ValidatorAction va, Field field, 
  +   ActionErrors errors, 
  +  HttpServletRequest request) {
  +   Short result = null;
  String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  
  -   if (!GenericValidator.isBlankOrNull(value)  
!GenericValidator.isShort(value)) {
  -  errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, 
va, field));
  -  return false;
  -   } else {
  -  return true;   
  +   if (!GenericValidator.isBlankOrNull(value)) {
  +   result = GenericTypeValidator.formatShort(value);
  +   
  +   if (result == null) {
  + errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, 
va, field));
  +  }
  }
  +   
  +   return result;
   }
   
   /**
  @@ -215,18 +222,22 @@
*  validation errors occur.
* @paramrequest Current request