Author: ningjiang Date: Fri Feb 6 05:29:59 2009 New Revision: 741417 URL: http://svn.apache.org/viewvc?rev=741417&view=rev Log: CAMEL-1318 fixed the ftp test errors in Windows box
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=741417&r1=741416&r2=741417&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java Fri Feb 6 05:29:59 2009 @@ -35,7 +35,7 @@ private long fileLength; private long lastModified; private T file; - private GenericFileBinding<T> binding; + private GenericFileBinding<T> binding; @Override public GenericFile<T> clone() { @@ -65,6 +65,14 @@ result.setBody(source.getBody()); result.setBinding(source.getBinding()); return result; + } + + public boolean needToNormalize() { + return true; + } + + public String getFileSeparator() { + return File.separator; } /** @@ -74,29 +82,33 @@ * @param newName the new name */ public void changeFileName(String newName) { - // must normalize path to cater for Windows and other OS - newName = FileUtil.normalizePath(newName); + + newName = needToNormalize() + // must normalize path to cater for Windows and other OS + ? FileUtil.normalizePath(newName) + // for the remote file we don't need to do that + : newName; - setAbsoluteFileName(getParent() + File.separator + newName); + setAbsoluteFileName(getParent() + getFileSeparator() + newName); // relative name is a bit more complex to set as newName itself can contain // folders we need to consider as well String baseNewName = null; - if (newName.indexOf(File.separator) != -1) { - baseNewName = newName.substring(0, newName.lastIndexOf(File.separator)); - newName = newName.substring(newName.lastIndexOf(File.separator) + 1); + if (newName.indexOf(getFileSeparator()) != -1) { + baseNewName = newName.substring(0, newName.lastIndexOf(getFileSeparator())); + newName = newName.substring(newName.lastIndexOf(getFileSeparator()) + 1); } - if (relativeFileName.indexOf(File.separator) != -1) { + if (relativeFileName.indexOf(getFileSeparator()) != -1) { String relative = relativeFileName.substring(0, relativeFileName.lastIndexOf(File.separator)); if (baseNewName != null) { - setRelativeFileName(relative + File.separator + baseNewName + File.separator + newName); + setRelativeFileName(relative + getFileSeparator() + baseNewName + getFileSeparator() + newName); } else { - setRelativeFileName(relative + File.separator + newName); + setRelativeFileName(relative + getFileSeparator() + newName); } } else { if (baseNewName != null) { - setRelativeFileName(baseNewName + File.separator + newName); + setRelativeFileName(baseNewName + getFileSeparator() + newName); } else { setRelativeFileName(newName); } @@ -154,8 +166,8 @@ } public String getParent() { - if (getAbsoluteFileName().lastIndexOf(File.separator) > 0) { - return getAbsoluteFileName().substring(0, getAbsoluteFileName().lastIndexOf(File.separator)); + if (getAbsoluteFileName().lastIndexOf(getFileSeparator()) > 0) { + return getAbsoluteFileName().substring(0, getAbsoluteFileName().lastIndexOf(getFileSeparator())); } else { return ""; } @@ -173,8 +185,13 @@ } public void setAbsoluteFileName(String absoluteFileName) { - // must normalize path to cater for Windows and other OS - this.absoluteFileName = FileUtil.normalizePath(absoluteFileName); + + this.absoluteFileName = needToNormalize() + // must normalize path to cater for Windows and other OS + ? FileUtil.normalizePath(absoluteFileName) + // we don't need to do that for Remote File + : absoluteFileName; + } public String getAbsoluteFileName() { Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java?rev=741417&r1=741416&r2=741417&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConfiguration.java Fri Feb 6 05:29:59 2009 @@ -22,6 +22,9 @@ public class GenericFileConfiguration { private String file; + public boolean needToNormalize() { + return true; + } public void configure(URI uri) { setFile(uri.getPath()); @@ -31,9 +34,12 @@ return file; } - public void setFile(String file) { - // must normalize path to cater for Windows and other OS - this.file = FileUtil.normalizePath(file); + public void setFile(String file) { + this.file = needToNormalize() + // must normalize path to cater for Windows and other OS + ? FileUtil.normalizePath(file) + // for the remote file we don't need to do that + : file; } public String toString() { Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=741417&r1=741416&r2=741417&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Fri Feb 6 05:29:59 2009 @@ -57,7 +57,7 @@ // gather list of files to process List<GenericFile<T>> files = new ArrayList<GenericFile<T>>(); - String name = endpoint.getConfiguration().getFile(); + String name = endpoint.getConfiguration().getFile(); boolean isDirectory = endpoint.isDirectory(); if (isDirectory) { pollDirectory(name, files); Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java?rev=741417&r1=741416&r2=741417&view=diff ============================================================================== --- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java (original) +++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFile.java Fri Feb 6 05:29:59 2009 @@ -16,6 +16,8 @@ */ package org.apache.camel.component.file.remote; +import java.io.File; + import org.apache.camel.component.file.GenericFile; /** @@ -34,6 +36,15 @@ public void setHostname(String hostname) { this.hostname = hostname; } + + @Override + public boolean needToNormalize() { + return false; + } + + public String getFileSeparator() { + return "/"; + } public RemoteFile<T> copyFrom(RemoteFile<T> source) { RemoteFile<T> result = (RemoteFile<T>) source.clone(); Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java?rev=741417&r1=741416&r2=741417&view=diff ============================================================================== --- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java (original) +++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java Fri Feb 6 05:29:59 2009 @@ -38,6 +38,11 @@ public RemoteFileConfiguration(URI uri) { configure(uri); } + + @Override + public boolean needToNormalize() { + return false; + } @Override public void configure(URI uri) {