View Javadoc

1   /*
2       Jameleon - An automation testing tool..
3       Copyright (C) 2007 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.reporting;
20  
21  import net.sf.jameleon.exception.JameleonException;
22  import net.sf.jameleon.util.Configurator;
23  import net.sf.jameleon.util.JameleonDefaultValues;
24  import net.sf.jameleon.util.JameleonUtility;
25  import net.sf.jameleon.util.TemplateProcessor;
26  
27  import java.io.File;
28  import java.io.IOException;
29  import java.io.Writer;
30  import java.text.SimpleDateFormat;
31  import java.util.Calendar;
32  import java.util.Map;
33  
34  /***
35   * A utility class for the reporting package
36   */
37  public class ReporterUtils {
38      private static final SimpleDateFormat shortFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
39  
40      private ReporterUtils(){}
41  
42      public static String getExecutionTime(Calendar startTime, Calendar endTime){
43          return JameleonUtility.executionTimeToString(endTime.getTimeInMillis() - startTime.getTimeInMillis());
44      }
45  
46      public static String formatTime(Calendar time){
47          return shortFormat.format(time.getTime());
48      }
49  
50      public static void outputToTemplate(Writer writer, String template, Map params){
51          try {
52              TemplateProcessor processor = new TemplateProcessor(template);
53              writer.write(processor.transformToString(params));
54              writer.flush();
55          } catch (IOException e) {
56              throw new JameleonException("Could not write results to main HTML results file: "+e.getMessage());
57          }
58      }
59  
60      public static File getBaseDir(){
61          return new File(Configurator.getInstance().getValue("baseDir", JameleonDefaultValues.BASE_DIR.getPath()));
62      }
63  
64      public static File getResultsDir(){
65          return new File(getBaseDir(), Configurator.getInstance().getValue("resultsDir", JameleonDefaultValues.RESULTS_DIR));
66  
67      }
68      
69  }