Commits

Anonymous committed 4e8ec41

o added metadata descriptors for apt based validation config generator

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@624e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (13)

tiger/src/java/com/opensymphony/xwork/validator/metadata/AbstractFieldValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * <code>AbstractFieldValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public abstract class AbstractFieldValidatorDescription implements ValidatorDescription {
+
+    /**
+     * Jakarta commons-logging reference.
+     */
+    protected static Log log = null;
+
+    public String[] aliasNames;
+    public String fieldName;
+    public String key;
+    public String message;
+    public boolean shortCircuit;
+    public boolean simpleValidator;
+
+
+    public AbstractFieldValidatorDescription() {
+        log = LogFactory.getLog(this.getClass());
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified field name.
+     *
+     * @param fieldName
+     */
+    public AbstractFieldValidatorDescription(String fieldName) {
+        this.fieldName = fieldName;
+        log = LogFactory.getLog(this.getClass());
+    }
+
+    /**
+     * Sets the aliasName of the Action alias as defined in the xwork.xml configuration.
+     *
+     * @param aliasNames the aliasName of the Action alias.
+     */
+    public void setAliasNames(String[] aliasNames) {
+        this.aliasNames = aliasNames;
+    }
+
+    /**
+     * Sets the field name for this validator rule.
+     *
+     * @return fieldName the field name for this validator rule
+     */
+    public String getFieldName() {
+        return fieldName;
+    }
+
+    /**
+     * Sets the field name for this validator rule.
+     *
+     * @param fieldName the field name for this validator rule
+     */
+    public void setFieldName(String fieldName) {
+        this.fieldName = fieldName;
+    }
+
+    /**
+     * Sets the I18N message key.
+     * @param key the I18N message key
+     */
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    /**
+     * Sets the default validator failure message.
+     *
+     * @param message the default validator failure message
+     */
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    /**
+     * Set the shortCircuit flag.
+     *
+     * @param shortCircuit the shortCircuit flag.
+     */
+    public void setShortCircuit(boolean shortCircuit) {
+        this.shortCircuit = shortCircuit;
+    }
+
+    public void setSimpleValidator(boolean simpleValidator) {
+        this.simpleValidator = simpleValidator;
+    }
+
+    public boolean isSimpleValidator() {
+        return simpleValidator;
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asXml() {
+        if ( simpleValidator) {
+            return asSimpleXml();
+        }
+        return asFieldXml();
+    }
+
+    /**
+     * Returns the field validator XML definition.
+     *
+     * @return the field validator XML definition.
+     */
+    public abstract String asFieldXml();
+
+     /**
+      * Returns the validator XML definition.
+      *
+      * @return the validator XML definition.
+      */
+     public abstract String asSimpleXml();
+
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/ConversionErrorFieldValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <code>ConversionErrorFieldValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class ConversionErrorFieldValidatorDescription extends AbstractFieldValidatorDescription {
+
+    public ConversionErrorFieldValidatorDescription() {
+        super();
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified field name.
+     *
+     * @param fieldName
+     */
+    public ConversionErrorFieldValidatorDescription(String fieldName) {
+        super(fieldName);
+    }
+
+
+    /**
+     * Returns the field validator XML definition.
+     *
+     * @return the field validator XML definition.
+     */
+    public String asFieldXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if (shortCircuit) {
+                writer.println("\t\t<field-validator type=\"conversion\">");
+            } else {
+                writer.println("\t\t<field-validator type=\"conversion\" short-circuit=\"true\">");
+            }
+
+            if (!"".equals(key)) {
+                writer.println("\t\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t\t</field-validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asSimpleXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if (shortCircuit) {
+                writer.println("\t<validator type=\"conversion\">");
+            } else {
+                writer.println("\t<validator type=\"conversion\" short-circuit=\"true\">");
+            }
+
+            writer.println("\t\t<param name=\"fieldName\">" + fieldName + "</param>");
+
+            if (!"".equals(key)) {
+                writer.println("\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t</validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+    }
+
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/DateRangeFieldValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <code>DateRangeFieldValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class DateRangeFieldValidatorDescription extends AbstractFieldValidatorDescription {
+
+    public String min;
+    public String max;
+
+    public DateRangeFieldValidatorDescription() {
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified field name.
+     *
+     * @param fieldName
+     */
+    public DateRangeFieldValidatorDescription(String fieldName) {
+        super(fieldName);
+    }
+
+    public void setMin(String min) {
+        this.min = min;
+    }
+
+    public void setMax(String max) {
+        this.max = max;
+    }
+
+ /**
+     * Returns the field validator XML definition.
+     *
+     * @return the field validator XML definition.
+     */
+    public String asFieldXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t\t<field-validator type=\"date\">");
+            } else {
+                writer.println("\t\t<field-validator type=\"date\" short-circuit=\"true\">");
+            }
+            if ( min != null && min.length() > 0) {
+                writer.println("\t\t\t<param name=\"min\">" + min + "</param>");
+            }
+            if ( max != null && max.length() > 0) {
+                writer.println("\t\t\t<param name=\"max\">" + max + "</param>");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t\t</field-validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asSimpleXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t<validator type=\"date\">");
+            } else {
+                writer.println("\t<validator type=\"date\" short-circuit=\"true\">");
+            }
+
+            writer.println("\t\t<param name=\"fieldName\">" + fieldName+ "</param>");
+
+
+            if ( min != null && min.length() > 0) {
+                writer.println("\t\t<param name=\"min\">" + min + "</param>");
+            }
+            if ( max != null && max.length() > 0) {
+                writer.println("\t\t<param name=\"max\">" + max + "</param>");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t</validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+    }
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/EmailValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <code>EmailValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class EmailValidatorDescription extends AbstractFieldValidatorDescription {
+
+
+    public EmailValidatorDescription() {
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified field name.
+     *
+     * @param fieldName
+     */
+    public EmailValidatorDescription(String fieldName) {
+        super(fieldName);
+    }
+
+    /**
+      * Returns the field validator XML definition.
+      *
+      * @return the field validator XML definition.
+      */
+     public String asFieldXml() {
+         StringWriter sw = new StringWriter();
+         PrintWriter writer = null;
+
+         try {
+             writer = new PrintWriter(sw);
+
+             if ( shortCircuit) {
+                 writer.println("\t\t<field-validator type=\"email\">");
+             } else {
+                 writer.println("\t\t<field-validator type=\"email\" short-circuit=\"true\">");
+             }
+
+             if ( !"".equals(key)) {
+                 writer.println("\t\t\t<message key=\"" + key + "\">" + message + "</message>");
+             } else {
+                 writer.println("\t\t\t<message>" + message + "</message>");
+             }
+
+             writer.println("\t\t</field-validator>");
+
+         } finally {
+             if (writer != null) {
+                 writer.flush();
+                 writer.close();
+             }
+         }
+         return sw.toString();
+
+     }
+
+     /**
+      * Returns the validator XML definition.
+      *
+      * @return the validator XML definition.
+      */
+     public String asSimpleXml() {
+         StringWriter sw = new StringWriter();
+         PrintWriter writer = null;
+
+         try {
+             writer = new PrintWriter(sw);
+
+             if ( shortCircuit) {
+                 writer.println("\t<validator type=\"email\">");
+             } else {
+                 writer.println("\t<validator type=\"email\" short-circuit=\"true\">");
+             }
+
+             writer.println("\t\t<param name=\"fieldName\">" + fieldName+ "</param>");
+
+             if ( !"".equals(key)) {
+                 writer.println("\t\t<message key=\"" + key + "\">" + message + "</message>");
+             } else {
+                 writer.println("\t\t<message>" + message + "</message>");
+             }
+
+             writer.println("\t</validator>");
+
+         } finally {
+             if (writer != null) {
+                 writer.flush();
+                 writer.close();
+             }
+         }
+         return sw.toString();
+     }
+
+
+
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/ExpressionValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.StringWriter;
+import java.io.PrintWriter;
+
+/**
+ * <code>ExpressionValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class ExpressionValidatorDescription implements ValidatorDescription {
+
+    public String[] aliasNames;
+    public String expression;
+    public String key;
+    public String message;
+    public boolean shortCircuit;
+
+    /**
+     * Sets the aliasNames of the Action aliases as defined in the xwork.xml configuration.
+     *
+     * @param aliasNames the aliasNames of the Action aliases.
+     */
+    public void setAliasNames(String[] aliasNames) {
+        this.aliasNames = aliasNames;
+    }
+
+    public void setExpression(String expression) {
+        this.expression = expression;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public void setShortCircuit(boolean shortCircuit) {
+        this.shortCircuit = shortCircuit;
+    }
+
+    /**
+     * Returns the field name to create the validation rule for.
+     *
+     * @return The field name to create the validation rule for
+     */
+    public String getFieldName() {
+        throw new UnsupportedOperationException("ExpressionValidator annotations cannot be applied to fields...");
+    }
+
+    public String asXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t<validator type=\"expression\">");
+            } else {
+                writer.println("\t<validator type=\"expression\" short-circuit=\"true\">");
+            }
+
+            writer.println("\t\t<param name=\"expression\">" + expression+ "</param>");
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t</validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+    }
+
+    public boolean isSimpleValidator() {
+        return false;
+    }
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/FieldExpressionValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <code>FieldExpressionValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class FieldExpressionValidatorDescription extends AbstractFieldValidatorDescription {
+
+    public String expression;
+    public String key;
+    public String message;
+    public boolean shortCircuit;
+
+    public FieldExpressionValidatorDescription() {
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified field name.
+     *
+     * @param fieldName
+     */
+    public FieldExpressionValidatorDescription(String fieldName) {
+        super(fieldName);
+    }
+
+    public void setExpression(String expression) {
+        this.expression = expression;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public void setShortCircuit(boolean shortCircuit) {
+        this.shortCircuit = shortCircuit;
+    }
+
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asFieldXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t\t<field-validator type=\"fieldexpression\">");
+            } else {
+                writer.println("\t\t<field-validator type=\"fieldexpression\" short-circuit=\"true\">");
+            }
+
+            writer.println("\t\t\t<param name=\"expression\">" + expression+ "</param>");
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t\t</field-validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asSimpleXml() {
+        throw new UnsupportedOperationException(getClass().getName() + " cannot be used for simple validators...");
+    }
+
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/IntRangeFieldValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <code>IntRangeFieldValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class IntRangeFieldValidatorDescription extends AbstractFieldValidatorDescription {
+
+    public String min;
+    public String max;
+
+    public IntRangeFieldValidatorDescription() {
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified field name.
+     *
+     * @param fieldName
+     */
+    public IntRangeFieldValidatorDescription(String fieldName) {
+        super(fieldName);
+    }
+
+    public void setMin(String min) {
+        this.min = min;
+    }
+
+    public void setMax(String max) {
+        this.max = max;
+    }
+
+    /**
+     * Returns the field validator XML definition.
+     *
+     * @return the field validator XML definition.
+     */
+    public String asFieldXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t\t<field-validator type=\"int\">");
+            } else {
+                writer.println("\t\t<field-validator type=\"int\" short-circuit=\"true\">");
+            }
+            if ( min != null && min.length() > 0) {
+                writer.println("\t\t\t<param name=\"min\">" + min + "</param>");
+            }
+            if ( max != null && max.length() > 0) {
+                writer.println("\t\t\t<param name=\"max\">" + max + "</param>");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t\t</field-validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asSimpleXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t<validator type=\"int\">");
+            } else {
+                writer.println("\t<validator type=\"int\" short-circuit=\"true\">");
+            }
+
+            writer.println("\t\t<param name=\"fieldName\">" + fieldName+ "</param>");
+
+
+            if ( min != null && min.length() > 0) {
+                writer.println("\t\t<param name=\"min\">" + min + "</param>");
+            }
+            if ( max != null && max.length() > 0) {
+                writer.println("\t\t<param name=\"max\">" + max + "</param>");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t</validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+    }
+
+
+
+
+
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/RequiredFieldValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <code>RequiredFieldValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class RequiredFieldValidatorDescription extends AbstractFieldValidatorDescription {
+
+    public RequiredFieldValidatorDescription() {
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified field name.
+     *
+     * @param fieldName
+     */
+    public RequiredFieldValidatorDescription(String fieldName) {
+        super(fieldName);
+    }
+
+     /**
+     * Returns the field validator XML definition.
+     *
+     * @return the field validator XML definition.
+     */
+    public String asFieldXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t\t<field-validator type=\"required\">");
+            } else {
+                writer.println("\t\t<field-validator type=\"required\" short-circuit=\"true\">");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t\t</field-validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asSimpleXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t<validator type=\"required\">");
+            } else {
+                writer.println("\t<validator type=\"required\" short-circuit=\"true\">");
+            }
+
+            writer.println("\t\t<param name=\"fieldName\">" + fieldName+ "</param>");
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t</validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+    }
+
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/RequiredStringValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <code>RequiredStringValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class RequiredStringValidatorDescription extends AbstractFieldValidatorDescription {
+
+    public boolean trim = true;
+
+    public RequiredStringValidatorDescription() {
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified field name.
+     *
+     * @param fieldName
+     */
+    public RequiredStringValidatorDescription(String fieldName) {
+        super(fieldName);
+    }
+
+    public void setTrim(boolean trim) {
+        this.trim = trim;
+    }
+
+    /**
+     * Returns the field validator XML definition.
+     *
+     * @return the field validator XML definition.
+     */
+    public String asFieldXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t\t<field-validator type=\"requiredstring\">");
+            } else {
+                writer.println("\t\t<field-validator type=\"requiredstring\" short-circuit=\"true\">");
+            }
+            if ( !trim) {
+                writer.println("\t\t\t<param name=\"trim\">" + trim + "</param>");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t\t</field-validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asSimpleXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t<validator type=\"requiredstring\">");
+            } else {
+                writer.println("\t<validator type=\"requiredstring\" short-circuit=\"true\">");
+            }
+
+            writer.println("\t\t<param name=\"fieldName\">" + fieldName+ "</param>");
+
+            if ( !trim) {
+                writer.println("\t\t<param name=\"trim\">" + trim + "</param>");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t</validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+    }
+
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/StringLengthFieldValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <code>StringLengthFieldValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class StringLengthFieldValidatorDescription extends AbstractFieldValidatorDescription {
+
+    public boolean trim = true;
+    public String minLength;
+    public String maxLength;
+
+    public StringLengthFieldValidatorDescription() {
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified field name.
+     *
+     * @param fieldName
+     */
+    public StringLengthFieldValidatorDescription(String fieldName) {
+        super(fieldName);
+    }
+
+    public void setTrim(boolean trim) {
+        this.trim = trim;
+    }
+
+    public void setMinLength(String minLength) {
+        this.minLength = minLength;
+    }
+
+    public void setMaxLength(String maxLength) {
+        this.maxLength = maxLength;
+    }
+
+   /**
+     * Returns the field validator XML definition.
+     *
+     * @return the field validator XML definition.
+     */
+    public String asFieldXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t\t<field-validator type=\"stringlength\">");
+            } else {
+                writer.println("\t\t<field-validator type=\"stringlength\" short-circuit=\"true\">");
+            }
+            if ( !trim) {
+                writer.println("\t\t\t<param name=\"trim\">" + trim + "</param>");
+            }
+            if ( minLength != null && minLength.length() > 0) {
+                writer.println("\t\t\t<param name=\"minLength\">" + minLength + "</param>");
+            }
+            if ( maxLength != null && maxLength.length() > 0) {
+                writer.println("\t\t\t<param name=\"maxLength\">" + maxLength + "</param>");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t</field-validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asSimpleXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t<validator type=\"stringlength\">");
+            } else {
+                writer.println("\t<validator type=\"stringlength\" short-circuit=\"true\">");
+            }
+
+            writer.println("\t\t<param name=\"fieldName\">" + fieldName+ "</param>");
+
+            if ( !trim) {
+                writer.println("\t\t<param name=\"trim\">" + trim + "</param>");
+            }
+
+            if ( minLength != null && minLength.length() > 0) {
+                writer.println("\t\t<param name=\"minLength\">" + minLength + "</param>");
+            }
+            if ( maxLength != null && maxLength.length() > 0) {
+                writer.println("\t\t<param name=\"maxLength\">" + maxLength + "</param>");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t</validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+    }
+
+
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/URLValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <code>URLValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class URLValidatorDescription extends AbstractFieldValidatorDescription {
+
+
+    public URLValidatorDescription() {
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified aliasNames.
+     *
+     * @param fieldName
+     */
+    public URLValidatorDescription(String fieldName) {
+        super(fieldName);
+    }
+
+
+   /**
+     * Returns the field validator XML definition.
+     *
+     * @return the field validator XML definition.
+     */
+    public String asFieldXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t\t<field-validator type=\"url\">");
+            } else {
+                writer.println("\t\t<field-validator type=\"url\" short-circuit=\"true\">");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t\t</field-validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asSimpleXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t<validator type=\"url\">");
+            } else {
+                writer.println("\t<validator type=\"url\" short-circuit=\"true\">");
+            }
+
+            writer.println("\t\t<param name=\"fieldName\">" + fieldName+ "</param>");
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t</validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+    }
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/ValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+/**
+ * <code>ValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public interface ValidatorDescription {
+
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    String asXml();
+
+    /**
+     * Returns the field name to create the validation rule for.
+     *
+     * @return The field name to create the validation rule for
+     */
+    String getFieldName();
+
+    /**
+     * Sets the aliasName of the Action alias as defined in the xwork.xml configuration.
+     *
+     * @param aliasNames the aliasName of the Action alias.
+     */
+    void setAliasNames(String[] aliasNames);
+
+    /**
+     * Sets the I18N message key.
+     * @param key the I18N message key
+     */
+    void setKey(String key);
+
+    /**
+     * Sets the default validator failure message.
+     *
+     * @param message the default validator failure message
+     */
+    void setMessage(String message);
+
+    /**
+     * Set the shortCircuit flag.
+     *
+     * @param shortCircuit the shortCircuit flag.
+     */
+    void setShortCircuit(boolean shortCircuit);
+
+    boolean isSimpleValidator();
+}

