Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 11274 invoked from network); 5 May 2010 04:47:47 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 5 May 2010 04:47:47 -0000 Received: (qmail 4361 invoked by uid 500); 5 May 2010 04:47:46 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 4154 invoked by uid 500); 5 May 2010 04:47:45 -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 4146 invoked by uid 99); 5 May 2010 04:47:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 May 2010 04:47:44 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of claus.ibsen@gmail.com designates 74.125.82.45 as permitted sender) Received: from [74.125.82.45] (HELO mail-ww0-f45.google.com) (74.125.82.45) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 May 2010 04:47:38 +0000 Received: by wwb28 with SMTP id 28so903390wwb.32 for ; Tue, 04 May 2010 21:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=pqWwuVevG6phJqa1OkNmj71sMUpuf1C3MRmq4Srf5mQ=; b=Pk5meFtFBVF4cMyB14ahhIOkyIobJdOPOv/psHOVqQsu4UXMg0NvSWxZurhZPi69Sn XWJvsvtClmeT1v8UvTBERFU/m4hPUA4kBFnpiJbNOfNpbe6LNb3PC+WAVLJKfwCvEBdO 8VI2jMQi0mJdXp6x77hyiymUumPgO3nsH0Xso= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=wHTy78fmvMMQkAaUqhni19BdWAzePJ58oPKXSvgMQdEelZBZpx419AWthWb+mW8DOf 8ECZXFFywrIXesil7+b3a6GAwPIlFVyzI89hCMQVGTiyj+J6cEYl7XZFm0S54jegxCpG AHJ4u8fHDTu/rniluVVHLgY/c9YeQH8nbgVwM= Received: by 10.216.172.66 with SMTP id s44mr585951wel.162.1273034838248; Tue, 04 May 2010 21:47:18 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.25.6 with HTTP; Tue, 4 May 2010 21:46:58 -0700 (PDT) In-Reply-To: References: <28443740.post@talk.nabble.com> From: Claus Ibsen Date: Wed, 5 May 2010 06:46:58 +0200 Message-ID: Subject: Re: Camel-csv 2.2.0: reading a single line csv file To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Tue, May 4, 2010 at 5:19 PM, Claus Ibsen wrote: > Hi > > On Tue, May 4, 2010 at 8:57 AM, Attilio Don=E0 w= rote: >> >> Hi all, >> >> I've to read a csv file and I want use camel to do this. Camel bindy see= ms >> to me that doesn't know the csv convention that a field separator can be= a >> character field using double quotes: >> >> "contains, =A0comma", "another field" >> > > Yeah that would be good to be able to do with camel-bindy. Do you mind > creating a JIRA ticket? > I have created the JIRA ticket https://issues.apache.org/activemq/browse/CAMEL-2691 > >> 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) >> { >> =A0 =A0// do magic here as in the manual if the file as more than one ro= w 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: >> >> >> =A0 =A0 =A0 =A0 public void modelsCsvFile(Exchange exchange) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 List csvData =3D (List) exchange.getIn()= .getBody(); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (csvData.get(0).getClass().equals(Str= ing.class)) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 log.debug("single row fi= le"); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Vendor vendor =3D vendor= DAO.bind((String)csvData.get(0)); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Model model =3D new Mode= l(vendor, (String)csvData.get(1)); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 modelDAO.bind(model); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 for (List row : (List)csvData) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 log.debug("read [{}] [{}= ]", row.get(0), row.get(1)); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Vendor vendor =3D vendor= DAO.bind((String)row.get(0)); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Model model =3D new Mode= l(vendor, (String)row.get(1)); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 modelDAO.bind(model); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 } >> >> Attilio >> >> -- >> View this message in context: http://old.nabble.com/Camel-csv-2.2.0%3A-r= eading-a-single-line-csv-file-tp28443740p28443740.html >> Sent from the Camel - Users mailing list archive at Nabble.com. >> > > > > -- > Claus Ibsen > Apache Camel Committer > > 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 Claus Ibsen Apache Camel Committer 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