View Javadoc

1   /*
2       Jameleon - An automation testing tool..
3       Copyright (C) 2003 Christian W. Hargraves (engrean@hotmail.com)
4       
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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  }