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
November 2011
- 8 participants
- 28 discussions
Author: maven-release
Date: 2011-11-28 23:21:43 +0100 (Mon, 28 Nov 2011)
New Revision: 2238
Url: http://nuiton.org/repositories/revision/nuiton-utils/2238
Log:
Update mavenpom4redmineAndCentral to 3.0.6.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-11-27 09:45:05 UTC (rev 2237)
+++ trunk/pom.xml 2011-11-28 22:21:43 UTC (rev 2238)
@@ -31,7 +31,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmineAndCentral</artifactId>
- <version>3.0.5</version>
+ <version>3.0.6</version>
</parent>
<artifactId>nuiton-utils-parent</artifactId>
1
0
r2237 - trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field
by tchemit@users.nuiton.org 27 Nov '11
by tchemit@users.nuiton.org 27 Nov '11
27 Nov '11
Author: tchemit
Date: 2011-11-27 10:45:05 +0100 (Sun, 27 Nov 2011)
New Revision: 2237
Url: http://nuiton.org/repositories/revision/nuiton-utils/2237
Log:
Anomalie #1824: NuitonFieldExpressionValidator should not be abstract
Modified:
trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java
Modified: trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java
===================================================================
--- trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java 2011-11-25 11:41:48 UTC (rev 2236)
+++ trunk/nuiton-validator/src/main/java/org/nuiton/validator/xwork2/field/NuitonFieldExpressionValidator.java 2011-11-27 09:45:05 UTC (rev 2237)
@@ -40,7 +40,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.3
*/
-public abstract class NuitonFieldExpressionValidator extends FieldExpressionValidator {
+public class NuitonFieldExpressionValidator extends FieldExpressionValidator {
/**
* extra parameter at the very beginning of the
1
0
25 Nov '11
Author: tchemit
Date: 2011-11-25 12:41:48 +0100 (Fri, 25 Nov 2011)
New Revision: 2236
Url: http://nuiton.org/repositories/revision/nuiton-utils/2236
Log:
add simple ToStringformatter
Modified:
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java
Modified: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java 2011-11-24 11:55:28 UTC (rev 2235)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java 2011-11-25 11:41:48 UTC (rev 2236)
@@ -50,6 +50,9 @@
public static final ValueParserFormatter<String> STRING =
new StringValueParser();
+
+ public static final ValueFormatter<?> TO_STRING_FORMATTER =
+ new ToStringValueFormatter();
public static final ValueParserFormatter<Boolean> BOOLEAN =
new BooleanParserFormatter(null, true);
@@ -110,6 +113,14 @@
}
}
+ public static class ToStringValueFormatter implements ValueFormatter<Object> {
+
+ @Override
+ public String format(Object value) {
+ return value==null?"":value.toString();
+ }
+ }
+
public static class BeanProperty<E, T> implements ValueGetterSetter<E, T> {
protected String propertyName;
1
0
24 Nov '11
Author: bpoussin
Date: 2011-11-24 12:55:28 +0100 (Thu, 24 Nov 2011)
New Revision: 2235
Url: http://nuiton.org/repositories/revision/nuiton-utils/2235
Log:
Evolution #1823: [ApplicationConfig] add method to launch all Action in step order
Modified:
trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-11-24 11:22:15 UTC (rev 2234)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-11-24 11:55:28 UTC (rev 2235)
@@ -58,6 +58,7 @@
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
@@ -208,7 +209,8 @@
* <p/>
* Les actions ne sont pas execute mais seulement parsees. Pour les executer
* il faut utiliser la méthode {@link #doAction(int)} qui prend en argument un numero
- * de 'step'. Par defaut toutes les actions sont de niveau 0 et sont executee
+ * de 'step' ou {@link #doAllAction()} qui fait les actions dans l'ordre de leur step.
+ * Par defaut toutes les actions sont de niveau 0 et sont executee
* dans l'ordre d'apparition sur la ligne de commande. Si l'on souhaite
* distinguer les actions il est possible d'utiliser l'annotation
* {@link ApplicationConfig.Action.Step} sur la methode qui fera l'action en
@@ -672,6 +674,40 @@
}
/**
+ * Return ordered action step number.
+ * example: 0,1,5,6
+ *
+ * @since 2.4
+ */
+ public List<Integer> getActionStep() {
+ List<Integer> result = new ArrayList<Integer>(actions.keySet());
+ Collections.sort(result);
+ return result;
+ }
+
+ /**
+ * Do all action in specified order step (first 0).
+ *
+ * @param step do action only defined in this step
+ *
+ * @throws IllegalAccessException if action invocation failed
+ * @throws IllegalArgumentException if action invocation failed
+ * @throws InvocationTargetException if action invocation failed
+ * @throws InstantiationException if action invocation failed
+ *
+ * @see Action.Step
+ * @since 2.4
+ */
+ public void doAllAction() throws IllegalAccessException,
+ IllegalArgumentException,
+ InvocationTargetException,
+ InstantiationException {
+ for (int step : getActionStep()) {
+ doAction(step);
+ }
+ }
+
+ /**
* Do action in specified step.
*
* @param step do action only defined in this step
1
0
r2234 - in trunk/nuiton-csv/src: main/java/org/nuiton test/java/org/nuiton
by tchemit@users.nuiton.org 24 Nov '11
by tchemit@users.nuiton.org 24 Nov '11
24 Nov '11
Author: tchemit
Date: 2011-11-24 12:22:15 +0100 (Thu, 24 Nov 2011)
New Revision: 2234
Url: http://nuiton.org/repositories/revision/nuiton-utils/2234
Log:
remove utils package
Added:
trunk/nuiton-csv/src/test/java/org/nuiton/util/
Removed:
trunk/nuiton-csv/src/main/java/org/nuiton/utils/
trunk/nuiton-csv/src/test/java/org/nuiton/utils/
1
0
23 Nov '11
Author: tchemit
Date: 2011-11-23 11:29:27 +0100 (Wed, 23 Nov 2011)
New Revision: 2233
Url: http://nuiton.org/repositories/revision/nuiton-utils/2233
Log:
little improvements (use contructor factory,...)
Modified:
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java
Modified: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java 2011-11-22 18:14:23 UTC (rev 2232)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java 2011-11-23 10:29:27 UTC (rev 2233)
@@ -50,8 +50,13 @@
protected Collection<E> data;
- public Export(ExportModel<E> exportModel, Collection<E> data) {
- model = exportModel;
+ public static <E> Export<E> newExport(ExportModel<E> model,
+ Collection<E> data) {
+ return new Export<E>(model, data);
+ }
+
+ protected Export(ExportModel<E> model, Collection<E> data) {
+ this.model = model;
this.data = data;
}
Modified: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java 2011-11-22 18:14:23 UTC (rev 2232)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java 2011-11-23 10:29:27 UTC (rev 2233)
@@ -64,56 +64,16 @@
/** save once done to prevent multiple headers read leading to consider first lines as headers */
protected ValidationResult csvValidationResult;
- protected List<ImportableColumn<E, Object>> getNonIgnoredHeaders() {
- List<ImportableColumn<E, Object>> nonIgnoredHeaders = new ArrayList<ImportableColumn<E, Object>>();
- for (ImportableColumn<E, Object> field : model.getColumnsForImport()) {
- if (!field.isIgnored()) {
- nonIgnoredHeaders.add(field);
- }
- }
- return nonIgnoredHeaders;
+ public static <E> Import<E> newImport(ImportModel<E> model,
+ InputStream inputStream) {
+ return new Import<E>(model, inputStream);
}
- protected List<ImportableColumn<E, ?>> getAllMandatoryHeaders() {
- List<ImportableColumn<E, ?>> allMandatoryHeaders = new ArrayList<ImportableColumn<E, ?>>();
- for (ImportableColumn<E, ?> field : model.getColumnsForImport()) {
- if (field.isMandatory()) {
- allMandatoryHeaders.add(field);
- }
- }
- return allMandatoryHeaders;
+ public static <E> Import<E> newImport(ImportModel<E> model,
+ Reader reader) {
+ return new Import<E>(model, reader);
}
- public Import(ImportModel<E> model, InputStream inputStream) {
- if (inputStream == null) {
- throw new NullPointerException("inputStream is null");
- }
- this.model = model;
- reader = new CsvReader(inputStream, model.getSeparator(), Charset.forName("UTF-8"));
- reader.setTrimWhitespace(true);
- }
-
- public Import(ImportModel<E> model, Reader reader) {
- if (reader == null) {
- throw new NullPointerException("reader is null");
- }
- this.model = model;
- this.reader = new CsvReader(reader, model.getSeparator());
- this.reader.setTrimWhitespace(true);
- }
-
- protected boolean validateModel() {
- Set<String> headerNames = new HashSet<String>();
- for (ImportableColumn<E, ?> importableColumn : model.getColumnsForImport()) {
- String headerName = importableColumn.getHeaderName();
- boolean alreadyUsed = !headerNames.add(headerName);
- if (alreadyUsed) {
- throw new IllegalArgumentException("model contains multiple columnsForImport named '" + headerName + "'");
- }
- }
- return true;
- }
-
public ValidationResult validateCsv() throws IOException {
if (csvValidationResult == null) {
@@ -266,21 +226,72 @@
return result;
}
- protected void readFirstLine() {
+ public void stopImport() {
+ reader.close();
+ }
+
+ protected List<ImportableColumn<E, Object>> getNonIgnoredHeaders() {
+ List<ImportableColumn<E, Object>> nonIgnoredHeaders = new ArrayList<ImportableColumn<E, Object>>();
+ for (ImportableColumn<E, Object> field : model.getColumnsForImport()) {
+ if (!field.isIgnored()) {
+ nonIgnoredHeaders.add(field);
+ }
+ }
+ return nonIgnoredHeaders;
+ }
+
+ protected List<ImportableColumn<E, ?>> getAllMandatoryHeaders() {
+ List<ImportableColumn<E, ?>> allMandatoryHeaders = new ArrayList<ImportableColumn<E, ?>>();
+ for (ImportableColumn<E, ?> field : model.getColumnsForImport()) {
+ if (field.isMandatory()) {
+ allMandatoryHeaders.add(field);
+ }
+ }
+ return allMandatoryHeaders;
+ }
+
+ protected Import(ImportModel<E> model, InputStream inputStream) {
+ if (inputStream == null) {
+ throw new NullPointerException("inputStream is null");
+ }
+ this.model = model;
+ reader = new CsvReader(inputStream, model.getSeparator(), Charset.forName("UTF-8"));
+ reader.setTrimWhitespace(true);
+ }
+
+ protected Import(ImportModel<E> model, Reader reader) {
+ if (reader == null) {
+ throw new NullPointerException("reader is null");
+ }
+ this.model = model;
+ this.reader = new CsvReader(reader, model.getSeparator());
+ this.reader.setTrimWhitespace(true);
+ }
+
+ protected boolean validateModel() {
+ Set<String> headerNames = new HashSet<String>();
+ for (ImportableColumn<E, ?> importableColumn : model.getColumnsForImport()) {
+ String headerName = importableColumn.getHeaderName();
+ boolean alreadyUsed = !headerNames.add(headerName);
+ if (alreadyUsed) {
+ throw new IllegalArgumentException("model contains multiple columnsForImport named '" + headerName + "'");
+ }
+ }
+ return true;
+ }
+
+ protected void readFirstLine() throws ImportRuntimeException {
try {
boolean emptyFile = !reader.readRecord();
if (emptyFile) {
- throw new IllegalArgumentException("CSV file has no line");
+ throw new ImportRuntimeException("CSV file has no line");
}
} catch (IOException e) {
reader.close();
- throw new RuntimeException(_("csv.import.error.unableToReadLine", 1), e);
+ throw new ImportRuntimeException(_("csv.import.error.unableToReadLine", 1), e);
}
}
- public void stopImport() {
- reader.close();
- }
}
1
0
22 Nov '11
Author: tchemit
Date: 2011-11-22 19:14:23 +0100 (Tue, 22 Nov 2011)
New Revision: 2232
Url: http://nuiton.org/repositories/revision/nuiton-utils/2232
Log:
fix methods
Modified:
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java
Modified: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java 2011-11-22 17:51:31 UTC (rev 2231)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java 2011-11-22 18:14:23 UTC (rev 2232)
@@ -36,9 +36,11 @@
*/
public class ModelBuilder<E> {
- protected Collection<ImportableColumn<E, ?>> columnsForImport = new LinkedList<ImportableColumn<E, ?>>();
+ protected Collection<ImportableColumn<E, ?>> columnsForImport =
+ new LinkedList<ImportableColumn<E, ?>>();
- protected Collection<ExportableColumn<E, ?>> columnsForExport = new LinkedList<ExportableColumn<E, ?>>();
+ protected Collection<ExportableColumn<E, ?>> columnsForExport =
+ new LinkedList<ExportableColumn<E, ?>>();
public <T> ImportableColumn<E, T> newIgnoredColumn(String headerName) {
Column<E, T> newColumn = Column.newImportableColumn(headerName, null, null, true);
@@ -47,13 +49,13 @@
}
public ImportableColumn<E, String> newMandatoryColumn(String headerName, String propertyName) {
- return newMandatoryColumn(headerName, Common.STRING, propertyName);
+ return newMandatoryColumn(headerName, propertyName, Common.STRING);
}
- public <T> ImportableColumn<E, T> newMandatoryColumn(String headerName, ValueParser<T> valueParser, String propertyName) {
+ public <T> ImportableColumn<E, T> newMandatoryColumn(String headerName, String propertyName, ValueParser<T> valueParser) {
return newMandatoryColumn(headerName, valueParser, new Common.BeanProperty<E, T>(propertyName));
}
-
+
public ImportableColumn<E, String> newMandatoryColumn(String headerName, ValueSetter<E, String> valueSetter) {
return newMandatoryColumn(headerName, Common.STRING, valueSetter);
}
1
0
r2231 - in trunk/nuiton-csv: . src src/license src/main/java/org/nuiton/util/csv src/main/resources/i18n
by tchemit@users.nuiton.org 22 Nov '11
by tchemit@users.nuiton.org 22 Nov '11
22 Nov '11
Author: tchemit
Date: 2011-11-22 18:51:31 +0100 (Tue, 22 Nov 2011)
New Revision: 2231
Url: http://nuiton.org/repositories/revision/nuiton-utils/2231
Log:
continue csv api
Added:
trunk/nuiton-csv/src/license/
trunk/nuiton-csv/src/license/THIRD-PARTY.properties
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportRuntimeException.java
Modified:
trunk/nuiton-csv/LICENSE.txt
trunk/nuiton-csv/README.txt
trunk/nuiton-csv/changelog.txt
trunk/nuiton-csv/pom.xml
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Column.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportModel.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportableColumn.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportExportModel.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportModel.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableColumn.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableExportableColumn.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValidationResult.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueFormatter.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetter.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetterSetter.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParser.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParserFormatter.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueSetter.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/package-info.java
trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_en_GB.properties
trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_es_ES.properties
trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_fr_FR.properties
Property changes on: trunk/nuiton-csv/LICENSE.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/README.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/changelog.txt
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/pom.xml
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: trunk/nuiton-csv/src/license/THIRD-PARTY.properties
===================================================================
--- trunk/nuiton-csv/src/license/THIRD-PARTY.properties (rev 0)
+++ trunk/nuiton-csv/src/license/THIRD-PARTY.properties 2011-11-22 17:51:31 UTC (rev 2231)
@@ -0,0 +1,20 @@
+# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
+#-------------------------------------------------------------------------------
+# Already used licenses in project :
+# - BSD License
+# - BSD style
+# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+# - Common Public License Version 1.0
+# - GNU Library or Lesser General Public License
+# - Indiana University Extreme! Lab Software License, vesion 1.1.1
+# - Lesser General Public License (LGPL) v 3.0
+# - Lesser General Public License (LPGL)
+# - Lesser General Public License (LPGL) v 2.1
+# - MIT License
+# - The Apache Software License, Version 2.0
+#-------------------------------------------------------------------------------
+# Please fill the missing licenses for dependencies :
+#
+#
+#Tue Nov 22 12:24:47 CET 2011
+commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0
Property changes on: trunk/nuiton-csv/src/license/THIRD-PARTY.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Column.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java 2011-11-22 11:29:24 UTC (rev 2230)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java 2011-11-22 17:51:31 UTC (rev 2231)
@@ -48,7 +48,57 @@
*/
public class Common {
+ public static final ValueParserFormatter<String> STRING =
+ new StringValueParser();
+
+ public static final ValueParserFormatter<Boolean> BOOLEAN =
+ new BooleanParserFormatter(null, true);
+
+ public static final ValueParserFormatter<Boolean> PRIMITIVE_BOOLEAN =
+ new BooleanParserFormatter(false, false);
+
+ public static ValueParserFormatter<Character> CHAR =
+ new CharacterParserFormatter(null, true);
+
+ public static ValueParserFormatter<Integer> INTEGER =
+ new IntegerParserFormatter(null, true);
+
+ public static ValueParserFormatter<Integer> PRIMITIVE_INTEGER =
+ new IntegerParserFormatter(0, false);
+
+ public static ValueParserFormatter<Long> LONG =
+ new LongParserFormatter(null, true);
+
+ public static ValueParserFormatter<Long> PRIMITIVE_LONG =
+ new LongParserFormatter(0l, false);
+
+ public static ValueParserFormatter<Float> FLOAT =
+ new FloatParserFormatter(null, true);
+
+ public static ValueParserFormatter<Float> PRIMITIVE_FLOAT =
+ new FloatParserFormatter(0f, false);
+
+ public static ValueParserFormatter<Double> DOUBLE =
+ new DoubleParserFormatter(null, true);
+
+ public static ValueParserFormatter<Double> DOUBLE_PRIMITIVE =
+ new DoubleParserFormatter(0d, false);
+
+ public static final ValueParserFormatter<Date> DAY =
+ new DateValue("dd/MM/yyyy");
+
+ public static final ValueParserFormatter<Date> DAY_TIME =
+ new DateValue("dd/MM/yyyy HH:mm");
+
+ public static final ValueParserFormatter<Date> DAY_TIME_SECOND =
+ new DateValue("dd/MM/yyyy HH:mm:ss");
+
+ /** A week in a given year, ie "1/2011" until "52/2011" */
+ public static final ValueParserFormatter<Date> WEEK =
+ new DateValue("w/yyyy");
+
public static class StringValueParser implements ValueParserFormatter<String> {
+
@Override
public String parse(String value) {
return value;
@@ -60,8 +110,6 @@
}
}
- public static final ValueParserFormatter<String> STRING = new StringValueParser();
-
public static class BeanProperty<E, T> implements ValueGetterSetter<E, T> {
protected String propertyName;
@@ -87,7 +135,7 @@
protected DateFormat dateFormat;
public DateValue(String dateFormatPattern) {
- this.dateFormat = new SimpleDateFormat(dateFormatPattern);
+ dateFormat = new SimpleDateFormat(dateFormatPattern);
}
@Override
@@ -123,19 +171,22 @@
computeToStrings(values, null);
}
- public ToStringParserFormatter(List<E> values, StringUtil.ToString<E> toString) {
+ public ToStringParserFormatter(List<E> values,
+ StringUtil.ToString<E> toString) {
computeToStrings(values, toString);
}
/** fill toStrings and fromString */
- protected void computeToStrings(E[] values, StringUtil.ToString<E> toString) {
+ protected void computeToStrings(E[] values,
+ StringUtil.ToString<E> toString) {
List<E> valuesAsList = new LinkedList<E>();
Collections.addAll(valuesAsList, values);
computeToStrings(valuesAsList, toString);
}
/** fill toStrings and fromString */
- protected void computeToStrings(List<E> values, StringUtil.ToString<E> toString) {
+ protected void computeToStrings(List<E> values,
+ StringUtil.ToString<E> toString) {
for (E value : values) {
String valueToString;
if (toString == null) {
@@ -161,26 +212,65 @@
public E parse(String valueAsString) throws ParseException {
E value = fromString.get(valueAsString);
if (value == null) {
- throw new IllegalArgumentException("Unaple to parse value '" + valueAsString +
+ throw new IllegalArgumentException("Unable to parse value '" + valueAsString +
"'. Possible values are " + fromString.keySet().toString());
}
return value;
}
}
- public static class BooleanParserFormatter implements
- ValueParserFormatter<Boolean> {
- protected Boolean defaultValue;
+ public static class ValueSaver<E, T> implements ValueGetterSetter<E, T> {
- protected Boolean nullAllowed;
+ protected T value;
- public BooleanParserFormatter(Boolean defaultValue,
- boolean nullAllowed) {
+ @Override
+ public T get(E object) throws Exception {
+ return value;
+ }
+
+ @Override
+ public void set(E object, T value) throws Exception {
+ this.value = value;
+ }
+ }
+
+ public static abstract class NullableParserFormatter<O> implements ValueParserFormatter<O> {
+
+ protected O defaultValue;
+
+ protected boolean nullAllowed;
+
+ protected abstract O parseNoneEmptyValue(String value);
+
+ protected NullableParserFormatter(O defaultValue,
+ boolean nullAllowed) {
this.defaultValue = defaultValue;
this.nullAllowed = nullAllowed;
}
@Override
+ public O parse(String value) throws ParseException {
+ O result;
+ if (StringUtils.isBlank(value)) {
+ result = defaultValue;
+ } else {
+ result = parseNoneEmptyValue(value);
+ }
+
+ if (result == null && !nullAllowed) {
+ throw new IllegalArgumentException();
+ }
+ return result;
+ }
+ }
+
+ public static class BooleanParserFormatter extends NullableParserFormatter<Boolean> {
+
+ public BooleanParserFormatter(Boolean defaultValue, boolean nullAllowed) {
+ super(defaultValue, nullAllowed);
+ }
+
+ @Override
public String format(Boolean bool) {
String value;
if (bool == null) {
@@ -198,11 +288,9 @@
}
@Override
- public Boolean parse(String value) throws ParseException {
+ protected Boolean parseNoneEmptyValue(String value) {
Boolean result;
- if (StringUtils.isBlank(value)) {
- result = defaultValue;
- } else if ("?".equals(value)) {
+ if ("?".equals(value)) {
result = null;
} else if ("Y".equals(value)) {
result = true;
@@ -211,48 +299,60 @@
} else {
result = Boolean.parseBoolean(value);
}
-
- if (result == null && !nullAllowed) {
- throw new IllegalArgumentException();
- }
return result;
}
}
- public static final ValueParserFormatter<Boolean> BOOLEAN =
- new BooleanParserFormatter(null, true);
+ public static class CharacterParserFormatter extends NullableParserFormatter<Character> {
- public static final ValueParserFormatter<Date> DAY =
- new DateValue("dd/MM/yyyy");
+ public CharacterParserFormatter(Character defaultValue, boolean nullAllowed) {
+ super(defaultValue, nullAllowed);
+ }
- public static final ValueParserFormatter<Date> DAY_TIME =
- new DateValue("dd/MM/yyyy HH:mm");
+ @Override
+ public String format(Character value) {
+ String str = "";
+ if (value != null) {
+ str = String.valueOf(value);
+ }
+ return str;
+ }
- public static final ValueParserFormatter<Date> DAY_TIME_SECOND =
- new DateValue("dd/MM/yyyy HH:mm:ss");
+ @Override
+ protected Character parseNoneEmptyValue(String value) {
+ return value.charAt(0);
+ }
+ }
- /** A week in a given year, ie "1/2011" until "52/2011" */
- public static final ValueParserFormatter<Date> WEEK =
- new DateValue("w/yyyy");
+ public static class IntegerParserFormatter extends NullableParserFormatter<Integer> {
- public static class ValueSaver<E, T> implements ValueGetterSetter<E, T> {
+ public IntegerParserFormatter(Integer defaultValue, boolean nullAllowed) {
+ super(defaultValue, nullAllowed);
+ }
- protected T value;
-
@Override
- public T get(E object) throws Exception {
- return value;
+ public String format(Integer value) {
+ String str = "";
+ if (value != null) {
+ str = String.valueOf(value);
+ }
+ return str;
}
@Override
- public void set(E object, T value) throws Exception {
- this.value = value;
+ protected Integer parseNoneEmptyValue(String value) {
+ return Integer.valueOf(value);
}
}
- public static class IntegerParserFormatter implements ValueParserFormatter<Integer> {
+ public static class LongParserFormatter extends NullableParserFormatter<Long> {
+
+ public LongParserFormatter(Long defaultValue, boolean nullAllowed) {
+ super(defaultValue, nullAllowed);
+ }
+
@Override
- public String format(Integer value) {
+ public String format(Long value) {
String str = "";
if (value != null) {
str = String.valueOf(value);
@@ -261,18 +361,40 @@
}
@Override
- public Integer parse(String value) throws ParseException {
- Integer integer = null;
- if (StringUtils.isNotBlank(value)) {
- integer = Integer.valueOf(value);
+ protected Long parseNoneEmptyValue(String value) {
+ return Long.valueOf(value);
+ }
+
+ }
+
+ public static class FloatParserFormatter extends NullableParserFormatter<Float> {
+
+ public FloatParserFormatter(Float defaultValue, boolean nullAllowed) {
+ super(defaultValue, nullAllowed);
+ }
+
+ @Override
+ public String format(Float value) {
+ String str = "";
+ if (value != null) {
+ str = String.valueOf(value);
}
- return integer;
+ return str;
}
+
+ @Override
+ protected Float parseNoneEmptyValue(String value) {
+ return Float.valueOf(value);
+ }
+
}
- public static ValueParserFormatter<Integer> INTEGER = new IntegerParserFormatter();
+ public static class DoubleParserFormatter extends NullableParserFormatter<Double> {
- public static class DoubleParserFormatter implements ValueParserFormatter<Double> {
+ public DoubleParserFormatter(Double defaultValue, boolean nullAllowed) {
+ super(defaultValue, nullAllowed);
+ }
+
@Override
public String format(Double value) {
String str = "";
@@ -283,14 +405,11 @@
}
@Override
- public Double parse(String value) throws ParseException {
- Double doubleValue = null;
- if (StringUtils.isNotBlank(value)) {
- doubleValue = Double.valueOf(value);
- }
- return doubleValue;
+ protected Double parseNoneEmptyValue(String value) {
+ return Double.valueOf(value);
}
+
}
- public static ValueParserFormatter<Double> DOUBLE = new DoubleParserFormatter();
+
}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java 2011-11-22 11:29:24 UTC (rev 2230)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java 2011-11-22 17:51:31 UTC (rev 2231)
@@ -55,7 +55,7 @@
this.data = data;
}
- public InputStream startExport() throws Exception {
+ public String startExportAsString() throws Exception {
String separator = String.valueOf(model.getSeparator());
StringBuilder csv = new StringBuilder();
@@ -65,37 +65,37 @@
headerNames.add(column.getHeaderName());
}
String headersLine = StringUtil.join(headerNames, separator, true);
- csv.append(headersLine).append("\n");
+ csv.append(headersLine).append('\n');
if (log.isDebugEnabled()) {
log.debug("headers for export are '" + headersLine + "'");
log.debug("will export " + data.size() + " lines");
}
+ Collection<ExportableColumn<E, Object>> columnsForExport =
+ model.getColumnsForExport();
+
for (E object : data) {
- for (ExportableColumn<E, Object> column : model.getColumnsForExport()) {
+ for (ExportableColumn<E, Object> column :
+ columnsForExport) {
Object value = column.getValue(object);
String formattedValue = column.formatValue(value);
if (formattedValue == null) {
- formattedValue = "";
- if (log.isWarnEnabled()) {
- log.warn("column for header " + column.getHeaderName() +
- " returned a null value." + column.toString());
- }
+ throw new NullPointerException(
+ "column for header " + column.getHeaderName() +
+ " returned a null value." + column.toString());
}
- boolean valueNeedQuotes = formattedValue.contains(separator)
- || formattedValue.contains("\n")
- || formattedValue.contains(";")
- || formattedValue.contains(",");
- if (valueNeedQuotes) {
- // escape '"' char to prevent
- formattedValue = formattedValue.replaceAll("\"", "\"\"");
- formattedValue = "\"" + formattedValue + "\"";
- }
+ formattedValue =
+ StringUtil.escapeCsvValue(formattedValue, separator);
csv.append(formattedValue).append(separator);
}
- csv.append("\n");
+ csv.append('\n');
}
- return IOUtils.toInputStream(csv);
+ return csv.toString();
}
+
+ public InputStream startExport() throws Exception {
+ String content = startExportAsString();
+ return IOUtils.toInputStream(content);
+ }
}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportModel.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportableColumn.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Modified: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java 2011-11-22 11:29:24 UTC (rev 2230)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java 2011-11-22 17:51:31 UTC (rev 2231)
@@ -28,7 +28,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.util.StringUtil;
-import org.nuiton.util.TimeLog;
import java.io.IOException;
import java.io.InputStream;
@@ -58,9 +57,6 @@
/** Logger. */
private static final Log log = LogFactory.getLog(Import.class);
- private static final TimeLog timeLog =
- new TimeLog(Import.class + "TimeLog");
-
protected ImportModel<E> model;
protected CsvReader reader;
@@ -181,16 +177,12 @@
public Iterator<E> startImport() throws IOException {
- long startValidateCSV = TimeLog.getTime();
-
ValidationResult validationResult = validateCsv();
if (!validationResult.isSuccess()) {
throw new IOException(validationResult.getMessage());
}
- timeLog.log(startValidateCSV, "validate CSV", "done");
-
readFirstLine();
Iterator<E> result = new Iterator<E>() {
@@ -207,7 +199,7 @@
}
@Override
- public E next() throws NoSuchElementException {
+ public E next() throws NoSuchElementException, ImportRuntimeException {
if (!hasNext) {
throw new NoSuchElementException();
@@ -215,69 +207,54 @@
lineNumber += 1;
- long time = TimeLog.getTime();
+ E element = model.newEmptyInstance();
- E element = startImportLine();
+ for (ImportableColumn<E, Object> field : getNonIgnoredHeaders()) {
- time = timeLog.log(time, "newEmptyInstance");
+ // read value from csv cell
+ String value;
+ try {
+ value = reader.get(field.getHeaderName());
+ } catch (Exception e) {
+ reader.close();
+ throw new ImportRuntimeException(_("csv.import.error.unableToReadField", field.getHeaderName(), lineNumber), e);
+ }
- try {
- for (ImportableColumn<E, Object> field : getNonIgnoredHeaders()) {
+ // contravariance ftw
+ Object parsedValue;
+ try {
+ parsedValue = field.parseValue(value);
+ } catch (Exception e) {
+ String message = _("csv.import.error.unableToParseValue", value, field.getHeaderName(), lineNumber)
+ + "\n" + e.getMessage();
+ throw new ImportRuntimeException(message, e);
+ }
- time = timeLog.log(time, "readValue", "read value for field " + field.getHeaderName());
- String value;
- try {
- value = reader.get(field.getHeaderName());
- } catch (IOException e) {
- reader.close();
- throw new RuntimeException(_("csv.import.error.unableToReadField", field.getHeaderName(), lineNumber), e);
+ // set value to element
+ try {
+ field.setValue(element, parsedValue);
+ } catch (Exception e) {
+ String message = _("csv.import.error.unableToSetValue",
+ parsedValue,
+ element.toString(),
+ lineNumber, field.getHeaderName());
+ if (log.isErrorEnabled()) {
+ log.error(message);
}
- time = timeLog.log(time, "readValue", "end read");
-
- // contravariance ftw
- Object parsedValue;
- try {
- parsedValue = field.parseValue(value);
- } catch (Exception e) {
- String message = _("csv.import.error.unableToParseValue", value, field.getHeaderName(), lineNumber)
- + "\n" + e.getMessage();
- throw new RuntimeException(message, e);
- }
-
- time = timeLog.log(time, "parseValue");
-
- try {
- field.setValue(element, parsedValue);
- } catch (Exception e) {
- String message = _("csv.import.error.unableToSetValue",
- parsedValue,
- element.toString(),
- lineNumber, field.getHeaderName());
- if (log.isErrorEnabled()) {
- log.error(message);
- }
- throw new RuntimeException(message, e);
- }
-
- time = timeLog.log(time, "setValue");
+ throw new ImportRuntimeException(message, e);
}
- } finally {
- endImportLine(element);
+
+ lastElement = element;
}
- lastElement = element;
-
try {
hasNext = reader.readRecord();
} catch (IOException e) {
reader.close();
- throw new RuntimeException(_("csv.import.error.unableToReadLine", lineNumber + 1), e);
+ throw new ImportRuntimeException(
+ _("csv.import.error.unableToReadLine", lineNumber + 1), e);
}
- if (log.isTraceEnabled()) {
- log.trace(timeLog.getCallCount().toString());
- }
-
return lastElement;
}
@@ -286,19 +263,9 @@
throw new UnsupportedOperationException();
}
};
-
return result;
}
- public E startImportLine() {
- E element = model.newEmptyInstance();
- return element;
- }
-
- public void endImportLine(E element) {
- // by default do nothing
- }
-
protected void readFirstLine() {
try {
boolean emptyFile = !reader.readRecord();
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportExportModel.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportModel.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportRuntimeException.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportRuntimeException.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportRuntimeException.java 2011-11-22 17:51:31 UTC (rev 2231)
@@ -0,0 +1,47 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Csv
+ *
+ * $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.util.csv;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public class ImportRuntimeException extends RuntimeException{
+ private static final long serialVersionUID = 1L;
+
+ public ImportRuntimeException(String message) {
+ super(message);
+ }
+
+ public ImportRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ImportRuntimeException(Throwable cause) {
+ super(cause);
+ }
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportRuntimeException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableColumn.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableExportableColumn.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValidationResult.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueFormatter.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetter.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetterSetter.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParser.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParserFormatter.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueSetter.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/package-info.java
___________________________________________________________________
Modified: svn:keywords
- Author Date Id Revision
+ Author Date Id Revision HeadURL
Property changes on: trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_en_GB.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_es_ES.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Property changes on: trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_fr_FR.properties
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
Author: tchemit
Date: 2011-11-22 12:29:24 +0100 (Tue, 22 Nov 2011)
New Revision: 2230
Url: http://nuiton.org/repositories/revision/nuiton-utils/2230
Log:
Evolution #1818: Introduce a csv importexport library (nuiton-csv)
Added:
trunk/nuiton-csv/
trunk/nuiton-csv/LICENSE.txt
trunk/nuiton-csv/README.txt
trunk/nuiton-csv/changelog.txt
trunk/nuiton-csv/pom.xml
trunk/nuiton-csv/src/
trunk/nuiton-csv/src/main/
trunk/nuiton-csv/src/main/java/
trunk/nuiton-csv/src/main/java/org/
trunk/nuiton-csv/src/main/java/org/nuiton/
trunk/nuiton-csv/src/main/java/org/nuiton/util/
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Column.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportModel.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportableColumn.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportExportModel.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportModel.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableColumn.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableExportableColumn.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValidationResult.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueFormatter.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetter.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetterSetter.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParser.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParserFormatter.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueSetter.java
trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/package-info.java
trunk/nuiton-csv/src/main/java/org/nuiton/utils/
trunk/nuiton-csv/src/main/java/org/nuiton/utils/csv/
trunk/nuiton-csv/src/main/resources/
trunk/nuiton-csv/src/main/resources/i18n/
trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_en_GB.properties
trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_es_ES.properties
trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_fr_FR.properties
trunk/nuiton-csv/src/test/
trunk/nuiton-csv/src/test/java/
trunk/nuiton-csv/src/test/java/org/
trunk/nuiton-csv/src/test/java/org/nuiton/
trunk/nuiton-csv/src/test/java/org/nuiton/utils/
trunk/nuiton-csv/src/test/java/org/nuiton/utils/csv/
trunk/nuiton-csv/src/test/resources/
Modified:
trunk/pom.xml
Property changes on: trunk/nuiton-csv
___________________________________________________________________
Added: svn:ignore
+ target
*.ipr
*.iml
*.iws
.classpath
.settings
.project
*.log
Added: trunk/nuiton-csv/LICENSE.txt
===================================================================
--- trunk/nuiton-csv/LICENSE.txt (rev 0)
+++ trunk/nuiton-csv/LICENSE.txt 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,166 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
+
Property changes on: trunk/nuiton-csv/LICENSE.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Property changes on: trunk/nuiton-csv/README.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Property changes on: trunk/nuiton-csv/changelog.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/pom.xml
===================================================================
--- trunk/nuiton-csv/pom.xml (rev 0)
+++ trunk/nuiton-csv/pom.xml 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,183 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ #%L
+ Nuiton Utils :: Nuiton Csv
+ %%
+ Copyright (C) 2004 - 2010 CodeLutin, Tony Chemit
+ %%
+ 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%
+ -->
+<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>
+
+ <!-- ************************************************************* -->
+ <!-- *** POM Relationships *************************************** -->
+ <!-- ************************************************************* -->
+
+ <parent>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-utils-parent</artifactId>
+ <version>2.4-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>nuiton-csv</artifactId>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>nuiton-utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sourceforge.javacsv</groupId>
+ <artifactId>javacsv</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>nuiton-i18n</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+
+
+ <!-- ************************************************************* -->
+ <!-- *** Project Information ************************************* -->
+ <!-- ************************************************************* -->
+
+ <name>Nuiton Utils :: Nuiton Csv</name>
+ <description>Library of usefull classes to import export csv.</description>
+ <inceptionYear>2011</inceptionYear>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Settings ****************************************** -->
+ <!-- ************************************************************* -->
+
+ <properties>
+
+ <!-- extra files to include in release -->
+ <redmine.releaseFiles>${redmine.libReleaseFiles}</redmine.releaseFiles>
+
+ </properties>
+
+ <build>
+
+ <plugins>
+
+ <!-- plugin i18n -->
+ <plugin>
+ <groupId>org.nuiton.i18n</groupId>
+ <artifactId>maven-i18n-plugin</artifactId>
+ <configuration>
+ <silent>true</silent>
+ <bundles>fr_FR,en_GB,es_ES</bundles>
+ </configuration>
+ <executions>
+ <execution>
+ <goals>
+ <goal>parserJava</goal>
+ <goal>gen</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+ <!-- ************************************************************* -->
+ <!-- *** Build Environment ************************************** -->
+ <!-- ************************************************************* -->
+
+ <profiles>
+ <!-- create assemblies at release time -->
+ <profile>
+ <id>assembly-profile</id>
+ <activation>
+ <property>
+ <name>performRelease</name>
+ <value>true</value>
+ </property>
+ </activation>
+ <build>
+ <defaultGoal>package</defaultGoal>
+ <plugins>
+
+ <!-- launch in a release the assembly automaticly -->
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>create-assemblies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <attach>false</attach>
+ <descriptorRefs>
+ <descriptorRef>deps</descriptorRef>
+ <descriptorRef>full</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ </plugin>
+
+ </plugins>
+
+ </build>
+ </profile>
+
+ </profiles>
+
+</project>
Property changes on: trunk/nuiton-csv/pom.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Column.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Column.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Column.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,182 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ * *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+import java.text.ParseException;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public class Column<E, T> implements ImportableExportableColumn<E, T> {
+
+ public static <E, T> Column<E, T> newExportableColumn(String headerName,
+ ValueGetter<E, T> valueGetter,
+ ValueFormatter<T> valueFormatter,
+ boolean ignored) {
+ return new Column<E, T>(headerName,
+ valueGetter,
+ valueFormatter,
+ null,
+ null,
+ ignored
+ );
+ }
+
+ public static <E, T> Column<E, T> newImportableColumn(String headerName,
+ ValueParser<T> valueParser,
+ ValueSetter<E, T> valueSetter,
+ boolean ignored) {
+ return new Column<E, T>(headerName,
+ null,
+ null,
+ valueParser,
+ valueSetter,
+ ignored
+ );
+ }
+
+ public static <E, T> Column<E, T> newImportableExportableColumn(String headerName,
+ ValueGetter<E, T> valueGetter,
+ ValueFormatter<T> valueFormatter,
+ ValueParser<T> valueParser,
+ ValueSetter<E, T> valueSetter,
+ boolean ignored) {
+ return new Column<E, T>(headerName,
+ valueGetter,
+ valueFormatter,
+ valueParser,
+ valueSetter,
+ ignored
+ );
+ }
+
+ public static <E, T> Column<E, T> newImportableExportableColumn(String headerName,
+ ValueGetterSetter<E, T> valueGetterSetter,
+ ValueParserFormatter<T> valueParserFormatter,
+ boolean ignored) {
+ return newImportableExportableColumn(headerName,
+ valueGetterSetter,
+ valueParserFormatter,
+ valueParserFormatter,
+ valueGetterSetter,
+ ignored
+ );
+ }
+
+ protected String headerName;
+
+ protected boolean mandatory = true;
+
+ protected boolean ignored;
+
+ protected ValueParser<T> valueParser;
+
+ protected ValueFormatter<T> valueFormatter;
+
+ protected ValueGetter<E, T> valueGetter;
+
+ protected ValueSetter<E, T> valueSetter;
+
+ protected Column(String headerName,
+ ValueGetter<E, T> valueGetter,
+ ValueFormatter<T> valueFormatter,
+ ValueParser<T> valueParser,
+ ValueSetter<E, T> valueSetter,
+ boolean ignored) {
+ this.headerName = headerName;
+ this.valueGetter = valueGetter;
+ this.valueFormatter = valueFormatter;
+ this.valueSetter = valueSetter;
+ this.valueParser = valueParser;
+ this.ignored = ignored;
+ mandatory = !ignored;
+ }
+
+ @Override
+ public String getHeaderName() {
+ return headerName;
+ }
+
+ @Override
+ public boolean isMandatory() {
+ return mandatory;
+ }
+
+ @Override
+ public boolean isIgnored() {
+ return ignored;
+ }
+
+ @Override
+ public String formatValue(T value) {
+ if (valueFormatter == null) {
+ throw new UnsupportedOperationException("no formatter provided for " + this);
+ } else {
+ return valueFormatter.format(value);
+ }
+ }
+
+ @Override
+ public T parseValue(String value) throws ParseException {
+ if (valueParser == null) {
+ throw new UnsupportedOperationException("no parser provided for " + this);
+ } else {
+ return valueParser.parse(value);
+ }
+ }
+
+ @Override
+ public T getValue(E object) throws Exception {
+ if (valueGetter == null) {
+ throw new UnsupportedOperationException("no getter provided for " + this);
+ } else {
+ return valueGetter.get(object);
+ }
+ }
+
+ @Override
+ public void setValue(E object, T value) throws Exception {
+ if (!isIgnored()) {
+ if (valueSetter == null) {
+ throw new UnsupportedOperationException("no setter provided for " + this);
+ } else {
+ valueSetter.set(object, value);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "{" +
+ "headerName='" + headerName + '\'' +
+ ", mandatory=" + mandatory +
+ ", ignored=" + ignored +
+ '}';
+ }
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Column.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,296 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+import org.apache.commons.beanutils.BeanUtilsBean;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.util.StringUtil;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public class Common {
+
+ public static class StringValueParser implements ValueParserFormatter<String> {
+ @Override
+ public String parse(String value) {
+ return value;
+ }
+
+ @Override
+ public String format(String value) {
+ return value == null ? "" : value;
+ }
+ }
+
+ public static final ValueParserFormatter<String> STRING = new StringValueParser();
+
+ public static class BeanProperty<E, T> implements ValueGetterSetter<E, T> {
+
+ protected String propertyName;
+
+ BeanProperty(String propertyName) {
+ this.propertyName = propertyName;
+ }
+
+ @Override
+ public void set(E bean, T value) throws Exception {
+ BeanUtilsBean.getInstance().getPropertyUtils().setProperty(bean, propertyName, value);
+ }
+
+ @Override
+ public T get(E object) throws Exception {
+ T value = (T) PropertyUtils.getProperty(object, propertyName);
+ return value;
+ }
+ }
+
+ public static class DateValue implements ValueParserFormatter<Date> {
+
+ protected DateFormat dateFormat;
+
+ public DateValue(String dateFormatPattern) {
+ this.dateFormat = new SimpleDateFormat(dateFormatPattern);
+ }
+
+ @Override
+ public Date parse(String value) throws ParseException {
+ Date date = null;
+ if (StringUtils.isNotBlank(value)) {
+ date = dateFormat.parse(value);
+ }
+ return date;
+ }
+
+ @Override
+ public String format(Date date) {
+ String value = "";
+ if (date != null) {
+ value = dateFormat.format(date);
+ }
+ return value;
+ }
+ }
+
+ public static class ToStringParserFormatter<E> implements ValueParserFormatter<E> {
+
+ protected Map<E, String> toStrings = new HashMap<E, String>();
+
+ protected Map<String, E> fromString = new HashMap<String, E>();
+
+ public ToStringParserFormatter(List<E> values) {
+ this(values, null);
+ }
+
+ public ToStringParserFormatter(E[] values) {
+ computeToStrings(values, null);
+ }
+
+ public ToStringParserFormatter(List<E> values, StringUtil.ToString<E> toString) {
+ computeToStrings(values, toString);
+ }
+
+ /** fill toStrings and fromString */
+ protected void computeToStrings(E[] values, StringUtil.ToString<E> toString) {
+ List<E> valuesAsList = new LinkedList<E>();
+ Collections.addAll(valuesAsList, values);
+ computeToStrings(valuesAsList, toString);
+ }
+
+ /** fill toStrings and fromString */
+ protected void computeToStrings(List<E> values, StringUtil.ToString<E> toString) {
+ for (E value : values) {
+ String valueToString;
+ if (toString == null) {
+ valueToString = value.toString();
+ } else {
+ valueToString = toString.toString(value);
+ }
+ toStrings.put(value, valueToString);
+ fromString.put(valueToString, value);
+ }
+ }
+
+ @Override
+ public String format(E value) {
+ String valueAsString = toStrings.get(value);
+ if (valueAsString == null) {
+ throw new IllegalArgumentException();
+ }
+ return valueAsString;
+ }
+
+ @Override
+ public E parse(String valueAsString) throws ParseException {
+ E value = fromString.get(valueAsString);
+ if (value == null) {
+ throw new IllegalArgumentException("Unaple to parse value '" + valueAsString +
+ "'. Possible values are " + fromString.keySet().toString());
+ }
+ return value;
+ }
+ }
+
+ public static class BooleanParserFormatter implements
+ ValueParserFormatter<Boolean> {
+ protected Boolean defaultValue;
+
+ protected Boolean nullAllowed;
+
+ public BooleanParserFormatter(Boolean defaultValue,
+ boolean nullAllowed) {
+ this.defaultValue = defaultValue;
+ this.nullAllowed = nullAllowed;
+ }
+
+ @Override
+ public String format(Boolean bool) {
+ String value;
+ if (bool == null) {
+ if (nullAllowed) {
+ value = "?";
+ } else {
+ throw new IllegalArgumentException();
+ }
+ } else if (bool) {
+ value = "Y";
+ } else {
+ value = "N";
+ }
+ return value;
+ }
+
+ @Override
+ public Boolean parse(String value) throws ParseException {
+ Boolean result;
+ if (StringUtils.isBlank(value)) {
+ result = defaultValue;
+ } else if ("?".equals(value)) {
+ result = null;
+ } else if ("Y".equals(value)) {
+ result = true;
+ } else if ("N".equals(value)) {
+ result = false;
+ } else {
+ result = Boolean.parseBoolean(value);
+ }
+
+ if (result == null && !nullAllowed) {
+ throw new IllegalArgumentException();
+ }
+ return result;
+ }
+ }
+
+ public static final ValueParserFormatter<Boolean> BOOLEAN =
+ new BooleanParserFormatter(null, true);
+
+ public static final ValueParserFormatter<Date> DAY =
+ new DateValue("dd/MM/yyyy");
+
+ public static final ValueParserFormatter<Date> DAY_TIME =
+ new DateValue("dd/MM/yyyy HH:mm");
+
+ public static final ValueParserFormatter<Date> DAY_TIME_SECOND =
+ new DateValue("dd/MM/yyyy HH:mm:ss");
+
+ /** A week in a given year, ie "1/2011" until "52/2011" */
+ public static final ValueParserFormatter<Date> WEEK =
+ new DateValue("w/yyyy");
+
+ public static class ValueSaver<E, T> implements ValueGetterSetter<E, T> {
+
+ protected T value;
+
+ @Override
+ public T get(E object) throws Exception {
+ return value;
+ }
+
+ @Override
+ public void set(E object, T value) throws Exception {
+ this.value = value;
+ }
+ }
+
+ public static class IntegerParserFormatter implements ValueParserFormatter<Integer> {
+ @Override
+ public String format(Integer value) {
+ String str = "";
+ if (value != null) {
+ str = String.valueOf(value);
+ }
+ return str;
+ }
+
+ @Override
+ public Integer parse(String value) throws ParseException {
+ Integer integer = null;
+ if (StringUtils.isNotBlank(value)) {
+ integer = Integer.valueOf(value);
+ }
+ return integer;
+ }
+ }
+
+ public static ValueParserFormatter<Integer> INTEGER = new IntegerParserFormatter();
+
+ public static class DoubleParserFormatter implements ValueParserFormatter<Double> {
+ @Override
+ public String format(Double value) {
+ String str = "";
+ if (value != null) {
+ str = String.valueOf(value);
+ }
+ return str;
+ }
+
+ @Override
+ public Double parse(String value) throws ParseException {
+ Double doubleValue = null;
+ if (StringUtils.isNotBlank(value)) {
+ doubleValue = Double.valueOf(value);
+ }
+ return doubleValue;
+ }
+ }
+
+ public static ValueParserFormatter<Double> DOUBLE = new DoubleParserFormatter();
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Common.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,101 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.StringUtil;
+
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public class Export<E> {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(Export.class);
+
+ protected ExportModel<E> model;
+
+ protected Collection<E> data;
+
+ public Export(ExportModel<E> exportModel, Collection<E> data) {
+ model = exportModel;
+ this.data = data;
+ }
+
+ public InputStream startExport() throws Exception {
+ String separator = String.valueOf(model.getSeparator());
+ StringBuilder csv = new StringBuilder();
+
+ // add headers
+ List<String> headerNames = new LinkedList<String>();
+ for (ExportableColumn<E, ?> column : model.getColumnsForExport()) {
+ headerNames.add(column.getHeaderName());
+ }
+ String headersLine = StringUtil.join(headerNames, separator, true);
+ csv.append(headersLine).append("\n");
+
+ if (log.isDebugEnabled()) {
+ log.debug("headers for export are '" + headersLine + "'");
+ log.debug("will export " + data.size() + " lines");
+ }
+
+ for (E object : data) {
+ for (ExportableColumn<E, Object> column : model.getColumnsForExport()) {
+ Object value = column.getValue(object);
+ String formattedValue = column.formatValue(value);
+ if (formattedValue == null) {
+ formattedValue = "";
+ if (log.isWarnEnabled()) {
+ log.warn("column for header " + column.getHeaderName() +
+ " returned a null value." + column.toString());
+ }
+ }
+ boolean valueNeedQuotes = formattedValue.contains(separator)
+ || formattedValue.contains("\n")
+ || formattedValue.contains(";")
+ || formattedValue.contains(",");
+ if (valueNeedQuotes) {
+ // escape '"' char to prevent
+ formattedValue = formattedValue.replaceAll("\"", "\"\"");
+ formattedValue = "\"" + formattedValue + "\"";
+ }
+ csv.append(formattedValue).append(separator);
+ }
+ csv.append("\n");
+ }
+ return IOUtils.toInputStream(csv);
+ }
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Export.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportModel.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportModel.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportModel.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,42 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+import java.util.Collection;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public interface ExportModel<E> {
+
+ char getSeparator();
+
+ Collection<ExportableColumn<E, Object>> getColumnsForExport();
+
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportableColumn.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportableColumn.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportableColumn.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,42 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public interface ExportableColumn<E, T> {
+
+ String getHeaderName();
+
+ T getValue(E object) throws Exception;
+
+ String formatValue(T value);
+
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ExportableColumn.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,319 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+import com.csvreader.CsvReader;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.StringUtil;
+import org.nuiton.util.TimeLog;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public class Import<E> {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(Import.class);
+
+ private static final TimeLog timeLog =
+ new TimeLog(Import.class + "TimeLog");
+
+ protected ImportModel<E> model;
+
+ protected CsvReader reader;
+
+ /** save once done to prevent multiple headers read leading to consider first lines as headers */
+ protected ValidationResult csvValidationResult;
+
+ protected List<ImportableColumn<E, Object>> getNonIgnoredHeaders() {
+ List<ImportableColumn<E, Object>> nonIgnoredHeaders = new ArrayList<ImportableColumn<E, Object>>();
+ for (ImportableColumn<E, Object> field : model.getColumnsForImport()) {
+ if (!field.isIgnored()) {
+ nonIgnoredHeaders.add(field);
+ }
+ }
+ return nonIgnoredHeaders;
+ }
+
+ protected List<ImportableColumn<E, ?>> getAllMandatoryHeaders() {
+ List<ImportableColumn<E, ?>> allMandatoryHeaders = new ArrayList<ImportableColumn<E, ?>>();
+ for (ImportableColumn<E, ?> field : model.getColumnsForImport()) {
+ if (field.isMandatory()) {
+ allMandatoryHeaders.add(field);
+ }
+ }
+ return allMandatoryHeaders;
+ }
+
+ public Import(ImportModel<E> model, InputStream inputStream) {
+ if (inputStream == null) {
+ throw new NullPointerException("inputStream is null");
+ }
+ this.model = model;
+ reader = new CsvReader(inputStream, model.getSeparator(), Charset.forName("UTF-8"));
+ reader.setTrimWhitespace(true);
+ }
+
+ public Import(ImportModel<E> model, Reader reader) {
+ if (reader == null) {
+ throw new NullPointerException("reader is null");
+ }
+ this.model = model;
+ this.reader = new CsvReader(reader, model.getSeparator());
+ this.reader.setTrimWhitespace(true);
+ }
+
+ protected boolean validateModel() {
+ Set<String> headerNames = new HashSet<String>();
+ for (ImportableColumn<E, ?> importableColumn : model.getColumnsForImport()) {
+ String headerName = importableColumn.getHeaderName();
+ boolean alreadyUsed = !headerNames.add(headerName);
+ if (alreadyUsed) {
+ throw new IllegalArgumentException("model contains multiple columnsForImport named '" + headerName + "'");
+ }
+ }
+ return true;
+ }
+
+ public ValidationResult validateCsv() throws IOException {
+
+ if (csvValidationResult == null) {
+
+ boolean canReadHeaders = reader.readHeaders();
+ if (!canReadHeaders) {
+ throw new IOException("can't read headers");
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace("headers of the CSV file are : " + Arrays.toString(reader.getHeaders()));
+ }
+
+ model.pushCsvHeaderNames(Arrays.asList(reader.getHeaders()));
+
+ validateModel();
+
+ csvValidationResult = new ValidationResult();
+ csvValidationResult.setSuccess(true);
+
+ List<String> csvHeaders = new ArrayList<String>();
+ Collections.addAll(csvHeaders, reader.getHeaders());
+
+ for (ImportableColumn<E, ?> field : model.getColumnsForImport()) {
+ csvHeaders.remove(field.getHeaderName());
+ }
+
+ if (!csvHeaders.isEmpty()) {
+ csvValidationResult.setSuccess(false);
+ List<String> validHeaderNames = new LinkedList<String>();
+ for (ImportableColumn<E, ?> importableColumn : model.getColumnsForImport()) {
+ validHeaderNames.add(importableColumn.getHeaderName());
+ }
+ String validationMessage = _(
+ "csv.import.error.unrecognizedHeaders",
+ StringUtil.join(csvHeaders, ", ", true),
+ StringUtil.join(validHeaderNames, ", ", true));
+ csvValidationResult.setMessage(validationMessage);
+ }
+
+ csvHeaders = new ArrayList<String>();
+ Collections.addAll(csvHeaders, reader.getHeaders());
+
+ List<String> mandatoryHeadersNames = new ArrayList<String>();
+ for (ImportableColumn<E, ?> field : getAllMandatoryHeaders()) {
+ mandatoryHeadersNames.add(field.getHeaderName());
+ }
+ mandatoryHeadersNames.removeAll(csvHeaders);
+
+ if (!mandatoryHeadersNames.isEmpty()) {
+ csvValidationResult.setSuccess(false);
+ String validationMessage = _(
+ "csv.import.error.missingMandatoryHeaders",
+ StringUtil.join(mandatoryHeadersNames, ", ", true));
+ csvValidationResult.setMessage(validationMessage);
+ }
+ }
+
+ return csvValidationResult;
+ }
+
+ public Iterator<E> startImport() throws IOException {
+
+ long startValidateCSV = TimeLog.getTime();
+
+ ValidationResult validationResult = validateCsv();
+
+ if (!validationResult.isSuccess()) {
+ throw new IOException(validationResult.getMessage());
+ }
+
+ timeLog.log(startValidateCSV, "validate CSV", "done");
+
+ readFirstLine();
+
+ Iterator<E> result = new Iterator<E>() {
+
+ boolean hasNext = true;
+
+ int lineNumber;
+
+ E lastElement;
+
+ @Override
+ public boolean hasNext() {
+ return hasNext;
+ }
+
+ @Override
+ public E next() throws NoSuchElementException {
+
+ if (!hasNext) {
+ throw new NoSuchElementException();
+ }
+
+ lineNumber += 1;
+
+ long time = TimeLog.getTime();
+
+ E element = startImportLine();
+
+ time = timeLog.log(time, "newEmptyInstance");
+
+ try {
+ for (ImportableColumn<E, Object> field : getNonIgnoredHeaders()) {
+
+ time = timeLog.log(time, "readValue", "read value for field " + field.getHeaderName());
+ String value;
+ try {
+ value = reader.get(field.getHeaderName());
+ } catch (IOException e) {
+ reader.close();
+ throw new RuntimeException(_("csv.import.error.unableToReadField", field.getHeaderName(), lineNumber), e);
+ }
+ time = timeLog.log(time, "readValue", "end read");
+
+ // contravariance ftw
+ Object parsedValue;
+ try {
+ parsedValue = field.parseValue(value);
+ } catch (Exception e) {
+ String message = _("csv.import.error.unableToParseValue", value, field.getHeaderName(), lineNumber)
+ + "\n" + e.getMessage();
+ throw new RuntimeException(message, e);
+ }
+
+ time = timeLog.log(time, "parseValue");
+
+ try {
+ field.setValue(element, parsedValue);
+ } catch (Exception e) {
+ String message = _("csv.import.error.unableToSetValue",
+ parsedValue,
+ element.toString(),
+ lineNumber, field.getHeaderName());
+ if (log.isErrorEnabled()) {
+ log.error(message);
+ }
+ throw new RuntimeException(message, e);
+ }
+
+ time = timeLog.log(time, "setValue");
+ }
+ } finally {
+ endImportLine(element);
+ }
+
+ lastElement = element;
+
+ try {
+ hasNext = reader.readRecord();
+ } catch (IOException e) {
+ reader.close();
+ throw new RuntimeException(_("csv.import.error.unableToReadLine", lineNumber + 1), e);
+ }
+
+ if (log.isTraceEnabled()) {
+ log.trace(timeLog.getCallCount().toString());
+ }
+
+ return lastElement;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ return result;
+ }
+
+ public E startImportLine() {
+ E element = model.newEmptyInstance();
+ return element;
+ }
+
+ public void endImportLine(E element) {
+ // by default do nothing
+ }
+
+ protected void readFirstLine() {
+ try {
+ boolean emptyFile = !reader.readRecord();
+
+ if (emptyFile) {
+ throw new IllegalArgumentException("CSV file has no line");
+ }
+ } catch (IOException e) {
+ reader.close();
+ throw new RuntimeException(_("csv.import.error.unableToReadLine", 1), e);
+ }
+ }
+
+ public void stopImport() {
+ reader.close();
+ }
+
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/Import.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportExportModel.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportExportModel.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportExportModel.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,35 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public interface ImportExportModel<E> extends ImportModel<E>, ExportModel<E> {
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportExportModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportModel.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportModel.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportModel.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,46 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public interface ImportModel<E> {
+
+ char getSeparator();
+
+ void pushCsvHeaderNames(List<String> headerNames);
+
+ E newEmptyInstance();
+
+ Collection<ImportableColumn<E, Object>> getColumnsForImport();
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableColumn.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableColumn.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableColumn.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,46 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+import java.text.ParseException;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public interface ImportableColumn<E, T> {
+ String getHeaderName();
+
+ boolean isMandatory();
+
+ boolean isIgnored();
+
+ T parseValue(String value) throws ParseException;
+
+ void setValue(E object, T value) throws Exception;
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableColumn.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableExportableColumn.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableExportableColumn.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableExportableColumn.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,28 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+public interface ImportableExportableColumn<E, T> extends ImportableColumn<E, T>, ExportableColumn<E, T> {
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ImportableExportableColumn.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,111 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public class ModelBuilder<E> {
+
+ protected Collection<ImportableColumn<E, ?>> columnsForImport = new LinkedList<ImportableColumn<E, ?>>();
+
+ protected Collection<ExportableColumn<E, ?>> columnsForExport = new LinkedList<ExportableColumn<E, ?>>();
+
+ public <T> ImportableColumn<E, T> newIgnoredColumn(String headerName) {
+ Column<E, T> newColumn = Column.newImportableColumn(headerName, null, null, true);
+ columnsForImport.add(newColumn);
+ return newColumn;
+ }
+
+ public ImportableColumn<E, String> newMandatoryColumn(String headerName, String propertyName) {
+ return newMandatoryColumn(headerName, Common.STRING, propertyName);
+ }
+
+ public <T> ImportableColumn<E, T> newMandatoryColumn(String headerName, ValueParser<T> valueParser, String propertyName) {
+ return newMandatoryColumn(headerName, valueParser, new Common.BeanProperty<E, T>(propertyName));
+ }
+
+ public ImportableColumn<E, String> newMandatoryColumn(String headerName, ValueSetter<E, String> valueSetter) {
+ return newMandatoryColumn(headerName, Common.STRING, valueSetter);
+ }
+
+ public <T> ImportableColumn<E, T> newMandatoryColumn(String headerName, ValueParser<T> valueParser, ValueSetter<E, T> valueSetter) {
+ Column<E, T> newColumn = Column.newImportableColumn(headerName, valueParser, valueSetter, false);
+ columnsForImport.add(newColumn);
+ return newColumn;
+ }
+
+ public ExportableColumn<E, String> newColumnForExport(String headerName, String propertyName) {
+ return newColumnForExport(headerName, propertyName, Common.STRING);
+ }
+
+ public ExportableColumn<E, String> newColumnForExport(String headerName, ValueGetter<E, String> valueGetter) {
+ return newColumnForExport(headerName, valueGetter, Common.STRING);
+ }
+
+ public <T> ExportableColumn<E, T> newColumnForExport(String headerName, String propertyName, ValueFormatter<T> valueFormatter) {
+ return newColumnForExport(headerName, new Common.BeanProperty<E, T>(propertyName), valueFormatter);
+ }
+
+ public <T> ExportableColumn<E, T> newColumnForExport(String headerName, ValueGetter<E, T> valueGetter, ValueFormatter<T> valueFormatter) {
+ ExportableColumn<E, T> newColumn = Column.newExportableColumn(headerName, valueGetter, valueFormatter, false);
+ columnsForExport.add(newColumn);
+ return newColumn;
+ }
+
+ public ImportableExportableColumn<E, String> newColumnForImportExport(String headerName, String propertyName) {
+ return newColumnForImportExport(headerName, propertyName, Common.STRING);
+ }
+
+ public ImportableExportableColumn<E, String> newColumnForImportExport(String headerName, ValueGetterSetter<E, String> valueGetterSetter) {
+ return newColumnForImportExport(headerName, valueGetterSetter, Common.STRING);
+ }
+
+ public <T> ImportableExportableColumn<E, T> newColumnForImportExport(String headerName, String propertyName, ValueParserFormatter<T> valueParserFormatter) {
+ return newColumnForImportExport(headerName, new Common.BeanProperty<E, T>(propertyName), valueParserFormatter);
+ }
+
+ public <T> ImportableExportableColumn<E, T> newColumnForImportExport(String headerName, ValueGetterSetter<E, T> valueGetterSetter, ValueParserFormatter<T> valueParserFormatter) {
+ ImportableExportableColumn<E, T> newColumn = Column.newImportableExportableColumn(headerName, valueGetterSetter, valueParserFormatter, false);
+ columnsForImport.add(newColumn);
+ columnsForExport.add(newColumn);
+ return newColumn;
+ }
+
+ public Collection<ImportableColumn<E, ?>> getColumnsForImport() {
+ return columnsForImport;
+ }
+
+ public Collection<ExportableColumn<E, ?>> getColumnsForExport() {
+ return columnsForExport;
+ }
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ModelBuilder.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValidationResult.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValidationResult.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValidationResult.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,110 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.Serializable;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public class ValidationResult implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String PROPERTY_SUCCESS = "success";
+
+ public static final String PROPERTY_MESSAGE = "message";
+
+ protected boolean success;
+
+ protected String message;
+
+ protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
+
+ public boolean getSuccess() {
+ return success;
+ }
+
+ public boolean isSuccess() {
+ return success;
+ }
+
+ public void setSuccess(boolean success) {
+ boolean oldValue = getSuccess();
+ this.success = success;
+ firePropertyChange(PROPERTY_SUCCESS, oldValue, success);
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ String oldValue = getMessage();
+ this.message = message;
+ firePropertyChange(PROPERTY_MESSAGE, oldValue, message);
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }
+
+ @Override
+ public String toString() {
+ String toString = ToStringBuilder.reflectionToString(this);
+ return toString;
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ pcs.firePropertyChange(propertyName, oldValue, newValue);
+ }
+
+
+ protected void firePropertyChange(String propertyName, Object newValue) {
+ firePropertyChange(propertyName, null, newValue);
+ }
+
+
+} //ValidationResult
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValidationResult.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueFormatter.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueFormatter.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueFormatter.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,38 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public interface ValueFormatter<T> {
+
+ String format(T value);
+
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueFormatter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetter.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetter.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetter.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,38 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public interface ValueGetter<E, T> {
+
+ T get(E object) throws Exception;
+
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetterSetter.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetterSetter.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetterSetter.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,35 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+/**
+ * TODO
+ *
+ * @author bleny <leny(a)codelutin.com>
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+public interface ValueGetterSetter<E, T> extends ValueGetter<E, T>, ValueSetter<E, T> {
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueGetterSetter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParser.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParser.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParser.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,33 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+import java.text.ParseException;
+
+public interface ValueParser<T> {
+
+ T parse(String value) throws ParseException;
+
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParser.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParserFormatter.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParserFormatter.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParserFormatter.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,28 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+public interface ValueParserFormatter<T> extends ValueParser<T>, ValueFormatter<T> {
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueParserFormatter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueSetter.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueSetter.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueSetter.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,31 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 CodeLutin, Tony Chemit, Brendan Le Ny
+ * %%
+ * 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.util.csv;
+
+public interface ValueSetter<E, T> {
+
+ void set(E object, T value) throws Exception;
+
+}
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/ValueSetter.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/package-info.java
===================================================================
--- trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/package-info.java (rev 0)
+++ trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/package-info.java 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,32 @@
+/*
+ * #%L
+ * Nuiton Utils :: Nuiton Utils
+ *
+ * $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%
+ */
+/**
+ * This package contains a framework to import and export data from a
+ * csv file using a model which permits us to validate what to do.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.4
+ */
+package org.nuiton.util.csv;
\ No newline at end of file
Property changes on: trunk/nuiton-csv/src/main/java/org/nuiton/util/csv/package-info.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_en_GB.properties
===================================================================
--- trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_en_GB.properties (rev 0)
+++ trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_en_GB.properties 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,4 @@
+csv.import.error.unableToParseValue=Unable to parse value '%s' (column '%s', line %s)
+csv.import.error.unableToReadField=Unable to read value of column '%s' at line %s
+csv.import.error.unableToReadLine=Unable to read line %s
+csv.import.error.unableToSetValue=Unable to set value '%s' (entity '%s', line %s, column '%s')
Added: trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_es_ES.properties
===================================================================
--- trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_es_ES.properties (rev 0)
+++ trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_es_ES.properties 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,4 @@
+csv.import.error.unableToParseValue=Unable to parse value '%s' (column '%s', line %s)
+csv.import.error.unableToReadField=Unable to read value of column '%s' at line %s
+csv.import.error.unableToReadLine=Unable to read line %s
+csv.import.error.unableToSetValue=Unable to set value '%s' (entity '%s', line %s, column '%s')
Added: trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_fr_FR.properties
===================================================================
--- trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_fr_FR.properties (rev 0)
+++ trunk/nuiton-csv/src/main/resources/i18n/nuiton-csv_fr_FR.properties 2011-11-22 11:29:24 UTC (rev 2230)
@@ -0,0 +1,4 @@
+csv.import.error.unableToParseValue=Erreur lors de l'interprétation de la valeur '%s' (colonne '%s', ligne %s)
+csv.import.error.unableToReadField=Impossible de lire la colonne '%s' à la ligne %s
+csv.import.error.unableToReadLine=Impossible de lire la ligne %s
+csv.import.error.unableToSetValue=Impossible d'enregistrer la valeur '%s' (entité '%s', ligne %s, column '%s')
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-11-18 11:28:09 UTC (rev 2229)
+++ trunk/pom.xml 2011-11-22 11:29:24 UTC (rev 2230)
@@ -2,8 +2,6 @@
<!--
#%L
Nuiton Utils
- $Id$
- $HeadURL$
%%
Copyright (C) 2004 - 2010 CodeLutin, Tony Chemit
%%
@@ -41,6 +39,7 @@
<modules>
<module>nuiton-utils</module>
+ <module>nuiton-csv</module>
<module>nuiton-validator</module>
<module>nuiton-profiling</module>
</modules>
@@ -55,6 +54,12 @@
<version>${nuitonI18nVersion}</version>
</dependency>
+ <dependency>
+ <groupId>net.sourceforge.javacsv</groupId>
+ <artifactId>javacsv</artifactId>
+ <version>2.0</version>
+ </dependency>
+
<!-- xworks dependencies -->
<dependency>
1
0
18 Nov '11
Author: sletellier
Date: 2011-11-18 12:28:09 +0100 (Fri, 18 Nov 2011)
New Revision: 2229
Url: http://nuiton.org/repositories/revision/nuiton-utils/2229
Log:
Revert ApplicationConfig modifications
Modified:
trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java
Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java
===================================================================
--- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-11-18 11:25:39 UTC (rev 2228)
+++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-11-18 11:28:09 UTC (rev 2229)
@@ -499,18 +499,6 @@
}
/**
- * Load all default options of enum pass in param (enum must extend {@link OptionDef})
- *
- * @param optionClasses to load
- * @param <O> type of enum extend {@link OptionDef}
- */
- public <O extends OptionDef> void loadAllDefaultOptions(Class<O>[] optionClasses) {
- for (Class<O> optionClass : optionClasses) {
- loadDefaultOptions(optionClass);
- }
- }
-
- /**
* Load default options of enum pass in param (enum must extend {@link OptionDef})
*
* @param optionClass to load
@@ -527,18 +515,6 @@
}
/**
- * Load all actions of enum pass in param (enum must extend {@link ActionDef})
- *
- * @param actionClasses to load
- * @param <A> type of enum extend {@link ActionDef}
- */
- public <A extends ActionDef> void loadAllActions(Class<A>[] actionClasses) {
- for (Class<A> optionClass : actionClasses) {
- loadActions(optionClass);
- }
- }
-
- /**
* Load actions of enum pass in param (enum must extend {@link ActionDef})
*
* @param actionClass to load
1
0