You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/10/26 09:16:50 UTC
svn commit: r829724 - 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: ningjiang
Date: Mon Oct 26 08:16:50 2009
New Revision: 829724
URL: http://svn.apache.org/viewvc?rev=829724&view=rev
Log:
CAMEL-2091, CAMEL-2108 Added perpertiesFile option to load the velocity configuration
Added:
camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java (with props)
camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/letterWithParser.vm
camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity.properties (with props)
Modified:
camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java
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/VelocityComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java?rev=829724&r1=829723&r2=829724&view=diff
==============================================================================
--- camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java (original)
+++ camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java Mon Oct 26 08:16:50 2009
@@ -20,6 +20,7 @@
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.ObjectHelper;
import org.apache.velocity.app.VelocityEngine;
/**
@@ -37,9 +38,15 @@
}
protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
- boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);
+ String propertiesFile = getAndRemoveParameter(parameters, "propertiesFile", String.class);
+ String encoding = getAndRemoveParameter(parameters, "encoding", String.class);
+ boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);
VelocityEndpoint answer = new VelocityEndpoint(uri, this, remaining);
answer.setContentCache(cache);
+ answer.setPropertiesFile(propertiesFile);
+ if (ObjectHelper.isNotEmpty(encoding)) {
+ answer.setEncoding(encoding);
+ }
answer.setVelocityEngine(velocityEngine);
return answer;
}
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=829724&r1=829723&r2=829724&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 Mon Oct 26 08:16:50 2009
@@ -16,11 +16,13 @@
*/
package org.apache.camel.component.velocity;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Map;
+import java.util.Properties;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
@@ -42,6 +44,7 @@
private VelocityEngine velocityEngine;
private boolean loaderCache = true;
private String encoding;
+ private String propertiesFile;
public VelocityEndpoint() {
}
@@ -68,10 +71,20 @@
private synchronized VelocityEngine getVelocityEngine() throws Exception {
if (velocityEngine == null) {
velocityEngine = new VelocityEngine();
- velocityEngine.setProperty(Velocity.FILE_RESOURCE_LOADER_CACHE, isLoaderCache() ? Boolean.TRUE : Boolean.FALSE);
- velocityEngine.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, CommonsLogLogChute.class.getName());
- velocityEngine.setProperty(CommonsLogLogChute.LOGCHUTE_COMMONS_LOG_NAME, VelocityEndpoint.class.getName());
- velocityEngine.init();
+ Properties properties = new Properties();
+ // load the velocity properties from property file
+ if (ObjectHelper.isNotEmpty(getPropertiesFile())) {
+ Resource resource = getResourceLoader().getResource(getPropertiesFile());
+ InputStream reader = resource.getInputStream();
+ properties.load(reader);
+ log.info("Loaded the velocity configuration file " + getPropertiesFile());
+ }
+
+ properties.setProperty(Velocity.FILE_RESOURCE_LOADER_CACHE, isLoaderCache() ? "true" : "false");
+ properties.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, CommonsLogLogChute.class.getName());
+ properties.setProperty(CommonsLogLogChute.LOGCHUTE_COMMONS_LOG_NAME, VelocityEndpoint.class.getName());
+ velocityEngine.init(properties);
+
}
return velocityEngine;
}
@@ -101,6 +114,14 @@
public String getEncoding() {
return encoding;
}
+
+ public void setPropertiesFile(String file) {
+ propertiesFile = file;
+ }
+
+ public String getPropertiesFile() {
+ return propertiesFile;
+ }
public VelocityEndpoint findOrCreateEndpoint(String uri, String newResourceUri) {
String newUri = uri.replace(getResourceUri(), newResourceUri);
@@ -146,7 +167,7 @@
if (log.isDebugEnabled()) {
log.debug("Velocity content read from resource " + resource + " with resourceUri: " + path + " for endpoint " + getEndpointUri());
}
- reader = encoding != null ? new InputStreamReader(getResourceAsInputStream(), encoding) : new InputStreamReader(getResourceAsInputStream());
+ reader = getEncoding() != null ? new InputStreamReader(getResourceAsInputStream(), getEncoding()) : new InputStreamReader(getResourceAsInputStream());
}
// getResourceAsInputStream also considers the content cache
Added: camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java?rev=829724&view=auto
==============================================================================
--- camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java (added)
+++ camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java Mon Oct 26 08:16:50 2009
@@ -0,0 +1,31 @@
+/**
+ * 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 VelocityLetterWithPaserTest 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/letterWithParser.vm?propertiesFile=org/apache/camel/component/velocity/velocity.properties").to("mock:result");
+ }
+ };
+ }
+
+}
Propchange: camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/letterWithParser.vm
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/letterWithParser.vm?rev=829724&view=auto
==============================================================================
--- camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/letterWithParser.vm (added)
+++ camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/letterWithParser.vm Mon Oct 26 08:16:50 2009
@@ -0,0 +1,23 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+#parse("/org/apache/camel/component/velocity/header.vm")
+
+
+Thanks for the order of ${headers.item}.
+
+Regards Camel Riders Bookstore
+PS: Next beer is on me, James
\ No newline at end of file
Added: camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity.properties?rev=829724&view=auto
==============================================================================
--- camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity.properties (added)
+++ camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity.properties Mon Oct 26 08:16:50 2009
@@ -0,0 +1,27 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# specify three resource loaders to use
+#
+resource.loader =file, class
+
+#
+# for the loader we call 'class', use the ClasspathResourceLoader
+#
+class.resource.loader.description = Velocity Classpath Resource Loader
+class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
Propchange: camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/velocity.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain