com.ls.util.validation
Class Validation

java.lang.Object
  |
  +--com.ls.util.validation.Validation

public class Validation
extends Object

This class is for testing of regular expressions. It uses the "gnu.regexp" library.

Version:
$Revision: 1.2 $
Author:
Last modified by $Author: PMandal $

Field Summary
static String ERROR
          The constant that store the "error" string
static String RULE_DEFAULTVALUE
          The constant that store the "default" string
static String RULE_MANDATORY
          The constant that store the "mandatory" string
static String RULE_MAXLENGTH
          The constant that store the "maxlength" string
static String RULE_MINLENGTH
          The constant that store the "minlength" string
static String RULE_NAME
          The constant that store the "name" string
static String RULE_REGEX
          The constant that store the "regex" string
static String RULE_TYPE
          The constant that store the "typecode" string
 
Constructor Summary
Validation()
          Creates a new Validator object.
 
Method Summary
 void addRule(String ruleKey, Map rule)
          The following function group adds a rule to the know rule sets.
 void addRuleType(String ruleTypeKey, Map rule)
          The following function adds a rule type to the typeHash.
 Map convertValues(Map rule)
          Convert values like MIN_LENGTH, MAX_LENGTH to integers and add them again to the map and returns it afterwards.
 List getAllErrors()
          Returns a list of all errors that occured during validation of an input map.
 List getErrors()
          Returns a list with the errors that occured during validation.
 boolean isValid(Map input)
          Function to check the content of an input Map against the rule set If no rule for a content entry exists the check for this entry will be successfull.
 boolean isValid(String value, String ruleKey)
          Function to check a value (from the user input side) against the rule set for a rule key.
 Map mergeRules(Map ruleType, Map rule)
          The following function group adds a rule to the know rule sets.
 boolean validateMandatory(String value, String ruleKey, Map rule)
          Check if the it is a mandatory flag and the value exits.
 boolean validateMaxLength(String value, String ruleKey, Map rule)
          Check if the value is long enough.
 boolean validateMinLength(String value, String ruleKey, Map rule)
          Check if the value is long enough.
 boolean validateRegEx(String value, String ruleKey, Map rule)
          Checks if the value is matching the regular expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RULE_NAME

public static final String RULE_NAME
The constant that store the "name" string

RULE_TYPE

public static final String RULE_TYPE
The constant that store the "typecode" string

RULE_MANDATORY

public static final String RULE_MANDATORY
The constant that store the "mandatory" string

RULE_DEFAULTVALUE

public static final String RULE_DEFAULTVALUE
The constant that store the "default" string

RULE_MAXLENGTH

public static final String RULE_MAXLENGTH
The constant that store the "maxlength" string

RULE_MINLENGTH

public static final String RULE_MINLENGTH
The constant that store the "minlength" string

RULE_REGEX

public static final String RULE_REGEX
The constant that store the "regex" string

ERROR

public static final String ERROR
The constant that store the "error" string
Constructor Detail

Validation

public Validation()
Creates a new Validator object.
Method Detail

addRuleType

public void addRuleType(String ruleTypeKey,
                        Map rule)
                 throws ValidationConfigurationException
The following function adds a rule type to the typeHash. The validate...() functions must be passed the rule code and the value to perform a check.
Parameters:
ruleTypeKey - The identifier of the rule if want to be called
rule - The Map containin the rules for one field / type
Throws:
ValidationConfigurationException - If an error happens when adding the rule type.

addRule

public void addRule(String ruleKey,
                    Map rule)
             throws ValidationConfigurationException
The following function group adds a rule to the know rule sets. The validate...() functions must be passed the rule code and the value to perform a check.
Parameters:
ruleKey - Rule code generated by makeRuleCode(), i.e. parse_template.insert_item.email
rule - The map of rules
Throws:
ValidationConfigurationException - If an error happens when adding the rule.

convertValues

public Map convertValues(Map rule)
                  throws ValidationConfigurationException
Convert values like MIN_LENGTH, MAX_LENGTH to integers and add them again to the map and returns it afterwards.
Parameters:
rule - The Map containing the rules for one field / type
Returns:
The Map with the converted values
Throws:
ValidationConfigurationException - If an error happens when converting the values.

mergeRules

public Map mergeRules(Map ruleType,
                      Map rule)
The following function group adds a rule to the know rule sets. The validate...() functions must be passed the rule code and the value to perform a check.
Parameters:
ruleType - Rule code generated by makeRuleCode(), i.e. parse_template.insert_item.email
rule - The set of rules
Returns:
The Map with the merged values

isValid

public boolean isValid(Map input)
Function to check the content of an input Map against the rule set If no rule for a content entry exists the check for this entry will be successfull. But the method itself will return only true if all validation on the content will be successful.
Parameters:
input - The Map with content that has to be validated.
Returns:
True or false, depending on validity of input. Returns true if all entries in the content have been successfully validated.

isValid

public boolean isValid(String value,
                       String ruleKey)
Function to check a value (from the user input side) against the rule set for a rule key. If no rule for that rule key was defined before, the check will always return true.
Parameters:
value - The user input to check.
ruleKey - The rule key that identifies the rule to use for the check.
Returns:
True or false, depending on validity of input. Also returns true if no rule with the specified rule code exists.

validateMandatory

public boolean validateMandatory(String value,
                                 String ruleKey,
                                 Map rule)
Check if the it is a mandatory flag and the value exits.
Parameters:
value - The user input to check.
ruleKey - The rule key that identifies the rule to use for the check.
rule - The rule that is applied to the rule key
Returns:
True if the field is not mandatory or it is mandatory and a value exists

validateMinLength

public boolean validateMinLength(String value,
                                 String ruleKey,
                                 Map rule)
Check if the value is long enough.
Parameters:
value - The user input to check.
ruleKey - The rule key that identifies the rule to use for the check.
rule - The rule that is applied to the rule key
Returns:
True if the value is long enough or a minimum length does not exist.

validateMaxLength

public boolean validateMaxLength(String value,
                                 String ruleKey,
                                 Map rule)
Check if the value is long enough.
Parameters:
value - The user input to check.
ruleKey - The rule key that identifies the rule to use for the check.
rule - The rule that is applied to the rule key
Returns:
True if the value is long enough or a minimum length does not exist.

validateRegEx

public boolean validateRegEx(String value,
                             String ruleKey,
                             Map rule)
Checks if the value is matching the regular expression.
Parameters:
value - The user input to check.
ruleKey - The rule key that identifies the rule to use for the check.
rule - The rule that is applied to the rule key
Returns:
True if the value is matching the regularexpression or if no regular expression exists.

getErrors

public List getErrors()
Returns a list with the errors that occured during validation.
Returns:
A list of errors

getAllErrors

public List getAllErrors()
Returns a list of all errors that occured during validation of an input map.
Returns:
A list of errors