Author: davsclaus
Date: Sun Jan 8 16:52:24 2012
New Revision: 1228892
URL: http://svn.apache.org/viewvc?rev=1228892&view=rev
Log:
CAMEL-4779: Applied 2nd patch. Thanks to Daniel. Added antInclude and
antExclude options to file component to make using Ant path styles easier.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/AntPathMatcherFileFilter.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilter.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
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/AntPathMatcherFileFilter.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/AntPathMatcherFileFilter.java?rev=1228892&r1=1228891&r2=1228892&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/AntPathMatcherFileFilter.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/AntPathMatcherFileFilter.java
Sun Jan 8 16:52:24 2012
@@ -72,7 +72,12 @@ public class AntPathMatcherFileFilter im
}
}
- // nothing to include so we cant accept it
+ if (excludes != null && includes == null) {
+ // if the user specified excludes but no includes, presumably we
should include by default
+ return true;
+ }
+
+ // nothing to include so we can't accept it
return false;
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilter.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilter.java?rev=1228892&r1=1228891&r2=1228892&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilter.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/AntPathMatcherGenericFileFilter.java
Sun Jan 8 16:52:24 2012
@@ -16,104 +16,57 @@
*/
package org.apache.camel.component.file;
-import java.lang.reflect.Method;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.CamelContextAware;
-import org.apache.camel.util.ObjectHelper;
-import static
org.apache.camel.util.CollectionHelper.collectionAsCommaDelimitedString;
-
/**
- * File filter using Spring's AntPathMatcher.
+ * File filter using AntPathMatcher.
* <p/>
* Exclude take precedence over includes. If a file match both exclude and
include it will be regarded as excluded.
* @param <T>
*/
-public class AntPathMatcherGenericFileFilter<T> implements
GenericFileFilter<T>, CamelContextAware {
- private static final String ANTPATHMATCHER_CLASSNAME =
"org.apache.camel.spring.util.SpringAntPathMatcherFileFilter";
+public class AntPathMatcherGenericFileFilter<T> implements
GenericFileFilter<T> {
- private CamelContext context;
+ private final AntPathMatcherFileFilter filter;
- private String[] excludes;
- private String[] includes;
+ public AntPathMatcherGenericFileFilter() {
+ filter = new AntPathMatcherFileFilter();
+ }
- private Object filter;
- private Method includesMethod;
- private Method excludesMethod;
- private Method acceptsMethod;
+ public AntPathMatcherGenericFileFilter(String... includes) {
+ filter = new AntPathMatcherFileFilter();
+ filter.setIncludes(includes);
+ }
public boolean accept(GenericFile<T> file) {
- try {
- synchronized (this) {
- if (filter == null) {
- init();
- }
- }
-
- // invoke setIncludes(String), must using string type as invoking
with string[] does not work
- ObjectHelper.invokeMethod(includesMethod, filter,
collectionAsCommaDelimitedString(includes));
-
- // invoke setExcludes(String), must using string type as invoking
with string[] does not work
- ObjectHelper.invokeMethod(excludesMethod, filter,
collectionAsCommaDelimitedString(excludes));
-
- // invoke acceptPathName(String)
- String path = file.getRelativeFilePath();
- return (Boolean) ObjectHelper.invokeMethod(acceptsMethod, filter,
path);
-
- } catch (NoSuchMethodException e) {
- throw new TypeNotPresentException(ANTPATHMATCHER_CLASSNAME, e);
- }
- }
-
- private void init() throws NoSuchMethodException {
- // we must use reflection to invoke the AntPathMatcherFileFilter that
reside in camel-spring.jar
- // and we don't want camel-core to have runtime dependency on
camel-spring.jar
- // use class resolver from CamelContext to ensure it works with OSGi
as well
- Class<?> clazz =
context.getClassResolver().resolveClass(ANTPATHMATCHER_CLASSNAME);
- ObjectHelper.notNull(clazz, ANTPATHMATCHER_CLASSNAME + " not found in
classpath. camel-spring.jar is required in the classpath.");
-
- filter = ObjectHelper.newInstance(clazz);
-
- includesMethod = filter.getClass().getMethod("setIncludes",
String.class);
- excludesMethod = filter.getClass().getMethod("setExcludes",
String.class);
- acceptsMethod = filter.getClass().getMethod("acceptPathName",
String.class);
+ String path = file.getRelativeFilePath();
+ return filter.acceptPathName(path);
}
public String[] getExcludes() {
- return excludes;
+ return filter.getExcludes();
}
public void setExcludes(String[] excludes) {
- this.excludes = excludes;
+ filter.setExcludes(excludes);
}
public String[] getIncludes() {
- return includes;
+ return filter.getIncludes();
}
public void setIncludes(String[] includes) {
- this.includes = includes;
+ filter.setIncludes(includes);
}
/**
* Sets excludes using a single string where each element can be separated
with comma
*/
public void setExcludes(String excludes) {
- setExcludes(excludes.split(","));
+ filter.setExcludes(excludes);
}
/**
* Sets includes using a single string where each element can be separated
with comma
*/
public void setIncludes(String includes) {
- setIncludes(includes.split(","));
- }
-
- public void setCamelContext(CamelContext camelContext) {
- this.context = camelContext;
- }
-
- public CamelContext getCamelContext() {
- return context;
+ filter.setIncludes(includes);
}
}
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=1228892&r1=1228891&r2=1228892&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
Sun Jan 8 16:52:24 2012
@@ -455,6 +455,12 @@ public abstract class GenericFileConsume
}
}
+ if (endpoint.getAntFilter() != null) {
+ if (!endpoint.getAntFilter().accept(file)) {
+ return false;
+ }
+ }
+
if (ObjectHelper.isNotEmpty(endpoint.getExclude())) {
if (name.matches(endpoint.getExclude())) {
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=1228892&r1=1228891&r2=1228892&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
Sun Jan 8 16:52:24 2012
@@ -86,6 +86,7 @@ public abstract class GenericFileEndpoin
protected Boolean idempotent;
protected IdempotentRepository<String> idempotentRepository;
protected GenericFileFilter<T> filter;
+ protected AntPathMatcherGenericFileFilter<T> antFilter;
protected Comparator<GenericFile<T>> sorter;
protected Comparator<Exchange> sortBy;
protected String readLock = "none";
@@ -255,6 +256,24 @@ public abstract class GenericFileEndpoin
this.exclude = exclude;
}
+ public void setAntInclude(String antInclude) {
+ if (this.antFilter == null) {
+ this.antFilter = new AntPathMatcherGenericFileFilter<T>();
+ }
+ this.antFilter.setIncludes(antInclude);
+ }
+
+ public void setAntExclude(String antExclude) {
+ if (this.antFilter == null) {
+ this.antFilter = new AntPathMatcherGenericFileFilter<T>();
+ }
+ this.antFilter.setExcludes(antExclude);
+ }
+
+ public GenericFileFilter<T> getAntFilter() {
+ return antFilter;
+ }
+
public boolean isDelete() {
return delete;
}