View Javadoc

1   package org.apache.torque.util;
2   
3   import java.io.File;
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   import org.codehaus.plexus.util.DirectoryScanner;
8   
9   /**
10   * This class provides a simple method for scanning a directory for files that match include/exclude patterns
11   */
12  public class SimpleScanner extends DirectoryScanner {
13  	private static final String FS = System.getProperty("file.separator");
14  
15  	public SimpleScanner() {
16  		this(null, null, null);
17  	}
18  
19  	public SimpleScanner(File baseDir, String include, String exclude) {
20  		super();
21  		if (baseDir != null) {
22  			setBasedir(baseDir);
23  		}
24  		if (include != null) {
25  			setIncludes(new String[] { include });
26  		}
27  		if (exclude != null) {
28  			setExcludes(new String[] { exclude });
29  		}
30  	}
31  
32  	/**
33  	 * This method returns files that match an include pattern but do not match an exclude pattern
34  	 */
35  	public List<File> getFiles() {
36  		scan();
37  		String[] includedFiles = getIncludedFiles();
38  		List<File> files = new ArrayList<File>();
39  		for (String includedFile : includedFiles) {
40  			String filename = getBasedir().getAbsolutePath() + FS + includedFile;
41  			File file = new File(filename);
42  			files.add(file);
43  		}
44  		return files;
45  	}
46  }