1 package jodd.file.filters; 2 3 import java.io.File; 4 import java.io.FileFilter; 5 import java.util.regex.Matcher; 6 import java.util.regex.Pattern; 7 8 import jodd.util.StringFlags; 9 import jodd.util.StringUtil; 10 11 27 abstract class FileFilterAbs implements FileFilter { 28 29 31 42 public FileFilterAbs(String pattern, String opt) { 43 flags.parse(opt, this); 44 setPattern(pattern); 45 } 46 47 52 public FileFilterAbs(String pattern) { 53 setPattern(pattern); 54 } 55 56 60 public FileFilterAbs() { 61 } 62 63 64 66 private static StringFlags flags = new StringFlags(); 67 68 static { 69 flags.addFlag('p', "matchPath", true); 70 flags.addFlag('d', "skipDirs", true); 71 } 72 73 boolean matchPath; 74 79 public void setMatchPath(boolean v) { 80 matchPath = v; 81 } 82 87 public boolean getMatchPath() { 88 return matchPath; 89 } 90 91 92 boolean skipDirs; 93 98 public void setSkipDirs(boolean v) { 99 skipDirs = v; 100 } 101 106 public boolean getSkipDirs() { 107 return skipDirs; 108 } 109 110 111 String pattern; 112 117 public void setPattern(String p) { 118 pattern = p; 119 } 120 125 public String getPattern() { 126 return pattern; 127 } 128 129 131 static boolean isUnix = false; 132 static { 133 if (File.separatorChar == '/') { 134 isUnix = true; 135 } else { 136 isUnix = false; 137 } 138 } 139 140 147 public boolean accept(File f) { 148 if (f.isDirectory()) { if (skipDirs == true) { return true; 151 } 152 } 153 if (pattern == null) { return true; } 156 157 return match(f); 158 } 159 160 161 171 String getFileName(File f) { 172 String fileName = null; 173 if (matchPath == false) { 174 fileName = f.getName(); } else { 176 fileName = f.getPath(); if (isUnix == false) { 178 fileName = StringUtil.replace(fileName, File.separatorChar, '/'); 179 } 180 } 181 return fileName; 182 } 183 184 192 abstract boolean match(File file); 193 } 194 | Popular Tags |