You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/09/02 11:54:06 UTC
svn commit: r1164451 - in /camel/branches/camel-2.8.x: ./
camel-core/src/main/java/org/apache/camel/component/file/
camel-core/src/test/java/org/apache/camel/component/file/
components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/
Author: davsclaus
Date: Fri Sep 2 09:54:06 2011
New Revision: 1164451
URL: http://svn.apache.org/viewvc?rev=1164451&view=rev
Log:
Merged revisions 1148706 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
Modified:
camel/branches/camel-2.8.x/ (props changed)
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerFileNamesTest.java
camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerFileWithPathPathSeparatorUnixNoStepwiseTest.java
camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerFileWithPathPathSeparatorWindowsNoStepwiseTest.java
Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep 2 09:54:06 2011
@@ -1 +1 @@
-/camel/trunk:1149570,1150651,1151000,1151054,1151087,1151362,1152170,1152755,1153620,1153812,1153829,1154684,1155230,1156108,1156260,1156277,1156479,1156524,1157348,1157798,1157831,1157878,1158153,1159171,1159174,1159326,1159457,1159460,1159606,1159682-1159683,1159867,1160547,1160637,1161010,1161082,1161524,1162309,1162395
+/camel/trunk:1148706,1149570,1150651,1151000,1151054,1151087,1151362,1152170,1152755,1153620,1153812,1153829,1154684,1155230,1156108,1156260,1156277,1156479,1156524,1157348,1157798,1157831,1157878,1158153,1159171,1159174,1159326,1159457,1159460,1159606,1159682-1159683,1159867,1160547,1160637,1161010,1161082,1161524,1162309,1162395
Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java?rev=1164451&r1=1164450&r2=1164451&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java Fri Sep 2 09:54:06 2011
@@ -281,10 +281,8 @@ public class GenericFileProducer<T> exte
// flatten name
if (name != null && endpoint.isFlatten()) {
- int pos = name.lastIndexOf(getFileSeparator());
- if (pos == -1) {
- pos = name.lastIndexOf('/');
- }
+ // check for both windows and unix separators
+ int pos = Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\"));
if (pos != -1) {
name = name.substring(pos + 1);
}
@@ -292,11 +290,15 @@ public class GenericFileProducer<T> exte
// compute path by adding endpoint starting directory
String endpointPath = endpoint.getConfiguration().getDirectory();
- // Its a directory so we should use it as a base path for the filename
- // If the path isn't empty, we need to add a trailing / if it isn't already there
String baseDir = "";
if (endpointPath.length() > 0) {
- baseDir = endpointPath + (endpointPath.endsWith(getFileSeparator()) ? "" : getFileSeparator());
+ // Its a directory so we should use it as a base path for the filename
+ // If the path isn't empty, we need to add a trailing / if it isn't already there
+ baseDir = endpointPath;
+ boolean trailingSlash = endpointPath.endsWith("/") || endpointPath.endsWith("\\");
+ if (!trailingSlash) {
+ baseDir += getFileSeparator();
+ }
}
if (name != null) {
answer = baseDir + name;
@@ -314,8 +316,7 @@ public class GenericFileProducer<T> exte
}
public String createTempFileName(Exchange exchange, String fileName) {
- // must normalize path to cater for Windows and other OS
- fileName = normalizePath(fileName);
+ String answer = fileName;
String tempName;
if (exchange.getIn().getHeader(Exchange.FILE_NAME) == null) {
@@ -328,15 +329,24 @@ public class GenericFileProducer<T> exte
tempName = endpoint.getTempFileName().evaluate(exchange, String.class);
}
- int path = fileName.lastIndexOf(getFileSeparator());
- if (path == -1) {
- // no path
- return tempName;
+ // check for both windows and unix separators
+ int pos = Math.max(answer.lastIndexOf("/"), answer.lastIndexOf("\\"));
+ if (pos == -1) {
+ // no path so use temp name as calculated
+ answer = tempName;
} else {
- StringBuilder sb = new StringBuilder(fileName.substring(0, path + 1));
+ // path should be prefixed before the temp name
+ StringBuilder sb = new StringBuilder(answer.substring(0, pos + 1));
sb.append(tempName);
- return sb.toString();
+ answer = sb.toString();
}
+
+ if (endpoint.getConfiguration().needToNormalize()) {
+ // must normalize path to cater for Windows and other OS
+ answer = normalizePath(answer);
+ }
+
+ return answer;
}
@Override
Modified: camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerFileNamesTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerFileNamesTest.java?rev=1164451&r1=1164450&r2=1164451&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerFileNamesTest.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/file/FilerProducerFileNamesTest.java Fri Sep 2 09:54:06 2011
@@ -28,6 +28,12 @@ import org.apache.camel.builder.RouteBui
*/
public class FilerProducerFileNamesTest extends ContextTestSupport {
+ @Override
+ protected void setUp() throws Exception {
+ deleteDirectory("target/reports");
+ super.setUp();
+ }
+
// START SNIPPET: e1
public void testProducerWithMessageIdAsFileName() throws Exception {
Endpoint endpoint = context.getEndpoint("direct:report");
Modified: camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerFileWithPathPathSeparatorUnixNoStepwiseTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerFileWithPathPathSeparatorUnixNoStepwiseTest.java?rev=1164451&r1=1164450&r2=1164451&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerFileWithPathPathSeparatorUnixNoStepwiseTest.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerFileWithPathPathSeparatorUnixNoStepwiseTest.java Fri Sep 2 09:54:06 2011
@@ -34,7 +34,7 @@ public class FtpProducerFileWithPathPath
Exchange out = template.send(getFtpUrl(), new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello World");
- exchange.getIn().setHeader(Exchange.FILE_NAME, "hello\\claus.txt");
+ exchange.getIn().setHeader(Exchange.FILE_NAME, "hello/claus.txt");
}
});
assertNotNull(out);
@@ -44,7 +44,7 @@ public class FtpProducerFileWithPathPath
assertTrue("The uploaded file should exists", file.exists());
assertEquals("Hello World", IOConverter.toString(file, null));
- assertEquals("upload/hello\\claus.txt", out.getIn().getHeader(Exchange.FILE_NAME_PRODUCED));
+ assertEquals("upload/hello/claus.txt", out.getIn().getHeader(Exchange.FILE_NAME_PRODUCED));
}
}
\ No newline at end of file
Modified: camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerFileWithPathPathSeparatorWindowsNoStepwiseTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerFileWithPathPathSeparatorWindowsNoStepwiseTest.java?rev=1164451&r1=1164450&r2=1164451&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerFileWithPathPathSeparatorWindowsNoStepwiseTest.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerFileWithPathPathSeparatorWindowsNoStepwiseTest.java Fri Sep 2 09:54:06 2011
@@ -34,7 +34,7 @@ public class FtpProducerFileWithPathPath
Exchange out = template.send(getFtpUrl(), new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Hello World");
- exchange.getIn().setHeader(Exchange.FILE_NAME, "hello/claus.txt");
+ exchange.getIn().setHeader(Exchange.FILE_NAME, "hello\\claus.txt");
}
});
assertNotNull(out);
@@ -44,7 +44,7 @@ public class FtpProducerFileWithPathPath
assertTrue("The uploaded file should exists", file.exists());
assertEquals("Hello World", IOConverter.toString(file, null));
- assertEquals("upload/hello/claus.txt", out.getIn().getHeader(Exchange.FILE_NAME_PRODUCED));
+ assertEquals("upload/hello\\claus.txt", out.getIn().getHeader(Exchange.FILE_NAME_PRODUCED));
}
}
\ No newline at end of file