1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.data;
20
21 import net.sf.jameleon.util.JameleonDefaultValues;
22
23 import java.io.File;
24
25 /***
26 * This DataDrivable implementation is for file based data sources.
27 */
28 public abstract class AbstractFileDrivableTag extends AbstractDataDrivableTag {
29
30 protected File dataDir = JameleonDefaultValues.DATA_DIR;
31 protected String charset;
32 protected String fileName;
33
34 /***
35 * Sets the character set to use to read the data file in.
36 * @param charset the character set to use to read the data file in.
37 * @jameleon.attribute
38 */
39 public void setCharset(String charset){
40 this.charset = charset;
41 }
42
43 /***
44 * Sets the directory of where the data will be looked for.
45 * The baseDir is then prepended on this
46 * @param dataDir the directory of where the data will be looked for.
47 * @jameleon.attribute
48 */
49 public void setDataDir(File dataDir){
50 this.dataDir = dataDir;
51 }
52
53 /***
54 * Sets the name of the file to use as a data source.
55 * @param fileName the name of the file to use as a data source.
56 * @jameleon.attribute
57 */
58 public void setFile(String fileName){
59 this.fileName = fileName;
60 }
61
62 /***
63 * Gets the directory of where the data will be looked for.
64 * @return the directory of where the data will be looked for.
65 */
66 public File getDataDir(){
67 String testEnvironment = tct.getTestEnvironment();
68 String organization = tct.getOrganization();
69 String filename = tct.getBaseDir().getPath() + File.separator + dataDir.getPath() + File.separator;
70 if (testEnvironment != null && testEnvironment.length() > 0){
71 filename += testEnvironment + File.separator;
72 }
73 if (organization != null && organization.length() > 0 ) {
74 filename += organization + File.separator;
75 }
76 return new File(filename);
77 }
78
79 /***
80 * Gets the directory of where the data will be looked for.
81 * @param calculate - if set to false, then the plain old dataDir is return. otherwise
82 * a calculation is done to add baseDir and testEnvironment and organization.
83 * @return the directory of where the data will be looked for.
84 */
85 public File getDataDir(boolean calculate){
86 File f = dataDir;
87 if (calculate) {
88 f = getDataDir();
89 }
90 return f;
91 }
92 }