camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1446616 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/model/dataformat/ camel-core/src/main/resources/org/apache/camel/model...
Date Fri, 15 Feb 2013 14:57:32 GMT
Author: davsclaus
Date: Fri Feb 15 14:57:31 2013
New Revision: 1446616

URL: http://svn.apache.org/r1446616
Log:
CAMEL-5807: Added base64 to the DSL.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/Base64DataFormat.java
      - copied, changed from r1446557, camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/BeanioDataFormat.java
    camel/trunk/components/camel-base64/src/test/java/org/apache/camel/dataformat/base64/Base64DataFormatDSLDefaultsTest.java
      - copied, changed from r1446557, camel/trunk/components/camel-base64/src/test/java/org/apache/camel/dataformat/base64/Base64DataFormatDefaultsTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
    camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java?rev=1446616&r1=1446615&r2=1446616&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java Fri
Feb 15 14:57:31 2013
@@ -21,10 +21,11 @@ import java.util.zip.Deflater;
 
 import org.w3c.dom.Node;
 
-
 import org.apache.camel.model.DataFormatDefinition;
 import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.model.dataformat.AvroDataFormat;
+import org.apache.camel.model.dataformat.Base64DataFormat;
+import org.apache.camel.model.dataformat.BeanioDataFormat;
 import org.apache.camel.model.dataformat.BindyDataFormat;
 import org.apache.camel.model.dataformat.BindyType;
 import org.apache.camel.model.dataformat.CastorDataFormat;
@@ -51,7 +52,6 @@ import org.apache.camel.model.dataformat
 import org.apache.camel.model.dataformat.ZipDataFormat;
 import org.apache.camel.util.jsse.KeyStoreParameters;
 
-
 /**
  * An expression for constructing the different possible {@link org.apache.camel.spi.DataFormat}
  * options.
@@ -74,7 +74,6 @@ public class DataFormatClause<T extends 
         this.operation = operation;
     }
 
-
     /**
      * Uses the Avro data format
      */
