source: trunk/gli/src/org/greenstone/gatherer/util/StatusHTML.java@ 6195

Last change on this file since 6195 was 6195, checked in by jmt12, 20 years ago

No longer encodes < and > as this was stuffing up html marked-up comments

  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
1package org.greenstone.gatherer.util;
2
3import java.io.*;
4import java.util.*;
5
6public class StatusHTML {
7
8 static final private String DARK_GREEN = "B0D0B0";
9 static final private String DARK_RED = "D0B0B0";
10 static final private String LIGHT_GREEN = "E0F0E0";
11 static final private String LIGHT_RED = "F0E0E0";
12
13 static final private String DARK_BLUE = "B0B0D0";
14 static final private String LIGHT_BLUE = "E0E0F0";
15
16 static final private String FIXED_STR = "Fixed";
17 static final private String NOTHING_STR = "Nothing";
18
19 static final private String FEATURES = " <!-- Header -->\n <TR bgcolor=\"#B0B0D0\">\n <TD colspan=\"2\"><STRONG><A name=\"23b\">GLI v2.41 - Feature Requests [FEATURE_COUNT total]</A></STRONG></TD>\n </TR>\n <TR>\n <TD bgcolor=\"#FFFFFF\" colspan=\"2\">In order received. Similar problems only mentioned once, with descriptions combined where possible.</TD>\n </TR>\n <TR>\n <TD colspan=\"2\">&#160;</TD>\n </TR>\n";
20
21 static final private String FIXED = " <!-- Header -->\n <TR bgcolor=\"#B0D0B0\">\n <TD colspan=\"2\"><STRONG><A name=\"23b\">GLI v2.41 - Closed Reports [FIXED_COUNT total]</A></STRONG></TD>\n </TR>\n <TR>\n <TD bgcolor=\"#FFFFFF\" colspan=\"2\">In order received. Similar problems only mentioned once, with descriptions combined where possible.</TD>\n </TR>\n <TR>\n <TD colspan=\"2\">&#160;</TD>\n </TR>\n";
22
23 static final private String FOOTER = " <TR><TD>&nbsp;</TD></TR>\n</TABLE>\n<TABLE bgcolor=\"#FFFFFF\" width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n <TR>\n <TD align=\"center\">Written by John Thompson. Any comments, bug reports email <A href=\"mailto:[email protected]\">here</A>.</TD>\n </TR>\n</TABLE>\n</BODY>\n</HTML>";
24 static final private String HEADER = "<HTML>\n<HEAD>\n<TITLE>GLI Project Status</TITLE>\n</HEAD>\n<BODY bgcolor=\"#CCCCCC\">\n<TABLE bgcolor=\"#FFFFFF\" width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n <!-- Header -->\n <TR bgcolor=\"#B0D0B0\">\n <TD align=\"center\" colspan=\"7\"><FONT size=\"4\"><STRONG>Greenstone Librarian Interface (GLI) version 2.41</STRONG></FONT></TD>\n </TR>\n <TR>\n <TD colspan=\"7\">This page lists the features planned for the Greenstone Librarian Interface in its next release. It also details the various bugs that have been found and reported in this version of the GLI.</TD>\n </TR>\n</TABLE>\n<BR/>\n<TABLE border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">\n";
25
26 static final private String PENDING = " <TR><TD bgcolor=\"#CCCCCC\">&nbsp;</TD></TR>\n <!-- Header -->\n <TR bgcolor=\"#D0B0B0\">\n <TD colspan=\"2\"><STRONG><A name=\"23b\">GLI v2.41 - Current Reports [PENDING_COUNT total]</A></STRONG></TD>\n </TR>\n <TR>\n <TD bgcolor=\"#FFFFFF\" colspan=\"2\">In order received. Similar problems only mentioned once, with descriptions combined where possible.</TD>\n </TR>\n <TR>\n <TD colspan=\"2\">&#160;</TD>\n </TR>\n";
27
28 static final private String[] PREFIX = { " <TR><TD bgcolor=\"#DARK_COLOR\" valign=\"top\">ID#</TD> <TD bgcolor=\"#DARK_COLOR\">"," <TR><TD bgcolor=\"#DARK_COLOR\" valign=\"top\">Description</TD> <TD bgcolor=\"#LIGHT_COLOR\">"," <TR><TD bgcolor=\"#DARK_COLOR\" valign=\"top\">Reported By</TD> <TD bgcolor=\"#FFFFFF\">"," <TR><TD bgcolor=\"#DARK_COLOR\" valign=\"top\">Platform</TD> <TD bgcolor=\"#FFFFFF\">"," <TR><TD bgcolor=\"#DARK_COLOR\" valign=\"top\">Test Item#</TD> <TD bgcolor=\"#FFFFFF\">"," <TR><TD bgcolor=\"#DARK_COLOR\" valign=\"top\">Status</TD> <TD bgcolor=\"#FFFFFF\">"," <TR><TD bgcolor=\"#DARK_COLOR\" valign=\"top\">Proposed Solution</TD><TD bgcolor=\"#FFFFFF\">"," <TR><TD bgcolor=\"#DARK_COLOR\" valign=\"top\">Solution</TD><TD bgcolor=\"#FFFFFF\">", " <TR><TD bgcolor=\"#CCCCCC\">&nbsp;"};
29
30 static final private String SUFFIX = "</TD></TR>\n";
31
32 static public void main(String[] args) {
33 File in_file = null;
34 File out_file = null;
35 if(args.length == 2) {
36 in_file = new File(args[0]);
37 if(!in_file.exists()) {
38 System.out.println("Can't find source file: " + in_file.getAbsolutePath());
39 in_file = null;
40 }
41 out_file = new File(args[1]);
42 }
43 if(in_file != null && out_file != null) {
44 new StatusHTML(in_file, out_file);
45 }
46 else {
47 System.out.println("Usage: java org.greenstone.gatherer.util.StatusHTML <input_file> <output_file>");
48 }
49 }
50
51 public StatusHTML(File in_file, File out_file) {
52 LinkedList reports = new LinkedList();
53 try {
54 int feature_count = 0;
55 int fixed_count = 0;
56 int pending_count = 0;
57 BufferedReader in = new BufferedReader(new FileReader(in_file));
58 // Read in the entire file, building report objects.
59 String line = null;
60 while((line = in.readLine()) != null) {
61 // We may of course end up with several nulls, but thats hardly our fault.
62 Report report = new Report(line, in.readLine(), in.readLine(), in.readLine(), in.readLine(), in.readLine(), in.readLine());
63 if(report.isFixed()) {
64 fixed_count++;
65 }
66 else if (report.isFeatureRequest()) {
67 feature_count++;
68 }
69 else {
70 pending_count++;
71 }
72 reports.add(report);
73 report = null;
74 // Throw away a line
75 in.readLine();
76 }
77 in.close();
78 in = null;
79
80 // Create and start writing the output file
81 FileOutputStream out = new FileOutputStream(out_file);
82 out.write(HEADER.getBytes());
83
84 // Write out all the pending jobs
85 out.write((PENDING.replaceAll("PENDING_COUNT", String.valueOf(pending_count))).getBytes());
86
87 // Write out the bugs
88 for (int i = 0; i < reports.size(); i++) {
89 Report report = (Report) reports.get(i);
90 if (!report.isFixed() && !report.isFeatureRequest()) {
91 out.write(report.getBytes(DARK_RED, LIGHT_RED));
92 }
93 }
94
95 // Write out all the feature requests
96 out.write((FEATURES.replaceAll("FEATURE_COUNT", String.valueOf(feature_count))).getBytes());
97
98 // Write out the feature requests
99 for (int i = 0; i < reports.size(); i++) {
100 Report report = (Report) reports.get(i);
101 if (!report.isFixed() && report.isFeatureRequest()) {
102 out.write(report.getBytes(DARK_BLUE, LIGHT_BLUE));
103 }
104 report = null;
105 }
106
107 // Write out everything else
108 out.write((FIXED.replaceAll("FIXED_COUNT", String.valueOf(fixed_count))).getBytes());
109 for(int i = 0; i < reports.size(); i++) {
110 Report report = (Report) reports.get(i);
111 if(report.isFixed()) {
112 out.write(report.getBytes(DARK_GREEN, LIGHT_GREEN));
113 }
114 report = null;
115 }
116
117 // Write the footer and close the file
118 out.write(FOOTER.getBytes());
119 out.close();
120 out = null;
121 }
122 catch(Exception error) {
123 error.printStackTrace();
124 }
125 }
126
127 private class Report {
128 public String bug_id;
129 public String description;
130 public String platform;
131 public String reported_by;
132 public String status;
133 public String solution;
134 public String test_item;
135
136 public Report(String bug_id, String description, String reported_by, String platform, String test_item, String status, String solution) {
137 if(bug_id != null) this.bug_id = bug_id; //.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
138 if(description != null) this.description = description; //.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
139 if(platform != null) this.platform = platform; //.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
140 if(reported_by != null) this.reported_by = reported_by; //.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
141 if(solution != null) this.solution = solution; //.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
142 if(status != null) this.status = status; // status.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
143 if(test_item != null) this.test_item = test_item; // test_item.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
144 }
145
146 public boolean isFixed() {
147 return (status != null && (status.startsWith(FIXED_STR) || status.startsWith(NOTHING_STR)));
148 }
149
150 public boolean isFeatureRequest() {
151 return (bug_id.indexOf("F") != -1);
152 }
153
154 public byte[] getBytes(String dark_color, String light_color) {
155 StringBuffer text_buffer = new StringBuffer();
156 text_buffer.append(PREFIX[0]);
157 text_buffer.append(bug_id);
158 text_buffer.append(SUFFIX);
159 text_buffer.append(PREFIX[1]);
160 text_buffer.append(description);
161 text_buffer.append(SUFFIX);
162 text_buffer.append(PREFIX[2]);
163 text_buffer.append(reported_by);
164 text_buffer.append(SUFFIX);
165 text_buffer.append(PREFIX[3]);
166 text_buffer.append(platform);
167 text_buffer.append(SUFFIX);
168 text_buffer.append(PREFIX[4]);
169 text_buffer.append(test_item);
170 text_buffer.append(SUFFIX);
171 text_buffer.append(PREFIX[5]);
172 text_buffer.append(status);
173 text_buffer.append(SUFFIX);
174 if(isFixed()) {
175 text_buffer.append(PREFIX[6]);
176 }
177 else {
178 text_buffer.append(PREFIX[7]);
179 }
180 text_buffer.append(solution);
181 text_buffer.append(SUFFIX);
182 text_buffer.append(PREFIX[8]);
183 text_buffer.append(SUFFIX);
184 text_buffer.append("\n");
185 String text = text_buffer.toString();
186 text = text.replaceAll("DARK_COLOR", dark_color);
187 text = text.replaceAll("LIGHT_COLOR", light_color);
188 return text.getBytes();
189 }
190 }
191}
Note: See TracBrowser for help on using the repository browser.