camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject svn commit: r788917 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/file/ components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/ components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/
Date Sat, 27 Jun 2009 02:16:18 GMT
Author: hadrian
Date: Sat Jun 27 02:16:17 2009
New Revision: 788917

URL: http://svn.apache.org/viewvc?rev=788917&view=rev
Log:
CAMEL-1078.  Moved RemoteFileExchange to oblivion.

Removed:
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileExchange.java
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/GenericFileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultRemoteFileSorter.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/RemoteFileEndpoint.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java
    camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerWithNoFileOptionTest.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=788917&r1=788916&r2=788917&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
Sat Jun 27 02:16:17 2009
@@ -18,7 +18,9 @@
 
 import java.io.File;
 import java.io.Serializable;
+import java.util.Date;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
@@ -79,6 +81,38 @@
         result.setBinding(source.getBinding());
         return result;
     }
+
+    /**
+     * Populates the {@link GenericFileMessage} relevant headers
+     *
+     * @param message the message to populate with headers
+     */
+    public void populateHeaders(GenericFileMessage<T> message) {
+        if (message != null) {
+            message.setHeader(Exchange.FILE_NAME_ONLY, getFileNameOnly());
+            message.setHeader(Exchange.FILE_NAME, getFileName());
+            message.setHeader("CamelFileAbsolute", isAbsolute());
+            message.setHeader("CamelFileAbsolutePath", getAbsoluteFilePath());
+    
+            if (isAbsolute()) {
+                message.setHeader(Exchange.FILE_PATH, getAbsoluteFilePath());
+            } else {
+                // we must normalize path according to protocol if we build our own paths
+                String path = normalizePathToProtocol(getEndpointPath() + File.separator
+ getRelativeFilePath());
+                message.setHeader(Exchange.FILE_PATH, path);
+            }
+    
+            message.setHeader("CamelFileRelativePath", getRelativeFilePath());
+            message.setHeader(Exchange.FILE_PARENT, getParent());
+    
+            if (getFileLength() > 0) {
+                message.setHeader("CamelFileLength", getFileLength());
+            }
+            if (getLastModified() > 0) {
+                message.setHeader("CamelFileLastModified", new Date(getLastModified()));
+            }
+        }
+    }
     
     protected boolean isAbsolute(String name) {
         File file = new File(name);

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=788917&r1=788916&r2=788917&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
Sat Jun 27 02:16:17 2009
@@ -73,7 +73,7 @@
         }
 
         // sort using build in sorters that is expression based
-        // first we need to convert to RemoteFileExchange objects so we can sort
+        // first we need to convert to GenericFileExchange objects so we can sort
         // using expressions
         LinkedList<GenericFileExchange> exchanges = new LinkedList<GenericFileExchange>();
         for (GenericFile<T> file : files) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java?rev=788917&r1=788916&r2=788917&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileExchange.java
Sat Jun 27 02:16:17 2009
@@ -22,6 +22,7 @@
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.apache.camel.PollingConsumerAware;
 import org.apache.camel.RuntimeExchangeException;
 import org.apache.camel.impl.DefaultExchange;