@@ -93,6 +92,61 @@ public class DataFormatClause<T extends 
     }
 
     /**
+     * Uses the base64 data format
+     */
+    public T base64() {
+        Base64DataFormat dataFormat = new Base64DataFormat();
+        return dataFormat(dataFormat);
+    }
+
+    /**
+     * Uses the base64 data format
+     */
+    public T base64(int lineLength, String lineSeparator, boolean urlSafe) {
+        Base64DataFormat dataFormat = new Base64DataFormat();
+        dataFormat.setLineLength(lineLength);
+        dataFormat.setLineSeparator(lineSeparator);
+        dataFormat.setUrlSafe(urlSafe);
+        return dataFormat(dataFormat);
+    }
+
+    /**
+     * Uses the beanio data format
+     */
+    public T beanio(String mapping, String streamName) {
+        BeanioDataFormat dataFormat = new BeanioDataFormat();
+        dataFormat.setMapping(mapping);
+        dataFormat.setStreamName(streamName);
+        return dataFormat(dataFormat);
+    }
+
+    /**
+     * Uses the beanio data format
+     */
+    public T beanio(String mapping, String streamName, String encoding) {
+        BeanioDataFormat dataFormat = new BeanioDataFormat();
+        dataFormat.setMapping(mapping);
+        dataFormat.setStreamName(streamName);
+        dataFormat.setEncoding(encoding);
+        return dataFormat(dataFormat);
+    }
+
+    /**
+     * Uses the beanio data format
+     */
+    public T beanio(String mapping, String streamName, String encoding,
+                    boolean ignoreUnidentifiedRecords, boolean ignoreUnexpectedRecords, boolean
ignoreInvalidRecords) {
+        BeanioDataFormat dataFormat = new BeanioDataFormat();
+        dataFormat.setMapping(mapping);
+        dataFormat.setStreamName(streamName);
+        dataFormat.setEncoding(encoding);
+        dataFormat.setIgnoreInvalidRecords(ignoreInvalidRecords);
+        dataFormat.setIgnoreUnexpectedRecords(ignoreUnexpectedRecords);
+        dataFormat.setIgnoreInvalidRecords(ignoreInvalidRecords);
+        return dataFormat(dataFormat);
+    }
+
+    /**
      * Uses the Bindy data format
      *
      * @param type     the type of bindy data format to use

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java?rev=1446616&r1=1446615&r2=1446616&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java Fri
Feb 15 14:57:31 2013
@@ -25,6 +25,7 @@ import javax.xml.bind.annotation.XmlRoot
 
 import org.apache.camel.Processor;
 import org.apache.camel.model.dataformat.AvroDataFormat;
+import org.apache.camel.model.dataformat.Base64DataFormat;
 import org.apache.camel.model.dataformat.BeanioDataFormat;
 import org.apache.camel.model.dataformat.BindyDataFormat;
 import org.apache.camel.model.dataformat.CastorDataFormat;
@@ -72,6 +73,7 @@ public class MarshalDefinition extends N
     // cannot use @XmlElementRef as it doesn't allow optional properties
     @XmlElements({
     @XmlElement(required = false, name = "avro", type = AvroDataFormat.class),
+    @XmlElement(required = false, name = "base64", type = Base64DataFormat.class),
     @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class),
     @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),
     @XmlElement(required = false, name = "castor", type = CastorDataFormat.class),

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java?rev=1446616&r1=1446615&r2=1446616&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java Fri
Feb 15 14:57:31 2013
@@ -25,6 +25,7 @@ import javax.xml.bind.annotation.XmlRoot
 
 import org.apache.camel.Processor;
 import org.apache.camel.model.dataformat.AvroDataFormat;
+import org.apache.camel.model.dataformat.Base64DataFormat;
 import org.apache.camel.model.dataformat.BeanioDataFormat;
 import org.apache.camel.model.dataformat.BindyDataFormat;
 import org.apache.camel.model.dataformat.CastorDataFormat;
@@ -72,6 +73,7 @@ public class UnmarshalDefinition extends
     // cannot use @XmlElementRef as it doesn't allow optional properties
     @XmlElements({
     @XmlElement(required = false, name = "avro", type = AvroDataFormat.class),
+    @XmlElement(required = false, name = "base64", type = Base64DataFormat.class),
     @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class),
     @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),
     @XmlElement(required = false, name = "castor", type = CastorDataFormat.class),

Copied: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/Base64DataFormat.java
(from r1446557, camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/BeanioDataFormat.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/Base64DataFormat.java?p2=camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/Base64DataFormat.java&p1=camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/BeanioDataFormat.java&r1=1446557&r2=1446616&rev=1446616&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/BeanioDataFormat.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/Base64DataFormat.java
Fri Feb 15 14:57:31 2013
@@ -25,95 +25,61 @@ import org.apache.camel.model.DataFormat
 import org.apache.camel.spi.DataFormat;
 
 /**
- * Represents the BeanIO {@link org.apache.camel.spi.DataFormat}
+ * Represents the Base64 {@link org.apache.camel.spi.DataFormat}
  *
  * @version 
  */
