Author: davsclaus Date: Sun Mar 8 11:28:45 2009 New Revision: 751402 URL: http://svn.apache.org/viewvc?rev=751402&view=rev Log: CAMEL-1428: Fixed checkstyle. Move code to FileUtil. And reverter experimental code in FileConsumer about file name.
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?rev=751402&r1=751401&r2=751402&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java Sun Mar 8 11:28:45 2009 @@ -27,8 +27,8 @@ import org.apache.camel.Routes; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.model.ChoiceDefinition; -import org.apache.camel.model.OnExceptionDefinition; import org.apache.camel.model.InterceptDefinition; +import org.apache.camel.model.OnExceptionDefinition; import org.apache.camel.model.ProcessorDefinition; import org.apache.camel.model.RouteDefinition; import org.apache.camel.model.RoutesDefinition; Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=751402&r1=751401&r2=751402&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java Sun Mar 8 11:28:45 2009 @@ -101,8 +101,9 @@ answer.setEndpointPath(endpointPath); answer.setBinding(new FileBinding()); answer.setFile(file); - answer.setFileLength(file.length()); + answer.setFileName(file.getName()); answer.setFileNameOnly(file.getName()); + answer.setFileLength(file.length()); answer.setAbsolute(file.isAbsolute()); answer.setAbsoluteFilePath(file.getAbsolutePath()); answer.setLastModified(file.lastModified()); @@ -125,9 +126,6 @@ } } - // name is the relative path as we want to preserve leading paths relative to the endpoint path - answer.setFileName(answer.getRelativeFilePath()); - // use file as body as we have converters if needed as stream answer.setBody(file); return answer; 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=751402&r1=751401&r2=751402&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 Sun Mar 8 11:28:45 2009 @@ -18,8 +18,6 @@ import java.io.File; import java.io.Serializable; -import java.util.Stack; -import java.util.Iterator; import org.apache.camel.util.FileUtil; import org.apache.camel.util.ObjectHelper; @@ -82,38 +80,6 @@ return File.separator; } - public static String normalizePath(String path) { - return path; - - // TODO: not needed -/* // only normalize path if it contains .. as we want to avoid: path/../sub/../sub2 as this can leads to trouble - if (path.indexOf("..") == -1) { - return path; - } - - Stack<String> stack = new Stack<String>(); - String[] parts = path.split(File.separator); - for (String part : parts) { - if (part.equals("..") && !stack.isEmpty()) { - // only pop if there is a previous path - stack.pop(); - } else { - stack.push(part); - } - } - - // build path based on stack - StringBuilder sb = new StringBuilder(); - for (Iterator it = stack.iterator(); it.hasNext();) { - sb.append(it.next()); - if (it.hasNext()) { - sb.append(File.separator); - } - } - - return sb.toString();*/ - } - /** * Changes the name of this remote file. This method alters the absolute and * relative names as well. @@ -173,8 +139,7 @@ } public void setRelativeFilePath(String relativeFilePath) { - String path = normalizePath(relativeFilePath); - this.relativeFilePath = needToNormalize() ? FileUtil.normalizePath(path) : path; + this.relativeFilePath = needToNormalize() ? FileUtil.normalizePath(relativeFilePath) : relativeFilePath; } public String getFileName() { @@ -241,8 +206,7 @@ } public void setAbsoluteFilePath(String absoluteFilePath) { - String path = normalizePath(absoluteFilePath); - this.absoluteFilePath = needToNormalize() ? FileUtil.normalizePath(path) : path; + this.absoluteFilePath = needToNormalize() ? FileUtil.normalizePath(absoluteFilePath) : absoluteFilePath; } public String getAbsoluteFilePath() { Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java?rev=751402&r1=751401&r2=751402&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java Sun Mar 8 11:28:45 2009 @@ -24,8 +24,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Stack; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -308,6 +310,9 @@ return results; } + /** + * Strip any leading separators + */ public static String stripLeadingSeparator(String name) { if (name == null) { return null; @@ -318,6 +323,9 @@ return name; } + /** + * Strips any leading paths + */ public static String stripPath(String name) { if (name == null) { return null; @@ -332,4 +340,36 @@ return name; } + /** + * Compacts a path by stacking it and reducing <tt>..</tt> + */ + public static String compactPath(String path) { + // only normalize path if it contains .. as we want to avoid: path/../sub/../sub2 as this can leads to trouble + if (path.indexOf("..") == -1) { + return path; + } + + Stack<String> stack = new Stack<String>(); + String[] parts = path.split(File.separator); + for (String part : parts) { + if (part.equals("..") && !stack.isEmpty()) { + // only pop if there is a previous path + stack.pop(); + } else { + stack.push(part); + } + } + + // build path based on stack + StringBuilder sb = new StringBuilder(); + for (Iterator it = stack.iterator(); it.hasNext();) { + sb.append(it.next()); + if (it.hasNext()) { + sb.append(File.separator); + } + } + + return sb.toString(); + } + } Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java?rev=751402&r1=751401&r2=751402&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/language/FileLanguageTest.java Sun Mar 8 11:28:45 2009 @@ -25,7 +25,6 @@ import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; import org.apache.camel.LanguageTestSupport; -import org.apache.camel.util.ObjectHelper; import org.apache.camel.component.file.FileConsumer; import org.apache.camel.component.file.FileEndpoint; import org.apache.camel.component.file.GenericFile;