KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > japex > report > TrendReportParams


1 /*
2  * TrendReportParams.java
3  *
4  * Created on April 8, 2005, 3:59 PM
5  */

6
7 package com.sun.japex.report;
8 import java.util.Date JavaDoc;
9 import java.text.DateFormat JavaDoc;
10 import java.text.ParseException JavaDoc;
11 import java.text.SimpleDateFormat JavaDoc;
12 import java.util.Calendar JavaDoc;
13 import java.util.GregorianCalendar JavaDoc;
14 import java.util.ArrayList JavaDoc;
15
16 /*
17  *TrendReport title reportPath outputPath date offset [driver] [test]
18     where parameters are the same as the first format except:
19     title -- name of the chart to be generated
20     reportPath -- path to where the report directory is
21     outputPath -- path where the html report will be saved. If
22     date -- a specific date in format "yyyy-MM-dd", including "Today",
23             from or to which a trend report shall be made
24     offset -- days, weeks, months or years from/to the above date a trend report will be created.
25             Supports format: xD where x is a positive or negative integer, and D indicates Days
26             Similarily, xW, xM and xY are also support where W=Week, M=Month, and Y=Year
27     driver -- name of a driver for which a trend report is to be generated. All drivers if not specified.
28     test(s) -- specific test(s) in a driver for which a trend report will be created.
29             Return means if no tests specified.
30   
31 */

32
33 public class TrendReportParams {
34     static final int ARGS_TITLE = 0;
35     static final int ARGS_PATH = 1;
36     static final int ARGS_OUTPUTPATH = 2;
37     static final int ARGS_DATE = 3;
38     static final int ARGS_OFFSET = 4;
39     static final int ARGS_DRIVER = 5;
40     static final int ARGS_TESTCASE = 6;
41     
42     String JavaDoc _title;
43     String JavaDoc _reportPath;
44     String JavaDoc _outputPath;
45     Date JavaDoc _from;
46     Date JavaDoc _to;
47     String JavaDoc _driver;
48     boolean _isDriverSpecified = false;
49     String JavaDoc[] _test;
50     boolean _isTestSpecified = false;
51     
52     /** Creates a new instance of TrendReportParams */
53     public TrendReportParams(String JavaDoc[] args) {
54         _title = args[ARGS_TITLE];
55         _reportPath = args[ARGS_PATH];
56         _outputPath = args[ARGS_OUTPUTPATH];
57         parseDates(args[ARGS_DATE], args[ARGS_OFFSET]);
58                 
59         try {
60             if (args.length > ARGS_DRIVER) {
61                 _driver = args[ARGS_DRIVER];
62                 _isDriverSpecified = true;
63             }
64             if (args.length > ARGS_TESTCASE) {
65                 ArrayList JavaDoc testcases = new ArrayList JavaDoc();
66                 for (int i=ARGS_TESTCASE; i<args.length; i++) {
67                     testcases.add((String JavaDoc)args[i]);
68                 }
69                 _test = new String JavaDoc[(testcases.size())];
70                 testcases.toArray(_test);
71                 //_test = (String[])testcases.toArray();
72
_isTestSpecified = true;
73             }
74         } catch (Exception JavaDoc e) {
75             e.printStackTrace();
76             
77         }
78     }
79     
80     public String JavaDoc title() {
81         return _title;
82     }
83     public String JavaDoc reportPath() {
84         return _reportPath;
85     }
86     public String JavaDoc outputPath() {
87         return _outputPath;
88     }
89     public Date JavaDoc dateFrom() {
90         return _from;
91     }
92     public Date JavaDoc dateTo() {
93         return _to;
94     }
95     public String JavaDoc driver() {
96         return _driver;
97     }
98     public boolean isDriverSpecified() {
99         return _isDriverSpecified;
100     }
101     public String JavaDoc[] test() {
102         return _test;
103     }
104     public boolean isTestSpecified() {
105         return _isTestSpecified;
106     }
107     
108     void parseDates(String JavaDoc date, String JavaDoc offset) {
109         try {
110             Date JavaDoc date1 = null;
111             
112             if (date.toUpperCase().equals("TODAY")) {
113                 date1 = new Date JavaDoc();
114             } else {
115                 DateFormat JavaDoc df= new SimpleDateFormat JavaDoc ("yyyy-MM-dd");
116                 date1 = df.parse(date);
117             }
118             
119             int n = Integer.parseInt(offset.substring(0, offset.length()-1));
120             char c = offset.toUpperCase().charAt(offset.length()-1);
121             Calendar JavaDoc cal = Calendar.getInstance();
122             cal.setTime(date1);
123             
124             //GregorianCalendar cal = new GregorianCalendar();
125
//cal.setTime(new Date());
126

127             switch (c) {
128                 case 68:
129                     cal.add(Calendar.DATE, n);
130                     break;
131                 case 87:
132                     cal.add(Calendar.WEEK_OF_YEAR, n);
133                     break;
134                 case 77:
135                     cal.add(Calendar.MONTH, n);
136                     break;
137                 case 89:
138                     cal.add(Calendar.YEAR, n);
139             }
140             
141             if (n > 0) {
142                 _from = date1;
143                 _to = cal.getTime();
144             } else {
145                 _from = cal.getTime();
146                 _to = date1;
147                 cal.setTime(_to);
148                 cal.add(Calendar.DATE, 1);
149                 _to = cal.getTime();
150             }
151         } catch (Exception JavaDoc e) {
152             e.printStackTrace();
153         }
154     }
155 }
156
Popular Tags