-@XmlRootElement(name = "beanio")
+@XmlRootElement(name = "base64")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class BeanioDataFormat extends DataFormatDefinition {
+public class Base64DataFormat extends DataFormatDefinition {
 
-    @XmlAttribute(required = true)
-    private String mapping;
-    @XmlAttribute(required = true)
-    private String streamName;
     @XmlAttribute
-    private Boolean ignoreUnidentifiedRecords;
+    private Integer lineLength;
     @XmlAttribute
-    private Boolean ignoreUnexpectedRecords;
+    private String lineSeparator;
     @XmlAttribute
-    private Boolean ignoreInvalidRecords;
-    @XmlAttribute
-    private String encoding;
+    private Boolean urlSafe;
 
-    public BeanioDataFormat() {
-        super("beanio");
+    public Base64DataFormat() {
+        super("base64");
     }
 
     @Override
     protected void configureDataFormat(DataFormat dataFormat) {
-        setProperty(dataFormat, "mapping", mapping);
-        setProperty(dataFormat, "streamName", streamName);
-        if (ignoreUnidentifiedRecords != null) {
-            setProperty(dataFormat, "ignoreUnidentifiedRecords", ignoreUnidentifiedRecords);
-        }
-        if (ignoreUnexpectedRecords != null) {
-            setProperty(dataFormat, "ignoreUnexpectedRecords", ignoreUnexpectedRecords);
+        if (getLineLength() != null) {
+            setProperty(dataFormat, "lineLength", getLineLength());
         }
-        if (ignoreInvalidRecords != null) {
-            setProperty(dataFormat, "ignoreInvalidRecords", ignoreInvalidRecords);
+        if (getUrlSafe() != null) {
+            setProperty(dataFormat, "urlSafe", getUrlSafe());
         }
-        if (encoding != null) {
-            setProperty(dataFormat, "encoding", encoding);
+        if (getLineSeparator() != null) {
+            // line separator must be a byte[]
+            byte[] bytes = getLineSeparator().getBytes();
+            setProperty(dataFormat, "lineSeparator", bytes);
         }
     }
 
-    public String getMapping() {
-        return mapping;
-    }
-
-    public void setMapping(String mapping) {
-        this.mapping = mapping;
-    }
-
-    public String getStreamName() {
-        return streamName;
-    }
-
-    public void setStreamName(String streamName) {
-        this.streamName = streamName;
+    public Integer getLineLength() {
+        return lineLength;
     }
 
-    public Boolean getIgnoreUnidentifiedRecords() {
-        return ignoreUnidentifiedRecords;
+    public void setLineLength(Integer lineLength) {
+        this.lineLength = lineLength;
     }
 
-    public void setIgnoreUnidentifiedRecords(Boolean ignoreUnidentifiedRecords) {
-        this.ignoreUnidentifiedRecords = ignoreUnidentifiedRecords;
+    public String getLineSeparator() {
+        return lineSeparator;
     }
 
-    public Boolean getIgnoreUnexpectedRecords() {
-        return ignoreUnexpectedRecords;
+    public void setLineSeparator(String lineSeparator) {
+        this.lineSeparator = lineSeparator;
     }
 
-    public void setIgnoreUnexpectedRecords(Boolean ignoreUnexpectedRecords) {
-        this.ignoreUnexpectedRecords = ignoreUnexpectedRecords;
+    public Boolean getUrlSafe() {
+        return urlSafe;
     }
 
-    public Boolean getIgnoreInvalidRecords() {
-        return ignoreInvalidRecords;
+    public void setUrlSafe(Boolean urlSafe) {
+        this.urlSafe = urlSafe;
     }
-
-    public void setIgnoreInvalidRecords(Boolean ignoreInvalidRecords) {
-        this.ignoreInvalidRecords = ignoreInvalidRecords;
-    }
-
-    public String getEncoding() {
-        return encoding;
-    }
-
-    public void setEncoding(String encoding) {
-        this.encoding = encoding;
-    }
-
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java?rev=1446616&r1=1446615&r2=1446616&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
Fri Feb 15 14:57:31 2013
@@ -38,6 +38,7 @@ public class DataFormatsDefinition {
     // cannot use @XmlElementRef as it doesn't allow optional properties
     @XmlElements({
         @XmlElement(required = false, name = "avro", type = AvroDataFormat.class),
+        @XmlElement(required = false, name = "base64", type = Base64DataFormat.class),
         @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class),
         @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),
         @XmlElement(required = false, name = "castor", type = CastorDataFormat.class),

Modified: camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index?rev=1446616&r1=1446615&r2=1446616&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
(original)
+++ camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
Fri Feb 15 14:57:31 2013
@@ -15,6 +15,7 @@
 ## limitations under the License.
 ## ------------------------------------------------------------------------
 AvroDataFormat
+Base64DataFormat
 BeanioDataFormat
 BindyDataFormat
 BindyType

Copied: camel/trunk/components/camel-base64/src/test/java/org/apache/camel/dataformat/base64/Base64DataFormatDSLDefaultsTest.java
(from r1446557, camel/trunk/components/camel-base64/src/test/java/org/apache/camel/dataformat/base64/Base64DataFormatDefaultsTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-base64/src/test/java/org/apache/camel/dataformat/base64/Base64DataFormatDSLDefaultsTest.java?p2=camel/trunk/components/camel-base64/src/test/java/org/apache/camel/dataformat/base64/Base64DataFormatDSLDefaultsTest.java&p1=camel/trunk/components/camel-base64/src/test/java/org/apache/camel/dataformat/base64/Base64DataFormatDefaultsTest.java&r1=1446557&r2=1446616&rev=1446616&view=diff
==============================================================================
--- camel/trunk/components/camel-base64/src/test/java/org/apache/camel/dataformat/base64/Base64DataFormatDefaultsTest.java
(original)
+++ camel/trunk/components/camel-base64/src/test/java/org/apache/camel/dataformat/base64/Base64DataFormatDSLDefaultsTest.java
Fri Feb 15 14:57:31 2013
@@ -16,41 +16,21 @@
  */
 package org.apache.camel.dataformat.base64;
 
-import org.junit.Test;
+import org.apache.camel.builder.RouteBuilder;
 
-public class Base64DataFormatDefaultsTest extends Base64DataFormatTestBase {
+public class Base64DataFormatDSLDefaultsTest extends Base64DataFormatDefaultsTest {
 
-    private static final String ENCODED = "IrRWhNZNjFxQ6WXJEIsehbnFdurtgacAq+t6Zh3uYlyclF3HAx995mbIydQlymM8V3yA+Yb1p3Ij\r\n"
-            + "7AS1VQaUNHAljNpHUqrWR6EmASZV/EQvR5Gk8XDvRrrtkoDm+jdZ/XKfest2OIzhixZF1mcqyi1P\r\n"
-            + "Hep/rFnVPclO9WOWtCCRhz+U2soBzNBtvTc6x1pz1gOZcoOEFKHSf2kmkq1/7hHFl5Cb9nbSBgyp\r\n"
-            + "lFzsInVBfCkRxXAFixwbC3B+LB8e15zSMvoG6okyDs7C8QShIZCXGHlsuUiH96izUbfB8qpTQK80\r\n"
-            + "PPAisxYhF/gb678wvO5e/03AmFmYbBqzwoNQ6PoZKFI8a4PUrLoCLrUnKQgwOXueb1y8d4bsVGrX\r\n"
-            + "H5QUFgAE3yZEn2ZQtVv6bZnm3lvBe/LLRD4xIU2Pcm5e+DJUZhHcl/8MaioDWFgYPLftDKvEUwLB\r\n"
-            + "3IFWLSKMKFoeXn2nkwxsCHrzhajhbkKl1+H9I7Gkd19DyAoPIriWOJScog+mcP0iqG9iMqYFko2n\r\n"
-            + "rh2rr+jcyKFBhrRUuNw3W8+h+FOwZDLcBmuTv2lEOvUdaPgD+1e6fXpuxhiih4wf/zlakeVa031T\r\n"
-            + "9c0/HN02z0cAhLT1vtEA0zDn6OzzhY//Mh332ZmC+xro+e9o2a6+dnwamDtLuRgDDd+EcoUQpfEL\r\n"
-            + "XobX3ZSX7OQw1ZXxWiJLtSOc5yLRkdbxdLK/C6fkcY4cqc/RwBGYtXN7Z1ENG/s/LnrZnRU/ErMW\r\n"
-            + "RtbRwehA/0a2KSbNOMwK8BpzDruXufLXZcGaDKRUektQfdX4XhhYESt1drewlQLVaEWrZBR8JOd5\r\n"
-            + "mckulPhwHp2Q00YyoScEj6Rs/9siyv49/FSaRCbnfzl3CRnNvCOD1cvF4OneYbVJCMOY49ucFmN/\r\n"
-            + "mBCyxLOtJ4Zz8EG1FC81QTg3Scw+FdFDsCgr7DqVrmPOLikqq6wJdLBjyHXuMiVP9Fq/aAxvXEgj\r\n"
-            + "RuVnN20wn2tUOXeaN4XqziQ66M229HsY0BX5riJ00yXArDxd+I9mFDpw/UDnGBAE2P//1fU1ns1A\r\n"
-            + "6zQ6hTv7axdlw3/FnOAdymEKqED9CPfbiDvJygcAcxv2fyORHQ+TiprMGxckAlnLZ2pGl+gOzbtZ\r\n"
-            + "zJgecyFJHBbhtkubGD4zzQhuJJw8ypqppSxqDs8SAW2frj42UT9qRMeCBGXLa1wyISt4GI6iOnfw\r\n"
-            + "TCRJ/SE7CVrEfmdmROlJpAJHfUlQIJq1aW3mTE5zTmAygypxRUDCmA+eY9wdCicFp6YptdCEK3P2\r\n"
-            + "7QzZsSASAByd5jxHMiIBkdwGzj1501xZ7hFLJDXDTQ==\r\n";
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
 
-    public Base64DataFormatDefaultsTest() {
-        format = new Base64DataFormat();
-    }
-
-    @Test
-    public void testEncode() throws Exception {
-        runEncoderTest(DECODED, ENCODED.getBytes());
-    }
+            @Override
+            public void configure() throws Exception {
+                from("direct:startEncode").marshal().base64().to("mock:result");
 
-    @Test
-    public void testDecode() throws Exception {
-        runDecoderTest(ENCODED.getBytes(), DECODED);
+                from("direct:startDecode").unmarshal().base64().to("mock:result");
+            }
+        };
     }
 
 }



Mime
View raw message