@@ -40,29 +41,9 @@
     }
 
     protected void populateHeaders(GenericFile<T> file) {
-        if (file != null) {
-            getIn().setHeader(Exchange.FILE_NAME_ONLY, file.getFileNameOnly());
-            getIn().setHeader(Exchange.FILE_NAME, file.getFileName());
-            getIn().setHeader("CamelFileAbsolute", file.isAbsolute());
-            getIn().setHeader("CamelFileAbsolutePath", file.getAbsoluteFilePath());
-
-            if (file.isAbsolute()) {
-                getIn().setHeader(Exchange.FILE_PATH, file.getAbsoluteFilePath());
-            } else {
-                // we must normalize path according to protocol if we build our own paths
-                String path = file.normalizePathToProtocol(file.getEndpointPath() + File.separator
+ file.getRelativeFilePath());
-                getIn().setHeader(Exchange.FILE_PATH, path);
-            }
-
-            getIn().setHeader("CamelFileRelativePath", file.getRelativeFilePath());
-            getIn().setHeader(Exchange.FILE_PARENT, file.getParent());
-
-            if (file.getFileLength() > 0) {
-                getIn().setHeader("CamelFileLength", file.getFileLength());
-            }
-            if (file.getLastModified() > 0) {
-                getIn().setHeader("CamelFileLastModified", new Date(file.getLastModified()));
-            }
+        Message message = getIn();
+        if (file != null && message instanceof GenericFileMessage) {
+            file.populateHeaders((GenericFileMessage<T>)message);
         }
     }
 

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultRemoteFileSorter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultRemoteFileSorter.java?rev=788917&r1=788916&r2=788917&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultRemoteFileSorter.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DefaultRemoteFileSorter.java
Sat Jun 27 02:16:17 2009
@@ -19,6 +19,7 @@
 import java.util.Comparator;
 
 import org.apache.camel.Expression;
+import org.apache.camel.component.file.GenericFileExchange;
 import org.apache.camel.language.simple.FileLanguage;
 import org.apache.camel.util.ObjectHelper;
 
@@ -93,7 +94,7 @@
      * @param reverse    true to reverse order
      * @return the comparator
      */
-    public static Comparator<RemoteFileExchange> sortByFileLanguage(final String expression,
final boolean reverse) {
+    public static Comparator<GenericFileExchange> sortByFileLanguage(final String expression,
final boolean reverse) {
         return sortByFileLanguage(expression, reverse, false, null);
     }
 
@@ -105,7 +106,7 @@
      * @param ignoreCase ignore case if comparing strings
      * @return the comparator
      */
-    public static Comparator<RemoteFileExchange> sortByFileLanguage(final String expression,
final boolean reverse,
+    public static Comparator<GenericFileExchange> sortByFileLanguage(final String expression,
final boolean reverse,
                                                                     final boolean ignoreCase)
{
         return sortByFileLanguage(expression, reverse, ignoreCase, null);
     }
@@ -119,10 +120,12 @@
      * @param nested     nested comparator for sub group sorting, can be null
      * @return the comparator
      */
-    public static Comparator<RemoteFileExchange> sortByFileLanguage(final String expression,
final boolean reverse,
-                                                                    final boolean ignoreCase,
final Comparator<RemoteFileExchange> nested) {
-        return new Comparator<RemoteFileExchange>() {
-            public int compare(RemoteFileExchange o1, RemoteFileExchange o2) {
+    public static Comparator<GenericFileExchange> sortByFileLanguage(
+        final String expression, final boolean reverse,
+        final boolean ignoreCase, final Comparator<GenericFileExchange> nested) {
+        
+        return new Comparator<GenericFileExchange>() {
+            public int compare(GenericFileExchange o1, GenericFileExchange o2) {
                 final Expression exp = FileLanguage.file(expression);
                 Object result1 = exp.evaluate(o1, Object.class);
                 Object result2 = exp.evaluate(o2, Object.class);
@@ -139,5 +142,4 @@
             }
         };
     }
-
 }

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=788917&r1=788916&r2=788917&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
Sat Jun 27 02:16:17 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote;
 
 import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.component.file.GenericFileMessage;
 import org.apache.camel.util.FileUtil;
 import org.apache.camel.util.ObjectHelper;
 
@@ -29,6 +30,18 @@
 
     private String hostname;
 
+    /**
+     * Populates the {@link GenericFileMessage} relevant headers
+     *
+     * @param message the message to populate with headers
+     */
+    public void populateHeaders(GenericFileMessage<T> message) {
+        if (message != null) {
+            super.populateHeaders(message);
+            message.setHeader("CamelFileHost", getHostname());
+        }
+    }
+
     public String getHostname() {
         return hostname;
     }
@@ -84,5 +97,4 @@
         // strip leading / for FTP protocol to avoid files with absolute paths
         return FileUtil.stripLeadingSeparator(path);
     }
-
 }

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java?rev=788917&r1=788916&r2=788917&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
Sat Jun 27 02:16:17 2009
@@ -39,14 +39,14 @@
     }
 
     @Override
-    public GenericFileExchange createExchange() {
-        return new RemoteFileExchange(this);
+    public GenericFileExchange<T> createExchange() {
+        return new GenericFileExchange<T>(this);
     }
 
     @Override
     @SuppressWarnings("unchecked")
     public GenericFileExchange<T> createExchange(GenericFile<T> file) {
-        RemoteFileExchange answer = new RemoteFileExchange<T>(this);
+        GenericFileExchange<T> answer = new GenericFileExchange<T>(this);
         answer.setGenericFile(file);
         return answer;
     }

Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java?rev=788917&r1=788916&r2=788917&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java
(original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerMultipleDirectoriesTest.java
Sat Jun 27 02:16:17 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.file.GenericFileExchange;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.Before;
 import org.junit.Test;
@@ -51,19 +52,19 @@
 
         assertMockEndpointsSatisfied();
 
-        RemoteFileExchange exchange = (RemoteFileExchange) mock.getExchanges().get(0);
+        GenericFileExchange exchange = (GenericFileExchange) mock.getExchanges().get(0);
         RemoteFile file = (RemoteFile) exchange.getGenericFile();
         assertDirectoryEquals("multidir/bye.txt", file.getAbsoluteFilePath());
         assertDirectoryEquals("bye.txt", file.getRelativeFilePath());
         assertEquals("bye.txt", file.getFileName());
 
-        exchange = (RemoteFileExchange) mock.getExchanges().get(1);
+        exchange = (GenericFileExchange) mock.getExchanges().get(1);
         file = (RemoteFile) exchange.getGenericFile();
         assertDirectoryEquals("multidir/sub/hello.txt", file.getAbsoluteFilePath());
         assertDirectoryEquals("sub/hello.txt", file.getRelativeFilePath());
         assertEquals("hello.txt", file.getFileName());
 
-        exchange = (RemoteFileExchange) mock.getExchanges().get(2);
+        exchange = (GenericFileExchange) mock.getExchanges().get(2);
         file = (RemoteFile) exchange.getGenericFile();
         assertDirectoryEquals("multidir/sub/sub2/godday.txt", file.getAbsoluteFilePath());
         assertDirectoryEquals("sub/sub2/godday.txt", file.getRelativeFilePath());
@@ -77,5 +78,4 @@
             }
         };
     }
-
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerWithNoFileOptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerWithNoFileOptionTest.java?rev=788917&r1=788916&r2=788917&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerWithNoFileOptionTest.java
(original)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerWithNoFileOptionTest.java
Sat Jun 27 02:16:17 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file.remote;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.file.GenericFileExchange;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.Before;
 import org.junit.Test;
@@ -52,7 +53,7 @@
 
         assertMockEndpointsSatisfied();
 
-        RemoteFileExchange exchange = (RemoteFileExchange) mock.getExchanges().get(0);
+        GenericFileExchange exchange = (GenericFileExchange) mock.getExchanges().get(0);
         RemoteFile file = (RemoteFile) exchange.getGenericFile();
         assertEquals("hello.txt", file.getAbsoluteFilePath());
         assertEquals("hello.txt", file.getRelativeFilePath());
@@ -66,5 +67,4 @@
             }
         };
     }
-
 }
\ No newline at end of file



Mime
View raw message