Skip to content
Permalink
Browse files

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.
  • Loading branch information
nmalin committed Nov 22, 2019
1 parent 4947e5c commit a1f16274c280754d5f8178e820cf261cc495aa1d
@@ -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"/>
@@ -62,6 +62,10 @@

/** 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 void setEOLType(String eolType) {
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 @@ private static ModelDataFile createModelDataFile(Element dataFileElement) {
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.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Stack;

/**
@@ -68,11 +69,12 @@ public RecordIterator(InputStream dataFileStream, ModelDataFile modelDataFile, S
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 {

0 comments on commit a1f1627

Please sign in to comment.
You can’t perform that action at this time.