1 6 7 package com.sun.japex.report; 8 9 import java.io.File ; 10 import java.io.FileInputStream ; 11 import java.io.DataInputStream ; 12 import java.io.FileOutputStream ; 13 import java.io.OutputStreamWriter ; 14 15 16 public class IndexPage { 17 static final String REPORT_NEWROW = "<!--{new row}-->"; 18 19 TrendReportParams _params; 20 String _chartName; 21 22 public IndexPage(TrendReportParams params, String chartName) { 23 _params = params; 24 _chartName = chartName; 25 } 26 27 public void report() { 28 try { 29 String filename = _params.outputPath()+"/index.html"; 31 File file = new File (filename); 32 String content = reportContent(file); 33 OutputStreamWriter osr = new OutputStreamWriter (new FileOutputStream (file)); 34 osr.write(content); 35 osr.close(); 36 } catch (Exception e) { 37 e.printStackTrace(); 38 } 39 } 40 public String reportContent(File file) { 41 StringBuffer content = new StringBuffer (); 42 if (file.exists()) { 43 content.append(readFromFile(file)); 44 } else { 45 content.append(getTemplate()); 46 } 47 48 int start = 0; 49 int end = 0; 50 StringBuffer newrow = new StringBuffer (); 51 newrow.append("<table width=\"100%\" border=\"0\">"); 52 newrow.append("<tr><th width=\"50%\"><h2>"+_params.title()); 53 newrow.append("</h2></th><th align=\"right\"><a HREF=\"#top\">Top</a></th></tr>"); 54 newrow.append("</table>"); 55 newrow.append("<ul>\n<li>Report Path: " + _params.reportPath() + "</li>\n"); 56 newrow.append("<li>Oupput Path: " + _params.outputPath() + "</li>\n"); 57 newrow.append("<li>Report Period: " + _params.dateFrom() + " - " + _params.dateTo() + "</li>\n"); 58 if (_params.isDriverSpecified()) { 59 newrow.append("<li>Driver: " + _params.driver() + "</li>\n"); 60 } else { 61 newrow.append("<li>Driver: not specified</li>\n"); 62 } 63 newrow.append("<li>Testcase(s): "); 64 if (_params.isTestSpecified()) { 65 for(int i=0; i<_params.test().length; i++) { 66 newrow.append(_params.test()[i]+" "); 67 } 68 } else { 69 newrow.append("not specified"); 70 } 71 newrow.append("</li>\n</ul>\n"); 72 newrow.append("<table width=\"80%\" border=\"0\">"); 73 newrow.append("<tr><td colspan=\"2\" align=\"center\"><img SRC=\""+_chartName+"\"></td></tr>"); 74 newrow.append("</table>"); 75 newrow.append(REPORT_NEWROW+"\n"); 76 77 start = content.indexOf(REPORT_NEWROW); 78 end = start + REPORT_NEWROW.length(); 79 content.replace(start, end, newrow.toString()); 80 return content.toString(); 81 } 82 83 private String readFromFile(File file) { 84 StringBuffer sb = new StringBuffer (); 85 try 86 { 87 FileInputStream fstream = new FileInputStream (file); 88 89 DataInputStream in = new DataInputStream (fstream); 92 93 while (in.available() !=0) 94 { 95 sb.append(in.readLine()); 96 } 97 98 in.close(); 99 } 100 catch (Exception e) 101 { 102 e.printStackTrace(); 103 } 104 return sb.toString(); 105 } 106 107 private String getTemplate() { 108 StringBuffer template = new StringBuffer (); 109 template.append("<html>\n<link HREF=\"report.css\" type=\"text/css\" rel=\"stylesheet\"/>\n"); 110 template.append("<head><title>Japex Trend Report</title></head>\n<body>\n"); 111 template.append("<a name=\"top\"><h1>Japex Trend Report</h1>\n"); 112 template.append(REPORT_NEWROW); 113 template.append("<small><hr/><i><font size=\"-2\"><!--datetime--></font></i></small>\n"); 114 template.append("</body>\n</html>"); 115 return template.toString(); 116 } 117 118 } 119 | Popular Tags |