You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2009/01/20 18:43:26 UTC

svn commit: r736046 - in /camel/trunk/components/camel-velocity/src: main/java/org/apache/camel/component/velocity/ test/java/org/apache/camel/component/velocity/ test/resources/org/apache/camel/component/velocity/

Author: janstey
Date: Tue Jan 20 09:43:25 2009
New Revision: 736046

URL: http://svn.apache.org/viewvc?rev=736046&view=rev
Log:
CAMEL-1278 - Adding option to set encoding for velocity template. Thanks to Damian for the patch!


Added:
    camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityEncodingTest.java   (with props)
    camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/letter-utf16.vm   (with props)
Modified:
    camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java

Modified: camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java?rev=736046&r1=736045&r2=736046&view=diff
==============================================================================
--- camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java (original)
+++ camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java Tue Jan 20 09:43:25 2009
@@ -40,6 +40,7 @@
     private final VelocityComponent component;
     private VelocityEngine velocityEngine;
     private boolean loaderCache = true;
+    private String encoding;
 
     public VelocityEndpoint(String uri, VelocityComponent component, String resourceUri, Map parameters) {
         super(uri, component, resourceUri, null);
@@ -84,13 +85,21 @@
         this.loaderCache = loaderCache;
     }
 
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
+    public String getEncoding() {
+        return encoding;
+    }
+
     @SuppressWarnings("unchecked")
     @Override
     protected void onExchange(Exchange exchange) throws Exception {
         Resource resource = getResource();
 
         // getResourceAsInputStream also considers the content cache
-        Reader reader = new InputStreamReader(getResourceAsInputStream());
+        Reader reader = encoding != null ? new InputStreamReader(getResourceAsInputStream(), encoding) : new InputStreamReader(getResourceAsInputStream());
         StringWriter buffer = new StringWriter();
         String logTag = getClass().getName();
         Map variableMap = ExchangeHelper.createVariableMap(exchange);

Added: camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityEncodingTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityEncodingTest.java?rev=736046&view=auto
==============================================================================
--- camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityEncodingTest.java (added)
+++ camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityEncodingTest.java Tue Jan 20 09:43:25 2009
@@ -0,0 +1,30 @@
+/**
+ * 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.velocity;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class VelocityEncodingTest extends VelocityLetterTest {
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:a").to("velocity:org/apache/camel/component/velocity/letter-utf16.vm?encoding=UTF-16").to("mock:result");
+            }
+        };
+    }
+}

Propchange: camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityEncodingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/letter-utf16.vm
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/letter-utf16.vm?rev=736046&view=auto
==============================================================================
Binary file - no diff available.

Propchange: camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/letter-utf16.vm
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream