Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 66377 invoked from network); 11 Jun 2010 15:27:05 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 Jun 2010 15:27:05 -0000 Received: (qmail 16817 invoked by uid 500); 11 Jun 2010 15:27:05 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 16796 invoked by uid 500); 11 Jun 2010 15:27:05 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 16783 invoked by uid 99); 11 Jun 2010 15:27:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Jun 2010 15:27:05 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_HELO_PASS,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Jun 2010 15:26:59 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1ON67y-0000QL-Kr for users@camel.apache.org; Fri, 11 Jun 2010 08:26:38 -0700 Message-ID: <28856669.post@talk.nabble.com> Date: Fri, 11 Jun 2010 08:26:38 -0700 (PDT) From: cmoulliard To: users@camel.apache.org Subject: Re: Camel-csv 2.2.0: reading a single line csv file In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Nabble-From: cmoulliard@gmail.com References: <28443740.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org Do you want also that the CSV generated contain double quotes like "xxxx","yyyy " ? KR, charles Claus Ibsen-2 wrote: >=20 > Hi >=20 > On Tue, May 4, 2010 at 8:57 AM, Attilio Don=C3=A0 > wrote: >> >> Hi all, >> >> I've to read a csv file and I want use camel to do this. Camel bindy >> seems >> to me that doesn't know the csv convention that a field separator can be >> a >> character field using double quotes: >> >> "contains, =C2=A0comma", "another field" >> >=20 > Yeah that would be good to be able to do with camel-bindy. Do you mind > creating a JIRA ticket? >=20 >=20 >> So the adopted solution is camel-csv. >> >> Using camel-csv to parse the csv file as in the camel manual works only >> if >> the csv file has more than one line of data: >> >> // Some comments here >> public void doHandleCsvData(List> csvData) >> { >> =C2=A0 =C2=A0// do magic here as in the manual if the file as more than = one row of >> data >> } >> >> If the csv file has 1 row the parameter passed to the method bean >> doHandleCsvData is a List. >> >> As a quick workaround, instead of using parametrized generics, it is >> possible to do something like this: >> >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 public void modelsCsvFile(Exchange exchange)= { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 List csvData =3D= (List) exchange.getIn().getBody(); >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (csvData.get(= 0).getClass().equals(String.class)) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 log.debug("single row file"); >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 Vendor vendor =3D >> vendorDAO.bind((String)csvData.get(0)); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 Model model =3D new Model(vendor, >> (String)csvData.get(1)); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 modelDAO.bind(model); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 return; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for (List row : = (List)csvData) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 log.debug("read [{}] [{}]", row.get(0), >> row.get(1)); >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 Vendor vendor =3D >> vendorDAO.bind((String)row.get(0)); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 Model model =3D new Model(vendor, >> (String)row.get(1)); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 modelDAO.bind(model); >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } >> >> Attilio >> >> -- >> View this message in context: >> http://old.nabble.com/Camel-csv-2.2.0%3A-reading-a-single-line-csv-file-= tp28443740p28443740.html >> Sent from the Camel - Users mailing list archive at Nabble.com. >> >=20 >=20 >=20 > --=20 > Claus Ibsen > Apache Camel Committer >=20 > Author of Camel in Action: http://www.manning.com/ibsen/ > Open Source Integration: http://fusesource.com > Blog: http://davsclaus.blogspot.com/ > Twitter: http://twitter.com/davsclaus >=20 >=20 ----- Charles Moulliard SOA Architect My Blog : http://cmoulliard.blogspot.com/ http://cmoulliard.blogspot.com/ = =20 --=20 View this message in context: http://old.nabble.com/Camel-csv-2.2.0%3A-read= ing-a-single-line-csv-file-tp28443740p28856669.html Sent from the Camel - Users mailing list archive at Nabble.com.