cvs commit: jakarta-struts/src/share/org/apache/struts/validator/validwhen ValidWhen.java ValidWhenLexer.java ValidWhenParser.g ValidWhenParser.java ValidWhenParserTokenTypes.java ValidWhenParserTokenTypes.txt
rleland 2003/09/28 21:19:37 Modified:src/share/org/apache/struts/validator/validwhen ValidWhen.java ValidWhenLexer.java ValidWhenParser.g ValidWhenParser.java ValidWhenParserTokenTypes.java ValidWhenParserTokenTypes.txt Log: Update validator methods in ValidWhenparser.g also update Apache license, to correct version. == Regenerate these files with ANTLR 2.7.2 not 2.7.1 == The only observed difference is that ignoring case boolean operators are moved up sooner in method calls. Revision ChangesPath 1.9 +21 -20 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhen.java Index: ValidWhen.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhen.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ValidWhen.java26 Sep 2003 18:12:24 - 1.8 +++ ValidWhen.java29 Sep 2003 04:19:37 - 1.9 @@ -23,20 +23,20 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/). - * Alternately, this acknowlegement may appear in the software itself, - * if and wherever such third-party acknowlegements normally appear. - * - * 4. The names The Jakarta Project, Struts, and Apache Software - * Foundation must not be used to endorse or promote products derived - * from this software without prior written permission. For written - * permission, please contact [EMAIL PROTECTED] - * - * 5. Products derived from this software may not be called Apache - * nor may Apache appear in their names without prior written - * permission of the Apache Group. + *any, must include the following acknowledgement: + * This product includes software developed by the + *Apache Software Foundation (http://www.apache.org/). + *Alternately, this acknowlegement may appear in the software itself, + *if and wherever such third-party acknowlegements normally appear. + * + * 4. The names The Jakarta Project, Struts, and Apache Software + *Foundation must not be used to endorse or promote products derived + *from this software without prior written permission. For written + *permission, please contact [EMAIL PROTECTED] + * + * 5. Products derived from this software may not be called Apache + *nor may Apache appear in their name, without prior written + *permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -56,6 +56,7 @@ * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * http://www.apache.org/. + * */ package org.apache.struts.validator.validwhen; @@ -67,7 +68,7 @@ import org.apache.commons.validator.Field; import org.apache.commons.validator.Validator; import org.apache.commons.validator.ValidatorAction; -import org.apache.commons.validator.ValidatorUtil; +import org.apache.commons.validator.util.ValidatorUtils; import org.apache.struts.action.ActionMessages; import org.apache.struts.validator.Resources; @@ -115,7 +116,7 @@ Validator validator, HttpServletRequest request) { -Object form = validator.getResource(Validator.BEAN_KEY); +Object form = validator.getParameterValue(Validator.BEAN_PARAM); String value = null; boolean valid = false; int index = -1; @@ -135,7 +136,7 @@ if (isString(bean)) { value = (String) bean; } else { -value = ValidatorUtil.getValueAsString(bean, field.getProperty()); +value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } String test = field.getVarValue(test); 1.5 +65 -33 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhenLexer.java Index: ValidWhenLexer.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhenLexer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ValidWhenLexer.java 27 Jul 2003 05:20:44 - 1.4 +++ ValidWhenLexer.java 29 Sep 2003 04:19:37 - 1.5 @@ -1,9 +1,15 @@ -// $ANTLR 2.7.1: ValidWhenParser.g - ValidWhenLexer.java$ +// $ANTLR 2.7.2: validWhenParser.g -
cvs commit: jakarta-struts/src/share/org/apache/struts/validator/validwhen ValidWhen.java
turner 2003/09/26 11:12:24 Modified:src/share/org/apache/struts/validator FieldChecks.java src/share/org/apache/struts/validator/validwhen ValidWhen.java Log: Changed validator signatures to use ActionMessages rather than ActionErrors, was breaking validations. Revision ChangesPath 1.13 +41 -41 jakarta-struts/src/share/org/apache/struts/validator/FieldChecks.java Index: FieldChecks.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/validator/FieldChecks.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- FieldChecks.java 22 Aug 2003 23:49:12 - 1.12 +++ FieldChecks.java 26 Sep 2003 18:12:24 - 1.13 @@ -73,7 +73,7 @@ import org.apache.commons.validator.GenericValidator; import org.apache.commons.validator.ValidatorAction; import org.apache.commons.validator.ValidatorUtil; -import org.apache.struts.action.ActionErrors; +import org.apache.struts.action.ActionMessages; import org.apache.struts.util.RequestUtils; /** @@ -111,14 +111,14 @@ * @param va The codeValidatorAction/code that is currently being performed. * @param field The codeField/code object associated with the current * field being validated. - * @param errors The codeActionErrors/code object to add errors to if + * @param errors The codeActionMessages/code object to add errors to if * any validation errors occur. * @param request Current request object. * @return true if meets stated requirements, false otherwise. */ public static boolean validateRequired(Object bean, ValidatorAction va, Field field, - ActionErrors errors, + ActionMessages errors, HttpServletRequest request) { String value = null; @@ -145,7 +145,7 @@ * performed. * @param field The codeField/code object associated with the current * field being validated. - * @param errors The codeActionErrors/code object to add errors to if + * @param errors The codeActionMessages/code object to add errors to if * any validation errors occur. * @param validator The codeValidator/code instance, used to access * other field values. @@ -154,7 +154,7 @@ */ public static boolean validateRequiredIf(Object bean, ValidatorAction va, Field field, - ActionErrors errors, + ActionMessages errors, org.apache.commons.validator.Validator validator, HttpServletRequest request) { @@ -251,14 +251,14 @@ * performed. * @param field The codeField/code object associated with the current * field being validated. - * @param errors The codeActionErrors/code object to add errors to if + * @param errors The codeActionMessages/code object to add errors to if * any validation errors occur. * @param request Current request object. * @return true if field matches mask, false otherwise. */ public static boolean validateMask(Object bean, ValidatorAction va, Field field, - ActionErrors errors, + ActionMessages errors, HttpServletRequest request) { String mask = field.getVarValue(mask); @@ -295,14 +295,14 @@ [EMAIL PROTECTED] va The codeValidatorAction/code that is currently being performed. [EMAIL PROTECTED] field The codeField/code object associated with the current *field being validated. - [EMAIL PROTECTED] errors The codeActionErrors/code object to add errors to if + [EMAIL PROTECTED] errors The codeActionMessages/code object to add errors to if *any validation errors occur. [EMAIL PROTECTED] request Current request object. [EMAIL PROTECTED] A Byte if valid, null otherwise. */ public static Byte validateByte(Object bean, ValidatorAction va, Field field, -ActionErrors errors, +ActionMessages errors, HttpServletRequest request) { Byte result = null; @@ -332,14 +332,14 @@ * @param va The codeValidatorAction/code that is
cvs commit: jakarta-struts/src/share/org/apache/struts/validator/validwhen ValidWhen.java
dgraham 2003/08/23 10:18:39 Modified:src/share/org/apache/struts/validator/validwhen ValidWhen.java Log: Replaced deprecated Resources.getActionError() calls. Revision ChangesPath 1.7 +30 -14 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhen.java Index: ValidWhen.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhen.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ValidWhen.java4 Jul 2003 20:38:19 - 1.6 +++ ValidWhen.java23 Aug 2003 17:18:39 - 1.7 @@ -91,14 +91,21 @@ * Checks if the field matches the boolean expression specified in * codetest/code parameter. * - [EMAIL PROTECTED] bean The bean validation is being performed on. - [EMAIL PROTECTED] va The codeValidatorAction/code that is currently being performed. - [EMAIL PROTECTED] fieldThe codeField/code object associated with the current + * @param bean The bean validation is being performed on. + * + * @param va The codeValidatorAction/code that is currently being + * performed. + * + * @param field The codeField/code object associated with the current * field being validated. - [EMAIL PROTECTED] errors The codeActionErrors/code object to add errors to if any + * + * @param errors The codeActionErrors/code object to add errors to if any * validation errors occur. - [EMAIL PROTECTED] request Current request object. - [EMAIL PROTECTED] True if meets stated requirements, False otherwise + * + * @param request Current request object. + * + * @return codetrue/code if meets stated requirements, + * codefalse/code otherwise. */ public static boolean validateValidWhen( Object bean, @@ -116,10 +123,12 @@ if (field.isIndexed()) { String key = field.getKey(); -if ((key.indexOf([) -1) (key.indexOf(]) -1)) { +final int leftBracket = key.indexOf([); +final int rightBracket = key.indexOf(]); + +if ((leftBracket -1) (rightBracket -1)) { index = -Integer.parseInt( -key.substring(key.indexOf([) + 1, key.indexOf(]))); +Integer.parseInt(key.substring(leftBracket + 1, rightBracket)); } } @@ -148,12 +157,19 @@ } catch (Exception ex) { ex.printStackTrace(); -errors.add(field.getKey(), Resources.getActionError(request, va, field)); + +errors.add( +field.getKey(), +Resources.getActionMessage(request, va, field)); + return false; } if (!valid) { -errors.add(field.getKey(), Resources.getActionError(request, va, field)); +errors.add( +field.getKey(), +Resources.getActionMessage(request, va, field)); + return false; } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-struts/src/share/org/apache/struts/validator/validwhen ValidWhen.java
dgraham 2003/07/04 13:34:53 Modified:src/share/org/apache/struts/validator/validwhen ValidWhen.java Log: Formatting and javadoc cleanup. Revision ChangesPath 1.5 +84 -66 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhen.java Index: ValidWhen.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhen.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ValidWhen.java1 Jul 2003 17:49:25 - 1.4 +++ ValidWhen.java4 Jul 2003 20:34:53 - 1.5 @@ -1,7 +1,13 @@ /* + * $Header$ + * $Revision$ + * $Date$ + * + * + * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,36 +60,36 @@ package org.apache.struts.validator.validwhen; -import org.apache.commons.validator.*; -import org.apache.struts.action.ActionErrors; -import org.apache.struts.action.ActionError; +import java.io.StringReader; + import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.validator.Field; +import org.apache.commons.validator.Validator; +import org.apache.commons.validator.ValidatorAction; +import org.apache.commons.validator.ValidatorUtil; +import org.apache.struts.action.ActionErrors; import org.apache.struts.validator.Resources; -import java.io.StringReader; /** - * p - * - * This class contains the validwhen validation that is used in the validator-rules.xml - * file./p - * + * This class contains the validwhen validation that is used in the + * validator-rules.xml file. * - [EMAIL PROTECTED] James Turner - [EMAIL PROTECTED] Struts 1.1 + * @author James Turner + * @since Struts 1.2 */ - public class ValidWhen { - private static Class stringClass = new String().getClass(); +private static Class stringClass = new String().getClass(); - private static boolean isString(Object o) { -if (o == null) return true; -return (stringClass.isInstance(o)); - } +private static boolean isString(Object o) { +if (o == null) +return true; +return (stringClass.isInstance(o)); +} /** - * p - * - * Checks if the field matches the boolean expression specified in codetest/code parameter/p + * Checks if the field matches the boolean expression specified in + * codetest/code parameter. * [EMAIL PROTECTED] bean The bean validation is being performed on. [EMAIL PROTECTED] va The codeValidatorAction/code that is currently being performed. @@ -94,52 +100,64 @@ [EMAIL PROTECTED] request Current request object. [EMAIL PROTECTED] True if meets stated requirements, False otherwise */ +public static boolean validateValidWhen( +Object bean, +ValidatorAction va, +Field field, +ActionErrors errors, +Validator validator, +HttpServletRequest request) { + +Object form = validator.getResource(Validator.BEAN_KEY); +String value = null; +boolean valid = false; +int index = -1; + +if (field.isIndexed()) { +String key = field.getKey(); + +if ((key.indexOf([) -1) (key.indexOf(]) -1)) { +index = +Integer.parseInt( +key.substring(key.indexOf([) + 1, key.indexOf(]))); +} +} + +if (isString(bean)) { +value = (String) bean; +} else { +value = ValidatorUtil.getValueAsString(bean, field.getProperty()); +} + +String test = field.getVarValue(test); +if (test == null) { +return false; +} + +ValidWhenLexer lexer = new ValidWhenLexer(new StringReader(test)); + +ValidWhenParser parser = new ValidWhenParser(lexer); - public static boolean validateValidWhen(Object bean, - ValidatorAction va, - Field field, - ActionErrors errors, - Validator validator, - HttpServletRequest request) { -Object form = validator.getResource(Validator.BEAN_KEY); -String value = null; -boolean valid = false; -int index = -1; - if (field.isIndexed()) { -String key = field.getKey(); - -if ((key.indexOf([) -1) -
cvs commit: jakarta-struts/src/share/org/apache/struts/validator/validwhen ValidWhen.java
dgraham 2003/07/04 13:38:19 Modified:src/share/org/apache/struts/validator/validwhen ValidWhen.java Log: Simplified isString() method. Revision ChangesPath 1.6 +8 -8 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhen.java Index: ValidWhen.java === RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhen.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ValidWhen.java4 Jul 2003 20:34:53 - 1.5 +++ ValidWhen.java4 Jul 2003 20:38:19 - 1.6 @@ -79,12 +79,12 @@ * @since Struts 1.2 */ public class ValidWhen { -private static Class stringClass = new String().getClass(); -private static boolean isString(Object o) { -if (o == null) -return true; -return (stringClass.isInstance(o)); +/** + * Returns true if codeobj/code is null or a String. + */ +private static boolean isString(Object obj) { +return (obj == null) ? true : String.class.isInstance(obj); } /** - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-struts/src/share/org/apache/struts/validator/validwhen ValidWhen.java ValidWhenLexer.java ValidWhenParser.g ValidWhenParser.java ValidWhenParserTokenTypes.java ValidWhenParserTokenTypes.txt
turner 2003/07/01 10:49:26 Modified:.build.properties.sample build.xml Added: src/share/org/apache/struts/validator/validwhen ValidWhen.java ValidWhenLexer.java ValidWhenParser.g ValidWhenParser.java ValidWhenParserTokenTypes.java ValidWhenParserTokenTypes.txt Log: Re-add validwhen validation removed for the 1.1 release. NOTE: The nightly build machine is going to need to be updated to have the required ANTLR support library James Revision ChangesPath 1.43 +7 -1 jakarta-struts/build.properties.sample Index: build.properties.sample === RCS file: /home/cvs/jakarta-struts/build.properties.sample,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- build.properties.sample 29 Jun 2003 05:27:58 - 1.42 +++ build.properties.sample 1 Jul 2003 17:49:25 - 1.43 @@ -98,6 +98,12 @@ # going to execute the deploy.catalina target. xerces.jar=${apache.home}/xerces-1_4_4/xerces.jar +# The JAR file containing the ANTLR runtime support classes, needed for the +# validwhen validator rule to work. You can get this file from: +# http://www.antlr.org/ +antlr.jar = ../../..//antlr-2.7.1/antlr.jar + + # Properties related to optional tasks # 1.112 +7 -0 jakarta-struts/build.xml Index: build.xml === RCS file: /home/cvs/jakarta-struts/build.xml,v retrieving revision 1.111 retrieving revision 1.112 diff -u -r1.111 -r1.112 --- build.xml 29 Jun 2003 05:25:32 - 1.111 +++ build.xml 1 Jul 2003 17:49:25 - 1.112 @@ -82,6 +82,10 @@ classes to compile against (currently, either version 2.2 or 2.3 supported). +antlr.jar (required) The path to the ANTLR classes + to copy. Required for the validwhen + validator rule to parser it's args. + tomcat.home (optional). The path to the Tomcat 3.x installation. This is required only when executing the deploy.tomcat target. @@ -204,6 +208,7 @@ pathelement location=${jdbc20ext.jar}/ pathelement location=${jsp.jar}/ pathelement location=${servlet.jar}/ + pathelement location=${antlr.jar}/ pathelement location=${xerces.jar}/ /path @@ -261,6 +266,8 @@ tofile=${build.home}/library/commons-validator.jar/ copy file=${jakarta-oro.jar} tofile=${build.home}/library/jakarta-oro.jar/ +copy file=${antlr.jar} failonerror=false +tofile=${build.home}/library/antlr.jar/ !-- Compile-time dependency only copy file=${jdbc20ext.jar} tofile=${build.home}/library/jdbc2_0-stdext.jar/ 1.4 +0 -0 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhen.java 1.3 +0 -0 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhenLexer.java 1.3 +0 -0 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhenParser.g 1.5 +0 -0 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhenParser.java 1.3 +0 -0 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhenParserTokenTypes.java 1.3 +0 -0 jakarta-struts/src/share/org/apache/struts/validator/validwhen/ValidWhenParserTokenTypes.txt - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]