1 10 11 package org.mule.providers.file.filters; 12 13 import java.util.regex.Matcher ; 14 import java.util.regex.Pattern ; 15 16 public class FilenameRegexFilter extends FilenameWildcardFilter 17 { 18 protected Pattern [] compiledPatterns = null; 19 20 public boolean accept(Object object) 22 { 23 if (object == null) 24 { 25 return false; 26 } 27 28 boolean foundMatch = false; 29 30 if (compiledPatterns != null) 31 { 32 for (int i = 0; i < compiledPatterns.length; i++) 33 { 34 Pattern pattern = compiledPatterns[i]; 35 String string = object.toString(); 36 37 38 Matcher matcher = pattern.matcher(string); 39 foundMatch = matcher.matches(); 40 41 if (foundMatch) 42 { 43 break; 45 } 46 } 47 } 48 49 return foundMatch; 50 } 51 52 public void setCaseSensitive(boolean caseSensitive) 54 { 55 super.setCaseSensitive(caseSensitive); 56 this.setPattern(pattern); 57 } 58 59 public void setPattern(String pattern) 61 { 62 super.setPattern(pattern); 63 64 if (patterns != null) 65 { 66 compiledPatterns = new Pattern [patterns.length]; 67 68 for (int i = 0; i < patterns.length; i++) 69 { 70 if (!isCaseSensitive()) 71 { 72 73 compiledPatterns[i] = Pattern.compile(patterns[i], Pattern.CASE_INSENSITIVE); 74 } 75 else 76 { 77 compiledPatterns[i] = Pattern.compile(patterns[i]); 78 } 79 } 80 } 81 } 82 83 } 84 | Popular Tags |