001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model.dataformat; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023 024import org.apache.camel.CamelContext; 025import org.apache.camel.spi.DataFormat; 026import org.apache.camel.spi.Metadata; 027 028/** 029 * The uniVocity CSV data format is used for working with CSV (Comma Separated Values) flat payloads. 030 */ 031@Metadata(firstVersion = "2.15.0", label = "dataformat,transformation,csv", title = "uniVocity CSV") 032@XmlRootElement(name = "univocity-csv") 033@XmlAccessorType(XmlAccessType.FIELD) 034public class UniVocityCsvDataFormat extends UniVocityAbstractDataFormat { 035 @XmlAttribute 036 private Boolean quoteAllFields; 037 @XmlAttribute @Metadata(defaultValue = "\"") 038 private String quote; 039 @XmlAttribute @Metadata(defaultValue = "\"") 040 private String quoteEscape; 041 @XmlAttribute @Metadata(defaultValue = ",") 042 private String delimiter; 043 044 public UniVocityCsvDataFormat() { 045 super("univocity-csv"); 046 } 047 048 public Boolean getQuoteAllFields() { 049 return quoteAllFields; 050 } 051 052 /** 053 * Whether or not all values must be quoted when writing them. 054 */ 055 public void setQuoteAllFields(Boolean quoteAllFields) { 056 this.quoteAllFields = quoteAllFields; 057 } 058 059 public String getQuote() { 060 return quote; 061 } 062 063 /** 064 * The quote symbol. 065 */ 066 public void setQuote(String quote) { 067 this.quote = quote; 068 } 069 070 public String getQuoteEscape() { 071 return quoteEscape; 072 } 073 074 /** 075 * The quote escape symbol 076 */ 077 public void setQuoteEscape(String quoteEscape) { 078 this.quoteEscape = quoteEscape; 079 } 080 081 public String getDelimiter() { 082 return delimiter; 083 } 084 085 /** 086 * The delimiter of values 087 */ 088 public void setDelimiter(String delimiter) { 089 this.delimiter = delimiter; 090 } 091 092 @Override 093 protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) { 094 super.configureDataFormat(dataFormat, camelContext); 095 096 if (quoteAllFields != null) { 097 setProperty(camelContext, dataFormat, "quoteAllFields", quoteAllFields); 098 } 099 if (quote != null) { 100 setProperty(camelContext, dataFormat, "quote", singleCharOf("quote", quote)); 101 } 102 if (quoteEscape != null) { 103 setProperty(camelContext, dataFormat, "quoteEscape", singleCharOf("quoteEscape", quoteEscape)); 104 } 105 if (delimiter != null) { 106 setProperty(camelContext, dataFormat, "delimiter", singleCharOf("delimiter", delimiter)); 107 } 108 } 109}