svn commit: r728718 - /ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r728718 - /ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java

jleroux@apache.org
Author: jleroux
Date: Mon Dec 22 08:11:01 2008
New Revision: 728718

URL: http://svn.apache.org/viewvc?rev=728718&view=rev
Log:
A patch from Ray Barlow "Export CSV file using specified text delimiter"  '(https://issues.apache.org/jira/browse/OFBIZ-2101) - OFBIZ-2101

Modified:
    ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java

Modified: ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java?rev=728718&r1=728717&r2=728718&view=diff
==============================================================================
--- ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java (original)
+++ ofbiz/trunk/framework/datafile/src/org/ofbiz/datafile/Record.java Mon Dec 22 08:11:01 2008
@@ -383,6 +383,10 @@
         for (ModelField modelField: modelRecord.fields) {
             String data = this.getFixedString(modelField.name);
 
+            if (isDelimited && null != modelDataFile.textDelimiter) {
+                lineBuf.append(modelDataFile.textDelimiter);
+            }
+
             // if field is null (not set) then assume we want to pad the field
             char PAD_CHAR = ' ';
 
@@ -407,9 +411,19 @@
                         modelField.name + "\" of record \"" + modelRecord.name + "\" data is: \"" + data + "\"");
 
             lineBuf.append(data);
-            if (isDelimited)
+            if (isDelimited) {
+                if (null != modelDataFile.textDelimiter) {
+                    lineBuf.append(modelDataFile.textDelimiter);
+                }
                 lineBuf.append(modelDataFile.delimiter);
+            }
         }
+
+        if (isDelimited) {
+            // just remove the last delimiter to finish clean, otherwise shows as extra column
+            lineBuf.setLength(lineBuf.length() - 1);
+        }
+
         if ((isFixedRecord || isFixedLength) && modelDataFile.recordLength > 0 && lineBuf.length() != modelDataFile.recordLength)
             throw new DataFileException("Got record length " + lineBuf.length() + " but expected record length is " + modelDataFile.recordLength +
                     " for record \"" + modelRecord.name + "\" data line is: \"" + lineBuf + "\"");