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 java.util.List; 020 021import javax.xml.bind.annotation.XmlAccessType; 022import javax.xml.bind.annotation.XmlAccessorType; 023import javax.xml.bind.annotation.XmlAttribute; 024import javax.xml.bind.annotation.XmlElement; 025import javax.xml.bind.annotation.XmlRootElement; 026 027import org.apache.camel.model.DataFormatDefinition; 028import org.apache.camel.spi.Metadata; 029 030/** 031 * The CSV data format is used for handling CSV payloads. 032 */ 033@Metadata(firstVersion = "1.3.0", label = "dataformat,transformation,csv", title = "CSV") 034@XmlRootElement(name = "csv") 035@XmlAccessorType(XmlAccessType.FIELD) 036public class CsvDataFormat extends DataFormatDefinition { 037 // Format options 038 @XmlAttribute 039 @Metadata(label = "advanced") 040 private String formatRef; 041 @XmlAttribute 042 @Metadata(enums = "DEFAULT,EXCEL,INFORMIX_UNLOAD,INFORMIX_UNLOAD_CSV,MYSQL,RFC4180") 043 private String formatName; 044 @XmlAttribute 045 private Boolean commentMarkerDisabled; 046 @XmlAttribute 047 private String commentMarker; 048 @XmlAttribute 049 private String delimiter; 050 @XmlAttribute 051 private Boolean escapeDisabled; 052 @XmlAttribute 053 private String escape; 054 @XmlAttribute 055 private Boolean headerDisabled; 056 @XmlElement 057 private List<String> header; 058 @XmlAttribute 059 private Boolean allowMissingColumnNames; 060 @XmlAttribute 061 private Boolean ignoreEmptyLines; 062 @XmlAttribute 063 private Boolean ignoreSurroundingSpaces; 064 @XmlAttribute 065 private Boolean nullStringDisabled; 066 @XmlAttribute 067 private String nullString; 068 @XmlAttribute 069 private Boolean quoteDisabled; 070 @XmlAttribute 071 private String quote; 072 @XmlAttribute 073 private String recordSeparatorDisabled; 074 @XmlAttribute 075 private String recordSeparator; 076 @XmlAttribute 077 private Boolean skipHeaderRecord; 078 @XmlAttribute 079 private String quoteMode; 080 @XmlAttribute 081 private Boolean ignoreHeaderCase; 082 @XmlAttribute 083 private Boolean trim; 084 @XmlAttribute 085 private Boolean trailingDelimiter; 086 @XmlAttribute 087 @Metadata(label = "advanced") 088 private String marshallerFactoryRef; 089 090 // Unmarshall options 091 @XmlAttribute 092 private Boolean lazyLoad; 093 @XmlAttribute 094 private Boolean useMaps; 095 @XmlAttribute 096 private Boolean useOrderedMaps; 097 @XmlAttribute 098 private String recordConverterRef; 099 100 public CsvDataFormat() { 101 super("csv"); 102 } 103 104 public CsvDataFormat(String delimiter) { 105 this(); 106 setDelimiter(delimiter); 107 } 108 109 public CsvDataFormat(boolean lazyLoad) { 110 this(); 111 setLazyLoad(lazyLoad); 112 } 113 114 /** 115 * Sets the implementation of the CsvMarshallerFactory interface which is 116 * able to customize marshalling/unmarshalling behavior by extending 117 * CsvMarshaller or creating it from scratch. 118 * 119 * @param marshallerFactoryRef the <code>CsvMarshallerFactory</code> 120 * reference. 121 */ 122 public void setMarshallerFactoryRef(String marshallerFactoryRef) { 123 this.marshallerFactoryRef = marshallerFactoryRef; 124 } 125 126 /** 127 * Returns the <code>CsvMarshallerFactory</code> reference. 128 * 129 * @return the <code>CsvMarshallerFactory</code> or <code>null</code> if 130 * none has been specified. 131 */ 132 public String getMarshallerFactoryRef() { 133 return marshallerFactoryRef; 134 } 135 136 public String getFormatRef() { 137 return formatRef; 138 } 139 140 /** 141 * The reference format to use, it will be updated with the other format 142 * options, the default value is CSVFormat.DEFAULT 143 */ 144 public void setFormatRef(String formatRef) { 145 this.formatRef = formatRef; 146 } 147 148 public String getFormatName() { 149 return formatName; 150 } 151 152 /** 153 * The name of the format to use, the default value is CSVFormat.DEFAULT 154 */ 155 public void setFormatName(String formatName) { 156 this.formatName = formatName; 157 } 158 159 public Boolean getCommentMarkerDisabled() { 160 return commentMarkerDisabled; 161 } 162 163 /** 164 * Disables the comment marker of the reference format. 165 */ 166 public void setCommentMarkerDisabled(Boolean commentMarkerDisabled) { 167 this.commentMarkerDisabled = commentMarkerDisabled; 168 } 169 170 public String getCommentMarker() { 171 return commentMarker; 172 } 173 174 /** 175 * Sets the comment marker of the reference format. 176 */ 177 public void setCommentMarker(String commentMarker) { 178 this.commentMarker = commentMarker; 179 } 180 181 public String getDelimiter() { 182 return delimiter; 183 } 184 185 /** 186 * Sets the delimiter to use. 187 * <p/> 188 * The default value is , (comma) 189 */ 190 public void setDelimiter(String delimiter) { 191 this.delimiter = delimiter; 192 } 193 194 public Boolean getEscapeDisabled() { 195 return escapeDisabled; 196 } 197 198 /** 199 * Use for disabling using escape character 200 */ 201 public void setEscapeDisabled(Boolean escapeDisabled) { 202 this.escapeDisabled = escapeDisabled; 203 } 204 205 public String getEscape() { 206 return escape; 207 } 208 209 /** 210 * Sets the escape character to use 211 */ 212 public void setEscape(String escape) { 213 this.escape = escape; 214 } 215 216 /** 217 * Use for disabling headers 218 */ 219 public Boolean getHeaderDisabled() { 220 return headerDisabled; 221 } 222 223 public void setHeaderDisabled(Boolean headerDisabled) { 224 this.headerDisabled = headerDisabled; 225 } 226 227 public List<String> getHeader() { 228 return header; 229 } 230 231 /** 232 * To configure the CSV headers 233 */ 234 public void setHeader(List<String> header) { 235 this.header = header; 236 } 237 238 public Boolean getAllowMissingColumnNames() { 239 return allowMissingColumnNames; 240 } 241 242 /** 243 * Whether to allow missing column names. 244 */ 245 public void setAllowMissingColumnNames(Boolean allowMissingColumnNames) { 246 this.allowMissingColumnNames = allowMissingColumnNames; 247 } 248 249 public Boolean getIgnoreEmptyLines() { 250 return ignoreEmptyLines; 251 } 252 253 /** 254 * Whether to ignore empty lines. 255 */ 256 public void setIgnoreEmptyLines(Boolean ignoreEmptyLines) { 257 this.ignoreEmptyLines = ignoreEmptyLines; 258 } 259 260 public Boolean getIgnoreSurroundingSpaces() { 261 return ignoreSurroundingSpaces; 262 } 263 264 /** 265 * Whether to ignore surrounding spaces 266 */ 267 public void setIgnoreSurroundingSpaces(Boolean ignoreSurroundingSpaces) { 268 this.ignoreSurroundingSpaces = ignoreSurroundingSpaces; 269 } 270 271 public Boolean getNullStringDisabled() { 272 return nullStringDisabled; 273 } 274 275 /** 276 * Used to disable null strings 277 */ 278 public void setNullStringDisabled(Boolean nullStringDisabled) { 279 this.nullStringDisabled = nullStringDisabled; 280 } 281 282 public String getNullString() { 283 return nullString; 284 } 285 286 /** 287 * Sets the null string 288 */ 289 public void setNullString(String nullString) { 290 this.nullString = nullString; 291 } 292 293 public Boolean getQuoteDisabled() { 294 return quoteDisabled; 295 } 296 297 /** 298 * Used to disable quotes 299 */ 300 public void setQuoteDisabled(Boolean quoteDisabled) { 301 this.quoteDisabled = quoteDisabled; 302 } 303 304 public String getQuote() { 305 return quote; 306 } 307 308 /** 309 * Sets the quote which by default is " 310 */ 311 public void setQuote(String quote) { 312 this.quote = quote; 313 } 314 315 public String getRecordSeparatorDisabled() { 316 return recordSeparatorDisabled; 317 } 318 319 /** 320 * Used for disabling record separator 321 */ 322 public void setRecordSeparatorDisabled(String recordSeparatorDisabled) { 323 this.recordSeparatorDisabled = recordSeparatorDisabled; 324 } 325 326 public String getRecordSeparator() { 327 return recordSeparator; 328 } 329 330 /** 331 * Sets the record separator (aka new line) which by default is new line 332 * characters (CRLF) 333 */ 334 public void setRecordSeparator(String recordSeparator) { 335 this.recordSeparator = recordSeparator; 336 } 337 338 public Boolean getSkipHeaderRecord() { 339 return skipHeaderRecord; 340 } 341 342 /** 343 * Whether to skip the header record in the output 344 */ 345 public void setSkipHeaderRecord(Boolean skipHeaderRecord) { 346 this.skipHeaderRecord = skipHeaderRecord; 347 } 348 349 public String getQuoteMode() { 350 return quoteMode; 351 } 352 353 /** 354 * Sets the quote mode 355 */ 356 public void setQuoteMode(String quoteMode) { 357 this.quoteMode = quoteMode; 358 } 359 360 public Boolean getLazyLoad() { 361 return lazyLoad; 362 } 363 364 /** 365 * Whether the unmarshalling should produce an iterator that reads the lines 366 * on the fly or if all the lines must be read at one. 367 */ 368 public void setLazyLoad(Boolean lazyLoad) { 369 this.lazyLoad = lazyLoad; 370 } 371 372 public Boolean getUseMaps() { 373 return useMaps; 374 } 375 376 /** 377 * Whether the unmarshalling should produce maps (HashMap)for the lines 378 * values instead of lists. It requires to have header (either defined or 379 * collected). 380 */ 381 public void setUseMaps(Boolean useMaps) { 382 this.useMaps = useMaps; 383 } 384 385 public Boolean getUseOrderedMaps() { 386 return useOrderedMaps; 387 } 388 389 /** 390 * Whether the unmarshalling should produce ordered maps (LinkedHashMap) for 391 * the lines values instead of lists. It requires to have header (either 392 * defined or collected). 393 */ 394 public void setUseOrderedMaps(Boolean useOrderedMaps) { 395 this.useOrderedMaps = useOrderedMaps; 396 } 397 398 public String getRecordConverterRef() { 399 return recordConverterRef; 400 } 401 402 /** 403 * Refers to a custom <tt>CsvRecordConverter</tt> to lookup from the 404 * registry to use. 405 */ 406 public void setRecordConverterRef(String recordConverterRef) { 407 this.recordConverterRef = recordConverterRef; 408 } 409 410 /** 411 * Sets whether or not to trim leading and trailing blanks. 412 */ 413 public void setTrim(Boolean trim) { 414 this.trim = trim; 415 } 416 417 public Boolean getTrim() { 418 return trim; 419 } 420 421 /** 422 * Sets whether or not to ignore case when accessing header names. 423 */ 424 public void setIgnoreHeaderCase(Boolean ignoreHeaderCase) { 425 this.ignoreHeaderCase = ignoreHeaderCase; 426 } 427 428 public Boolean getIgnoreHeaderCase() { 429 return ignoreHeaderCase; 430 } 431 432 /** 433 * Sets whether or not to add a trailing delimiter. 434 */ 435 public void setTrailingDelimiter(Boolean trailingDelimiter) { 436 this.trailingDelimiter = trailingDelimiter; 437 } 438 439 public Boolean getTrailingDelimiter() { 440 return trailingDelimiter; 441 } 442 443}