1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }