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