You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2012/11/10 12:51:35 UTC
svn commit: r1407779 - in /camel/branches/camel-2.10.x: ./
camel-core/src/main/java/org/apache/camel/component/properties/
camel-core/src/test/java/org/apache/camel/component/properties/
Author: bvahdat
Date: Sat Nov 10 11:51:34 2012
New Revision: 1407779
URL: http://svn.apache.org/viewvc?rev=1407779&view=rev
Log:
Merged revisions 1407776 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r1407776 | bvahdat | 2012-11-10 12:48:43 +0100 (Sa, 10 Nov 2012) | 1 line
CAMEL-5784: Preparing the loaded properties should only trim any potential whitespace characters.
........
Modified:
camel/branches/camel-2.10.x/ (props changed)
camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java
camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesFromFileTrimValuesTest.java
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1407776
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java?rev=1407779&r1=1407778&r2=1407779&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java (original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java Sat Nov 10 11:51:34 2012
@@ -131,11 +131,20 @@ public class DefaultPropertiesResolver i
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
Object key = entry.getKey();
Object value = entry.getValue();
- // trim string values which can be a problem when loading from a properties file and there
- // is leading or trailing spaces in the value
+ // trim any trailing spaces which can be a problem when loading from
+ // a properties file, note that java.util.Properties does already this
+ // for any potential leading spaces so there's nothing to do there
if (value instanceof String) {
String s = (String) value;
- s = s.trim();
+ int endIndex = s.length();
+ for (int index = s.length() - 1; index >= 0; index--) {
+ if (s.charAt(index) == ' ') {
+ endIndex = index;
+ } else {
+ break;
+ }
+ }
+ s = s.substring(0, endIndex);
value = s;
}
answer.put(key, value);
Modified: camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesFromFileTrimValuesTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesFromFileTrimValuesTest.java?rev=1407779&r1=1407778&r2=1407779&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesFromFileTrimValuesTest.java (original)
+++ camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentLoadPropertiesFromFileTrimValuesTest.java Sat Nov 10 11:51:34 2012
@@ -16,7 +16,6 @@
*/
package org.apache.camel.component.properties;
-import java.io.File;
import java.io.FileOutputStream;
import org.apache.camel.CamelContext;
@@ -39,15 +38,27 @@ public class PropertiesComponentLoadProp
CamelContext context = super.createCamelContext();
// create space.properties file
- File file = new File("target/space/space.properties");
- file.createNewFile();
- FileOutputStream fos = new FileOutputStream(file);
- fos.write("cool.leading= Leading space\ncool.trailing=Trailing space \ncool.both= Both leading and trailing space ".getBytes());
+ FileOutputStream fos = new FileOutputStream("target/space/space.properties");
+ String cool = "cool.leading= Leading space" + LS + "cool.trailing=Trailing space " + LS + "cool.both= Both leading and trailing space ";
+ fos.write(cool.getBytes());
+ fos.write(LS.getBytes());
+
+ String space = "space.leading= \\r\\n" + LS + "space.trailing=\\t " + LS + "space.both= \\r \\t \\n ";
+ fos.write(space.getBytes());
+ fos.write(LS.getBytes());
+
+ String mixed = "mixed.leading= Leading space\\r\\n" + LS + "mixed.trailing=Trailing space\\t " + LS + "mixed.both= Both leading and trailing space\\r \\t \\n ";
+ fos.write(mixed.getBytes());
+ fos.write(LS.getBytes());
+
+ String empty = "empty.line= ";
+ fos.write(empty.getBytes());
+
fos.close();
PropertiesComponent pc = new PropertiesComponent();
pc.setCamelContext(context);
- pc.setLocations(new String[]{"file:target/space/space.properties"});
+ pc.setLocation("file:target/space/space.properties");
context.addComponent("properties", pc);
return context;
@@ -57,6 +68,16 @@ public class PropertiesComponentLoadProp
assertEquals("Leading space", context.resolvePropertyPlaceholders("{{cool.leading}}"));
assertEquals("Trailing space", context.resolvePropertyPlaceholders("{{cool.trailing}}"));
assertEquals("Both leading and trailing space", context.resolvePropertyPlaceholders("{{cool.both}}"));
+
+ assertEquals("\r\n", context.resolvePropertyPlaceholders("{{space.leading}}"));
+ assertEquals("\t", context.resolvePropertyPlaceholders("{{space.trailing}}"));
+ assertEquals("\r \t \n", context.resolvePropertyPlaceholders("{{space.both}}"));
+
+ assertEquals("Leading space\r\n", context.resolvePropertyPlaceholders("{{mixed.leading}}"));
+ assertEquals("Trailing space\t", context.resolvePropertyPlaceholders("{{mixed.trailing}}"));
+ assertEquals("Both leading and trailing space\r \t \n", context.resolvePropertyPlaceholders("{{mixed.both}}"));
+
+ assertEquals("", context.resolvePropertyPlaceholders("{{empty.line}}"));
}
}
\ No newline at end of file