1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.addam.ddlrun.utils;
20
21 import java.io.File;
22
23
24 /**
25 * Used to retrieve a FileSystemReader.
26 *
27 * @author TIM3
28 * @since Mar 5, 2005
29 */
30 public class FileSystemReaderFactory implements ResourceReaderFactory {
31
32 /**
33 * Constructs a FileSystemReaderFactory with a base path of CWD
34 */
35 public FileSystemReaderFactory() {
36 basePath = new File(".");
37 }
38
39 /**
40 * Constructs a FileSystemReaderFactory the provided base path
41 *
42 * @param basePath the path to prepend to relative paths passed to getReader
43 */
44 public FileSystemReaderFactory(String basePath) {
45 this(new File(basePath));
46 }
47
48 /**
49 * Constructs a FileSystemReaderFactory the provided base path
50 *
51 * @param basePath the path to prepend to relative paths passed to getReader
52 */
53 public FileSystemReaderFactory(File basePath) {
54 this.basePath = basePath;
55 }
56
57 public ResourceReader getReader(String resource) {
58 return this.getReader(".", resource);
59 }
60
61 public ResourceReader getReader(String path, String resource) {
62 File dirToUse = (path == null) ? basePath : new File(basePath, path);
63 File fileToRead = new File(dirToUse, resource);
64 return new FileSystemReader(fileToRead);
65 }
66
67 private final File basePath;
68 static private final String SEPARATOR = System.getProperty("file.separator");
69 }