1 6 7 package com.sun.japex.report; 8 import java.util.Date ; 9 import java.text.DateFormat ; 10 import java.text.ParseException ; 11 import java.text.SimpleDateFormat ; 12 import java.util.Calendar ; 13 import java.util.GregorianCalendar ; 14 import java.util.ArrayList ; 15 16 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 _title; 43 String _reportPath; 44 String _outputPath; 45 Date _from; 46 Date _to; 47 String _driver; 48 boolean _isDriverSpecified = false; 49 String [] _test; 50 boolean _isTestSpecified = false; 51 52 53 public TrendReportParams(String [] 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 testcases = new ArrayList (); 66 for (int i=ARGS_TESTCASE; i<args.length; i++) { 67 testcases.add((String )args[i]); 68 } 69 _test = new String [(testcases.size())]; 70 testcases.toArray(_test); 71 _isTestSpecified = true; 73 } 74 } catch (Exception e) { 75 e.printStackTrace(); 76 77 } 78 } 79 80 public String title() { 81 return _title; 82 } 83 public String reportPath() { 84 return _reportPath; 85 } 86 public String outputPath() { 87 return _outputPath; 88 } 89 public Date dateFrom() { 90 return _from; 91 } 92 public Date dateTo() { 93 return _to; 94 } 95 public String driver() { 96 return _driver; 97 } 98 public boolean isDriverSpecified() { 99 return _isDriverSpecified; 100 } 101 public String [] test() { 102 return _test; 103 } 104 public boolean isTestSpecified() { 105 return _isTestSpecified; 106 } 107 108 void parseDates(String date, String offset) { 109 try { 110 Date date1 = null; 111 112 if (date.toUpperCase().equals("TODAY")) { 113 date1 = new Date (); 114 } else { 115 DateFormat df= new SimpleDateFormat ("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 cal = Calendar.getInstance(); 122 cal.setTime(date1); 123 124 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 e) { 152 e.printStackTrace(); 153 } 154 } 155 } 156 | Popular Tags |