View Javadoc

1   /*
2    * $Id: FilenameWildcardFilter.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
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 FilenameFilter
25  {
26  
27      public FilenameWildcardFilter()
28      {
29          super();
30      }
31  
32      public FilenameWildcardFilter(String pattern)
33      {
34          super(pattern);
35      }
36  
37      /**
38       * Filter condition decider method. <p/> Returns
39       * <code>boolean</code> <code>TRUE</code> if the file conforms to an
40       * acceptable pattern or <code>FALSE</code> otherwise.
41       * 
42       * @param dir The directory to apply the filter to.
43       * @param name The name of the file to apply the filter to.
44       * @return indication of acceptance as boolean.
45       */
46      public boolean accept(File dir, String name)
47      {
48          if (name == null)
49          {
50              logger.warn("The filename and/or directory was null");
51              return false;
52          }
53          else
54          {
55              return accept(name);
56          }
57      }
58  
59      public boolean accept(MuleMessage message)
60      {
61          // TODO revisit, shouldn't it be looking in the inbound scope?
62          Object filename = message.getOutboundProperty(FileConnector.PROPERTY_ORIGINAL_FILENAME);
63          return accept(filename);
64      }
65  
66  }