Coverage Report - org.mule.transport.file.filters.FilenameRegexFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
FilenameRegexFilter
0%
0/25
0%
0/14
0
 
 1  
 /*
 2  
  * $Id: FilenameRegexFilter.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 java.util.regex.Matcher;
 14  
 import java.util.regex.Pattern;
 15  
 
 16  
 /**
 17  
  * <code>FilenameRegexFilter</code> filters incoming files from a directory, based
 18  
  * on a regular expression. If the expression evaluates to true, then the file will
 19  
  * be accepted.
 20  
  */
 21  0
 public class FilenameRegexFilter extends FilenameWildcardFilter
 22  
 {
 23  0
     protected volatile Pattern[] compiledPatterns = null;
 24  
 
 25  
     /**
 26  
      * Filter condition decider method.
 27  
      * <p>
 28  
      * Returns <code>boolean</code> <code>TRUE</code> if the file conforms to the
 29  
      * regular expression pattern or <code>FALSE</code> otherwise.
 30  
      * 
 31  
      * @return indication of acceptance as boolean.
 32  
      */
 33  
     @Override
 34  
     public boolean accept(Object object)
 35  
     {
 36  0
         if (object == null)
 37  
         {
 38  0
             return false;
 39  
         }
 40  
 
 41  0
         boolean foundMatch = false;
 42  
 
 43  0
         if (compiledPatterns != null)
 44  
         {
 45  0
             for (int i = 0; i < compiledPatterns.length; i++)
 46  
             {
 47  0
                 Pattern pattern = compiledPatterns[i];
 48  0
                 String string = object.toString();
 49  
 
 50  
                 /* Determine if there is an exact match. */
 51  0
                 Matcher matcher = pattern.matcher(string);
 52  0
                 foundMatch = matcher.matches();
 53  
 
 54  0
                 if (foundMatch)
 55  
                 {
 56  
                     // we found a match, bail
 57  0
                     break;
 58  
                 }
 59  
             }
 60  
         }
 61  
 
 62  0
         return foundMatch;
 63  
     }
 64  
 
 65  
     @Override
 66  
     public void setCaseSensitive(boolean caseSensitive)
 67  
     {
 68  0
         super.setCaseSensitive(caseSensitive);
 69  0
         this.setPattern(pattern);
 70  0
     }
 71  
 
 72  
     @Override
 73  
     public void setPattern(String pattern)
 74  
     {
 75  0
         super.setPattern(pattern);
 76  
 
 77  0
         if (patterns != null)
 78  
         {
 79  0
             compiledPatterns = new Pattern[patterns.length];
 80  
 
 81  0
             for (int i = 0; i < patterns.length; i++)
 82  
             {
 83  0
                 if (!isCaseSensitive())
 84  
                 {
 85  
                     /* Add insensitive option if set in the configuration. */
 86  0
                     compiledPatterns[i] = Pattern.compile(patterns[i], Pattern.CASE_INSENSITIVE);
 87  
                 }
 88  
                 else
 89  
                 {
 90  0
                     compiledPatterns[i] = Pattern.compile(patterns[i]);
 91  
                 }
 92  
             }
 93  
         }
 94  0
     }
 95  
 
 96  
 }