Author: davsclaus Date: Fri Feb 6 07:02:26 2009 New Revision: 741441 URL: http://svn.apache.org/viewvc?rev=741441&view=rev Log: CAMEL-1319: Added includeNameXX options to the file component.
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java (with props) camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java (contents, props changed) - copied, changed from r741417, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java Modified: 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/FileEndpoint.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/GenericFileEndpoint.java camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java 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=741441&r1=741440&r2=741441&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 Fri Feb 6 07:02:26 2009 @@ -304,13 +304,13 @@ } } - if (ObjectHelper.isNotEmpty(endpoint.getExcludedNamePrefix())) { - if (name.startsWith(endpoint.getExcludedNamePrefix())) { + if (ObjectHelper.isNotEmpty(endpoint.getExcludeNamePrefix())) { + if (name.startsWith(endpoint.getExcludeNamePrefix())) { return false; } } - if (ObjectHelper.isNotEmpty(endpoint.getExcludedNamePostfix())) { - if (name.endsWith(endpoint.getExcludedNamePostfix())) { + if (ObjectHelper.isNotEmpty(endpoint.getExcludeNamePostfix())) { + if (name.endsWith(endpoint.getExcludeNamePostfix())) { return false; } } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=741441&r1=741440&r2=741441&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java Fri Feb 6 07:02:26 2009 @@ -69,8 +69,8 @@ private String moveNamePostfix; private String preMoveNamePrefix; private String preMoveNamePostfix; - private String excludedNamePrefix; - private String excludedNamePostfix; + private String excludeNamePrefix; + private String excludeNamePostfix; private int bufferSize = 128 * 1024; private boolean ignoreFileNameHeader; private Expression expression; @@ -343,20 +343,20 @@ this.ignoreFileNameHeader = ignoreFileNameHeader; } - public String getExcludedNamePrefix() { - return excludedNamePrefix; + public String getExcludeNamePrefix() { + return excludeNamePrefix; } - public void setExcludedNamePrefix(String excludedNamePrefix) { - this.excludedNamePrefix = excludedNamePrefix; + public void setExcludeNamePrefix(String excludeNamePrefix) { + this.excludeNamePrefix = excludeNamePrefix; } - public String getExcludedNamePostfix() { - return excludedNamePostfix; + public String getExcludeNamePostfix() { + return excludeNamePostfix; } - public void setExcludedNamePostfix(String excludedNamePostfix) { - this.excludedNamePostfix = excludedNamePostfix; + public void setExcludeNamePostfix(String excludeNamePostfix) { + this.excludeNamePostfix = excludeNamePostfix; } public Expression getExpression() { 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=741441&r1=741440&r2=741441&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 07:02:26 2009 @@ -324,13 +324,24 @@ } } - if (ObjectHelper.isNotEmpty(endpoint.getExcludedNamePrefix())) { - if (name.startsWith(endpoint.getExcludedNamePrefix())) { + if (ObjectHelper.isNotEmpty(endpoint.getExcludeNamePrefix())) { + if (name.startsWith(endpoint.getExcludeNamePrefix())) { return false; } } - if (ObjectHelper.isNotEmpty(endpoint.getExcludedNamePostfix())) { - if (name.endsWith(endpoint.getExcludedNamePostfix())) { + if (ObjectHelper.isNotEmpty(endpoint.getExcludeNamePostfix())) { + if (name.endsWith(endpoint.getExcludeNamePostfix())) { + return false; + } + } + + if (ObjectHelper.isNotEmpty(endpoint.getIncludeNamePrefix())) { + if (!name.startsWith(endpoint.getIncludeNamePrefix())) { + return false; + } + } + if (ObjectHelper.isNotEmpty(endpoint.getIncludeNamePostfix())) { + if (!name.endsWith(endpoint.getIncludeNamePostfix())) { return false; } } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java?rev=741441&r1=741440&r2=741441&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java Fri Feb 6 07:02:26 2009 @@ -62,8 +62,10 @@ protected String moveNamePostfix; protected String preMoveNamePrefix; protected String preMoveNamePostfix; - protected String excludedNamePrefix; - protected String excludedNamePostfix; + protected String excludeNamePrefix; + protected String excludeNamePostfix; + protected String includeNamePrefix; + protected String includeNamePostfix; protected String regexPattern; protected Expression expression; protected Expression preMoveExpression; @@ -188,20 +190,36 @@ this.preMoveNamePostfix = preMoveNamePostfix; } - public String getExcludedNamePrefix() { - return excludedNamePrefix; + public String getExcludeNamePrefix() { + return excludeNamePrefix; } - public void setExcludedNamePrefix(String excludedNamePrefix) { - this.excludedNamePrefix = excludedNamePrefix; + public void setExcludeNamePrefix(String excludeNamePrefix) { + this.excludeNamePrefix = excludeNamePrefix; } - public String getExcludedNamePostfix() { - return excludedNamePostfix; + public String getExcludeNamePostfix() { + return excludeNamePostfix; } - public void setExcludedNamePostfix(String excludedNamePostfix) { - this.excludedNamePostfix = excludedNamePostfix; + public void setExcludeNamePostfix(String excludeNamePostfix) { + this.excludeNamePostfix = excludeNamePostfix; + } + + public String getIncludeNamePrefix() { + return includeNamePrefix; + } + + public void setIncludeNamePrefix(String includeNamePrefix) { + this.includeNamePrefix = includeNamePrefix; + } + + public String getIncludeNamePostfix() { + return includeNamePostfix; + } + + public void setIncludeNamePostfix(String includeNamePostfix) { + this.includeNamePostfix = includeNamePostfix; } public boolean isRecursive() { Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java?rev=741441&r1=741440&r2=741441&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java Fri Feb 6 07:02:26 2009 @@ -46,7 +46,7 @@ protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - from("file://target/exclude/?excludedNamePrefix=secret&excludedNamePostfix=xml") + from("file://target/exclude/?excludeNamePrefix=secret&excludeNamePostfix=xml") .to("mock:result"); } }; Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java?rev=741441&view=auto ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java (added) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java Fri Feb 6 07:02:26 2009 @@ -0,0 +1,55 @@ +/** + * 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; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; + +/** + * Unit test that file consumer will include/exclude pre and postfixes + */ +public class FileConsumerIncludeAndExcludeNameTest extends ContextTestSupport { + + public void testIncludePreAndPostfixes() throws Exception { + deleteDirectory("./target/includeexclude"); + prepareFiles(); + + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(2); + mock.expectedBodiesReceivedInAnyOrder("Report 2", "Report 3"); + mock.assertIsSatisfied(); + } + + private void prepareFiles() throws Exception { + String url = "newfile://target/includeexclude"; + template.sendBodyAndHeader(url, "Hello World", NewFileComponent.HEADER_FILE_NAME, "hello.xml"); + template.sendBodyAndHeader(url, "Report 1", NewFileComponent.HEADER_FILE_NAME, "report1.xml"); + template.sendBodyAndHeader(url, "Report 2", NewFileComponent.HEADER_FILE_NAME, "report2.txt"); + template.sendBodyAndHeader(url, "Report 3", NewFileComponent.HEADER_FILE_NAME, "report3.txt"); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("newfile://target/includeexclude/?includeNamePrefix=report&excludeNamePostfix=xml") + .to("mock:result"); + } + }; + } + +} \ No newline at end of file Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeAndExcludeNameTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java (from r741417, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java&r1=741417&r2=741441&rev=741441&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerExcludeNameTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java Fri Feb 6 07:02:26 2009 @@ -21,12 +21,12 @@ import org.apache.camel.component.mock.MockEndpoint; /** - * Unit test that file consumer will exclude pre and postfixes + * Unit test that file consumer will include pre and postfixes */ -public class FileConsumerExcludeNameTest extends ContextTestSupport { +public class FileConsumerIncludeNameTest extends ContextTestSupport { - public void testExludePreAndPostfixes() throws Exception { - deleteDirectory("./target/exclude"); + public void testIncludePreAndPostfixes() throws Exception { + deleteDirectory("./target/include"); prepareFiles(); MockEndpoint mock = getMockEndpoint("mock:result"); @@ -36,20 +36,20 @@ } private void prepareFiles() throws Exception { - String url = "file://target/exclude"; - template.sendBodyAndHeader(url, "Hello World", FileComponent.HEADER_FILE_NAME, "hello.xml"); - template.sendBodyAndHeader(url, "Reports", FileComponent.HEADER_FILE_NAME, "report1.txt"); - template.sendBodyAndHeader(url, "Bye World", FileComponent.HEADER_FILE_NAME, "secret.txt"); - template.sendBodyAndHeader(url, "Reports", FileComponent.HEADER_FILE_NAME, "report2.txt"); + String url = "newfile://target/include"; + template.sendBodyAndHeader(url, "Hello World", NewFileComponent.HEADER_FILE_NAME, "hello.xml"); + template.sendBodyAndHeader(url, "Reports", NewFileComponent.HEADER_FILE_NAME, "report1.txt"); + template.sendBodyAndHeader(url, "Bye World", NewFileComponent.HEADER_FILE_NAME, "secret.txt"); + template.sendBodyAndHeader(url, "Reports", NewFileComponent.HEADER_FILE_NAME, "report2.txt"); } protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - from("file://target/exclude/?excludedNamePrefix=secret&excludedNamePostfix=xml") + from("newfile://target/include/?includeNamePrefix=report&includeNamePostfix=txt") .to("mock:result"); } }; } -} +} \ No newline at end of file Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerIncludeNameTest.java ------------------------------------------------------------------------------ svn:mergeinfo =