org.nuiton.validator.xwork2.field
Class FrenchSiretFieldValidator

java.lang.Object
  extended by com.opensymphony.xwork2.validator.validators.ValidatorSupport
      extended by com.opensymphony.xwork2.validator.validators.FieldValidatorSupport
          extended by org.nuiton.validator.xwork2.field.NuitonFieldValidatorSupport
              extended by org.nuiton.validator.xwork2.field.FrenchSiretFieldValidator
All Implemented Interfaces:
com.opensymphony.xwork2.validator.FieldValidator, com.opensymphony.xwork2.validator.ShortCircuitableValidator, com.opensymphony.xwork2.validator.Validator

public class FrenchSiretFieldValidator
extends NuitonFieldValidatorSupport

Validator for French SIRET numbers

Siret can be in:

  • String format: "44211670300038"
  • long, int: 44211670300038
  • Array or Collection of something: [4,4,2,1,1,6,7,0,,3,0,0,0,3,8] or ["442","116","703", "0003", "8"]

    Since:
    2.3 Validation do the Luhn checksum too
    Author:
    jcouteau

    Field Summary
    protected static Pattern p
               
    protected static String SIRET_REGEXP
               
     
    Fields inherited from class org.nuiton.validator.xwork2.field.NuitonFieldValidatorSupport
    skip
     
    Fields inherited from class com.opensymphony.xwork2.validator.validators.ValidatorSupport
    defaultMessage, log, messageKey
     
    Constructor Summary
    FrenchSiretFieldValidator()
               
     
    Method Summary
    static int getDigit(char c)
              Converti un char en un entier '0' => 0 et '9' => 9, et 'A' => 10 a 'Z' => 36, les autres caractere sont aussi convertis pour que 'a' = 10 et 'z' = 36.
     String getValidatorType()
               
    static boolean luhnChecksum(String siret)
              Verifie la validite d'un numero en suivant l'algorithme Luhn tel que d'ecrit dans wikipedia

    Algo: en fonction de la position du numero dans la sequence, on multiplie pas 1 (pour les impaires) ou par 2 pour les paires (1 etant le numero le plus a droite) On fait la somme de tous les chiffres qui resulte de ces multiplications (si un resultat etait 14, on ne fait pas +14 mais +1+4)

    Si le résultat de cette somme donne un reste de 0 une fois divisé par 10 le numero est valide.

     void validateWhenNotSkip(Object object)
              Method to be invoked when skip parameter was not evaludated to true.
     
    Methods inherited from class org.nuiton.validator.xwork2.field.NuitonFieldValidatorSupport
    evaluateSkipParameter, getFieldValue, setSkip, validate
     
    Methods inherited from class com.opensymphony.xwork2.validator.validators.FieldValidatorSupport
    getFieldName, setFieldName, setValidatorType
     
    Methods inherited from class com.opensymphony.xwork2.validator.validators.ValidatorSupport
    addActionError, addFieldError, conditionalParse, getDefaultMessage, getMessage, getMessageKey, getMessageParameters, getParse, getValidatorContext, isShortCircuit, setDefaultMessage, setMessageKey, setMessageParameters, setParse, setShortCircuit, setValidatorContext, setValueStack
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     
    Methods inherited from interface com.opensymphony.xwork2.validator.Validator
    getDefaultMessage, getMessage, getMessageKey, getMessageParameters, getValidatorContext, setDefaultMessage, setMessageKey, setMessageParameters, setValidatorContext, setValueStack
     

    Field Detail

    SIRET_REGEXP

    protected static final String SIRET_REGEXP
    See Also:
    Constant Field Values

    p

    protected static final Pattern p
    Constructor Detail

    FrenchSiretFieldValidator

    public FrenchSiretFieldValidator()
    Method Detail

    validateWhenNotSkip

    public void validateWhenNotSkip(Object object)
                             throws com.opensymphony.xwork2.validator.ValidationException
    Description copied from class: NuitonFieldValidatorSupport
    Method to be invoked when skip parameter was not evaludated to true.

    Specified by:
    validateWhenNotSkip in class NuitonFieldValidatorSupport
    Parameters:
    object - the object to be validated.
    Throws:
    com.opensymphony.xwork2.validator.ValidationException - is thrown if there is validation error(s).

    getValidatorType

    public String getValidatorType()
    Specified by:
    getValidatorType in interface com.opensymphony.xwork2.validator.Validator
    Overrides:
    getValidatorType in class com.opensymphony.xwork2.validator.validators.FieldValidatorSupport

    luhnChecksum

    public static boolean luhnChecksum(String siret)
    Verifie la validite d'un numero en suivant l'algorithme Luhn tel que d'ecrit dans wikipedia

    Algo: en fonction de la position du numero dans la sequence, on multiplie pas 1 (pour les impaires) ou par 2 pour les paires (1 etant le numero le plus a droite) On fait la somme de tous les chiffres qui resulte de ces multiplications (si un resultat etait 14, on ne fait pas +14 mais +1+4)

    Si le résultat de cette somme donne un reste de 0 une fois divisé par 10 le numero est valide.

    Parameters:
    siret - une chaine composer que de chiffre
    Returns:
    vrai si on a reussi a valider le numero

    getDigit

    public static int getDigit(char c)
    Converti un char en un entier '0' => 0 et '9' => 9, et 'A' => 10 a 'Z' => 36, les autres caractere sont aussi convertis pour que 'a' = 10 et 'z' = 36. Pour les autres c'est un indedermine

    Parameters:
    c - le caractere qui doit etre converti
    Returns:
    le chiffre


    Copyright © 2011-2012 CodeLutin. All Rights Reserved.