Author: davsclaus
Date: Fri Mar 15 15:42:25 2013
New Revision: 1456990
URL: http://svn.apache.org/r1456990
Log:
CAMEL-6056: Restore camel-ftp to use loigc from working Camel 2.10.2 as
otherwise we risk break other stuff for people.
Added:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=1456990&r1=1456989&r2=1456990&view=diff
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
(original)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
Fri Mar 15 15:42:25 2013
@@ -696,12 +696,8 @@ public class FtpOperations implements Re
}
// must compact path so FTP server can traverse correctly
- String before = path;
- char separatorChar = endpoint.getFileSeparator();
- path = FileUtil.compactPath(path, separatorChar);
- if (log.isTraceEnabled()) {
- log.trace("Compacted path: {} -> {} using separator: {}", new
Object[]{before, path, separatorChar});
- }
+ // use the ftp utils implementation of the compact path
+ path = FtpUtils.compactPath(path);
// not stepwise should change directory in one operation
if (!endpoint.getConfiguration().isStepwise()) {
Added:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java?rev=1456990&view=auto
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java
(added)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpUtils.java
Fri Mar 15 15:42:25 2013
@@ -0,0 +1,97 @@
+/**
+ * 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.file.remote;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Stack;
+
+import org.apache.camel.util.FileUtil;
+
+/**
+ * Various FTP utils.
+ */
+public final class FtpUtils {
+
+ private FtpUtils() {
+ }
+
+ /**
+ * Compacts a path by stacking it and reducing <tt>..</tt>,
+ * and uses OS specific file separators (eg {@link
java.io.File#separator}).
+ * <p/>
+ * <b>Important: </b> This implementation works for the camel-ftp component
+ * for various FTP clients and FTP servers using different platforms and
whatnot.
+ * This implementation has been working for many Camel releases, and is
included here
+ * to restore patch compatibility with the Camel releases.
+ */
+ public static String compactPath(String path) {
+ if (path == null) {
+ return null;
+ }
+
+ // only normalize if contains a path separator
+ if (path.indexOf(File.separator) == -1) {
+ return path;
+ }
+
+ // preserve ending slash if given in input path
+ boolean endsWithSlash = path.endsWith("/") || path.endsWith("\\");
+
+ // preserve starting slash if given in input path
+ boolean startsWithSlash = path.startsWith("/") ||
path.startsWith("\\");
+
+ Stack<String> stack = new Stack<String>();
+
+ String separatorRegex = File.separator;
+ if (FileUtil.isWindows()) {
+ separatorRegex = "\\\\";
+ }
+ String[] parts = path.split(separatorRegex);
+ for (String part : parts) {
+ if (part.equals("..") && !stack.isEmpty() &&
!"..".equals(stack.peek())) {
+ // only pop if there is a previous path, which is not a ".."
path either
+ stack.pop();
+ } else if (part.equals(".") || part.isEmpty()) {
+ // do nothing because we don't want a path like foo/./bar or
foo//bar
+ } else {
+ stack.push(part);
+ }
+ }
+
+ // build path based on stack
+ StringBuilder sb = new StringBuilder();
+
+ if (startsWithSlash) {
+ sb.append(File.separator);
+ }
+
+ for (Iterator<String> it = stack.iterator(); it.hasNext();) {
+ sb.append(it.next());
+ if (it.hasNext()) {
+ sb.append(File.separator);
+ }
+ }
+
+ if (endsWithSlash) {
+ sb.append(File.separator);
+ }
+
+ return sb.toString();
+ }
+
+}