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.XmlElementRef;
025
026import org.apache.camel.model.DataFormatDefinition;
027import org.apache.camel.spi.Metadata;
028
029/**
030 * Represents the common parts of all uniVocity
031 * {@link org.apache.camel.spi.DataFormat} parsers.
032 */
033@Metadata(label = "dataformat,transformation,csv", title = "uniVocity")
034@XmlAccessorType(XmlAccessType.FIELD)
035public abstract class UniVocityAbstractDataFormat extends DataFormatDefinition {
036
037    @XmlAttribute
038    protected String nullValue;
039    @XmlAttribute
040    @Metadata(javaType = "java.lang.Boolean", defaultValue = "true")
041    protected String skipEmptyLines;
042    @XmlAttribute
043    @Metadata(javaType = "java.lang.Boolean", defaultValue = "true")
044    protected String ignoreTrailingWhitespaces;
045    @XmlAttribute
046    @Metadata(javaType = "java.lang.Boolean", defaultValue = "true")
047    protected String ignoreLeadingWhitespaces;
048    @XmlAttribute
049    @Metadata(javaType = "java.lang.Boolean")
050    protected String headersDisabled;
051    @XmlElementRef
052    protected List<UniVocityHeader> headers;
053    @XmlAttribute
054    @Metadata(javaType = "java.lang.Boolean")
055    protected String headerExtractionEnabled;
056    @XmlAttribute
057    @Metadata(javaType = "java.lang.Integer")
058    protected String numberOfRecordsToRead;
059    @XmlAttribute
060    protected String emptyValue;
061    @XmlAttribute
062    protected String lineSeparator;
063    @XmlAttribute
064    @Metadata(defaultValue = "\\n")
065    protected String normalizedLineSeparator;
066    @XmlAttribute
067    @Metadata(defaultValue = "#")
068    protected String comment;
069    @XmlAttribute
070    @Metadata(javaType = "java.lang.Boolean")
071    protected String lazyLoad;
072    @XmlAttribute
073    @Metadata(javaType = "java.lang.Boolean")
074    protected String asMap;
075
076    protected UniVocityAbstractDataFormat() {
077        // This constructor is needed by jaxb for schema generation
078    }
079
080    protected UniVocityAbstractDataFormat(String dataFormatName) {
081        super(dataFormatName);
082    }
083
084    public String getNullValue() {
085        return nullValue;
086    }
087
088    /**
089     * The string representation of a null value.
090     * <p/>
091     * The default value is null
092     */
093    public void setNullValue(String nullValue) {
094        this.nullValue = nullValue;
095    }
096
097    public String getSkipEmptyLines() {
098        return skipEmptyLines;
099    }
100
101    /**
102     * Whether or not the empty lines must be ignored.
103     * <p/>
104     * The default value is true
105     */
106    public void setSkipEmptyLines(String skipEmptyLines) {
107        this.skipEmptyLines = skipEmptyLines;
108    }
109
110    public String getIgnoreTrailingWhitespaces() {
111        return ignoreTrailingWhitespaces;
112    }
113
114    /**
115     * Whether or not the trailing white spaces must ignored.
116     * <p/>
117     * The default value is true
118     */
119    public void setIgnoreTrailingWhitespaces(String ignoreTrailingWhitespaces) {
120        this.ignoreTrailingWhitespaces = ignoreTrailingWhitespaces;
121    }
122
123    public String getIgnoreLeadingWhitespaces() {
124        return ignoreLeadingWhitespaces;
125    }
126
127    /**
128     * Whether or not the leading white spaces must be ignored.
129     * <p/>
130     * The default value is true
131     */
132    public void setIgnoreLeadingWhitespaces(String ignoreLeadingWhitespaces) {
133        this.ignoreLeadingWhitespaces = ignoreLeadingWhitespaces;
134    }
135
136    public String getHeadersDisabled() {
137        return headersDisabled;
138    }
139
140    /**
141     * Whether or not the headers are disabled. When defined, this option
142     * explicitly sets the headers as null which indicates that there is no
143     * header.
144     * <p/>
145     * The default value is false
146     */
147    public void setHeadersDisabled(String headersDisabled) {
148        this.headersDisabled = headersDisabled;
149    }
150
151    public List<UniVocityHeader> getHeaders() {
152        return headers;
153    }
154
155    /**
156     * The headers to use.
157     */
158    public void setHeaders(List<UniVocityHeader> headers) {
159        this.headers = headers;
160    }
161
162    public String getHeaderExtractionEnabled() {
163        return headerExtractionEnabled;
164    }
165
166    /**
167     * Whether or not the header must be read in the first line of the test
168     * document
169     * <p/>
170     * The default value is false
171     */
172    public void setHeaderExtractionEnabled(String headerExtractionEnabled) {
173        this.headerExtractionEnabled = headerExtractionEnabled;
174    }
175
176    public String getNumberOfRecordsToRead() {
177        return numberOfRecordsToRead;
178    }
179
180    /**
181     * The maximum number of record to read.
182     */
183    public void setNumberOfRecordsToRead(String numberOfRecordsToRead) {
184        this.numberOfRecordsToRead = numberOfRecordsToRead;
185    }
186
187    public String getEmptyValue() {
188        return emptyValue;
189    }
190
191    /**
192     * The String representation of an empty value
193     */
194    public void setEmptyValue(String emptyValue) {
195        this.emptyValue = emptyValue;
196    }
197
198    public String getLineSeparator() {
199        return lineSeparator;
200    }
201
202    /**
203     * The line separator of the files
204     * <p/>
205     * The default value is to use the JVM platform line separator
206     */
207    public void setLineSeparator(String lineSeparator) {
208        this.lineSeparator = lineSeparator;
209    }
210
211    public String getNormalizedLineSeparator() {
212        return normalizedLineSeparator;
213    }
214
215    /**
216     * The normalized line separator of the files
217     * <p/>
218     * The default value is a new line character.
219     */
220    public void setNormalizedLineSeparator(String normalizedLineSeparator) {
221        this.normalizedLineSeparator = normalizedLineSeparator;
222    }
223
224    public String getComment() {
225        return comment;
226    }
227
228    /**
229     * The comment symbol.
230     * <p/>
231     * The default value is #
232     */
233    public void setComment(String comment) {
234        this.comment = comment;
235    }
236
237    public String getLazyLoad() {
238        return lazyLoad;
239    }
240
241    /**
242     * Whether the unmarshalling should produce an iterator that reads the lines
243     * on the fly or if all the lines must be read at one.
244     * <p/>
245     * The default value is false
246     */
247    public void setLazyLoad(String lazyLoad) {
248        this.lazyLoad = lazyLoad;
249    }
250
251    public String getAsMap() {
252        return asMap;
253    }
254
255    /**
256     * Whether the unmarshalling should produce maps for the lines values
257     * instead of lists. It requires to have header (either defined or
258     * collected).
259     * <p/>
260     * The default value is false
261     */
262    public void setAsMap(String asMap) {
263        this.asMap = asMap;
264    }
265
266}