01: /*
02: * $Id: FilenameWildcardFilter.java 10489 2008-01-23 17:53:38Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.transport.file.filters;
12:
13: import org.mule.api.MuleMessage;
14: import org.mule.routing.filters.WildcardFilter;
15: import org.mule.transport.file.FileConnector;
16:
17: import java.io.File;
18: import java.io.FilenameFilter;
19:
20: /**
21: * <code>FilenameWildcardFilter</code> filters incoming files from a directory,
22: * based on file patterns.
23: */
24: public class FilenameWildcardFilter extends WildcardFilter implements
25: FilenameFilter {
26:
27: public FilenameWildcardFilter() {
28: super ();
29: }
30:
31: public FilenameWildcardFilter(String pattern) {
32: super (pattern);
33: }
34:
35: /**
36: * Filter condition decider method. <p/> Returns
37: * <code>boolean</code> <code>TRUE</code> if the file conforms to an
38: * acceptable pattern or <code>FALSE</code> otherwise.
39: *
40: * @param dir The directory to apply the filter to.
41: * @param name The name of the file to apply the filter to.
42: * @return indication of acceptance as boolean.
43: */
44: public boolean accept(File dir, String name) {
45: if (name == null) {
46: logger.warn("The filename and/or directory was null");
47: return false;
48: } else {
49: return accept(name);
50: }
51: }
52:
53: public boolean accept(MuleMessage message) {
54: return accept(message
55: .getProperty(FileConnector.PROPERTY_ORIGINAL_FILENAME));
56: }
57:
58: }
|