tiger/src/java/com/opensymphony/xwork/validator/metadata/VisitorFieldValidatorDescription.java

+/*
+ * Copyright (c) 2002-2005 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.validator.metadata;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * <code>VisitorFieldValidatorDescription</code>
+ *
+ * @author Rainer Hermanns
+ * @version $Id$
+ */
+public class VisitorFieldValidatorDescription extends AbstractFieldValidatorDescription {
+
+    public String context;
+    public boolean appendPrefix = true;
+
+    public VisitorFieldValidatorDescription() {
+    }
+
+    /**
+     * Creates an AbstractFieldValidatorDescription with the specified field name.
+     *
+     * @param fieldName
+     */
+    public VisitorFieldValidatorDescription(String fieldName) {
+        super(fieldName);
+    }
+
+    public void setContext(String context) {
+        this.context = context;
+    }
+
+    public void setAppendPrefix(boolean appendPrefix) {
+        this.appendPrefix = appendPrefix;
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asFieldXml() {
+        StringWriter sw = new StringWriter();
+        PrintWriter writer = null;
+
+        try {
+            writer = new PrintWriter(sw);
+
+            if ( shortCircuit) {
+                writer.println("\t\t<field-validator type=\"visitor\">");
+            } else {
+                writer.println("\t\t<field-validator type=\"visitor\" short-circuit=\"true\">");
+            }
+
+            if ( context != null && context.length() > 0) {
+                writer.println("\t\t\t<param name=\"context\">" + context + "</param>");
+            }
+
+            if ( !appendPrefix) {
+                writer.println("\t\t\t<param name=\"appendPrefix\">" + appendPrefix + "</param>");
+            }
+
+            if ( !"".equals(key)) {
+                writer.println("\t\t\t<message key=\"" + key + "\">" + message + "</message>");
+            } else {
+                writer.println("\t\t\t<message>" + message + "</message>");
+            }
+
+            writer.println("\t\t</field-validator>");
+
+        } finally {
+            if (writer != null) {
+                writer.flush();
+                writer.close();
+            }
+        }
+        return sw.toString();
+    }
+
+    /**
+     * Returns the validator XML definition.
+     *
+     * @return the validator XML definition.
+     */
+    public String asSimpleXml() {
+        throw new UnsupportedOperationException(getClass().getName() + " cannot be used for simple validators...");
+    }
+}