You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2011/12/02 17:33:45 UTC

svn commit: r1209569 [35/50] - in /struts/struts2/branches/STRUTS_3_X: apps/blank/src/main/java/example/ apps/blank/src/test/java/example/ apps/jboss-blank/src/main/java/example/ apps/jboss-blank/src/test/java/example/ apps/mailreader/src/main/java/mai...

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ConversionErrorFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ConversionErrorFieldValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ConversionErrorFieldValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ConversionErrorFieldValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.conversion.impl.XWorkConverter;
+import org.apache.struts2.xwork2.validator.ValidationException;
+
+import java.util.Map;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * Field Validator that checks if a conversion error occured for this field.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ *     <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ *
+ * <!-- START SNIPPET: example -->
+ * <pre>
+ *     &lt;!-- Plain Validator Syntax --&gt;
+ *     &lt;validator type="conversion"&gt;
+ *     		&lt;param name="fieldName"&gt;myField&lt;/param&gt;
+ *          &lt;message&gt;Conversion Error Occurred&lt;/message&gt;
+ *     &lt;/validator&gt;
+ *      
+ *     &lt;!-- Field Validator Syntax --&gt;
+ *     &lt;field name="myField"&gt;
+ *        &lt;field-validator type="conversion"&gt;
+ *           &lt;message&gt;Conversion Error Occurred&lt;/message&gt;
+ *        &lt;/field-validator&gt;
+ *     &lt;/field&gt;
+ * </pre>
+ * <!-- END SNIPPET: example -->
+ *
+ * @author Jason Carreira
+ * @author tm_jee
+ * 
+ * @version $Date $Id: ConversionErrorFieldValidator.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class ConversionErrorFieldValidator extends RepopulateConversionErrorFieldValidatorSupport {
+
+    /**
+     * The validation implementation must guarantee that setValidatorContext will
+     * be called with a non-null ValidatorContext before validate is called.
+     *
+     * @param object
+     * @throws ValidationException
+     */
+    @Override
+    public void doValidate(Object object) throws ValidationException {
+        String fieldName = getFieldName();
+        String fullFieldName = getValidatorContext().getFullFieldName(fieldName);
+        ActionContext context = ActionContext.getContext();
+        Map<String, Object> conversionErrors = context.getConversionErrors();
+        
+        if (conversionErrors.containsKey(fullFieldName)) {
+            if ((defaultMessage == null) || ("".equals(defaultMessage.trim()))) {
+                defaultMessage = XWorkConverter.getConversionErrorMessage(fullFieldName, context.getValueStack());
+            }
+            
+            addFieldError(fieldName, object);
+        }
+    }
+    
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/DateRangeFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/DateRangeFieldValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/DateRangeFieldValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/DateRangeFieldValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import java.util.Date;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * 
+ * Field Validator that checks if the date supplied is within a specific range.
+ * 
+ * <b>NOTE:</b> If no date converter is specified, XWorkBasicConverter will kick
+ * in to do the date conversion, which by default using the <code>Date.SHORT</code> format using 
+ * the a programmatically specified locale else falling back to the system 
+ * default locale.
+ * 
+ * 
+ * <!-- END SNIPPET: javadoc -->
+ * 
+ * <p/>
+ *
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * 		<li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ *      <li>min - the min date range. If not specified will not be checked.</li>
+ *      <li>max - the max date range. If not specified will not be checked.</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * 
+ * 
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ *    &lt;validators>
+ *    		&lt;!-- Plain Validator syntax --&gt;
+ *    		&lt;validator type="date"&gt;
+ *    	        &lt;param name="fieldName"&gt;birthday&lt;/param&gt;
+ *              &lt;param name="min"&gt;01/01/1990&lt;/param&gt;
+ *              &lt;param name="max"&gt;01/01/2000&lt;/param&gt;
+ *              &lt;message&gt;Birthday must be within ${min} and ${max}&lt;/message&gt;
+ *    		&lt;/validator&gt;
+ *    
+ *          &lt;!-- Field Validator Syntax --&gt;
+ *          &lt;field name="birthday"&gt;
+ *          	&lt;field-validator type="date"&gt;
+ *           	    &lt;param name="min"&gt;01/01/1990&lt;/param&gt;
+ *                  &lt;param name="max"&gt;01/01/2000&lt;/param&gt;
+ *                  &lt;message&gt;Birthday must be within ${min} and ${max}&lt;/message&gt;
+ *          	&lt;/field&gt;
+ *          &lt;/field&gt;
+ *    
+ *    &lt;/validators&gt;
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ * 
+ *
+ * @author Jason Carreira
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Id: DateRangeFieldValidator.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class DateRangeFieldValidator extends AbstractRangeValidator {
+
+    private Date max;
+    private Date min;
+
+
+    public void setMax(Date max) {
+        this.max = max;
+    }
+
+    public Date getMax() {
+        return max;
+    }
+
+    public void setMin(Date min) {
+        this.min = min;
+    }
+
+    public Date getMin() {
+        return min;
+    }
+
+    @Override
+    protected Comparable getMaxComparatorValue() {
+        return max;
+    }
+
+    @Override
+    protected Comparable getMinComparatorValue() {
+        return min;
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/DoubleRangeFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/DoubleRangeFieldValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/DoubleRangeFieldValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/DoubleRangeFieldValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.validator.ValidationException;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * Field Validator that checks if the double specified is within a certain range.
+ * <!-- END SNIPPET: javadoc -->
+ *
+ *
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ *                 <li>fieldName - The field name this validator is validating. Required if using
+Plain-Validator Syntax otherwise not required</li>
+ *                 <li>minInclusive - the minimum inclusive value in FloatValue format specified by Java language (if none is specified, it will
+not be checked) </li>
+ *                 <li>maxInclusive - the maximum inclusive value in FloatValue format specified by Java language (if none is specified, it will
+not be checked) </li>
+ *                 <li>minExclusive - the minimum exclusive value in FloatValue format specified by Java language (if none is specified, it will
+not be checked) </li>
+ *                 <li>maxExclusive - the maximum exclusive value in FloatValue format specified by Java language (if none is specified, it will
+not be checked) </li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ *
+ *
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ *                 &lt;validators>
+ *           &lt;!-- Plain Validator Syntax --&gt;
+ *           &lt;validator type="double">
+ *               &lt;param name="fieldName"&gt;percentage&lt;/param&gt;
+ *               &lt;param name="minInclusive"&gt;20.1&lt;/param&gt;
+ *               &lt;param name="maxInclusive"&gt;50.1&lt;/param&gt;
+ *               &lt;message&gt;Age needs to be between ${minInclusive} and
+${maxInclusive} (inclusive)&lt;/message&gt;
+ *           &lt;/validator&gt;
+ *
+ *           &lt;!-- Field Validator Syntax --&gt;
+ *           &lt;field name="percentage"&gt;
+ *               &lt;field-validator type="double"&gt;
+ *                   &lt;param name="minExclusive"&gt;0.123&lt;/param&gt;
+ *                   &lt;param name="maxExclusive"&gt;99.98&lt;/param&gt;
+ *                   &lt;message&gt;Percentage needs to be between ${minExclusive}
+and ${maxExclusive} (exclusive)&lt;/message&gt;
+ *               &lt;/field-validator&gt;
+ *           &lt;/field&gt;
+ *      &lt;/validators&gt;
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ *
+ * @author Rainer Hermanns
+ * @author Rene Gielen
+ *
+ * @version $Id: DoubleRangeFieldValidator.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+// START SNIPPET: field-level-validator
+public class DoubleRangeFieldValidator extends FieldValidatorSupport {
+    
+    String maxInclusive = null;
+    String minInclusive = null;
+    String minExclusive = null;
+    String maxExclusive = null;
+
+    Double maxInclusiveValue = null;
+    Double minInclusiveValue = null;
+    Double minExclusiveValue = null;
+    Double maxExclusiveValue = null;
+
+    public void validate(Object object) throws ValidationException {
+        String fieldName = getFieldName();
+        Double value;
+        try {
+            Object obj = this.getFieldValue(fieldName, object);
+            if (obj == null) {
+                return;
+            }
+            value = Double.valueOf(obj.toString());
+        } catch (NumberFormatException e) {
+            return;
+        }
+
+        parseParameterValues();
+        if ((maxInclusiveValue != null && value.compareTo(maxInclusiveValue) > 0) ||
+                (minInclusiveValue != null && value.compareTo(minInclusiveValue) < 0) ||
+                (maxExclusiveValue != null && value.compareTo(maxExclusiveValue) >= 0) ||
+                (minExclusiveValue != null && value.compareTo(minExclusiveValue) <= 0)) {
+            addFieldError(fieldName, object);
+        }
+    }
+
+    private void parseParameterValues() {
+        this.minInclusiveValue = parseDouble(minInclusive);
+        this.maxInclusiveValue = parseDouble(maxInclusive);
+        this.minExclusiveValue = parseDouble(minExclusive);
+        this.maxExclusiveValue = parseDouble(maxExclusive);
+    }
+
+    private Double parseDouble (String value) {
+        if (value != null) {
+            try {
+                return Double.valueOf(value);
+            } catch (NumberFormatException e) {
+                if (log.isWarnEnabled()) {
+                    log.warn("DoubleRangeFieldValidator - [parseDouble]: Unable to parse given double parameter " + value);
+                }
+            }
+        }
+        return null;
+    }
+
+    public void setMaxInclusive(String maxInclusive) {
+        this.maxInclusive = maxInclusive;
+    }
+
+    public String getMaxInclusive() {
+        return maxInclusive;
+    }
+
+    public void setMinInclusive(String minInclusive) {
+        this.minInclusive = minInclusive;
+    }
+
+    public String getMinInclusive() {
+        return minInclusive;
+    }
+
+    public String getMinExclusive() {
+        return minExclusive;
+    }
+
+    public void setMinExclusive(String minExclusive) {
+        this.minExclusive = minExclusive;
+    }
+
+    public String getMaxExclusive() {
+        return maxExclusive;
+    }
+
+    public void setMaxExclusive(String maxExclusive) {
+        this.maxExclusive = maxExclusive;
+    }
+}
+// END SNIPPET: field-level-validator

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/EmailValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/EmailValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/EmailValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/EmailValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * EmailValidator checks that a given String field, if not empty,
+ * is a valid email address.
+ * <p/>
+ * <p/>
+ * The regular expression used to validate that the string is an email address
+ * is:
+ * </p>
+ * <pre>
+ * \\b(^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+((\\.com)|(\\.net)|(\\.org)|(\\.info)|(\\.edu)|(\\.mil)|(\\.gov)|(\\.biz)|(\\.ws)|(\\.us)|(\\.tv)|(\\.cc)|(\\.aero)|(\\.arpa)|(\\.coop)|(\\.int)|(\\.jobs)|(\\.museum)|(\\.name)|(\\.pro)|(\\.travel)|(\\.nato)|(\\..{2,3})|(\\..{2,3}\\..{2,3}))$)\\b
+ * </pre>
+ * <!-- END SNIPPET: javadoc -->
+ * 
+ * 
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * 		<li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * 
+ * 
+ * <pre>
+ * <!-- START SNIPPET: example -->
+ *     &lt;!-- Plain Validator Syntax --&gt;
+ *     &lt;validators&gt;
+ *         &lt;validator type="email"&gt;
+ *             &lt;param name="fieldName"&gt;myEmail&lt;/param&gt;
+ *             &lt;message&gt;Must provide a valid email&lt;/message&gt;
+ *         &lt;/validator&gt;
+ *     &lt;/validators&gt;
+ *     
+ *     &lt;!-- Field Validator Syntax --&gt;
+ *     &lt;field name="myEmail"&gt;
+ *        &lt;field-validator type="email"&gt;
+ *           &lt;message&gt;Must provide a valid email&lt;/message&gt;
+ *        &lt;/field-validator&gt;
+ *     &lt;/field&gt;
+ * <!-- END SNIPPET: example -->
+ * </pre>
+ *
+ * @author jhouse
+ * @author tm_jee
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Id: EmailValidator.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class EmailValidator extends RegexFieldValidator {
+
+	// see XW-371 
+    public static final String emailAddressPattern =
+    	"\\b(^['_A-Za-z0-9-]+(\\.['_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\\.[A-Za-z0-9-]+)*((\\.[A-Za-z0-9]{2,})|(\\.[A-Za-z0-9]{2,}\\.[A-Za-z0-9]{2,}))$)\\b";
+
+    public EmailValidator() {
+        setExpression(emailAddressPattern);
+        setCaseSensitive(false);
+    }
+
+}
+
+

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ExpressionValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ExpressionValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ExpressionValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ExpressionValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.validator.ValidationException;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * A Non-Field Level validator that validates based on regular expression supplied.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * 
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * 	 <li>expression - the Ognl expression to be evaluated against the stack (Must evaluate to a Boolean)</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ *
+ * 
+ * <pre>
+ * <!-- START SNIPPET: example -->
+ *     &lt;validators&gt;
+ *           &lt;validator type="expression"&gt;
+ *              &lt;param name="expression"&gt; .... &lt;/param&gt;
+ *              &lt;message&gt;Failed to meet Ognl Expression  .... &lt;/message&gt;
+ *           &lt;/validator&gt;
+ *     &lt;/validators&gt;
+ * <!-- END SNIPPET: example -->
+ * </pre>
+ *
+ * @author Jason Carreira
+ */
+// START SNIPPET: global-level-validator
+public class ExpressionValidator extends ValidatorSupport {
+
+    private String expression;
+
+
+    public void setExpression(String expression) {
+        this.expression = expression;
+    }
+
+    public String getExpression() {
+        return expression;
+    }
+
+    public void validate(Object object) throws ValidationException {
+        Boolean answer = Boolean.FALSE;
+        Object obj = null;
+
+        try {
+            obj = getFieldValue(expression, object);
+        } catch (ValidationException e) {
+            throw e;
+        } catch (Exception e) {
+            // let this pass, but it will be logged right below
+        }
+
+        if ((obj != null) && (obj instanceof Boolean)) {
+            answer = (Boolean) obj;
+        } else {
+            log.warn("Got result of " + obj + " when trying to get Boolean.");
+        }
+
+        if (!answer.booleanValue()) {
+            if (log.isDebugEnabled()) log.debug("Validation failed on expression " + expression + " with validated object "+ object);
+            addActionError(object);
+        }
+    }
+}
+// END SNIPPET: global-level-validator 
+

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/FieldExpressionValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/FieldExpressionValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/FieldExpressionValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/FieldExpressionValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.validator.ValidationException;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * Validates a field using an OGNL expression.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * 
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ *    <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ *    <li>expression - The Ognl expression (must evaluate to a boolean) which is to be evalidated the stack</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * 
+ * <pre>
+ * <!-- START SNIPPET: example -->
+ *    &lt;!-- Plain Validator Syntax --&gt;
+ *    &lt;validators&gt;
+ *        &lt;!-- Plain Validator Syntax --&gt;
+ *        &lt;validator type="fieldexpression"&gt;
+ *           &lt;param name="fieldName"&gt;myField&lt;/param&gt;
+ *           &lt;param name="expression"&gt;&lt;![CDATA[#myCreditLimit &gt; #myGirfriendCreditLimit]]&gt;&lt;/param&gt;
+ *           &lt;message&gt;My credit limit should be MORE than my girlfriend&lt;/message&gt;
+ *        &lt;validator&gt;
+ *        
+ *        &lt;!-- Field Validator Syntax --&gt;
+ *        &lt;field name="myField"&gt;
+ *            &lt;field-validator type="fieldexpression"&gt;
+ *                &lt;param name="expression"&gt;&lt;![CDATA[#myCreditLimit &gt; #myGirfriendCreditLimit]]&gt;&lt;/param&gt;
+ *                &lt;message&gt;My credit limit should be MORE than my girlfriend&lt;/message&gt;
+ *            &lt;/field-validator&gt;
+ *        &lt;/field&gt;
+ *        
+ *    &lt;/vaidators&gt;
+ * <!-- END SNIPPET: example -->
+ * </pre>
+ * 
+ *
+ * @author $Author: lukaszlenart $
+ * @version $Revision: 1209415 $
+ */
+public class FieldExpressionValidator extends FieldValidatorSupport {
+
+    private String expression;
+
+
+    public void setExpression(String expression) {
+        this.expression = expression;
+    }
+
+    public String getExpression() {
+        return expression;
+    }
+
+    public void validate(Object object) throws ValidationException {
+        String fieldName = getFieldName();
+
+        Boolean answer = Boolean.FALSE;
+        Object obj = null;
+
+        try {
+            obj = getFieldValue(expression, object);
+        } catch (ValidationException e) {
+            throw e;
+        } catch (Exception e) {
+            // let this pass, but it will be logged right below
+        }
+
+        if ((obj != null) && (obj instanceof Boolean)) {
+            answer = (Boolean) obj;
+        } else {
+            log.warn("Got result of " + obj + " when trying to get Boolean.");
+        }
+
+        if (!answer.booleanValue()) {
+            addFieldError(fieldName, object);
+        }
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/FieldValidatorSupport.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/FieldValidatorSupport.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/FieldValidatorSupport.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/FieldValidatorSupport.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.validator.FieldValidator;
+
+
+/**
+ * Base class for field validators.
+ *
+ * @author Jason Carreira
+ */
+public abstract class FieldValidatorSupport extends ValidatorSupport implements FieldValidator {
+
+    private String fieldName;
+    private String type;
+
+    public void setFieldName(String fieldName) {
+        this.fieldName = fieldName;
+    }
+
+    public String getFieldName() {
+        return fieldName;
+    }
+
+    @Override
+    public void setValidatorType(String type) {
+        this.type = type;
+    }
+
+    @Override
+    public String getValidatorType() {
+        return type;
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/IntRangeFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/IntRangeFieldValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/IntRangeFieldValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/IntRangeFieldValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * Field Validator that checks if the integer specified is within a certain range.
+ * <!-- END SNIPPET: javadoc -->
+ * 
+ * 
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * 		<li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * 		<li>min - the minimum value (if none is specified, it will not be checked) </li>
+ * 		<li>max - the maximum value (if none is specified, it will not be checked) </li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * 
+ * 
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ * 		&lt;validators>
+ *           &lt;!-- Plain Validator Syntax --&gt;
+ *           &lt;validator type="int">
+ *               &lt;param name="fieldName"&gt;age&lt;/param&gt;
+ *               &lt;param name="min"&gt;20&lt;/param&gt;
+ *               &lt;param name="max"&gt;50&lt;/param&gt;
+ *               &lt;message&gt;Age needs to be between ${min} and ${max}&lt;/message&gt;
+ *           &lt;/validator&gt;
+ *           
+ *           &lt;!-- Field Validator Syntax --&gt;
+ *           &lt;field name="age"&gt;
+ *               &lt;field-validator type="int"&gt;
+ *                   &lt;param name="min"&gt;20&lt;/param&gt;
+ *                   &lt;param name="max"&gt;50&lt;/param&gt;
+ *                   &lt;message&gt;Age needs to be between ${min} and ${max}&lt;/message&gt;
+ *               &lt;/field-validator&gt;
+ *           &lt;/field&gt;
+ *      &lt;/validators&gt;
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ * 
+ * 
+ * 
+ * @author Jason Carreira
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Id: IntRangeFieldValidator.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class IntRangeFieldValidator extends AbstractRangeValidator {
+
+    Integer max = null;
+    Integer min = null;
+
+
+    public void setMax(Integer max) {
+        this.max = max;
+    }
+
+    public Integer getMax() {
+        return max;
+    }
+
+    @Override
+    public Comparable getMaxComparatorValue() {
+        return max;
+    }
+
+    public void setMin(Integer min) {
+        this.min = min;
+    }
+
+    public Integer getMin() {
+        return min;
+    }
+
+    @Override
+    public Comparable getMinComparatorValue() {
+        return min;
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/LongRangeFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/LongRangeFieldValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/LongRangeFieldValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/LongRangeFieldValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * Field Validator that checks if the long specified is within a certain range.
+ * <!-- END SNIPPET: javadoc -->
+ * 
+ * 
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ *              <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ *              <li>min - the minimum value (if none is specified, it will not be checked) </li>
+ *              <li>max - the maximum value (if none is specified, it will not be checked) </li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * 
+ * 
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ *              &lt;validators>
+ *           &lt;!-- Plain Validator Syntax --&gt;
+ *           &lt;validator type="long">
+ *               &lt;param name="fieldName"&gt;age&lt;/param&gt;
+ *               &lt;param name="min"&gt;20&lt;/param&gt;
+ *               &lt;param name="max"&gt;50&lt;/param&gt;
+ *               &lt;message&gt;Age needs to be between ${min} and ${max}&lt;/message&gt;
+ *           &lt;/validator&gt;
+ *           
+ *           &lt;!-- Field Validator Syntax --&gt;
+ *           &lt;field name="age"&gt;
+ *               &lt;field-validator type="long"&gt;
+ *                   &lt;param name="min"&gt;20&lt;/param&gt;
+ *                   &lt;param name="max"&gt;50&lt;/param&gt;
+ *                   &lt;message&gt;Age needs to be between ${min} and ${max}&lt;/message&gt;
+ *               &lt;/field-validator&gt;
+ *           &lt;/field&gt;
+ *      &lt;/validators&gt;
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ * 
+ * 
+ * 
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $
+ */
+public class LongRangeFieldValidator extends AbstractRangeValidator {
+
+    Long max = null;
+    Long min = null;
+
+
+    public void setMax(Long max) {
+        this.max = max;
+    }
+
+    public Long getMax() {
+        return max;
+    }
+
+    @Override
+    public Comparable getMaxComparatorValue() {
+        return max;
+    }
+
+    public void setMin(Long min) {
+        this.min = min;
+    }
+
+    public Long getMin() {
+        return min;
+    }
+
+    @Override
+    public Comparable getMinComparatorValue() {
+        return min;
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RegexFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RegexFieldValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RegexFieldValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RegexFieldValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.validator.ValidationException;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * Validates a string field using a regular expression.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * 
+ * 
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * 	  <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ *    <li>expression - The RegExp expression  REQUIRED</li>
+ *    <li>caseSensitive - Boolean (Optional). Sets whether the expression should be matched against in a case-sensitive way. Default is <code>true</code>.</li>
+ *    <li>trim - Boolean (Optional). Sets whether the expression should be trimed before matching. Default is <code>true</code>.</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * 
+ * 
+ * <pre>
+ * <!-- START SNIPPET: example -->
+ *    &lt;validators&gt;
+ *        &lt;!-- Plain Validator Syntax --&gt;
+ *        &lt;validator type="regex"&gt;
+ *            &lt;param name="fieldName"&gt;myStrangePostcode&lt;/param&gt;
+ *            &lt;param name="expression"&gt;&lt;![CDATA[([aAbBcCdD][123][eEfFgG][456])]]&lt;&gt;/param&gt;
+ *        &lt;/validator&gt;
+ *    
+ *        &lt;!-- Field Validator Syntax --&gt;
+ *        &lt;field name="myStrangePostcode"&gt;
+ *            &lt;field-validator type="regex"&gt;
+ *               &lt;param name="expression"&gt;&lt;![CDATA[([aAbBcCdD][123][eEfFgG][456])]]&gt;&lt;/param&gt;
+ *            &lt;/field-validator&gt;
+ *        &lt;/field&gt;
+ *    &lt;/validators&gt;
+ * <!-- END SNIPPET: example -->
+ * </pre>
+ *
+ * @author Quake Wang
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Revision: 1209415 $
+ */
+public class RegexFieldValidator extends FieldValidatorSupport {
+
+    private String expression;
+    private boolean caseSensitive = true;
+    private boolean trim = true;
+
+    public void validate(Object object) throws ValidationException {
+        String fieldName = getFieldName();
+        Object value = this.getFieldValue(fieldName, object);
+        // if there is no value - don't do comparison
+        // if a value is required, a required validator should be added to the field
+        if (value == null || expression == null) {
+            return;
+        }
+
+        // XW-375 - must be a string
+        if (!(value instanceof String)) {
+            return;
+        }
+
+        // string must not be empty
+        String str = ((String) value).trim();
+        if (str.length() == 0) {
+            return;
+        }
+
+        // match against expression
+        Pattern pattern;
+        if (isCaseSensitive()) {
+            pattern = Pattern.compile(expression);
+        } else {
+            pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
+        }
+
+        String compare = (String) value;
+        if ( trim ) {
+            compare = compare.trim();
+        }
+        Matcher matcher = pattern.matcher( compare );
+
+        if (!matcher.matches()) {
+            addFieldError(fieldName, object);
+        }
+    }
+
+    /**
+     * @return Returns the regular expression to be matched.
+     */
+    public String getExpression() {
+        return expression;
+    }
+
+    /**
+     * Sets the regular expression to be matched.
+     */
+    public void setExpression(String expression) {
+        this.expression = expression;
+    }
+
+    /**
+     * @return Returns whether the expression should be matched against in
+     *         a case-sensitive way.  Default is <code>true</code>.
+     */
+    public boolean isCaseSensitive() {
+        return caseSensitive;
+    }
+
+    /**
+     * Sets whether the expression should be matched against in
+     * a case-sensitive way.  Default is <code>true</code>.
+     */
+    public void setCaseSensitive(boolean caseSensitive) {
+        this.caseSensitive = caseSensitive;
+    }
+
+    /**
+     * @return Returns whether the expression should be trimed before matching.
+     * Default is <code>true</code>.
+     */
+    public boolean isTrimed() {
+        return trim;
+    }
+
+    /**
+     * Sets whether the expression should be trimed before matching.
+     * Default is <code>true</code>.
+     */
+    public void setTrim(boolean trim) {
+        this.trim = trim;
+    }
+
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RepopulateConversionErrorFieldValidatorSupport.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RepopulateConversionErrorFieldValidatorSupport.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RepopulateConversionErrorFieldValidatorSupport.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RepopulateConversionErrorFieldValidatorSupport.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.ActionInvocation;
+import org.apache.struts2.xwork2.interceptor.PreResultListener;
+import org.apache.struts2.xwork2.util.ValueStack;
+import org.apache.struts2.xwork2.util.logging.Logger;
+import org.apache.struts2.xwork2.util.logging.LoggerFactory;
+import org.apache.struts2.xwork2.validator.ValidationException;
+import org.apache.commons.lang.StringEscapeUtils;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ *
+ *
+ * An abstract base class that adds in the capability to populate the stack with
+ * a fake parameter map when a conversion error has occurred and the 'repopulateField'
+ * property is set to "true".
+ *
+ * <p/>
+ *
+ *
+ * <!-- START SNIPPET: javadoc -->
+ *
+ * The capability of auto-repopulating the stack with a fake parameter map when
+ * a conversion error has occurred can be done with 'repopulateField' property
+ * set to "true".
+ *
+ * <p/>
+ *
+ * This is typically usefull when one wants to repopulate the field with the original value
+ * when a conversion error occurred. Eg. with a textfield that only allows an Integer
+ * (the action class have an Integer field declared), upon conversion error, the incorrectly
+ * entered integer (maybe a text 'one') will not appear when dispatched back. With 'repopulateField'
+ * porperty set to true, it will, meaning the textfield will have 'one' as its value
+ * upon conversion error.
+ *
+ * <!-- END SNIPPET: javadoc -->
+ *
+ * <p/>
+ *
+ * <pre>
+ * <!-- START SNIPPET: exampleJspPage -->
+ *
+ * &lt;!-- myJspPage.jsp --&gt;
+ * &lt;ww:form action="someAction" method="POST"&gt;
+ *   ....
+ *   &lt;ww:textfield
+ *       label="My Integer Field"
+ *       name="myIntegerField" /&gt;
+ *   ....
+ *   &lt;ww:submit /&gt;
+ * &lt;/ww:form&gt;
+ *
+ * <!-- END SNIPPET: exampleJspPage -->
+ * </pre>
+ *
+ * <pre>
+ * <!-- START SNIPPET: exampleXwork -->
+ *
+ * &lt;!-- xwork.xml --&gt;
+ * &lt;xwork&gt;
+ * &lt;include file="xwork-default.xml" /&gt;
+ * ....
+ * &lt;package name="myPackage" extends="xwork-default"&gt;
+ *   ....
+ *   &lt;action name="someAction" class="example.MyActionSupport.java"&gt;
+ *      &lt;result name="input"&gt;myJspPage.jsp&lt;/result&gt;
+ *      &lt;result&gt;success.jsp&lt;/result&gt;
+ *   &lt;/action&gt;
+ *   ....
+ * &lt;/package&gt;
+ * ....
+ * &lt;/xwork&gt;
+ *
+ * <!-- END SNIPPET:exampleXwork -->
+ * </pre>
+ *
+ *
+ * <pre>
+ * <!-- START SNIPPET: exampleJava -->
+ *
+ * &lt;!-- MyActionSupport.java --&gt;
+ * public class MyActionSupport extends ActionSupport {
+ *    private Integer myIntegerField;
+ *
+ *    public Integer getMyIntegerField() { return this.myIntegerField; }
+ *    public void setMyIntegerField(Integer myIntegerField) {
+ *       this.myIntegerField = myIntegerField;
+ *    }
+ * }
+ *
+ * <!-- END SNIPPET: exampleJava -->
+ * </pre>
+ *
+ *
+ * <pre>
+ * <!-- START SNIPPET: exampleValidation -->
+ *
+ * &lt;!-- MyActionSupport-someAction-validation.xml --&gt;
+ * &lt;validators&gt;
+ *   ...
+ *   &lt;field name="myIntegerField"&gt;
+ *      &lt;field-validator type="conversion"&gt;
+ *         &lt;param name="repopulateField"&gt;true&lt;/param&gt;
+ *         &lt;message&gt;Conversion Error (Integer Wanted)&lt;/message&gt;
+ *      &lt;/field-validator&gt;
+ *   &lt;/field&gt;
+ *   ...
+ * &lt;/validators&gt;
+ *
+ * <!-- END SNIPPET: exampleValidation -->
+ * </pre>
+ *
+ * @author tm_jee
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Id: RepopulateConversionErrorFieldValidatorSupport.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public abstract class RepopulateConversionErrorFieldValidatorSupport extends FieldValidatorSupport {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RepopulateConversionErrorFieldValidatorSupport.class);
+
+    private String repopulateFieldAsString = "false";
+    private boolean repopulateFieldAsBoolean = false;
+
+    public String getRepopulateField() {
+        return repopulateFieldAsString;
+    }
+
+    public void setRepopulateField(String repopulateField) {
+        this.repopulateFieldAsString = repopulateField == null ? repopulateField : repopulateField.trim();
+        this.repopulateFieldAsBoolean = "true".equalsIgnoreCase(this.repopulateFieldAsString) ? (true) : (false);
+    }
+
+    public void validate(Object object) throws ValidationException {
+        doValidate(object);
+        if (repopulateFieldAsBoolean) {
+            repopulateField(object);
+        }
+    }
+
+    public void repopulateField(Object object) throws ValidationException {
+
+        ActionInvocation invocation = ActionContext.getContext().getActionInvocation();
+        Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
+
+        String fieldName = getFieldName();
+        String fullFieldName = getValidatorContext().getFullFieldName(fieldName);
+        if (conversionErrors.containsKey(fullFieldName)) {
+            Object value = conversionErrors.get(fullFieldName);
+
+            final Map<Object, Object> fakeParams = new LinkedHashMap<Object, Object>();
+            boolean doExprOverride = false;
+
+            if (value instanceof String[]) {
+                // take the first element, if possible
+                String[] tmpValue = (String[]) value;
+                if ((tmpValue.length > 0)) {
+                    doExprOverride = true;
+                    fakeParams.put(fullFieldName, escape(tmpValue[0]));
+                } else {
+                    if (LOG.isWarnEnabled()) {
+                        LOG.warn("value is an empty array of String or with first element in it as null [" + value + "], will not repopulate conversion error ");
+                    }
+                }
+            } else if (value instanceof String) {
+                String tmpValue = (String) value;
+                doExprOverride = true;
+                fakeParams.put(fullFieldName, escape(tmpValue));
+            } else {
+                // opps... it should be 
+                if (LOG.isWarnEnabled()) {
+                    LOG.warn("conversion error value is not a String or array of String but instead is [" + value + "], will not repopulate conversion error");
+                }
+            }
+
+            if (doExprOverride) {
+                invocation.addPreResultListener(new PreResultListener() {
+                    public void beforeResult(ActionInvocation invocation, String resultCode) {
+                        ValueStack stack = ActionContext.getContext().getValueStack();
+                        stack.setExprOverrides(fakeParams);
+                    }
+                });
+            }
+        }
+    }
+
+    protected String escape(String value) {
+        return "\"" + StringEscapeUtils.escapeJava(value) + "\"";
+    }
+
+    protected abstract void doValidate(Object object) throws ValidationException;
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RequiredFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RequiredFieldValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RequiredFieldValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RequiredFieldValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.validator.ValidationException;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * RequiredFieldValidator checks if the specified field is not null.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * 
+ * 
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * 		<li>fieldName - field name if plain-validator syntax is used, not needed if field-validator syntax is used</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * 
+ * 
+ * <pre>
+ * <!-- START SNIPPET: example -->
+ * 	   &lt;validators&gt;
+ * 
+ *         &lt;!-- Plain Validator Syntax --&gt;
+ *         &lt;validator type="required"&gt;
+ *             &lt;param name="fieldName"&gt;username&lt;/param&gt;
+ *             &lt;message&gt;username must not be null&lt;/message&gt;
+ *         &lt;/validator&gt;
+ * 
+ * 
+ *         &lt;!-- Field Validator Syntax --&gt;
+ *         &lt;field name="username"&gt;
+ *             &lt;field-validator type="required"&gt;
+ *             	   &lt;message&gt;username must not be null&lt;/message&gt;
+ *             &lt;/field-validator&gt;
+ *         &lt;/field&gt;
+ * 
+ *     &lt;/validators&gt;
+ * <!-- END SNIPPET: example -->
+ * </pre>
+ * 
+ * 
+ *
+ * @author rainerh
+ * @version $Revision: 1209415 $
+ */
+public class RequiredFieldValidator extends FieldValidatorSupport {
+
+    public void validate(Object object) throws ValidationException {
+        String fieldName = getFieldName();
+        Object value = this.getFieldValue(fieldName, object);
+
+        if (value == null) {
+            addFieldError(fieldName, object);
+        }
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RequiredStringValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RequiredStringValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RequiredStringValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/RequiredStringValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.validator.ValidationException;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * RequiredStringValidator checks that a String field is non-null and has a length > 0.
+ * (i.e. it isn't "").  The "trim" parameter determines whether it will {@link String#trim() trim}
+ * the String before performing the length check.  If unspecified, the String will be trimmed.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ *
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * 		<li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ *      <li>trim - trim the field name value before validating (default is true)</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * 
+ * 
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ *     &lt;validators&gt;
+ *         &lt;!-- Plain-Validator Syntax --&gt;
+ *         &lt;validator type="requiredstring"&gt;
+ *             &lt;param name="fieldName"&gt;username&lt;/param&gt;
+ *             &lt;param name="trim"&gt;true&lt;/param&gt;
+ *             &lt;message&gt;username is required&lt;/message&gt;
+ *         &lt;/validator&gt;
+ *         
+ *         &lt;!-- Field-Validator Syntax --&gt;
+ *         &lt;field name="username"&gt;
+ *         	  &lt;field-validator type="requiredstring"&gt;
+ *                 &lt;param name="trim"&gt;true&lt;/param&gt;
+ *                 &lt;message&gt;username is required&lt;/message&gt;
+ *            &lt;/field-validator&gt;
+ *         &lt;/field&gt;
+ *     &lt;/validators&gt;
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ * 
+ * @author rainerh
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Id: RequiredStringValidator.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class RequiredStringValidator extends FieldValidatorSupport {
+
+    private boolean doTrim = true;
+
+
+    public void setTrim(boolean trim) {
+        doTrim = trim;
+    }
+
+    public boolean getTrim() {
+        return doTrim;
+    }
+
+    public void validate(Object object) throws ValidationException {
+        String fieldName = getFieldName();
+        Object value = this.getFieldValue(fieldName, object);
+
+        if (!(value instanceof String)) {
+            addFieldError(fieldName, object);
+        } else {
+            String s = (String) value;
+
+            if (doTrim) {
+                s = s.trim();
+            }
+
+            if (s.length() == 0) {
+                addFieldError(fieldName, object);
+            }
+        }
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ShortRangeFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ShortRangeFieldValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ShortRangeFieldValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ShortRangeFieldValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * Field Validator that checks if the short specified is within a certain range.
+ * <!-- END SNIPPET: javadoc -->
+ * 
+ * 
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ *              <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ *              <li>min - the minimum value (if none is specified, it will not be checked) </li>
+ *              <li>max - the maximum value (if none is specified, it will not be checked) </li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * 
+ * 
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ *              &lt;validators>
+ *           &lt;!-- Plain Validator Syntax --&gt;
+ *           &lt;validator type="short">
+ *               &lt;param name="fieldName"&gt;age&lt;/param&gt;
+ *               &lt;param name="min"&gt;20&lt;/param&gt;
+ *               &lt;param name="max"&gt;50&lt;/param&gt;
+ *               &lt;message&gt;Age needs to be between ${min} and ${max}&lt;/message&gt;
+ *           &lt;/validator&gt;
+ *           
+ *           &lt;!-- Field Validator Syntax --&gt;
+ *           &lt;field name="age"&gt;
+ *               &lt;field-validator type="short"&gt;
+ *                   &lt;param name="min"&gt;20&lt;/param&gt;
+ *                   &lt;param name="max"&gt;50&lt;/param&gt;
+ *                   &lt;message&gt;Age needs to be between ${min} and ${max}&lt;/message&gt;
+ *               &lt;/field-validator&gt;
+ *           &lt;/field&gt;
+ *      &lt;/validators&gt;
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ * 
+ * 
+ * 
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $
+ */
+public class ShortRangeFieldValidator extends AbstractRangeValidator {
+
+    Short max = null;
+    Short min = null;
+
+
+    public void setMax(Short max) {
+        this.max = max;
+    }
+
+    public Short getMax() {
+        return max;
+    }
+
+    @Override
+    public Comparable getMaxComparatorValue() {
+        return max;
+    }
+
+    public void setMin(Short min) {
+        this.min = min;
+    }
+
+    public Short getMin() {
+        return min;
+    }
+
+    @Override
+    public Comparable getMinComparatorValue() {
+        return min;
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/StringLengthFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/StringLengthFieldValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/StringLengthFieldValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/StringLengthFieldValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.validator.ValidationException;
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * StringLengthFieldValidator checks that a String field is of a certain length.  If the "minLength"
+ * parameter is specified, it will make sure that the String has at least that many characters.  If
+ * the "maxLength" parameter is specified, it will make sure that the String has at most that many
+ * characters.  The "trim" parameter determines whether it will {@link String#trim() trim} the
+ * String before performing the length check.  If unspecified, the String will be trimmed.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ * 
+ * 
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ *    <li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ *    <li>maxLength - The max length of the field value. Default ignore.</li>
+ *    <li>minLength - The min length of the field value. Default ignore.</li>
+ *    <li>trim - Trim the field value before evaluating its min/max length. Default true</li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ * 
+ * 
+ * <pre>
+ * <!--START SNIPPET: example -->
+ *      &lt;validators&gt;
+ *           &lt;!-- Plain Validator Syntax --&gt;
+ *           &lt;validator type="stringlength"&gt;
+ *                &lt;param name="fieldName"&gt;myPurchaseCode&lt;/param&gt;
+ *                &lt;param name="minLength"&gt;10&lt;/param&gt;
+ *                &lt;param name="maxLength"&gt;10&lt;/param&gt;
+ *                &lt;param name="trim"&gt;true&lt;/param&gt;
+ *                &lt;message&gt;Your purchase code needs to be 10 characters long&lt;/message&gt;		
+ *            &lt;/validator&gt;
+ * 
+ *            &lt;!-- Field Validator Syntax --&gt;
+ *            &lt;field name="myPurchaseCode"&gt;
+ *                &lt;field-validator type="stringlength"&gt;
+ *                     &lt;param name="minLength"&gt;10&lt;/param&gt;
+ *                     &lt;param name="maxLength"&gt;10&lt;/param&gt;
+ *                     &lt;param name="trim"&gt;true&lt;/param&gt;
+ *                     &lt;message&gt;Your purchase code needs to be 10 characters long&lt;/message&gt;
+ *                &lt;/field-validator&gt;
+ *            &lt;/field&gt;
+ *      &lt;/validators&gt;
+ * <!-- END SNIPPET: example -->
+ * </pre>
+ * 
+ *
+ * @author Jason Carreira
+ * @author Mark Woon
+ * @author tmjee
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Id: StringLengthFieldValidator.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class StringLengthFieldValidator extends FieldValidatorSupport {
+
+    private boolean doTrim = true;
+    private int maxLength = -1;
+    private int minLength = -1;
+
+
+    public void setMaxLength(int maxLength) {
+        this.maxLength = maxLength;
+    }
+
+    public int getMaxLength() {
+        return maxLength;
+    }
+
+    public void setMinLength(int minLength) {
+        this.minLength = minLength;
+    }
+
+    public int getMinLength() {
+        return minLength;
+    }
+
+    public void setTrim(boolean trim) {
+        doTrim = trim;
+    }
+
+    public boolean getTrim() {
+        return doTrim;
+    }
+
+    public void validate(Object object) throws ValidationException {
+        String fieldName = getFieldName();
+        String val = (String) getFieldValue(fieldName, object);
+
+        if (val == null || val.length() <= 0) {
+            // use a required validator for these
+            return;
+        }
+        if (doTrim) {
+            val = val.trim();
+            if (val.length() <= 0) { 
+            	// use a required validator
+            	return;
+            }
+        }
+
+        if ((minLength > -1) && (val.length() < minLength)) {
+            addFieldError(fieldName, object);
+        } else if ((maxLength > -1) && (val.length() > maxLength)) {
+            addFieldError(fieldName, object);
+        }
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/URLValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/URLValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/URLValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/URLValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.validator.ValidationException;
+import org.apache.struts2.xwork2.util.URLUtil;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * 
+ * URLValidator checks that a given field is a String and a valid URL
+ * 
+ * <!-- END SNIPPET: javadoc -->
+ * 
+ * <p/>
+ * 
+ * <!-- START SNIPPET: parameters -->
+ * 
+ * <ul>
+ * 		<li>fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required</li>
+ * </ul>
+ * 
+ * <!-- END SNIPPET: parameters -->
+ *
+ * <p/>
+ *
+ * <pre>
+ * <!-- START SNIPPET: examples -->
+ * 
+ *     &lt;validators&gt;
+ *          &lt;!-- Plain Validator Syntax --&gt;
+ *          &lt;validator type="url"&gt;
+ *              &lt;param name="fieldName"&gt;myHomePage&lt;/param&gt;
+ *              &lt;message&gt;Invalid homepage url&lt;/message&gt;
+ *          &lt;/validator&gt;
+ *          
+ *          &lt;!-- Field Validator Syntax --&gt;
+ *          &lt;field name="myHomepage"&gt;
+ *              &lt;message&gt;Invalid homepage url&lt;/message&gt;
+ *          &lt;/field&gt;
+ *     &lt;/validators&gt;
+ *     
+ * <!-- END SNIPPET: examples -->
+ * </pre>
+ *
+ *
+ * @author $Author: lukaszlenart $
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Revision: 1209415 $
+ */
+public class URLValidator extends FieldValidatorSupport {
+
+    public void validate(Object object) throws ValidationException {
+        String fieldName = getFieldName();
+        Object value = this.getFieldValue(fieldName, object);
+
+        // if there is no value - don't do comparison
+        // if a value is required, a required validator should be added to the field
+        if (value == null || value.toString().length() == 0) {
+            return;
+        }
+
+        if (!(value.getClass().equals(String.class)) || !URLUtil.verifyUrl((String) value)) {
+            addFieldError(fieldName, object);
+        }
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ValidatorSupport.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ValidatorSupport.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ValidatorSupport.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/ValidatorSupport.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.util.TextParseUtil;
+import org.apache.struts2.xwork2.util.ValueStack;
+import org.apache.struts2.xwork2.util.logging.Logger;
+import org.apache.struts2.xwork2.util.logging.LoggerFactory;
+import org.apache.struts2.xwork2.validator.DelegatingValidatorContext;
+import org.apache.struts2.xwork2.validator.ShortCircuitableValidator;
+import org.apache.struts2.xwork2.validator.ValidationException;
+import org.apache.struts2.xwork2.validator.Validator;
+import org.apache.struts2.xwork2.validator.ValidatorContext;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * Abstract implementation of the Validator interface suitable for subclassing.
+ *
+ * @author Jason Carreira
+ * @author tm_jee
+ * @author Martin Gilday
+ */
+public abstract class ValidatorSupport implements Validator, ShortCircuitableValidator {
+
+    protected final Logger log = LoggerFactory.getLogger(this.getClass());
+    protected String defaultMessage = "";
+    protected String messageKey;
+    private ValidatorContext validatorContext;
+    private boolean shortCircuit;
+    private boolean parse;
+    private String type;
+    private String[] messageParameters;
+    private ValueStack stack;
+
+
+    public void setValueStack(ValueStack stack) {
+        this.stack = stack;
+    }
+
+    public void setDefaultMessage(String message) {
+        if (StringUtils.isNotEmpty(message)) {
+            this.defaultMessage = message;
+        }
+    }
+
+    public String getDefaultMessage() {
+        return defaultMessage;
+    }
+
+    public void setParse(boolean parse) {
+        this.parse = parse;
+    }
+
+    public boolean getParse() {
+        return parse;
+    }
+
+    public String getMessage(Object object) {
+        String message;
+        boolean pop = false;
+
+        if (!stack.getRoot().contains(object)) {
+            stack.push(object);
+            pop = true;
+        }
+
+        stack.push(this);
+
+        if (messageKey != null) {
+            if ((defaultMessage == null) || ("".equals(defaultMessage.trim()))) {
+                defaultMessage = messageKey;
+            }
+            if (validatorContext == null) {
+                validatorContext = new DelegatingValidatorContext(object);
+            }
+            List<Object> parsedMessageParameters = null;
+            if (messageParameters != null) {
+                parsedMessageParameters = new ArrayList<Object>();
+                for (String messageParameter : messageParameters) {
+                    if (messageParameter != null) {
+                        try {
+                            Object val = stack.findValue(messageParameter);
+                            parsedMessageParameters.add(val);
+                        } catch (Exception e) {
+                            // if there's an exception in parsing, we'll just treat the expression itself as the
+                            // parameter
+                            log.warn("exception while parsing message parameter [" + messageParameter + "]", e);
+                            parsedMessageParameters.add(messageParameter);
+                        }
+                    }
+                }
+            }
+
+            message = validatorContext.getText(messageKey, defaultMessage, parsedMessageParameters);
+
+        } else {
+            message = defaultMessage;
+        }
+
+        if (StringUtils.isNotBlank(message))
+            message = TextParseUtil.translateVariables(message, stack);
+
+        stack.pop();
+
+        if (pop) {
+            stack.pop();
+        }
+
+        return message;
+    }
+
+    public void setMessageKey(String key) {
+        messageKey = key;
+    }
+
+    public String getMessageKey() {
+        return messageKey;
+    }
+
+    public String[] getMessageParameters() {
+        return this.messageParameters;
+    }
+
+    public void setMessageParameters(String[] messageParameters) {
+        this.messageParameters = messageParameters;
+    }
+
+    public void setShortCircuit(boolean shortcircuit) {
+        shortCircuit = shortcircuit;
+    }
+
+    public boolean isShortCircuit() {
+        return shortCircuit;
+    }
+
+    public void setValidatorContext(ValidatorContext validatorContext) {
+        this.validatorContext = validatorContext;
+    }
+
+    public ValidatorContext getValidatorContext() {
+        return validatorContext;
+    }
+
+    public void setValidatorType(String type) {
+        this.type = type;
+    }
+
+    public String getValidatorType() {
+        return type;
+    }
+
+    /**
+     * Parse <code>expression</code> passed in against value stack. Only parse
+     * when 'parse' param is set to true, else just returns the expression unparsed.
+     *
+     * @param expression
+     * @return Object
+     */
+    protected Object conditionalParse(String expression) {
+        if (parse) {
+            return TextParseUtil.translateVariables('$', expression, stack);
+        }
+        return expression;
+    }
+
+    /**
+     * Return the field value named <code>name</code> from <code>object</code>,
+     * <code>object</code> should have the appropriate getter/setter.
+     *
+     * @param name
+     * @param object
+     * @return Object as field value
+     * @throws ValidationException
+     */
+    protected Object getFieldValue(String name, Object object) throws ValidationException {
+
+        boolean pop = false;
+
+        if (!stack.getRoot().contains(object)) {
+            stack.push(object);
+            pop = true;
+        }
+
+        Object retVal = stack.findValue(name);
+
+        if (pop) {
+            stack.pop();
+        }
+
+        return retVal;
+    }
+
+    protected void addActionError(Object object) {
+        validatorContext.addActionError(getMessage(object));
+    }
+
+    protected void addFieldError(String propertyName, Object object) {
+        validatorContext.addFieldError(propertyName, getMessage(object));
+    }
+
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/VisitorFieldValidator.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/VisitorFieldValidator.java?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/VisitorFieldValidator.java (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/VisitorFieldValidator.java Fri Dec  2 16:33:03 2011
@@ -0,0 +1,216 @@
+/*
+ * Copyright 2002-2006,2009 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts2.xwork2.validator.validators;
+
+import org.apache.struts2.xwork2.ActionContext;
+import org.apache.struts2.xwork2.inject.Inject;
+import org.apache.struts2.xwork2.util.ValueStack;
+import org.apache.struts2.xwork2.validator.ActionValidatorManager;
+import org.apache.struts2.xwork2.validator.DelegatingValidatorContext;
+import org.apache.struts2.xwork2.validator.ValidationException;
+import org.apache.struts2.xwork2.validator.ValidatorContext;
+
+import java.util.Collection;
+
+
+/**
+ * <!-- START SNIPPET: javadoc -->
+ * The VisitorFieldValidator allows you to forward validation to object
+ * properties of your action using the object's own validation files.  This
+ * allows you to use the ModelDriven development pattern and manage your
+ * validations for your models in one place, where they belong, next to your
+ * model classes.  The VisitorFieldValidator can handle either simple Object
+ * properties, Collections of Objects, or Arrays.
+ * <!-- END SNIPPET: javadoc -->
+ * <p/>
+ *
+ * <!-- START SNIPPET: parameters -->
+ * <ul>
+ * <li>fieldName - field name if plain-validator syntax is used, not needed if field-validator syntax is used</li>
+ * <li>context - the context of which validation should take place. Optional</li>
+ * <li>appendPrefix - the prefix to be added to field. Optional </li>
+ * </ul>
+ * <!-- END SNIPPET: parameters -->
+ *
+ * <pre>
+ * <!-- START SNIPPET: example -->
+ *    &lt;validators&gt;
+ *        &lt;!-- Plain Validator Syntax --&gt;
+ *        &lt;validator type="visitor"&gt;
+ *            &lt;param name="fieldName"&gt;user&lt;/param&gt;
+ *            &lt;param name="context"&gt;myContext&lt;/param&gt;
+ *            &lt;param name="appendPrefix"&gt;true&lt;/param&gt;
+ *        &lt;/validator&gt;
+ *
+ *        &lt;!-- Field Validator Syntax --&gt;
+ *        &lt;field name="user"&gt;
+ *           &lt;field-validator type="visitor"&gt;
+ *              &lt;param name="context"&gt;myContext&lt;/param&gt;
+ *              &lt;param name="appendPrefix"&gt;true&lt;/param&gt;
+ *           &lt;/field-validator&gt;
+ *        &lt;/field&gt;
+ *    &lt;/validators&gt;
+ * <!-- END SNIPPET: example -->
+ * </pre>
+ *
+ * <!-- START SNIPPET: explanation -->
+ * <p>In the example above, if the acion's getUser() method return User object, XWork
+ * will look for User-myContext-validation.xml for the validators. Since appednPrefix is true,
+ * every field name will be prefixed with 'user' such that if the actual field name for 'name' is
+ * 'user.name' </p>
+ * <!-- END SNIPPET: explanation -->
+ *
+ * @author Jason Carreira
+ * @author Rainer Hermanns
+ * @version $Date: 2011-12-02 12:24:48 +0100 (Fri, 02 Dec 2011) $ $Id: VisitorFieldValidator.java 1209415 2011-12-02 11:24:48Z lukaszlenart $
+ */
+public class VisitorFieldValidator extends FieldValidatorSupport {
+
+    private String context;
+    private boolean appendPrefix = true;
+    private ActionValidatorManager actionValidatorManager;
+
+
+    @Inject
+    public void setActionValidatorManager(ActionValidatorManager mgr) {
+        this.actionValidatorManager = mgr;
+    }
+
+    /**
+     * Sets whether the field name of this field validator should be prepended to the field name of
+     * the visited field to determine the full field name when an error occurs.  The default is
+     * true.
+     */
+    public void setAppendPrefix(boolean appendPrefix) {
+        this.appendPrefix = appendPrefix;
+    }
+
+    /**
+     * Flags whether the field name of this field validator should be prepended to the field name of
+     * the visited field to determine the full field name when an error occurs.  The default is
+     * true.
+     */
+    public boolean isAppendPrefix() {
+        return appendPrefix;
+    }
+
+    public void setContext(String context) {
+        this.context = context;
+    }
+
+    public String getContext() {
+        return context;
+    }
+
+    public void validate(Object object) throws ValidationException {
+        String fieldName = getFieldName();
+        Object value = this.getFieldValue(fieldName, object);
+        if (value == null) {
+            log.warn("The visited object is null, VisitorValidator will not be able to handle validation properly. Please make sure the visited object is not null for VisitorValidator to function properly");
+            return;
+        }
+        ValueStack stack = ActionContext.getContext().getValueStack();
+
+        stack.push(object);
+
+        String visitorContext = (context == null) ? ActionContext.getContext().getName() : context;
+
+        if (value instanceof Collection) {
+            Collection coll = (Collection) value;
+            Object[] array = coll.toArray();
+
+            validateArrayElements(array, fieldName, visitorContext);
+        } else if (value instanceof Object[]) {
+            Object[] array = (Object[]) value;
+
+            validateArrayElements(array, fieldName, visitorContext);
+        } else {
+            validateObject(fieldName, value, visitorContext);
+        }
+
+        stack.pop();
+    }
+
+    private void validateArrayElements(Object[] array, String fieldName, String visitorContext) throws ValidationException {
+        if (array == null) {
+            return;
+        }
+
+        for (int i = 0; i < array.length; i++) {
+            Object o = array[i];
+            if (o != null) {
+                validateObject(fieldName + "[" + i + "]", o, visitorContext);
+            }
+        }
+    }
+
+    private void validateObject(String fieldName, Object o, String visitorContext) throws ValidationException {
+        ValueStack stack = ActionContext.getContext().getValueStack();
+        stack.push(o);
+
+        ValidatorContext validatorContext;
+
+        if (appendPrefix) {
+            validatorContext = new AppendingValidatorContext(getValidatorContext(), o, fieldName, getMessage(o));
+        } else {
+            ValidatorContext parent = getValidatorContext();
+            validatorContext = new DelegatingValidatorContext(parent, DelegatingValidatorContext.makeTextProvider(o, parent), parent);
+        }
+
+        actionValidatorManager.validate(o, visitorContext, validatorContext);
+        stack.pop();
+    }
+
+
+    public static class AppendingValidatorContext extends DelegatingValidatorContext {
+        private String field;
+        private String message;
+        private ValidatorContext parent;
+
+        public AppendingValidatorContext(ValidatorContext parent, Object object, String field, String message) {
+            super(parent, makeTextProvider(object, parent), parent);
+
+            this.field = field;
+            this.message = message;
+            this.parent = parent;
+        }
+
+        /**
+         * Translates a simple field name into a full field name in Ognl syntax
+         *
+         * @param fieldName field name in OGNL syntax
+         * @return field name in OGNL syntax
+         */
+        @Override
+        public String getFullFieldName(String fieldName) {
+            return field + "." + fieldName;
+        }
+
+        public String getFullFieldNameFromParent(String fieldName) {
+            return parent.getFullFieldName(field + "." + fieldName);
+        }
+
+        @Override
+        public void addActionError(String anErrorMessage) {
+            super.addFieldError(getFullFieldName(field), message + anErrorMessage);
+        }
+
+        @Override
+        public void addFieldError(String fieldName, String errorMessage) {
+            super.addFieldError(getFullFieldName(fieldName), message + errorMessage);
+        }
+    }
+}

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/package.html
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/package.html?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/package.html (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/java/org/apache/struts2/xwork2/validator/validators/package.html Fri Dec  2 16:33:03 2011
@@ -0,0 +1 @@
+<body>XWork default validator classes.</body>

Added: struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/resources/org/apache/struts2/xwork2/validator/validators/default.xml
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/resources/org/apache/struts2/xwork2/validator/validators/default.xml?rev=1209569&view=auto
==============================================================================
--- struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/resources/org/apache/struts2/xwork2/validator/validators/default.xml (added)
+++ struts/struts2/branches/STRUTS_3_X/xwork-core/src/main/resources/org/apache/struts2/xwork2/validator/validators/default.xml Fri Dec  2 16:33:03 2011
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE validators PUBLIC
+        "-//Apache Struts//XWork Validator Config 1.0//EN"
+        "http://struts.apache.org/dtds/xwork-validator-config-1.0.dtd">
+
+<!-- START SNIPPET: validators-default -->
+<validators>
+    <validator name="required" class="org.apache.struts2.xwork2.validator.validators.RequiredFieldValidator"/>
+    <validator name="requiredstring" class="org.apache.struts2.xwork2.validator.validators.RequiredStringValidator"/>
+    <validator name="int" class="org.apache.struts2.xwork2.validator.validators.IntRangeFieldValidator"/>
+    <validator name="long" class="org.apache.struts2.xwork2.validator.validators.LongRangeFieldValidator"/>
+    <validator name="short" class="org.apache.struts2.xwork2.validator.validators.ShortRangeFieldValidator"/>
+    <validator name="double" class="org.apache.struts2.xwork2.validator.validators.DoubleRangeFieldValidator"/>
+    <validator name="date" class="org.apache.struts2.xwork2.validator.validators.DateRangeFieldValidator"/>
+    <validator name="expression" class="org.apache.struts2.xwork2.validator.validators.ExpressionValidator"/>
+    <validator name="fieldexpression" class="org.apache.struts2.xwork2.validator.validators.FieldExpressionValidator"/>
+    <validator name="email" class="org.apache.struts2.xwork2.validator.validators.EmailValidator"/>
+    <validator name="url" class="org.apache.struts2.xwork2.validator.validators.URLValidator"/>
+    <validator name="visitor" class="org.apache.struts2.xwork2.validator.validators.VisitorFieldValidator"/>
+    <validator name="conversion" class="org.apache.struts2.xwork2.validator.validators.ConversionErrorFieldValidator"/>
+    <validator name="stringlength" class="org.apache.struts2.xwork2.validator.validators.StringLengthFieldValidator"/>
+    <validator name="regex" class="org.apache.struts2.xwork2.validator.validators.RegexFieldValidator"/>
+    <validator name="conditionalvisitor" class="org.apache.struts2.xwork2.validator.validators.ConditionalVisitorFieldValidator"/>
+</validators>
+<!--  END SNIPPET: validators-default -->