Author: nmalin
Date: Sat Dec 23 14:14:45 2017 New Revision: 1819151 URL: http://svn.apache.org/viewvc?rev=1819151&view=rev Log: Improved: In CSV export file from data-file add a new attribute to select the EOL type (OFBIZ-9536) During the file CSV generation by data-file engine, it is not possible to choose the end of line char. It is always "CR". With this improvement it's now possible to define a eol-type attribute on data-file element with value CR or CRLF to use in the csv file result. Example: <data-file name="MyCsvTest" separator-style="delimited" type-code="text" delimiter=";" eol-type="CRLF"> <record name="Test">... </data-file> Thanks Pierre Gaudin for this proposal. Modified: ofbiz/ofbiz-framework/trunk/framework/datafile/dtd/datafiles.xsd ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFile.java ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFileReader.java ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/Record.java Modified: ofbiz/ofbiz-framework/trunk/framework/datafile/dtd/datafiles.xsd URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/datafile/dtd/datafiles.xsd?rev=1819151&r1=1819150&r2=1819151&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/datafile/dtd/datafiles.xsd (original) +++ ofbiz/ofbiz-framework/trunk/framework/datafile/dtd/datafiles.xsd Sat Dec 23 14:14:45 2017 @@ -51,6 +51,14 @@ under the License. </xs:restriction> </xs:simpleType> </xs:attribute> + <xs:attribute name="eol-type" default="CR"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="CR"/> + <xs:enumeration value="CRLF"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> <xs:attribute name="description"/> </xs:attributeGroup> <xs:element name="record"> Modified: ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFile.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFile.java?rev=1819151&r1=1819150&r2=1819151&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFile.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFile.java Sat Dec 23 14:14:45 2017 @@ -63,6 +63,11 @@ public class ModelDataFile { /** A free form description of the file */ public String description = ""; + /** + * the End Of Line type (CRLF or CR) + */ + private String eolType = null; + /** List of record definitions for the file */ public List<ModelRecord> records = new ArrayList<>(); @@ -148,6 +153,14 @@ public class ModelDataFile { this.description = description; } + public String getEOLType() { + return eolType; + } + + public void setEOLType(String eolType) { + this.eolType = eolType; + } + public List<ModelRecord> getRecords() { return records; } Modified: ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFileReader.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFileReader.java?rev=1819151&r1=1819150&r2=1819151&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFileReader.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/ModelDataFileReader.java Sat Dec 23 14:14:45 2017 @@ -93,6 +93,11 @@ public final class ModelDataFileReader { dataFile.textDelimiter = tempStr; } + tempStr = UtilXml.checkEmpty(dataFileElement.getAttribute("eol-type")); + if (UtilValidate.isNotEmpty(tempStr)) { + dataFile.setEOLType(tempStr); + } + dataFile.separatorStyle = UtilXml.checkEmpty(dataFileElement.getAttribute("separator-style")); dataFile.description = UtilXml.checkEmpty(dataFileElement.getAttribute("description")); Modified: ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/Record.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/Record.java?rev=1819151&r1=1819150&r2=1819151&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/Record.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/datafile/src/main/java/org/apache/ofbiz/datafile/Record.java Sat Dec 23 14:14:45 2017 @@ -436,7 +436,11 @@ public class Record implements Serializa } if (isFixedLength || isDelimited) { - lineBuf.append('\n'); + if ("CRLF".equals(modelDataFile.getEOLType())) { + lineBuf.append("\\r\\n"); + } else { + lineBuf.append('\n'); + } } return lineBuf.toString(); |
Free forum by Nabble | Edit this page |