Nuiton-utils-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
August 2011
- 5 participants
- 40 discussions
r2177 - in trunk/nuiton-profiling: . src/test/java/org/nuiton src/test/java/org/nuiton/profiling src/test/resources
by tchemit@users.nuiton.org 22 Aug '11
by tchemit@users.nuiton.org 22 Aug '11
22 Aug '11
Author: tchemit
Date: 2011-08-22 17:15:47 +0200 (Mon, 22 Aug 2011)
New Revision: 2177
Url: http://nuiton.org/repositories/revision/nuiton-utils/2177
Log:
add a test
Added:
trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/
trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java
trunk/nuiton-profiling/src/test/resources/log4j.properties
Modified:
trunk/nuiton-profiling/pom.xml
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-profiling/pom.xml 2011-08-22 10:58:03 UTC (rev 2176)
+++ trunk/nuiton-profiling/pom.xml 2011-08-22 15:15:47 UTC (rev 2177)
@@ -83,6 +83,18 @@
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
@@ -109,6 +121,30 @@
<!-- *** Build Environment ************************************** -->
<!-- ************************************************************* -->
+ <build>
+
+ <plugins>
+
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ <silent>true</silent>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
<profiles>
<profile>
<id>reporting</id>
Added: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java
===================================================================
--- trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java (rev 0)
+++ trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java 2011-08-22 15:15:47 UTC (rev 2177)
@@ -0,0 +1,64 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Profiling
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.profiling;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codehaus.aspectwerkz.annotation.Aspect;
+import org.codehaus.aspectwerkz.annotation.Expression;
+import org.codehaus.aspectwerkz.definition.Pointcut;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since TODO
+ */
+@Aspect("perJVM")
+public class MyNuitonTrace extends NuitonTrace {
+
+ @Expression("execution(* org.apache.commons.logging.Log.*(..))")
+ Pointcut executeMethod;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(MyNuitonTrace.class);
+
+ public static void main(String[] args) {
+
+ log.debug("DEBUG");
+ log.info("INFO");
+ log.warn("WARN");
+ log.warn("TRACE");
+
+ // trace should have somethin inside it...
+ String statisticsAndClear = getStatisticsAndClear();
+// Assert.assertTrue(StringUtils.isNotEmpty(statisticsAndClear));
+
+ if (log.isInfoEnabled()) {
+ log.info("First trace = " + statisticsAndClear);
+ }
+ }
+
+}
Property changes on: trunk/nuiton-profiling/src/test/java/org/nuiton/profiling/MyNuitonTrace.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/nuiton-profiling/src/test/resources/log4j.properties (from rev 2176, trunk/nuiton-utils/src/test/resources/log4j.properties)
===================================================================
--- trunk/nuiton-profiling/src/test/resources/log4j.properties (rev 0)
+++ trunk/nuiton-profiling/src/test/resources/log4j.properties 2011-08-22 15:15:47 UTC (rev 2177)
@@ -0,0 +1,41 @@
+###
+# #%L
+# Nuiton Utils
+#
+# $Id$
+# $HeadURL$
+# %%
+# Copyright (C) 2004 - 2011 CodeLutin, Chatellier Eric
+# %%
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Lesser Public License for more details.
+#
+# You should have received a copy of the GNU General Lesser Public
+# License along with this program. If not, see
+# <http://www.gnu.org/licenses/lgpl-3.0.html>.
+# #L%
+###
+# Global logging configuration
+log4j.rootLogger=DEBUG, stdout, fileout
+
+# Console output...
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n
+
+log4j.appender.fileout=org.apache.log4j.FileAppender
+log4j.appender.fileout.File=target/nuitontrace.log
+log4j.appender.fileout.Append=true
+log4j.appender.fileout.Threshold=DEBUG
+log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
+log4j.appender.fileout.layout.ConversionPattern=%5p (%F:%L) %m%n
+
+# package level
+#log4j.logger.org.apache.commons.logging.Log=DEBUG
1
0
Author: athimel
Date: 2011-08-22 12:58:03 +0200 (Mon, 22 Aug 2011)
New Revision: 2176
Url: http://nuiton.org/repositories/revision/nuiton-utils/2176
Log:
Check asm-attrs and asm-util groupId in exclusion
Modified:
trunk/nuiton-profiling/pom.xml
trunk/pom.xml
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-profiling/pom.xml 2011-08-22 10:50:32 UTC (rev 2175)
+++ trunk/nuiton-profiling/pom.xml 2011-08-22 10:58:03 UTC (rev 2176)
@@ -56,20 +56,6 @@
<groupId>aspectwerkz</groupId>
<artifactId>aspectwerkz-core</artifactId>
<scope>runtime</scope>
- <exclusions>
- <exclusion>
- <groupId>asm</groupId>
- <artifactId>asm</artifactId>
- </exclusion>
- <exclusion>
- <groupId>asm</groupId>
- <artifactId>asm-attrs</artifactId>
- </exclusion>
- <exclusion>
- <groupId>asm</groupId>
- <artifactId>asm-util</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-08-22 10:50:32 UTC (rev 2175)
+++ trunk/pom.xml 2011-08-22 10:58:03 UTC (rev 2176)
@@ -78,6 +78,20 @@
<groupId>aspectwerkz</groupId>
<artifactId>aspectwerkz-core</artifactId>
<version>${aspectwerkzVersion}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>asm-attrs</groupId>
+ <artifactId>asm-attrs</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>asm-util</groupId>
+ <artifactId>asm-util</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
1
0
Author: tchemit
Date: 2011-08-22 12:50:32 +0200 (Mon, 22 Aug 2011)
New Revision: 2175
Url: http://nuiton.org/repositories/revision/nuiton-utils/2175
Log:
fix asm bad dependencies
Modified:
trunk/nuiton-profiling/pom.xml
trunk/pom.xml
Modified: trunk/nuiton-profiling/pom.xml
===================================================================
--- trunk/nuiton-profiling/pom.xml 2011-08-22 10:47:48 UTC (rev 2174)
+++ trunk/nuiton-profiling/pom.xml 2011-08-22 10:50:32 UTC (rev 2175)
@@ -50,13 +50,42 @@
<artifactId>commons-lang</artifactId>
</dependency>
+ <!-- aspectwerkz use asm* dependencies which are not on central... -->
+ <!-- Event if we relocated them to a org.nuiton.thirdparty groupId -->
<dependency>
<groupId>aspectwerkz</groupId>
<artifactId>aspectwerkz-core</artifactId>
<scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>asm</groupId>
+ <artifactId>asm-attrs</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>asm</groupId>
+ <artifactId>asm-util</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
+ <groupId>org.nuiton.thirdparty</groupId>
+ <artifactId>asm</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.thirdparty</groupId>
+ <artifactId>asm-attrs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.thirdparty</groupId>
+ <artifactId>asm-util</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>aspectwerkz</groupId>
<artifactId>aspectwerkz</artifactId>
<scope>compile</scope>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-08-22 10:47:48 UTC (rev 2174)
+++ trunk/pom.xml 2011-08-22 10:50:32 UTC (rev 2175)
@@ -22,7 +22,9 @@
<http://www.gnu.org/licenses/lgpl-3.0.html>.
#L%
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -90,6 +92,22 @@
<version>${aspectwerkzVersion}</version>
</dependency>
+ <dependency>
+ <groupId>org.nuiton.thirdparty</groupId>
+ <artifactId>asm</artifactId>
+ <version>${asmVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.thirdparty</groupId>
+ <artifactId>asm-attrs</artifactId>
+ <version>${asmVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.thirdparty</groupId>
+ <artifactId>asm-util</artifactId>
+ <version>${asmVersion}</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>
@@ -184,11 +202,12 @@
<projectId>nuiton-utils</projectId>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
<aspectwerkzVersion>2.0</aspectwerkzVersion>
+ <asmVersion>1.5.4-snapshot</asmVersion>
<xworkVersion>2.2.3</xworkVersion>
<!-- i18n configuration -->
<i18n.bundles>fr_FR,en_GB,es_ES</i18n.bundles>
-
+
</properties>
<distributionManagement>
1
0
r2174 - trunk/nuiton-profiling/src/main/java/org/nuiton/profiling
by tchemit@users.nuiton.org 22 Aug '11
by tchemit@users.nuiton.org 22 Aug '11
22 Aug '11
Author: tchemit
Date: 2011-08-22 12:47:48 +0200 (Mon, 22 Aug 2011)
New Revision: 2174
Url: http://nuiton.org/repositories/revision/nuiton-utils/2174
Log:
Make javadoc at least renderable... But still not understable for a quidam :(
Modified:
trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java
Modified: trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java
===================================================================
--- trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-19 18:56:55 UTC (rev 2173)
+++ trunk/nuiton-profiling/src/main/java/org/nuiton/profiling/NuitonTrace.java 2011-08-22 10:47:48 UTC (rev 2174)
@@ -45,12 +45,10 @@
* Pour l'utiliser il faut définir un fichier XML qui intercepte les methodes
* souhaiter.
* <pre>
- * <?xml version="1.0" encoding="ISO-8859-1"?>
- * <p/>
+ * <?xml version="1.0" encoding="UTF-8"?>
* <!DOCTYPE aspectwerkz PUBLIC
* "-//AspectWerkz//DTD//EN"
* "http://aspectwerkz.codehaus.org/dtd/aspectwerkz2.dtd">
- * <p/>
* <aspectwerkz>
* <system id="sample">
* <aspect class="fr.ifremer.isisfish.aspect.TraceIsis">
@@ -66,30 +64,26 @@
* </aspect>
* </system>
* </aspectwerkz>
- * <p/>
* </pre>
* Ensuite il faut lancer la JVM avec deux options
- * <li> -javaagent:path/to/aspectwerkz-jdk5-2.0.jar
- * <li> -Daspectwerkz.definition.file=path/to/trace-aop.xml
- * <p/>
+ * <pre>
+ * -Djavaagent:path/to/aspectwerkz-jdk5-2.0.jar
+ * -Daspectwerkz.definition.file=path/to/trace-aop.xml
+ * </pre>
* il doit être possible d'utiliser des noms normalisé et
* trouvable dans le classpath a la place de -Daspectwerkz.definition.file
* <li> /aspectwerkz.xml
* <li> META-INF/aop.xml
* <li> WEB-INF/aop.xml
- * <p/>
+ * <br/>
* Ensuite pour afficher les statistiques dans votre programme
* <li> log.info(NuitonTrace.getStatisticsAndClear());
* <li> NuitonTrace.printStatistiqueAndClear();
- * <p/>
- * <p/>
- * <p/>
* Il doit être possible, plutot que d'écrire un fichier XML, de sous classer
* NuitonTrace en ajoutant par exemple
- * <p/>
*
- * @author poussin
- * @Expression( "execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..))" +
+ * <pre>
+ * \@Expression( "execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..))" +
* "|| execution(* fr.ifremer.isisfish.aspect.Cache.*(..))" +
* "|| execution(* fr.ifremer.isisfish.aspect.Trace.*(..))" +
* "|| execution(* org.nuiton.topia..*(..))" +
@@ -98,6 +92,12 @@
* "|| execution(* org.apache.commons.collections..*(..))"
* )
* Pointcut executeMethod;
+ * </pre>
+ *
+ * <p/>
+ *
+ * @author poussin
+ *
* </p>
*/
@Aspect("perJVM")
@@ -135,17 +135,6 @@
/** array : [nest method call, start time, start time with child] */
protected Stack<long[]> callStack = new Stack<long[]>();
-// @Expression(
-// "execution(* fr.ifremer.isisfish.datastore.ResultStorage.*(..))" +
-// "|| execution(* fr.ifremer.isisfish.aspect.Cache.*(..))" +
-// "|| execution(* fr.ifremer.isisfish.aspect.Trace.*(..))" +
-// "|| execution(* org.nuiton.topia..*(..))" +
-// "|| execution(* org.nuiton.math.matrix..*(..))" +
-// "|| execution(* fr.ifremer.isisfish.types..*(..))" +
-// "|| execution(* org.apache.commons.collections..*(..))"
-// )
-// Pointcut executeMethod;
-
public NuitonTrace() {
instances.add(this);
}
1
0
r2173 - trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field
by bpoussin@users.nuiton.org 19 Aug '11
by bpoussin@users.nuiton.org 19 Aug '11
19 Aug '11
Author: bpoussin
Date: 2011-08-19 20:56:55 +0200 (Fri, 19 Aug 2011)
New Revision: 2173
Url: http://nuiton.org/repositories/revision/nuiton-utils/2173
Log:
Evolution #1686: Add new standard validators
- enhance Luhn checksum algorithme implementation (less string -> int conversion)
Modified:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java 2011-08-19 16:29:21 UTC (rev 2172)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java 2011-08-19 18:56:55 UTC (rev 2173)
@@ -106,12 +106,15 @@
* @return vrai si on a reussi a valider le numero
*/
static public boolean luhnChecksum(String siret) {
- // variable intermediaire pour stocker le resultat de la 1ere multiplication
- // on restocke dans une chaine, car il faut additionner les composantes
- // des nombres et non pas les nombres eux meme.
- String tmp = "";
- for (int i=siret.length()-1; i>=0; i--) {
- int n = getDigit(siret, i);
+
+ char[] tab = siret.toCharArray();
+ int sum = 0;
+ for (int i=tab.length-1; i>=0; i--) {
+ // recuperation de la valeur
+ int n = getDigit(tab[i]);
+
+ // 1ere phase il faut faire la multiplication par 1 ou 2
+
// il faut faire x1 pour les paires et x2 sur les impaires.
// en prenant en compte que le numero siret le plus a droite est le
// 1 et le plus a gauche le 14.
@@ -119,13 +122,17 @@
// il faut faire +1 sur l'indice puis un simple module 2 + 1
// nous convient
n *= (i+1)%2+1;
- tmp = n + tmp;
- }
- // 2eme phase on additionne tous les chiffres
- int sum = 0;
- for (int i=0; i<tmp.length(); i++) {
- int n = getDigit(tmp, i);
+ // 2eme phase il faut faire l'addition
+
+ // si une fois multiplie il est superieur a 9, il faut additionner
+ // toutes ces constituante, mais comme il ne peut pas etre superieur
+ // a 18, cela revient a retrancher 9
+ if (n > 9) {
+ n -= 9;
+ }
+
+ // on peut directement faire la somme
sum += n;
}
@@ -137,16 +144,22 @@
/**
- * Recupere un des chiffres de la string qui ne contient que des chiffres
+ * 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
*
- * @param s une chaine ne contenant que des chiffres ex: 1234455688
- * @param indice la position du chiffre a recuperer, l'indice doit etre entre
- * 0 et s.length()-1
+ * @param c le caractere qui doit etre converti
* @return le chiffre
*/
- static public int getDigit(String s, int indice) {
- String d = s.substring(indice, indice+1);
- int result = Integer.parseInt(d);
+ static public int getDigit(char c) {
+ int result = 0;
+ if (c >= '0' && c <= '9') {
+ result = c - '0';
+ } else if (c >= 'A' && c <= 'Z'){
+ result = c - 'A' + 10;
+ } else {
+ result = c - 'a' + 10;
+ }
return result;
}
}
1
0
Author: tchemit
Date: 2011-08-19 18:29:21 +0200 (Fri, 19 Aug 2011)
New Revision: 2172
Url: http://nuiton.org/repositories/revision/nuiton-utils/2172
Log:
Update mavenpom4redmineAndCentral to 3.0.2.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-08-19 15:56:03 UTC (rev 2171)
+++ trunk/pom.xml 2011-08-19 16:29:21 UTC (rev 2172)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>3.0.1</version>
+ <version>3.0.2</version>
</parent>
<artifactId>nuiton-utils-parent</artifactId>
1
0
r2171 - in trunk/nuiton-validator/src: main/java/org/nuiton/validator/xwork2/field test/java/org/nuiton/validator/xwork2/field
by bpoussin@users.nuiton.org 19 Aug '11
by bpoussin@users.nuiton.org 19 Aug '11
19 Aug '11
Author: bpoussin
Date: 2011-08-19 17:56:03 +0200 (Fri, 19 Aug 2011)
New Revision: 2171
Url: http://nuiton.org/repositories/revision/nuiton-utils/2171
Log:
Evolution #1686: Add new standard validators
- SIRET can be in other format that String (int, long, array, collection, ...)
- use Luhn checksum for SIRET
Modified:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java 2011-08-19 13:18:58 UTC (rev 2170)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java 2011-08-19 15:56:03 UTC (rev 2171)
@@ -26,19 +26,26 @@
import com.opensymphony.xwork2.validator.ValidationException;
import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+import java.lang.reflect.Array;
+import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Validator for French SIRET numbers
+ *
+ * Siret can be in:
+ * <li>String format: "44211670300038"
+ * <li>long, int: 44211670300038
+ * <li>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"]
+ *
+ * Validation do the Luhn checksum too
*/
public class SiretFieldValidator extends FieldValidatorSupport {
- protected static String LAST_NAME_REGEXP = "[0-9]{14}";
- protected static Pattern p = Pattern.compile(LAST_NAME_REGEXP);
+ protected static final String SIRET_REGEXP = "[0-9]{14}";
+ protected static final Pattern p = Pattern.compile(SIRET_REGEXP);
- //TODO JC-19082011- Need to validate the numbers too cf: http://fr.wikipedia.org/wiki/SIRET
-
@Override
public void validate(Object object) throws ValidationException {
@@ -49,15 +56,30 @@
// no value defined
return;
}
- if (value instanceof String) {
- Matcher m = p.matcher((String) value);
- if (!m.matches()) {
- addFieldError(fieldName, object);
- return;
+ String siret;
+
+ if (value.getClass().isArray()) {
+ // le siret est stocker dans un tableau, par exemple un byte[]
+ siret = "";
+ for (int i=0; i<Array.getLength(value); i++) {
+ siret += String.valueOf(Array.get(value, i));
}
+ } else if (value instanceof Collection) {
+ // le siret est stocker dans une collection,
+ // ca doit pas arriver souvent :D, mais autant le gerer
+ siret = "";
+ for (Object o : (Collection)value) {
+ siret += String.valueOf(o);
+ }
} else {
+ // sinon dans tous les autres cas (String, int, long, BigInteger ...)
+ // on prend le toString
+ siret = String.valueOf(value);
+ }
+
+ Matcher m = p.matcher(siret);
+ if (!m.matches() || !luhnChecksum(siret)) {
addFieldError(fieldName, object);
- return;
}
}
@@ -65,4 +87,66 @@
public String getValidatorType() {
return "siret";
}
+
+ /**
+ * Verifie la validite d'un numero en suivant l'algorithme Luhn tel que d'ecrit
+ * dans <a href="http://fr.wikipedia.org/wiki/Luhn">wikipedia</a>
+ *
+ * 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.
+ *
+ * @param siret une chaine composer que de chiffre
+ * @return vrai si on a reussi a valider le numero
+ */
+ static public boolean luhnChecksum(String siret) {
+ // variable intermediaire pour stocker le resultat de la 1ere multiplication
+ // on restocke dans une chaine, car il faut additionner les composantes
+ // des nombres et non pas les nombres eux meme.
+ String tmp = "";
+ for (int i=siret.length()-1; i>=0; i--) {
+ int n = getDigit(siret, i);
+ // il faut faire x1 pour les paires et x2 sur les impaires.
+ // en prenant en compte que le numero siret le plus a droite est le
+ // 1 et le plus a gauche le 14.
+ // mais comme en informatique on commence a 0 :D
+ // il faut faire +1 sur l'indice puis un simple module 2 + 1
+ // nous convient
+ n *= (i+1)%2+1;
+ tmp = n + tmp;
+ }
+
+ // 2eme phase on additionne tous les chiffres
+ int sum = 0;
+ for (int i=0; i<tmp.length(); i++) {
+ int n = getDigit(tmp, i);
+ sum += n;
+ }
+
+ // 3eme phase on verifie que c'est bien un multiple de 10
+ boolean result = (sum % 10 == 0);
+
+ return result;
+ }
+
+
+ /**
+ * Recupere un des chiffres de la string qui ne contient que des chiffres
+ *
+ * @param s une chaine ne contenant que des chiffres ex: 1234455688
+ * @param indice la position du chiffre a recuperer, l'indice doit etre entre
+ * 0 et s.length()-1
+ * @return le chiffre
+ */
+ static public int getDigit(String s, int indice) {
+ String d = s.substring(indice, indice+1);
+ int result = Integer.parseInt(d);
+ return result;
+ }
}
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java 2011-08-19 13:18:58 UTC (rev 2170)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java 2011-08-19 15:56:03 UTC (rev 2171)
@@ -38,6 +38,18 @@
}
@Test
+ public void TestLuhnChecksum () throws Exception {
+ // verification sur de vrai numero siret (ca doit passer :)
+ assertTrue(SiretFieldValidator.luhnChecksum("44211670300038"));
+ assertTrue(SiretFieldValidator.luhnChecksum("73282932000074"));
+
+ // verification avec les memes, en ne modifiant que le dernier chiffre
+ // ca doit failer
+ assertFalse(SiretFieldValidator.luhnChecksum("44211670300030"));
+ assertFalse(SiretFieldValidator.luhnChecksum("73282932000070"));
+ }
+
+ @Test
@Override
public void testValidator() throws Exception {
@@ -48,6 +60,16 @@
assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
false);
+ // Valid siret
+ bean.setSiret("73282932000074");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ false);
+
+ // Not Valid siret, because bad checksum
+ bean.setSiret("73282932000071");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ true);
+
// Not valid siret
bean.setSiret("4421167030003");
assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
1
0
r2170 - in trunk/nuiton-validator/src: main/java/org/nuiton/validator/xwork2/field test/java/org/nuiton/validator/model test/java/org/nuiton/validator/xwork2/field test/resources test/resources/org/nuiton/validator/model
by jcouteau@users.nuiton.org 19 Aug '11
by jcouteau@users.nuiton.org 19 Aug '11
19 Aug '11
Author: jcouteau
Date: 2011-08-19 15:18:58 +0200 (Fri, 19 Aug 2011)
New Revision: 2170
Url: http://nuiton.org/repositories/revision/nuiton-utils/2170
Log:
Vat and Siret validators
Added:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java
trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml
Modified:
trunk/nuiton-validator/src/test/resources/validators.xml
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/SiretFieldValidator.java 2011-08-19 13:18:58 UTC (rev 2170)
@@ -0,0 +1,68 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validator for French SIRET numbers
+ */
+public class SiretFieldValidator extends FieldValidatorSupport {
+
+ protected static String LAST_NAME_REGEXP = "[0-9]{14}";
+ protected static Pattern p = Pattern.compile(LAST_NAME_REGEXP);
+
+ //TODO JC-19082011- Need to validate the numbers too cf: http://fr.wikipedia.org/wiki/SIRET
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String) value);
+ if (!m.matches()) {
+ addFieldError(fieldName, object);
+ return;
+ }
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "siret";
+ }
+}
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/VATIntraFieldValidator.java 2011-08-19 13:18:58 UTC (rev 2170)
@@ -0,0 +1,66 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validator for EU VAT number
+ */
+public class VATIntraFieldValidator extends FieldValidatorSupport {
+
+ protected static String VAT_INTRA_REGEXP = "^(RO\\d{2,10}|GB\\d{5}|(ATU|DK|FI|HU|LU|MT|CZ|SI)\\d{8}|IE[A-Z\\d]{8}|(DE|BG|EE|EL|LT|BE0|PT|CZ)\\d{9}|CY\\d{8}[A-Z]|(ES|GB)[A-Z\\d]{9}|(BE0|PL|SK|CZ)\\d{10}|(FR|IT|LV)\\d{11}|(LT|SE)\\d{12}|(NL|GB)[A-Z\\d]{12})$";
+ protected static Pattern p = Pattern.compile(VAT_INTRA_REGEXP);
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String) value);
+ if (!m.matches()) {
+ addFieldError(fieldName, object);
+ return;
+ }
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "VATIntra";
+ }
+}
Added: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Company.java 2011-08-19 13:18:58 UTC (rev 2170)
@@ -0,0 +1,55 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.model;
+
+/**
+ *
+ */
+public class Company {
+
+ public static final String PROPERTY_VAT_NUMBER = "vat";
+
+ public static final String PROPERTY_SIRET = "siret";
+
+ protected String vat;
+
+ protected String siret;
+
+ public String getVat() {
+ return vat;
+ }
+
+ public void setVat(String vat) {
+ this.vat = vat;
+ }
+
+ public String getSiret() {
+ return siret;
+ }
+
+ public void setSiret(String siret) {
+ this.siret = siret;
+ }
+}
Added: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/SiretFieldValidatorTest.java 2011-08-19 13:18:58 UTC (rev 2170)
@@ -0,0 +1,66 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Company;
+
+/**
+ * User: couteau
+ * Date: 19/08/11
+ */
+public class SiretFieldValidatorTest extends AbstractFieldValidatorTest<Company> {
+
+ public SiretFieldValidatorTest() {
+ super(Company.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getSiret());
+
+ // Valid siret
+ bean.setSiret("44211670300038");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ false);
+
+ // Not valid siret
+ bean.setSiret("4421167030003");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ true);
+
+ // Not valid siret
+ bean.setSiret("442116703000389");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ true);
+
+ // Not valid siret
+ bean.setSiret("4421bf1670300038");
+ assertFieldInError(Company.PROPERTY_SIRET, "company.siret.format",
+ true);
+ }
+}
Added: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/VatIntraFieldValidatorTest.java 2011-08-19 13:18:58 UTC (rev 2170)
@@ -0,0 +1,65 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Company;
+
+/**
+ *
+ */
+public class VatIntraFieldValidatorTest extends AbstractFieldValidatorTest<Company> {
+
+ public VatIntraFieldValidatorTest() {
+ super(Company.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getVat());
+
+ // Valid vat
+ bean.setVat("FR57442116703");
+ assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
+ false);
+
+ // Not valid vat
+ bean.setVat("FR 57 44211670332");
+ assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
+ true);
+
+ // Not valid vat
+ bean.setVat("442116703000389");
+ assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
+ true);
+
+ // Not valid vat, spaces in it
+ bean.setVat("FR 57 442116703");
+ assertFieldInError(Company.PROPERTY_VAT_NUMBER, "company.vat.format",
+ true);
+ }
+}
Added: trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml
===================================================================
--- trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml (rev 0)
+++ trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Company-error-validation.xml 2011-08-19 13:18:58 UTC (rev 2170)
@@ -0,0 +1,42 @@
+<!--
+ #%L
+ Nuiton Utils :: Nuiton Validator
+
+ $Id$
+ $HeadURL$
+ %%
+ Copyright (C) 2011 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
+<!DOCTYPE validators PUBLIC
+ "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+ "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+<validators>
+
+ <field name="siret">
+ <field-validator type="siret">
+ <message>company.siret.format</message>
+ </field-validator>
+ </field>
+
+ <field name="vat">
+ <field-validator type="vat">
+ <message>company.vat.format</message>
+ </field-validator>
+ </field>
+
+</validators>
\ No newline at end of file
Modified: trunk/nuiton-validator/src/test/resources/validators.xml
===================================================================
--- trunk/nuiton-validator/src/test/resources/validators.xml 2011-08-19 07:35:44 UTC (rev 2169)
+++ trunk/nuiton-validator/src/test/resources/validators.xml 2011-08-19 13:18:58 UTC (rev 2170)
@@ -61,5 +61,7 @@
<validator name="cityName" class="org.nuiton.validator.xwork2.field.CityNameFieldValidator"/>
<validator name="lastName" class="org.nuiton.validator.xwork2.field.LastNameFieldValidator"/>
<validator name="postCode" class="org.nuiton.validator.xwork2.field.PostCodeFieldValidator"/>
+ <validator name="siret" class="org.nuiton.validator.xwork2.field.SiretFieldValidator"/>
+ <validator name="vat" class="org.nuiton.validator.xwork2.field.VATIntraFieldValidator"/>
</validators>
\ No newline at end of file
1
0
r2169 - in trunk/nuiton-validator/src: main/java/org/nuiton/validator/xwork2/field test/java/org/nuiton/validator/model test/java/org/nuiton/validator/xwork2/field
by jcouteau@users.nuiton.org 19 Aug '11
by jcouteau@users.nuiton.org 19 Aug '11
19 Aug '11
Author: jcouteau
Date: 2011-08-19 09:35:44 +0200 (Fri, 19 Aug 2011)
New Revision: 2169
Url: http://nuiton.org/repositories/revision/nuiton-utils/2169
Log:
Does not put the fields mandatory, there is another validator for that
Add License header
Modified:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
@@ -25,7 +49,6 @@
if (value == null) {
// no value defined
- addFieldError(fieldName, object);
return;
}
if (value instanceof String) {
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
@@ -18,7 +42,6 @@
if (value == null) {
// no value defined
- addFieldError(fieldName, object);
return;
}
if (value instanceof String) {
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
@@ -23,7 +47,6 @@
if (value == null) {
// no value defined
- addFieldError(fieldName, object);
return;
}
if (value instanceof String) {
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
@@ -26,7 +50,6 @@
if (value == null) {
// no value defined
- addFieldError(fieldName, object);
return;
}
if (value instanceof String) {
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.xwork2.field;
import com.opensymphony.xwork2.validator.ValidationException;
@@ -25,7 +49,6 @@
if (value == null) {
// no value defined
- addFieldError(fieldName, object);
return;
}
if (value instanceof String) {
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.model;
/**
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.xwork2.field;
import org.junit.Test;
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.xwork2.field;
import org.junit.Test;
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.xwork2.field;
import org.junit.Test;
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.xwork2.field;
import org.junit.Test;
Modified: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java 2011-08-18 15:20:18 UTC (rev 2168)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java 2011-08-19 07:35:44 UTC (rev 2169)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Validator
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.validator.xwork2.field;
import org.junit.Test;
1
0
r2168 - in trunk/nuiton-validator/src: main/java/org/nuiton/validator/xwork2/field test/java/org/nuiton/validator/model test/java/org/nuiton/validator/xwork2/field test/resources test/resources/org/nuiton/validator/model
by jcouteau@users.nuiton.org 18 Aug '11
by jcouteau@users.nuiton.org 18 Aug '11
18 Aug '11
Author: jcouteau
Date: 2011-08-18 17:20:18 +0200 (Thu, 18 Aug 2011)
New Revision: 2168
Url: http://nuiton.org/repositories/revision/nuiton-utils/2168
Log:
Add validators for #1686
Added:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java
trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java
trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml
Modified:
trunk/nuiton-validator/src/test/resources/validators.xml
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/CityNameFieldValidator.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,47 @@
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validator for French cities names :
+ * - No number accepted
+ * - Accept spaces, - and '
+ */
+public class CityNameFieldValidator extends FieldValidatorSupport {
+
+ protected static String CITY_NAME_REGEXP = "[^\\d]+";
+ protected static Pattern p = Pattern.compile(CITY_NAME_REGEXP);
+
+ //TODO JC18082011 - Deal with cedex
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ addFieldError(fieldName, object);
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String) value);
+ if (!m.matches()) {
+ addFieldError(fieldName, object);
+ return;
+ }
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "cityName";
+ }
+}
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/EmailFieldValidator.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,39 @@
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+import org.nuiton.util.StringUtil;
+
+/**
+ * Validator for email addresses :
+ * - Deal with + in addresses
+ */
+public class EmailFieldValidator extends FieldValidatorSupport {
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ addFieldError(fieldName, object);
+ return;
+ }
+ if (value instanceof String) {
+ if (!StringUtil.isEmail((String)value)) {
+ addFieldError(fieldName, object);
+ return;
+ }
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "email";
+ }
+}
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/LastNameFieldValidator.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,45 @@
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validator for French last names :
+ * - No number accepted
+ * - Accept spaces, - and '
+ */
+public class LastNameFieldValidator extends FieldValidatorSupport {
+
+ protected static String LAST_NAME_REGEXP = "[^\\d]+";
+ protected static Pattern p = Pattern.compile(LAST_NAME_REGEXP);
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ addFieldError(fieldName, object);
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String) value);
+ if (!m.matches()) {
+ addFieldError(fieldName, object);
+ return;
+ }
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "lastName";
+ }
+}
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidator.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,48 @@
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ *
+ * Validator used to validate French phone numbers like :
+ * - 0000000000
+ * - 00.00.00.00.00
+ * - 00-00-00-00-00
+ * - 00 00 00 00 00
+ */
+public class PhoneNumberFieldValidator extends FieldValidatorSupport {
+
+ protected static String PHONE_NUMBER_REGEXP = "[0-9]{10}|(([0-9]{2}[-\\.\\s]){4})[0-9]{2}";
+ protected static Pattern p = Pattern.compile(PHONE_NUMBER_REGEXP);
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ addFieldError(fieldName, object);
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String)value);
+ if (!m.matches()){
+ addFieldError(fieldName, object);
+ return;
+ }
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "phoneNumber";
+ }
+}
Added: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java (rev 0)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidator.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,47 @@
+package org.nuiton.validator.xwork2.field;
+
+import com.opensymphony.xwork2.validator.ValidationException;
+import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Validate post codes for French cities
+ *
+ * - Take into account 2A and 2B
+ * - Take into account DOMs and TOMs
+ * - Postcodes starting with 99 are not valid
+ */
+public class PostCodeFieldValidator extends FieldValidatorSupport {
+
+ protected static String POST_CODE_REGEXP = "^((0[1-9])|([1-8][0-9])|(9[0-8])|(2A)|(2B))[0-9]{3}$";
+ protected static Pattern p = Pattern.compile(POST_CODE_REGEXP);
+
+ @Override
+ public void validate(Object object) throws ValidationException {
+
+ String fieldName = getFieldName();
+ Object value = getFieldValue(fieldName, object);
+
+ if (value == null) {
+ // no value defined
+ addFieldError(fieldName, object);
+ return;
+ }
+ if (value instanceof String) {
+ Matcher m = p.matcher((String) value);
+ if (!m.matches()) {
+ addFieldError(fieldName, object);
+ return;
+ }
+ } else {
+ addFieldError(fieldName, object);
+ return;
+ }
+ }
+
+ @Override
+ public String getValidatorType() {
+ return "postCode";
+ }
+}
Added: trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/model/Contact.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,67 @@
+package org.nuiton.validator.model;
+
+/**
+ *
+ */
+public class Contact {
+
+ public static final String PROPERTY_LAST_NAME = "name";
+
+ public static final String PROPERTY_EMAIL = "email";
+
+ public static final String PROPERTY_PHONE = "phone";
+
+ public static final String PROPERTY_POSTCODE = "postCode";
+
+ public static final String PROPERTY_CITY = "city";
+
+ protected String name;
+
+ protected String email;
+
+ protected String phone;
+
+ protected String postCode;
+
+ protected String city;
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ public String getPostCode() {
+ return postCode;
+ }
+
+ public void setPostCode(String postCode) {
+ this.postCode = postCode;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/CityNameFieldValidatorTest.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,72 @@
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Contact;
+
+/**
+ *
+ */
+public class CityNameFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
+
+ public CityNameFieldValidatorTest() {
+ super(Contact.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getCity());
+
+ // Valid city
+ bean.setCity("Nantes");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("Couëron");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("Saint Sébastien Sur Loire");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("St Sebastien sur Loire");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("St-Sebastien-sur-Loire");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("Y");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Valid city
+ bean.setCity("Saint-Remy-en-Bouzemont-Saint-Genest-et-Isson");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ false);
+
+ // Not Valid city name
+ bean.setCity("2Ville");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ true);
+
+ // Not Valid city name
+ bean.setCity("Ville2Merde");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ true);
+
+ // Not Valid city name
+ bean.setCity("Ville 2 Merde");
+ assertFieldInError(Contact.PROPERTY_CITY, "contact.city.format",
+ true);
+
+ }
+}
Added: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/EmailFieldValidatorTest.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,34 @@
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Contact;
+
+/**
+ *
+ */
+public class EmailFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
+
+ public EmailFieldValidatorTest() {
+ super(Contact.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getEmail());
+
+ // Valid email
+ bean.setEmail("toto(a)toto.com");
+ assertFieldInError(Contact.PROPERTY_EMAIL, "contact.email.format", false);
+
+ // Valid email with +
+ bean.setEmail("toto+validation(a)toto.com");
+ assertFieldInError(Contact.PROPERTY_EMAIL, "contact.email.format", false);
+
+ // Not valid email
+ bean.setEmail("toto");
+ assertFieldInError(Contact.PROPERTY_EMAIL, "contact.email.format", true);
+
+ }
+}
Added: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/LastNameFieldValidatorTest.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,54 @@
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Contact;
+
+/**
+ * User: couteau
+ * Date: 18/08/11
+ */
+public class LastNameFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
+
+ public LastNameFieldValidatorTest() {
+ super(Contact.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getCity());
+
+ // Valid name
+ bean.setName("Couteau");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ false);
+
+ // Valid name
+ bean.setName("Le Ny");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ false);
+
+ // Valid name
+ bean.setName("Clémenceau");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ false);
+
+ // Valid name
+ bean.setName("Couteau--Viney");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ false);
+
+ // Not valid name
+ bean.setName("2Pac");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ true);
+
+ // Not valid name
+ bean.setName("Nom2Merde");
+ assertFieldInError(Contact.PROPERTY_LAST_NAME, "contact.name.format",
+ true);
+
+
+ }
+}
Added: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PhoneNumberFieldValidatorTest.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,103 @@
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Contact;
+
+/**
+ * User: couteau
+ * Date: 18/08/11
+ */
+public class PhoneNumberFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
+
+ public PhoneNumberFieldValidatorTest() {
+ super(Contact.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getPhone());
+
+ // Valid phone Number
+ bean.setPhone("0000000000");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ false);
+
+ // Valid phone Number
+ bean.setPhone("00 00 00 00 00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ false);
+
+ // Valid phone Number
+ bean.setPhone("00-00-00-00-00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ false);
+
+ // Valid phone Number
+ bean.setPhone("00.00.00.00.00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ false);
+
+ // Too long phone Number
+ bean.setPhone("00 00 00 00 00 00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too long phone Number
+ bean.setPhone("00-00-00-00-00-00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too long phone Number
+ bean.setPhone("000000000000");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too long phone Number
+ bean.setPhone("00.00.00.00.00.00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too short phone Number
+ bean.setPhone("00.00.00.00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too short phone Number
+ bean.setPhone("00000000");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too short phone Number
+ bean.setPhone("00-00-00-00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Too short phone Number
+ bean.setPhone("00 00 00 00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Invalid character in phone Number
+ bean.setPhone("00 00 ab 00 00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Invalid character in phone Number
+ bean.setPhone("0000ab0000");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Invalid character in phone Number
+ bean.setPhone("00.00.ab.00.00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ // Invalid character in phone Number
+ bean.setPhone("00-00-ab-00-00");
+ assertFieldInError(Contact.PROPERTY_PHONE, "contact.phoneNumber.format",
+ true);
+
+ }
+}
Added: trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java
===================================================================
--- trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java (rev 0)
+++ trunk/nuiton-validator/src/test/java/org/nuiton/validator/xwork2/field/PostCodeFieldValidatorTest.java 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,57 @@
+package org.nuiton.validator.xwork2.field;
+
+import org.junit.Test;
+import org.nuiton.validator.model.Contact;
+
+/**
+ *
+ */
+public class PostCodeFieldValidatorTest extends AbstractFieldValidatorTest<Contact> {
+
+ public PostCodeFieldValidatorTest() {
+ super(Contact.class);
+ }
+
+ @Test
+ @Override
+ public void testValidator() throws Exception {
+
+ assertNull(bean.getPostCode());
+
+ // Valid postCode
+ bean.setPostCode("44230");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ false);
+
+ // Valid postCode for Corsica
+ bean.setEmail("2A220");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ false);
+
+ // Valid postCode for DOM
+ bean.setEmail("97120");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ false);
+
+ // Valid postCode for TOM
+ bean.setPostCode("98120");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ false);
+
+ // Too long postCode
+ bean.setPostCode("442300");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ true);
+
+ // Too short postCode
+ bean.setPostCode("4423");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ true);
+
+ // postCode cannot start with 99
+ bean.setPostCode("99230");
+ assertFieldInError(Contact.PROPERTY_POSTCODE, "contact.postCode.format",
+ true);
+
+ }
+}
Added: trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml
===================================================================
--- trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml (rev 0)
+++ trunk/nuiton-validator/src/test/resources/org/nuiton/validator/model/Contact-error-validation.xml 2011-08-18 15:20:18 UTC (rev 2168)
@@ -0,0 +1,60 @@
+<!--
+ #%L
+ Nuiton Utils :: Nuiton Validator
+
+ $Id: Pet-error-validation.xml 2033 2011-01-23 17:28:26Z tchemit $
+ $HeadURL: http://svn.nuiton.org/svn/nuiton-utils/trunk/nuiton-validator/src/test/reso… $
+ %%
+ Copyright (C) 2011 CodeLutin
+ %%
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Lesser Public License for more details.
+
+ You should have received a copy of the GNU General Lesser Public
+ License along with this program. If not, see
+ <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ #L%
+ -->
+<!DOCTYPE validators PUBLIC
+ "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+ "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+<validators>
+
+ <field name="email">
+ <field-validator type="emailNuiton">
+ <message>contact.email.format</message>
+ </field-validator>
+ </field>
+
+ <field name="postCode">
+ <field-validator type="postCode">
+ <message>contact.postCode.format</message>
+ </field-validator>
+ </field>
+
+ <field name="city">
+ <field-validator type="cityName">
+ <message>contact.city.format</message>
+ </field-validator>
+ </field>
+
+ <field name="name">
+ <field-validator type="lastName">
+ <message>contact.name.format</message>
+ </field-validator>
+ </field>
+
+ <field name="phone">
+ <field-validator type="phoneNumber">
+ <message>contact.phoneNumber.format</message>
+ </field-validator>
+ </field>
+
+</validators>
\ No newline at end of file
Modified: trunk/nuiton-validator/src/test/resources/validators.xml
===================================================================
--- trunk/nuiton-validator/src/test/resources/validators.xml 2011-08-18 05:42:41 UTC (rev 2167)
+++ trunk/nuiton-validator/src/test/resources/validators.xml 2011-08-18 15:20:18 UTC (rev 2168)
@@ -56,5 +56,10 @@
<validator name="existingDirectory" class="org.nuiton.validator.xwork2.field.ExistingDirectoryFieldValidator"/>
<validator name="notExistingDirectory" class="org.nuiton.validator.xwork2.field.NotExistingDirectoryFieldValidator"/>
<validator name="fieldexpressionwithparams" class="org.nuiton.validator.xwork2.field.FieldExpressionWithParamsValidator"/>
+ <validator name="phoneNumber" class="org.nuiton.validator.xwork2.field.PhoneNumberFieldValidator"/>
+ <validator name="emailNuiton" class="org.nuiton.validator.xwork2.field.EmailFieldValidator"/>
+ <validator name="cityName" class="org.nuiton.validator.xwork2.field.CityNameFieldValidator"/>
+ <validator name="lastName" class="org.nuiton.validator.xwork2.field.LastNameFieldValidator"/>
+ <validator name="postCode" class="org.nuiton.validator.xwork2.field.PostCodeFieldValidator"/>
</validators>
\ No newline at end of file
1
0