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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user