camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1201277 - in /camel/branches/camel-2.8.x: ./ components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/ components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/ components/camel-bindy/src/test/java/or...
Date Sat, 12 Nov 2011 15:03:50 GMT
Author: davsclaus
Date: Sat Nov 12 15:03:50 2011
New Revision: 1201277

URL: http://svn.apache.org/viewvc?rev=1201277&view=rev
Log:
CAMEL-4672: Added quote option to CsvRecord in bindy to make it easy to configure using a
quote when unmarshalling to CSV.

Added:
    camel/branches/camel-2.8.x/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv2/BindyMarshalWithQuoteTest.java
      - copied unchanged from r1201276, camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv2/BindyMarshalWithQuoteTest.java
Modified:
    camel/branches/camel-2.8.x/   (props changed)
    camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
    camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
    camel/branches/camel-2.8.x/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv2/WeatherModel.java

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Nov 12 15:03:50 2011
@@ -1 +1 @@
-/camel/trunk:1186106,1186625,1186772,1187221,1187485,1187882,1187893,1188070-1188085,1188642,1188674,1188879,1188881,1189139,1189600,1189681,1189693,1189737,1190212-1190213,1190246,1190303,1195317,1195616,1196210,1197450,1197933,1197948,1198199,1198338,1198340,1199123,1199137,1199654,1199683,1199703,1199739,1199804,1200214,1200771,1200819,1200861,1201263
+/camel/trunk:1186106,1186625,1186772,1187221,1187485,1187882,1187893,1188070-1188085,1188642,1188674,1188879,1188881,1189139,1189600,1189681,1189693,1189737,1190212-1190213,1190246,1190303,1195317,1195616,1196210,1197450,1197933,1197948,1198199,1198338,1198340,1199123,1199137,1199654,1199683,1199703,1199739,1199804,1200214,1200771,1200819,1200861,1201263,1201276

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java?rev=1201277&r1=1201276&r2=1201277&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
(original)
+++ camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
Sat Nov 12 15:03:50 2011
@@ -63,6 +63,7 @@ public class BindyCsvFactory extends Bin
     private boolean skipFirstLine;
     private boolean generateHeaderColumnNames;
     private boolean messageOrdered;
+    private String quote;
 
     public BindyCsvFactory(PackageScanClassResolver resolver, String... packageNames) throws
Exception {
         super(resolver, packageNames);
@@ -288,7 +289,14 @@ public class BindyCsvFactory extends Bin
                 while (itx.hasNext()) {
                     String res = (String)itx.next();
                     if (res != null) {
+                        // the field may be enclosed in quotes if a quote was configured
+                        if (quote != null) {
+                            buffer.append(quote);
+                        }
                         buffer.append(res);
+                        if (quote != null) {
+                            buffer.append(quote);
+                        }
                     }
 
                     if (itx.hasNext()) {
@@ -534,6 +542,11 @@ public class BindyCsvFactory extends Bin
                     // Get isOrdered parameter
                     messageOrdered = record.isOrdered();
                     LOG.debug("Must CSV record be ordered: {}", messageOrdered);
+
+                    if (ObjectHelper.isNotEmpty(record.quote())) {
+                        quote = record.quote();
+                        LOG.debug("Quoting columns with: {}", quote);
+                    }
                 }
 
                 if (section != null) {

Modified: camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java?rev=1201277&r1=1201276&r2=1201277&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
(original)
+++ camel/branches/camel-2.8.x/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
Sat Nov 12 15:03:50 2011
@@ -39,47 +39,40 @@ public @interface CsvRecord {
 
     /**
      * Name describing the record (optional)
-     * 
-     * @return String
      */
     String name() default "";
 
     /**
      * Separator used to split a record in tokens (mandatory)
-     * 
-     * @return String
      */
     String separator();
 
     /**
      * The skipFirstLine parameter will allow to skip or not the first line of a
      * CSV file. This line often contains columns definition
-     * 
-     * @return boolean
      */
     boolean skipFirstLine() default false;
 
     /**
      * Character to be used to add a carriage return after each record
-     * (optional) Three values can be used : WINDOWS, UNIX or MAC
-     * 
-     * @return String
+     * (optional) Three values can be used : WINDOWS, UNIX or MAC.
      */
     String crlf() default "WINDOWS";
 
     /**
      * The generateHeaderColumns parameter allow to add in the CSV generated the
      * header containing names of the columns
-     * 
-     * @return boolean
      */
     boolean generateHeaderColumns() default false;
 
     /**
      * Indicates if the message must be ordered in output
-     * 
-     * @return boolean
      */
     boolean isOrdered() default false;
 
+    /**
+     * Whether to marshal columns with the given quote character (optional)
+     */
+    String quote() default "";
+
 }

Modified: camel/branches/camel-2.8.x/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv2/WeatherModel.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv2/WeatherModel.java?rev=1201277&r1=1201276&r2=1201277&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv2/WeatherModel.java
(original)
+++ camel/branches/camel-2.8.x/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv2/WeatherModel.java
Sat Nov 12 15:03:50 2011
@@ -22,7 +22,7 @@ import org.apache.camel.dataformat.bindy
 /**
  *
  */
-@CsvRecord(separator = ",")
+@CsvRecord(separator = ",", quote = "\"")
 public class WeatherModel {
 
     @DataField(pos = 1)



Mime
View raw message