This is an automated email from the ASF dual-hosted git repository.
nmalin pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new a1f1627 Improved: Add enconding type attribute for import data file
tools (OFBIZ-10234) During the import of file via datafile import you may want
to set encoding type. Actually only the type UTF-8 is supported. This commit
allows to add a new "encoding-type" attribute into data-file to indicate the
type of encoding of the imported file.
a1f1627 is described below
commit a1f16274c280754d5f8178e820cf261cc495aa1d
Author: Nicolas Malin <[email protected]>
AuthorDate: Fri Nov 22 15:10:37 2019 +0100
Improved: Add enconding type attribute for import data file tools
(OFBIZ-10234)
During the import of file via datafile import you may want to set encoding
type.
Actually only the type UTF-8 is supported.
This commit allows to add a new "encoding-type" attribute into data-file to
indicate the type of encoding of the imported file.
Thanks to Pierre Gaudin for this improvement.
---
framework/datafile/dtd/datafiles.xsd | 1 +
.../main/java/org/apache/ofbiz/datafile/ModelDataFile.java | 13 +++++++++++++
.../java/org/apache/ofbiz/datafile/ModelDataFileReader.java | 1 +
.../main/java/org/apache/ofbiz/datafile/RecordIterator.java | 6 ++++--
4 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/framework/datafile/dtd/datafiles.xsd
b/framework/datafile/dtd/datafiles.xsd
index 3974ba9..6196c44 100644
--- a/framework/datafile/dtd/datafiles.xsd
+++ b/framework/datafile/dtd/datafiles.xsd
@@ -37,6 +37,7 @@ under the License.
<xs:attribute name="name" use="required"/>
<xs:attribute name="type-code" use="required"/>
<xs:attribute name="sender"/>
+ <xs:attribute name="encoding-type"/>
<xs:attribute name="receiver"/>
<xs:attribute name="delimiter"/>
<xs:attribute name="start-line"/>
diff --git
a/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFile.java
b/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFile.java
index abcf49c..0a268f5 100644
---
a/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFile.java
+++
b/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFile.java
@@ -62,6 +62,10 @@ public class ModelDataFile {
/** A free form description of the file */
public String description = "";
+
+ /** file enconding, by default UTF-8 is used */
+ public String encodingType = "UTF-8";
+
/**
* the End Of Line type (CRLF or CR)
@@ -168,4 +172,13 @@ public class ModelDataFile {
public void setRecords(List<ModelRecord> records) {
this.records = records;
}
+
+ public String getEncodingType() {
+ return encodingType;
+ }
+
+ public void setEncodingType(String encodingType) {
+ this.encodingType = encodingType;
+ }
+
}
diff --git
a/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFileReader.java
b/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFileReader.java
index 3c4a2d0..2cc7e5c 100644
---
a/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFileReader.java
+++
b/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFileReader.java
@@ -74,6 +74,7 @@ public final class ModelDataFileReader {
dataFile.typeCode =
UtilXml.checkEmpty(dataFileElement.getAttribute("type-code"));
dataFile.sender =
UtilXml.checkEmpty(dataFileElement.getAttribute("sender"));
dataFile.receiver =
UtilXml.checkEmpty(dataFileElement.getAttribute("receiver"));
+
dataFile.setEncodingType(UtilXml.checkEmpty(dataFileElement.getAttribute("encoding-type")));
tempStr =
UtilXml.checkEmpty(dataFileElement.getAttribute("record-length"));
if (UtilValidate.isNotEmpty(tempStr)) {
diff --git
a/framework/datafile/src/main/java/org/apache/ofbiz/datafile/RecordIterator.java
b/framework/datafile/src/main/java/org/apache/ofbiz/datafile/RecordIterator.java
index 2ea7fc8..7431cee 100644
---
a/framework/datafile/src/main/java/org/apache/ofbiz/datafile/RecordIterator.java
+++
b/framework/datafile/src/main/java/org/apache/ofbiz/datafile/RecordIterator.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
+import java.nio.charset.Charset;
import java.util.Stack;
/**
@@ -68,11 +69,12 @@ public class RecordIterator {
protected void setupStream(InputStream dataFileStream, String
locationInfo) throws DataFileException {
this.locationInfo = locationInfo;
this.dataFileStream = dataFileStream;
+ String charsetStr = modelDataFile.getEncodingType();
try {
- this.br = new BufferedReader(new InputStreamReader(dataFileStream,
"UTF-8"));
+ this.br = new BufferedReader(new InputStreamReader(dataFileStream,
Charset.forName(charsetStr)));
}
catch (Exception e) {
- throw new DataFileException("UTF-8 is not supported");
+ throw new DataFileException( charsetStr + " is not supported");
}
//move the cursor to the good start line
try {