You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/02/18 09:33:06 UTC
[4/4] camel git commit: CAMEL-10853: Aligned code. This closes #1474
CAMEL-10853: Aligned code. This closes #1474
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1911e501
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1911e501
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1911e501
Branch: refs/heads/camel-2.18.x
Commit: 1911e501563547e5aad0b2d859328a3f8e38d66e
Parents: 05a7d0c
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Feb 18 10:28:21 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Feb 18 10:33:02 2017 +0100
----------------------------------------------------------------------
.../camel/model/dataformat/CsvDataFormat.java | 39 +++------
.../model/dataformat/CsvDataFormatTest.java | 89 --------------------
.../springboot/CsvDataFormatConfiguration.java | 36 ++++++++
.../camel-csv/src/main/docs/csv-dataformat.adoc | 5 +-
4 files changed, 50 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1911e501/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java b/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
index 5e35f62..1a6838a 100644
--- a/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
@@ -17,7 +17,6 @@
package org.apache.camel.model.dataformat;
import java.util.List;
-import java.util.stream.Stream;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@@ -171,17 +170,16 @@ public class CsvDataFormat extends DataFormatDefinition {
if (quoteMode != null) {
setProperty(camelContext, dataFormat, "quoteMode", quoteMode);
}
- Stream.of("trim", "ignoreHeaderCase", "trailingDelimiter")
- .forEach(item -> {
- try {
- setProperty(camelContext, dataFormat, item,
- CsvDataFormat.class.getDeclaredField(item).get(this));
- } catch (Exception e) {
- // Not expected to happen
- throw new AssertionError(e);
- }
- });
-
+ if (trim != null) {
+ setProperty(camelContext, dataFormat, "trim", trim);
+ }
+ if (ignoreHeaderCase != null) {
+ setProperty(camelContext, dataFormat, "ignoreHeaderCase", ignoreHeaderCase);
+ }
+ if (trailingDelimiter != null) {
+ setProperty(camelContext, dataFormat, "trailingDelimiter", trailingDelimiter);
+ }
+
// Unmarshall options
if (lazyLoad != null) {
setProperty(camelContext, dataFormat, "lazyLoad", lazyLoad);
@@ -459,12 +457,6 @@ public class CsvDataFormat extends DataFormatDefinition {
/**
* Sets whether or not to trim leading and trailing blanks.
- * <p>
- * If {@code null} then the default value of the format used.
- * </p>
- *
- * @param trim whether or not to trim leading and trailing blanks.
- * <code>null</code> value allowed.
*/
public void setTrim(Boolean trim) {
this.trim = trim;
@@ -476,12 +468,6 @@ public class CsvDataFormat extends DataFormatDefinition {
/**
* Sets whether or not to ignore case when accessing header names.
- * <p>
- * If {@code null} then the default value of the format used.
- * </p>
- *
- * @param ignoreHeaderCase whether or not to ignore case when accessing header names.
- * <code>null</code> value allowed.
*/
public void setIgnoreHeaderCase(Boolean ignoreHeaderCase) {
this.ignoreHeaderCase = ignoreHeaderCase;
@@ -493,11 +479,6 @@ public class CsvDataFormat extends DataFormatDefinition {
/**
* Sets whether or not to add a trailing delimiter.
- * <p>
- * If {@code null} then the default value of the format used.
- * </p>
- *
- * @param trailingDelimiter whether or not to add a trailing delimiter.
*/
public void setTrailingDelimiter(Boolean trailingDelimiter) {
this.trailingDelimiter = trailingDelimiter;
http://git-wip-us.apache.org/repos/asf/camel/blob/1911e501/camel-core/src/test/java/org/apache/camel/model/dataformat/CsvDataFormatTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/model/dataformat/CsvDataFormatTest.java b/camel-core/src/test/java/org/apache/camel/model/dataformat/CsvDataFormatTest.java
deleted file mode 100644
index 6831b67..0000000
--- a/camel-core/src/test/java/org/apache/camel/model/dataformat/CsvDataFormatTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.model.dataformat;
-
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.BitSet;
-
-import javax.xml.bind.annotation.XmlAttribute;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.spi.DataFormat;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test cases for corresponding class {@link CsvDataFormat}.
- */
-public class CsvDataFormatTest {
-
- @Test
- public void testConfigureDataFormatDataFormatCamelContext() {
- CsvDataFormat csvDataFormat = new CsvDataFormat();
- csvDataFormat.setIgnoreHeaderCase(true);
- csvDataFormat.setTrim(true);
- csvDataFormat.setTrailingDelimiter(true);
- MyDataFormat dataFormat = new MyDataFormat();
- DefaultCamelContext camelContext = new DefaultCamelContext();
- csvDataFormat.configureDataFormat(dataFormat, camelContext);
- assertEquals(3, dataFormat.bitSet.cardinality());
- csvDataFormat.setIgnoreHeaderCase(false);
- csvDataFormat.setTrim(false);
- csvDataFormat.setTrailingDelimiter(false);
- csvDataFormat.configureDataFormat(dataFormat, camelContext);
- assertEquals(dataFormat.bitSet.cardinality(), 0);
- }
-
- //
- // Helper classes
- //
-
- static final class MyDataFormat implements DataFormat {
-
- final BitSet bitSet = new BitSet();
-
- MyDataFormat() {
- }
-
- public void setIgnoreHeaderCase(Boolean ignoreHeaderCase) {
- bitSet.set(0, ignoreHeaderCase);
- }
-
- public void setTrim(Boolean trim) {
- bitSet.set(2, trim);
- }
-
- public void setTrailingDelimiter(Boolean trailingDelimiter) {
- bitSet.set(3, trailingDelimiter);
- }
-
- @Override
- public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
- throw new UnsupportedOperationException();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1911e501/components-starter/camel-csv-starter/src/main/java/org/apache/camel/dataformat/csv/springboot/CsvDataFormatConfiguration.java
----------------------------------------------------------------------
diff --git a/components-starter/camel-csv-starter/src/main/java/org/apache/camel/dataformat/csv/springboot/CsvDataFormatConfiguration.java b/components-starter/camel-csv-starter/src/main/java/org/apache/camel/dataformat/csv/springboot/CsvDataFormatConfiguration.java
index 705275f..e09a34a 100644
--- a/components-starter/camel-csv-starter/src/main/java/org/apache/camel/dataformat/csv/springboot/CsvDataFormatConfiguration.java
+++ b/components-starter/camel-csv-starter/src/main/java/org/apache/camel/dataformat/csv/springboot/CsvDataFormatConfiguration.java
@@ -109,6 +109,18 @@ public class CsvDataFormatConfiguration {
*/
private String quoteMode;
/**
+ * Sets whether or not to ignore case when accessing header names.
+ */
+ private Boolean ignoreHeaderCase = false;
+ /**
+ * Sets whether or not to trim leading and trailing blanks.
+ */
+ private Boolean trim = false;
+ /**
+ * Sets whether or not to add a trailing delimiter.
+ */
+ private Boolean trailingDelimiter = false;
+ /**
* Whether the unmarshalling should produce an iterator that reads the lines
* on the fly or if all the lines must be read at one.
*/
@@ -284,6 +296,30 @@ public class CsvDataFormatConfiguration {
this.quoteMode = quoteMode;
}
+ public Boolean getIgnoreHeaderCase() {
+ return ignoreHeaderCase;
+ }
+
+ public void setIgnoreHeaderCase(Boolean ignoreHeaderCase) {
+ this.ignoreHeaderCase = ignoreHeaderCase;
+ }
+
+ public Boolean getTrim() {
+ return trim;
+ }
+
+ public void setTrim(Boolean trim) {
+ this.trim = trim;
+ }
+
+ public Boolean getTrailingDelimiter() {
+ return trailingDelimiter;
+ }
+
+ public void setTrailingDelimiter(Boolean trailingDelimiter) {
+ this.trailingDelimiter = trailingDelimiter;
+ }
+
public Boolean getLazyLoad() {
return lazyLoad;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/1911e501/components/camel-csv/src/main/docs/csv-dataformat.adoc
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/main/docs/csv-dataformat.adoc b/components/camel-csv/src/main/docs/csv-dataformat.adoc
index b10793a..f84ecbc 100644
--- a/components/camel-csv/src/main/docs/csv-dataformat.adoc
+++ b/components/camel-csv/src/main/docs/csv-dataformat.adoc
@@ -13,7 +13,7 @@ Options
^^^^^^^
// dataformat options: START
-The CSV dataformat supports 23 options which are listed below.
+The CSV dataformat supports 26 options which are listed below.
@@ -41,6 +41,9 @@ The CSV dataformat supports 23 options which are listed below.
| recordSeparator | | String | Sets the record separator (aka new line) which by default is \r\n (CRLF)
| skipHeaderRecord | false | Boolean | Whether to skip the header record in the output
| quoteMode | | String | Sets the quote mode
+| ignoreHeaderCase | false | Boolean | Sets whether or not to ignore case when accessing header names.
+| trim | false | Boolean | Sets whether or not to trim leading and trailing blanks.
+| trailingDelimiter | false | Boolean | Sets whether or not to add a trailing delimiter.
| lazyLoad | false | Boolean | Whether the unmarshalling should produce an iterator that reads the lines on the fly or if all the lines must be read at one.
| useMaps | false | Boolean | Whether the unmarshalling should produce maps for the lines values instead of lists. It requires to have header (either defined or collected).
| recordConverterRef | | String | Refers to a custom CsvRecordConverter to lookup from the registry to use.