Updated Branches:
  refs/heads/camel-2.11.x 799736421 -> a2b1df78e

CAMEL-6363 Allow to specify the string-template delimiters with thanks to 
Antoine


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a2b1df78
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a2b1df78
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a2b1df78

Branch: refs/heads/camel-2.11.x
Commit: a2b1df78e7d5db653878a7e65cd916c55a26e116
Parents: 7997364
Author: Willem Jiang <ningji...@apache.org>
Authored: Thu May 16 09:49:14 2013 +0800
Committer: Willem Jiang <ningji...@apache.org>
Committed: Thu May 16 09:51:47 2013 +0800

----------------------------------------------------------------------
 .../stringtemplate/StringTemplateEndpoint.java     |   26 +++++-
 .../StringTemplateCustomDelimiterTest.java         |   63 +++++++++++++++
 .../stringtemplate/custom-delimiter-brace.tm       |   17 ++++
 .../stringtemplate/custom-delimiter-dollar.tm      |   17 ++++
 4 files changed, 119 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a2b1df78/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
----------------------------------------------------------------------
diff --git 
a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
 
b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
index 61f6086..a5d6837 100644
--- 
a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
+++ 
b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
@@ -27,11 +27,14 @@ import org.apache.camel.component.ResourceEndpoint;
 import org.apache.camel.util.ExchangeHelper;
 import org.stringtemplate.v4.NoIndentWriter;
 import org.stringtemplate.v4.ST;
+import org.stringtemplate.v4.STGroup;
 
 /**
- * @version 
+ * @version
  */
 public class StringTemplateEndpoint extends ResourceEndpoint {
+    private char delimiterStart = STGroup.defaultGroup.delimiterStartChar;
+    private char delimiterStop = STGroup.defaultGroup.delimiterStopChar;
 
     public StringTemplateEndpoint() {
     }
@@ -50,6 +53,22 @@ public class StringTemplateEndpoint extends ResourceEndpoint 
{
         return ExchangePattern.InOut;
     }
 
+    public char getDelimiterStart() {
+        return delimiterStart;
+    }
+
+    public void setDelimiterStart(char delimiterStart) {
+        this.delimiterStart = delimiterStart;
+    }
+
+    public char getDelimiterStop() {
+        return delimiterStop;
+    }
+
+    public void setDelimiterStop(char delimiterStop) {
+        this.delimiterStop = delimiterStop;
+    }
+
     @Override
     protected void onExchange(Exchange exchange) throws Exception {
         StringWriter buffer = new StringWriter();
@@ -57,7 +76,7 @@ public class StringTemplateEndpoint extends ResourceEndpoint {
 
         // getResourceAsInputStream also considers the content cache
         String text = 
exchange.getContext().getTypeConverter().mandatoryConvertTo(String.class, 
getResourceAsInputStream());
-        ST template = new ST(text);
+        ST template = new ST(text, delimiterStart, delimiterStop);
         for (Map.Entry<String, Object> entry : variableMap.entrySet()) {
             template.add(entry.getKey(), entry.getValue());
         }
@@ -71,5 +90,4 @@ public class StringTemplateEndpoint extends ResourceEndpoint {
         out.setHeader(StringTemplateConstants.STRINGTEMPLATE_RESOURCE_URI, 
getResourceUri());
         out.setAttachments(exchange.getIn().getAttachments());
     }
-
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a2b1df78/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateCustomDelimiterTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateCustomDelimiterTest.java
 
b/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateCustomDelimiterTest.java
new file mode 100644
index 0000000..9560f95
--- /dev/null
+++ 
b/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateCustomDelimiterTest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.component.stringtemplate;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class StringTemplateCustomDelimiterTest extends CamelTestSupport {
+    private static final String DIRECT_BRACE = "direct:brace";
+    private static final String DIRECT_DOLLAR = "direct:dollar";
+
+    @Test
+    public void testWithBraceDelimiter() {
+        Exchange response = template.request(DIRECT_BRACE, new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("Yay !");
+            }
+        });
+
+        assertEquals("With brace delimiter Yay !", 
response.getOut().getBody().toString().trim());
+    }
+
+    @Test
+    public void testWithDollarDelimiter() {
+        Exchange response = template.request(DIRECT_DOLLAR, new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("Yay !");
+            }
+        });
+
+        assertEquals("With identical dollar delimiter Yay !", 
response.getOut().getBody().toString().trim());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                
from(DIRECT_BRACE).to("string-template:org/apache/camel/component/stringtemplate/custom-delimiter-brace.tm?delimiterStart={&delimiterStop=}");
+                
from(DIRECT_DOLLAR).to("string-template:org/apache/camel/component/stringtemplate/custom-delimiter-dollar.tm?delimiterStart=$&delimiterStop=$");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a2b1df78/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/custom-delimiter-brace.tm
----------------------------------------------------------------------
diff --git 
a/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/custom-delimiter-brace.tm
 
b/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/custom-delimiter-brace.tm
new file mode 100644
index 0000000..b07efd8
--- /dev/null
+++ 
b/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/custom-delimiter-brace.tm
@@ -0,0 +1,17 @@
+{! ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------ !}
+With brace delimiter {body}

http://git-wip-us.apache.org/repos/asf/camel/blob/a2b1df78/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/custom-delimiter-dollar.tm
----------------------------------------------------------------------
diff --git 
a/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/custom-delimiter-dollar.tm
 
b/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/custom-delimiter-dollar.tm
new file mode 100644
index 0000000..84fb234
--- /dev/null
+++ 
b/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/custom-delimiter-dollar.tm
@@ -0,0 +1,17 @@
+$! ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------ !$
+With identical dollar delimiter $body$

Reply via email to