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 2009/02/02 12:12:26 UTC
svn commit: r739960 - in
/camel/trunk/camel-core/src/main/java/org/apache/camel: component/file/
component/file/strategy/ util/
Author: davsclaus
Date: Mon Feb 2 11:12:25 2009
New Revision: 739960
URL: http://svn.apache.org/viewvc?rev=739960&view=rev
Log:
Added FileUtil
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java (with props)
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/GenericFileProducer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DefaultFileRenamer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileExpressionRenamer.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=739960&r1=739959&r2=739960&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 Mon Feb 2 11:12:25 2009
@@ -17,8 +17,8 @@
package org.apache.camel.component.file;
import java.io.File;
-import java.util.Date;
+import org.apache.camel.util.FileUtil;
import org.apache.camel.util.ObjectHelper;
/**
@@ -73,9 +73,9 @@
* @param newName the new name
*/
public void changeFileName(String newName) {
- if (System.getProperty("os.name").startsWith("Windows") && newName.indexOf("/") >= 0) {
- newName = newName.replaceAll("/", "\\\\");
- }
+ // must normalize path to cater for Windows and other OS
+ newName = FileUtil.normalizePath(newName);
+
setAbsoluteFileName(getParent() + File.separator + newName);
// relative name is a bit more complex to set as newName itself can contain
@@ -175,12 +175,8 @@
* @param absoluteFileName the absoluteFileName to set
*/
public void setAbsoluteFileName(String absoluteFileName) {
- // should replace the "/" with "\\" in windows
- if (absoluteFileName != null && System.getProperty("os.name").startsWith("Windows") && absoluteFileName.indexOf("/") >= 0) {
- this.absoluteFileName = absoluteFileName.replaceAll("/", "\\\\");
- } else {
- this.absoluteFileName = absoluteFileName;
- }
+ // must normalize path to cater for Windows and other OS
+ this.absoluteFileName = FileUtil.normalizePath(absoluteFileName);
}
/**
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java?rev=739960&r1=739959&r2=739960&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java Mon Feb 2 11:12:25 2009
@@ -24,6 +24,7 @@
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.language.simple.FileLanguage;
import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.FileUtil;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -164,11 +165,9 @@
Object result = expression.evaluate(exchange);
name = exchange.getContext().getTypeConverter().convertTo(String.class, result);
}
-
- // replace the "/" with the "\\" for Windows
- if (name != null && System.getProperty("os.name").startsWith("Windows") && name.indexOf("/") >= 0) {
- name = name.replaceAll("/", "\\\\");
- }
+
+ // must normalize path to cater for Windows and other OS
+ name = FileUtil.normalizePath(name);
String endpointFile = endpoint.getConfiguration().getFile();
if (endpoint.isDirectory()) {
@@ -182,7 +181,6 @@
answer = baseDir + name;
} else {
// use a generated filename if no name provided
- // TODO: Consider to require end user to always provide a filename instead of generating a new name
answer = baseDir + endpoint.getGeneratedFileName(exchange.getIn());
}
} else {
@@ -193,10 +191,9 @@
}
protected String createTempFileName(String fileName) {
- if (fileName != null && System.getProperty("os.name").startsWith("Windows") && fileName.indexOf("/") >= 0) {
- fileName = fileName.replaceAll("/", "\\\\");
- }
-
+ // must normalize path to cater for Windows and other OS
+ fileName = FileUtil.normalizePath(fileName);
+
int path = fileName.lastIndexOf(File.separator);
if (path == -1) {
// no path
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DefaultFileRenamer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DefaultFileRenamer.java?rev=739960&r1=739959&r2=739960&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DefaultFileRenamer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/DefaultFileRenamer.java Mon Feb 2 11:12:25 2009
@@ -19,6 +19,7 @@
import java.io.File;
import org.apache.camel.component.file.FileExchange;
+import org.apache.camel.util.FileUtil;
/**
* Camel default file renamer.
@@ -44,7 +45,9 @@
File parent = file.getParentFile();
String name = renameFileName(file);
- if (ON_WINDOWS && (name.indexOf(":") >= 0 || name.startsWith("//"))) {
+ name = FileUtil.normalizePath(name);
+
+ if (ON_WINDOWS && (name.indexOf(":") >= 0 || name.startsWith("\\\\"))) {
return new File(name);
}
return new File(parent, name);
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileExpressionRenamer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileExpressionRenamer.java?rev=739960&r1=739959&r2=739960&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileExpressionRenamer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileExpressionRenamer.java Mon Feb 2 11:12:25 2009
@@ -20,6 +20,7 @@
import org.apache.camel.Expression;
import org.apache.camel.component.file.FileExchange;
+import org.apache.camel.util.FileUtil;
import org.apache.camel.util.ObjectHelper;
/**
@@ -40,7 +41,11 @@
Object result = expression.evaluate(exchange);
String name = exchange.getContext().getTypeConverter().convertTo(String.class, result);
- if (ON_WINDOWS && (name.indexOf(":") >= 0 || name.startsWith("//"))) {
+ // must normalize path to cater for Windows and other OS
+ name = FileUtil.normalizePath(name);
+
+ // special handling for Windows \\ paths
+ if (ON_WINDOWS && (name.indexOf(":") >= 0 || name.startsWith("\\\\"))) {
return new File(name);
}
Added: 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=739960&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java Mon Feb 2 11:12:25 2009
@@ -0,0 +1,38 @@
+/**
+ * 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.util;
+
+/**
+ * File utilities
+ */
+public final class FileUtil {
+
+ private FileUtil() {
+ }
+
+ /**
+ * Normalizes the path to cater for Windows and other platforms
+ */
+ public static String normalizePath(String path) {
+ // special handling for Windows where we need to convert / to \\
+ if (path != null && System.getProperty("os.name").startsWith("Windows") && path.indexOf("/") >= 0) {
+ return path.replaceAll("/", "\\\\");
+ }
+ return path;
+ }
+
+}
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/util/FileUtil.java
------------------------------------------------------------------------------
svn:keywords = Rev Date