• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *****************************************************************************
3  * Copyright (C) 2000-2007, International Business Machines Corporation and  *
4  * others. All Rights Reserved.                                              *
5  *****************************************************************************
6  */
7 package com.ibm.rbm;
8 
9 import javax.swing.*;
10 import java.awt.*;
11 import java.awt.event.*;
12 import java.io.*;
13 import java.util.*;
14 
15 import org.apache.xerces.dom.DocumentImpl;
16 import org.apache.xml.serialize.*;
17 import org.w3c.dom.*;
18 
19 import com.ibm.rbm.gui.RBManagerGUI;
20 
21 /**
22  * RBReporter is a fully functional application that runs separate from RBManager.
23  * The report produces statistically based reports on specified resource bundles,
24  * and it allows the user to set time intervals at which those reports will be
25  * generated. For more information on command line arguments and usage see the
26  * comments for the main() method.
27  *
28  * @author Jared Jackson
29  * @see com.ibm.rbm.RBManager
30  */
31 public class RBReporter extends JFrame {
32 
33 	// ** COMPONENTS **
34 	JLabel       statusLabel;                       // Indicates if the reported is running
35 	JButton      statusButton;                      // Button for toggling the reporter on/off
36 	JLabel       nextReportLabel;                   // Indicates date/time of next report
37 	JLabel       lastReportLabel;                   // Indicates date/time of last report
38 	JTextField   bundleField;                       // Indicates input base class file
39 	JTextField   directoryField;                    // Indicates output directory
40 	JCheckBox    textCheck;                         // Is text report generated?
41 	JCheckBox    htmlCheck;                         // Is HTML report generated?
42 	JCheckBox    xmlCheck;                          // Is XML report generated?
43 	JCheckBox    scanCheck;                         // Is code scan performed?
44 	JTextField   textField;                         // Text report file name
45 	JTextField   htmlField;                         // HTML report file name
46 	JTextField   xmlField;                          // XML report file name
47 	JTextField   scanField;                         // XML scanner file location
48 	JComboBox    textCombo;                         // Text report detail level
49 	JComboBox    htmlCombo;                         // HTML report detail level
50 	JComboBox    xmlCombo;                          // XML report detail level
51 	JRadioButton sequentialRadio;                   // Report at sequential interval?
52 	JRadioButton definedRadio;                      // Report at defined time?
53 	JComboBox    valueCombo;                        // Number of units to wait between reports
54 	JComboBox    unitCombo;                         // Units of time
55 	JComboBox    hourCombo;                         // Defined time to report -- hours
56 	JComboBox    minuteCombo;                       // Defined time to report -- minutes
57 	JComboBox    dayCombo;                          // Defined time to report -- day
58 
59 	// ** File Chooser **
60 	JFileChooser bundleFileChooser = new JFileChooser();
61 	JFileChooser directoryFileChooser = new JFileChooser();
62 	JFileChooser scanFileChooser = new JFileChooser();
63 
64 	// ** DATA **
65 	Date lastReport = null;
66 	Date nextReport = null;
67 	boolean running = false;
68     /** For generating a report */
69     RBManager rbm;
70 
RBReporter(boolean makeVisible)71 	private RBReporter(boolean makeVisible) {
72 		try {
73 			// Get the look and feel from preferences
74 			try {
75 				String laf = Preferences.getPreference("lookandfeel");
76 				if (!laf.equals(""))
77 					UIManager.setLookAndFeel(laf);
78 			}
79 			catch (Exception e) {
80 			}
81 			// Get the locale from preferences
82 			if (!Preferences.getPreference("locale").equals("")) {
83 				String localeStr = Preferences.getPreference("locale");
84 				String language = Resources.getLanguage(localeStr);
85 				String country = Resources.getCountry(localeStr);
86 				String variant = Resources.getVariant(localeStr);
87 				if (language == null || language.equals("") || language.length() > 3) language = "en";
88 				if (country == null) country = new String();
89 				if (variant == null) Resources.setLocale(new Locale(language, country));
90 				else Resources.setLocale(new Locale(language, country, variant));
91 			}
92 			Resources.initBundle();
93 		}
94 		catch (Exception e) {
95 			e.printStackTrace();
96 		}
97 		initComponents();
98 		setVisible(makeVisible);
99 		Thread reportThread = new Thread(){
100 			public void run() {
101 				if (nextReport != null && (nextReport.compareTo(new Date()) <= 0)) {
102 					try { generateReports(); } catch (IOException ioe) {}
103 				}
104 				if (nextReport == null)
105 				    nextReport = generateNextReportDate();
106 				updateStatusComponents();
107 				updateDateFields();
108 				while (true) {
109 					if (running && (nextReport.compareTo(new Date()) < 0)) {
110 						try {generateReports();}
111 						catch (IOException ioe) {
112 							JOptionPane.showMessageDialog(null, ioe.getMessage(),
113 														  Resources.getTranslation("error"),
114 														  JOptionPane.ERROR_MESSAGE);
115 						}
116 					}
117 					try {
118 						sleep(1000);
119 					} catch (Exception e) {
120 						e.printStackTrace(System.err);
121 					}
122 				}
123 			}
124 		};
125 		reportThread.start();
126 	}
127 
128 	// Called when a report should be generated. Does not check if it should be generated
generateReports()129 	private void generateReports() throws IOException {
130 		File baseFile = new File(bundleField.getText());
131 		if (baseFile == null || !baseFile.isFile())
132 		    throw new IOException("Specified input file is unusable");
133 		File directory = new File(directoryField.getText());
134 		rbm = new RBManager(baseFile);
135 
136 		if (rbm == null)
137 		    throw new IOException("Unable to load the resource bundle file");
138 		if (directory == null || !directory.isDirectory())
139 		    throw new IOException("Specified output directory is unusable");
140 		RBReporterScanner scanner = null;
141 		if (scanCheck.isSelected()) {
142 			scanner = new RBReporterScanner((Bundle)rbm.getBundles().elementAt(0),
143 										    new File(scanField.getText()));
144 			scanner.performScan();
145 		}
146 		if (textCheck.isSelected()) {
147 			File textFile = new File(directory, textField.getText());
148 			String textReport = getAllLanguageReports(textCombo.getSelectedIndex() == 0);
149 			if (scanCheck.isSelected()) {
150 				// Add file scan information
151 				StringBuffer buffer = new StringBuffer();
152 				buffer.append("\n\nCode Scan Results:\n\n");
153 				buffer.append("\n\tNumber of unique resources found: " + scanner.getNumberResourcesFound());
154 				buffer.append("\n\tNumber of resources missing from bundle: " + scanner.getNumberMissingResources());
155 				// Missing resources from the bundle
156 				buffer.append("\n\tMissing Resources: ");
157 				Vector v = scanner.getMissingResources();
158 				for (int i=0; i < v.size(); i++) {
159 					ScanResult result = (ScanResult)v.elementAt(i);
160 					if (textCombo.getSelectedIndex() == 0) {
161 						buffer.append("\n\t\t" + result.getName() + " (" + result.getOccurances().size() + " Occurances)");
162 						buffer.append("\n\t\t\t" + result.getOccurances());
163 					} else {
164 						buffer.append((i==0 ? "" : ", ") + result.getName() + " (" + result.getOccurances().size() + " Occurances)");
165 					}
166 				}
167 				// Bundle resources not found in the code
168 				buffer.append("\n\tNumber of potentially unused resources in bundle: " + scanner.getNumberUnusedResources());
169 				v = scanner.getUnusedResources();
170 				for (int i=0; i < v.size(); i++) {
171 					ScanResult result = (ScanResult)v.elementAt(i);
172 					if (textCombo.getSelectedIndex() == 0) {
173 						buffer.append("\n\t\t" + result.getName() + " (Group: " + result.getGroupName() + ")");
174 					} else {
175 						buffer.append((i==0 ? "" : ", ") + result.getName());
176 					}
177 				}
178 
179 				textReport = textReport + buffer.toString();
180 			}
181 			FileWriter fw = new FileWriter(textFile);
182 			fw.write(textReport);
183 			fw.flush();
184 			fw.close();
185 		}
186 		if (htmlCheck.isSelected()) {
187 			File htmlFile = new File(directory, htmlField.getText());
188 			Document htmlReport = getHTMLReportz(htmlCombo.getSelectedIndex() == 0);
189 			if (scanCheck.isSelected()) {
190 				// Add file scan information
191 				Element html_elem = htmlReport.getDocumentElement();
192 				NodeList nl = html_elem.getElementsByTagName("BODY");
193 				Element body_elem = (Element)nl.item(0);
194 				Element h2_elem = htmlReport.createElement("H2");
195 				Text    h2_text = htmlReport.createTextNode("Code Scan Results");
196 				Element block_elem = htmlReport.createElement("BLOCKQUOTE");
197 				Element p1_elem = htmlReport.createElement("P");
198 				Element p2_elem = htmlReport.createElement("P");
199 				Element p3_elem = htmlReport.createElement("P");
200 				Text    p1_text = htmlReport.createTextNode("Number of unique resources found: " +
201 															scanner.getNumberMissingResources());
202 				Text    p2_text = htmlReport.createTextNode("Number of resources missing from bundle: " +
203 															scanner.getNumberMissingResources());
204 				Text    p3_text = htmlReport.createTextNode("Number of potentially unused resources in bundle: " +
205 															scanner.getNumberUnusedResources());
206 
207 				h2_elem.appendChild(h2_text);
208 				p1_elem.appendChild(p1_text);
209 				p2_elem.appendChild(p2_text);
210 				p3_elem.appendChild(p3_text);
211 				block_elem.appendChild(p1_elem);
212 				block_elem.appendChild(p2_elem);
213 				block_elem.appendChild(p3_elem);
214 				body_elem.appendChild(h2_elem);
215 				body_elem.appendChild(block_elem);
216 
217 				// Missing resources from the bundle
218 				Text   missing_text = null;
219 				Vector v = scanner.getMissingResources();
220 				if (htmlCombo.getSelectedIndex() == 0) {
221 					Element ul_elem = htmlReport.createElement("UL");
222 					missing_text = htmlReport.createTextNode("Missing Resources:");
223 					ul_elem.appendChild(missing_text);
224 					for (int i=0; i < v.size(); i++) {
225 						ScanResult result = (ScanResult)v.elementAt(i);
226 						Element li_elem = htmlReport.createElement("LI");
227 						Element br_elem = htmlReport.createElement("BR");
228 						Text    t1_text = htmlReport.createTextNode(result.getName() + " (" +
229 																				  result.getOccurances().size() + " Occurances)");
230 						Text    t2_text = htmlReport.createTextNode(result.getOccurances().toString());
231 						li_elem.appendChild(t1_text);
232 						li_elem.appendChild(br_elem);
233 						li_elem.appendChild(t2_text);
234 						ul_elem.appendChild(li_elem);
235 					}
236 					p2_elem.appendChild(ul_elem);
237 				} else {
238 					StringBuffer buffer = new StringBuffer();
239 					buffer.append("Missing Resources: ");
240 					for (int i=0; i < v.size(); i++) {
241 						ScanResult result = (ScanResult)v.elementAt(i);
242 						buffer.append((i==0 ? "" : ", ") + result.getName() + " (" + result.getOccurances().size() + " Occurances)");
243 					}
244 					missing_text = htmlReport.createTextNode(buffer.toString());
245 					Element br_elem = htmlReport.createElement("BR");
246 					p2_elem.appendChild(br_elem);
247 					p2_elem.appendChild(missing_text);
248 				}
249 				// Bundle resources not found in the code
250 				Text   unused_text = null;
251 				v = scanner.getUnusedResources();
252 				if (htmlCombo.getSelectedIndex() == 0) {
253 					Element ul_elem = htmlReport.createElement("UL");
254 					unused_text = htmlReport.createTextNode("Unused Resources:");
255 					ul_elem.appendChild(unused_text);
256 					for (int i=0; i < v.size(); i++) {
257 						ScanResult result = (ScanResult)v.elementAt(i);
258 						Element li_elem = htmlReport.createElement("LI");
259 						Text    t1_text = htmlReport.createTextNode(result.getName() + " (Group: " +
260 																				  result.getGroupName() + ")");
261 						li_elem.appendChild(t1_text);
262 						ul_elem.appendChild(li_elem);
263 					}
264 					p3_elem.appendChild(ul_elem);
265 				} else {
266 					StringBuffer buffer = new StringBuffer();
267 					buffer.append("Unused Resources: ");
268 					for (int i=0; i < v.size(); i++) {
269 						ScanResult result = (ScanResult)v.elementAt(i);
270 						buffer.append((i==0 ? "" : ", ") + result.getName());
271 					}
272 					unused_text = htmlReport.createTextNode(buffer.toString());
273 					Element br_elem = htmlReport.createElement("BR");
274 					p3_elem.appendChild(br_elem);
275 					p3_elem.appendChild(unused_text);
276 				}
277 			}
278 			FileWriter fw = new FileWriter(htmlFile);
279 			OutputFormat of = new OutputFormat(htmlReport);
280 			of.setIndenting(true);
281 			of.setEncoding("ISO-8859-1");
282 			HTMLSerializer serializer = new HTMLSerializer(fw, of);
283 			serializer.serialize(htmlReport);
284 		}
285 		if (xmlCheck.isSelected()) {
286 			File xmlFile = new File(directory, xmlField.getText());
287 			Document xmlReport = getXMLReportz(xmlCombo.getSelectedIndex() == 0);
288 			if (scanCheck.isSelected()) {
289 				// Add file scan information
290 				Element root = xmlReport.getDocumentElement();
291 				Element code_scan_elem = xmlReport.createElement("CODE_SCAN");
292 				Element unique_elem = xmlReport.createElement("UNIQUE_RESOURCES");
293 				Element missing_elem = xmlReport.createElement("MISSING_RESOURCES");
294 				Element unused_elem = xmlReport.createElement("UNUSED_RESOURCES");
295 				Element unique_total_elem = xmlReport.createElement("TOTAL");
296 				Element missing_total_elem = xmlReport.createElement("TOTAL");
297 				Element unused_total_elem = xmlReport.createElement("TOTAL");
298 				Text    unique_total_text = xmlReport.createTextNode(String.valueOf(scanner.getNumberMissingResources()));
299 				Text    missing_total_text = xmlReport.createTextNode(String.valueOf(scanner.getNumberMissingResources()));
300 				Text    unused_total_text = xmlReport.createTextNode(String.valueOf(scanner.getNumberUnusedResources()));
301 
302 				unique_total_elem.appendChild(unique_total_text);
303 				missing_total_elem.appendChild(missing_total_text);
304 				unused_total_elem.appendChild(unused_total_text);
305 				unique_elem.appendChild(unique_total_elem);
306 				missing_elem.appendChild(missing_total_elem);
307 				unused_elem.appendChild(unused_total_elem);
308 				code_scan_elem.appendChild(unique_elem);
309 				code_scan_elem.appendChild(missing_elem);
310 				code_scan_elem.appendChild(unused_elem);
311 				root.appendChild(code_scan_elem);
312 				// Missing resources from the bundle
313 				Vector v = scanner.getMissingResources();
314 				for (int i=0; i < v.size(); i++) {
315 					ScanResult result = (ScanResult)v.elementAt(i);
316 					Element item_elem = xmlReport.createElement("RESOURCE");
317 					item_elem.setAttribute("NAME",result.getName());
318 					if (xmlCombo.getSelectedIndex() == 0) {
319 						Vector occ_v = result.getOccurances();
320 						for (int j=0; j < occ_v.size(); j++) {
321 							Occurance occ = (Occurance)occ_v.elementAt(j);
322 							Element occ_elem = xmlReport.createElement("OCCURANCE");
323 							occ_elem.setAttribute("FILE_NAME", occ.getFileName());
324 							occ_elem.setAttribute("FILE_PATH", occ.getFilePath());
325 							occ_elem.setAttribute("LINE_NUMBER", String.valueOf(occ.getLineNumber()));
326 							item_elem.appendChild(occ_elem);
327 						}
328 					}
329 					missing_elem.appendChild(item_elem);
330 				}
331 				// Bundle resources not found in the code
332 				v = scanner.getUnusedResources();
333 				for (int i=0; i < v.size(); i++) {
334 					ScanResult result = (ScanResult)v.elementAt(i);
335 					Element item_elem = xmlReport.createElement("RESOURCE");
336 					item_elem.setAttribute("NAME",result.getName());
337 					item_elem.setAttribute("GROUP",result.getGroupName());
338 					unused_elem.appendChild(item_elem);
339 				}
340 			}
341 			FileWriter fw = new FileWriter(xmlFile);
342 			OutputFormat of = new OutputFormat(xmlReport);
343 			of.setIndenting(true);
344 			of.setEncoding("ISO-8859-1");
345 			XMLSerializer serializer = new XMLSerializer(fw, of);
346 			serializer.serialize(xmlReport);
347 		}
348 
349 		lastReport = new Date();
350 		nextReport = generateNextReportDate();
351 		updateDateFields();
352 		if (!isVisible()) {
353 			System.out.println("RBReporter: Generated report at " + lastReport.toString());
354 			System.out.println("RBReporter: Next report at " + nextReport.toString());
355 		}
356 	}
357 
358 	// Assumes the last report was just generated, and computes the next report time accordingly
generateNextReportDate()359 	private Date generateNextReportDate() {
360 		Date retDate = null;
361 		GregorianCalendar now = new GregorianCalendar();
362 		if (sequentialRadio.isSelected()) {
363 			int value = Integer.parseInt(valueCombo.getSelectedItem().toString());
364 			if (unitCombo.getSelectedIndex() == 0) now.add(Calendar.MINUTE, value);
365 			else if (unitCombo.getSelectedIndex() == 1) now.add(Calendar.HOUR, value);
366 			else if (unitCombo.getSelectedIndex() == 2) now.add(Calendar.DATE, value);
367 			retDate = now.getTime();
368 		} else if (definedRadio.isSelected()) {
369 			int hour = Integer.parseInt(hourCombo.getSelectedItem().toString());
370 			int minute = Integer.parseInt(minuteCombo.getSelectedItem().toString());
371 			int day = dayCombo.getSelectedIndex();
372 
373 			GregorianCalendar then = new GregorianCalendar();
374 			then.set(Calendar.HOUR, hour);
375 			then.set(Calendar.MINUTE, minute);
376 			then.set(Calendar.SECOND, 0);
377 
378 			if (then.getTime().compareTo(now.getTime()) <= 0) then.add(Calendar.DATE, 1);
379 			if (day > 0 && day <= 7) {
380 				// Make sure we are at the right day
381 				boolean rightDay = false;
382 				while (!rightDay) {
383 					int weekDay = then.get(Calendar.DAY_OF_WEEK);
384 					if ((day == 1 && weekDay == Calendar.MONDAY) ||
385 						(day == 2 && weekDay == Calendar.TUESDAY) ||
386 						(day == 3 && weekDay == Calendar.WEDNESDAY) ||
387 						(day == 4 && weekDay == Calendar.THURSDAY) ||
388 						(day == 5 && weekDay == Calendar.FRIDAY) ||
389 						(day == 6 && weekDay == Calendar.SATURDAY) ||
390 						(day == 7 && weekDay == Calendar.SUNDAY)) rightDay = true;
391 					else then.add(Calendar.DATE, 1);
392 				}
393 			}
394 			retDate = then.getTime();
395 		}
396 		RBManagerGUI.debugMsg("Next Date: " + retDate.toString());
397 		return retDate;
398 	}
399 
400     /**
401      * Returns a string based text report about all of the language files on record
402      */
getAllLanguageReports(boolean detailed)403     public String getAllLanguageReports(boolean detailed) {
404         String retStr = new String();
405         retStr =    "Resource Bundle Report: " + rbm.getBaseClass();
406         retStr += "\nReport Generated:       " + (new Date()).toString() + "\n\n";
407         Vector bundles = rbm.getBundles();
408         for (int i=0; i < bundles.size(); i++) {
409             retStr += getLanguageReport(detailed, (Bundle)bundles.elementAt(i));
410         }
411         return retStr;
412     }
413 
getLanguageReport(boolean detailed, Bundle dict)414     private String getLanguageReport(boolean detailed, Bundle dict) {
415         if (dict == null) return "";
416         String retStr = new String();
417         retStr += "\nLanguage: " + (dict.language == null ? dict.encoding : dict.language);
418         retStr += (dict.country == null ? "" : " - Country: " + dict.country);
419         retStr += (dict.variant == null ? "" : " - Variant: " + dict.variant);
420         retStr += "\n";
421         retStr += "  Number of NLS items in the file: " + dict.allItems.size() + "\n";
422 
423         int untranslated = 0;
424         String untransStr = new String();
425         Enumeration items = dict.allItems.elements();
426         while (items.hasMoreElements()) {
427             BundleItem tempItem = (BundleItem)items.nextElement();
428             if (tempItem.isTranslated()) continue;
429             untranslated++;
430             untransStr += " " + tempItem.getKey();
431         }
432         retStr += "  Number of NLS items not translated: " + untranslated;
433         if (detailed) {
434             retStr += "\n  Untranslated NLS keys: " + untransStr;
435         }
436 
437         return retStr;
438     }
439 
440     /**
441      * Returns an XHTML formatted report on the status of the currently opened resource bundle
442      */
getHTMLReportz(boolean detailed)443     public Document getHTMLReportz(boolean detailed) {
444         Document html = new DocumentImpl();
445         Element root = html.createElement("HTML");
446         html.appendChild(root);
447         Element head_elem = html.createElement("HEAD");
448         Element title_elem = html.createElement("TITLE");
449         Text    title_text = html.createTextNode("Resource Bundle Report - " + rbm.getBaseClass());
450         Element body_elem = html.createElement("BODY");
451         Element center1_elem = html.createElement("CENTER");
452         Element h1_elem = html.createElement("H1");
453         Element center2_elem = html.createElement("CENTER");
454         Element h3_elem = html.createElement("H1");
455         Text    title1_text = html.createTextNode("Resource Bundle Report: " + rbm.getBaseClass());
456         Text    title2_text = html.createTextNode("Report Generated: " + (new Date()).toString());
457         Vector bundles = rbm.getBundles();
458 
459         title_elem.appendChild(title_text);
460         head_elem.appendChild(title_elem);
461         h1_elem.appendChild(title1_text);
462         h3_elem.appendChild(title2_text);
463         center1_elem.appendChild(h1_elem);
464         center2_elem.appendChild(h3_elem);
465         body_elem.appendChild(center1_elem);
466         body_elem.appendChild(center2_elem);
467         root.appendChild(head_elem);
468         root.appendChild(body_elem);
469 
470         for (int i=0; i < bundles.size(); i++) {
471             getHTMLLanguageReportz(html, body_elem, detailed, (Bundle)bundles.elementAt(i));
472         }
473 
474         return html;
475     }
476 
477     /**
478      * Returns a HTML report as a String object on the status of the currently opened resource bundle
479      */
getHTMLReport(boolean detailed)480     public String getHTMLReport(boolean detailed) {
481         StringBuffer buffer = new StringBuffer();
482         buffer.append("<HTML>\n<HEAD><TITLE>Resource Bundle Report - " + rbm.getBaseClass() + "</TITLE></HEAD>\n<BODY>\n");
483         buffer.append("<CENTER><H1>Resource Bundle Report: " + rbm.getBaseClass() + "</H1></CENTER>\n");
484         buffer.append("<CENTER><H3>Report Generated: " + (new Date()).toString() + "</H3></CENTER>\n");
485 
486         Vector bundles = rbm.getBundles();
487         for (int i=0; i < bundles.size(); i++) {
488             buffer.append(getHTMLLanguageReport(detailed, (Bundle)bundles.elementAt(i)));
489         }
490 
491         buffer.append("</BODY>\n</HTML>");
492         return buffer.toString();
493     }
494 
getHTMLLanguageReportz(Document html, Element body_elem, boolean detailed, Bundle dict)495     private void getHTMLLanguageReportz(Document html, Element body_elem, boolean detailed, Bundle dict) {
496         Element h2_elem = html.createElement("H2");
497         Text    h2_text = html.createTextNode("Language: " + (dict.language == null ? dict.encoding : dict.language) +
498                           (dict.country == null ? "" : " - Country: " + dict.country) +
499                           (dict.variant == null ? "" : " - Variant: " + dict.variant));
500         Element block_elem = html.createElement("BLOCKQUOTE");
501         Element p_elem = html.createElement("P");
502         Text    p_text = html.createTextNode("Number of NLS items in the file: " +
503                          String.valueOf(dict.allItems.size()));
504         Element ul_elem = html.createElement("UL");
505         Text    ul_text = html.createTextNode("Untranslated NLS keys:");
506 
507         h2_elem.appendChild(h2_text);
508         p_elem.appendChild(p_text);
509         ul_elem.appendChild(ul_text);
510         block_elem.appendChild(p_elem);
511         body_elem.appendChild(h2_elem);
512         body_elem.appendChild(block_elem);
513 
514         int untranslated = 0;
515         Enumeration items = dict.allItems.elements();
516         while (items.hasMoreElements()) {
517             BundleItem tempItem = (BundleItem)items.nextElement();
518             if (tempItem.isTranslated()) continue;
519             untranslated++;
520             if (detailed) {
521                 Element li_elem = html.createElement("LI");
522                 Text    li_text = html.createTextNode(tempItem.getKey());
523                 li_elem.appendChild(li_text);
524                 ul_elem.appendChild(li_elem);
525             }
526         }
527         Element p2_elem = html.createElement("P");
528         Text    p2_text = html.createTextNode("Number of NLS items not translated: " +
529                           String.valueOf(untranslated));
530         p2_elem.appendChild(p2_text);
531         block_elem.appendChild(p2_elem);
532         if (detailed) block_elem.appendChild(ul_elem);
533     }
534 
getHTMLLanguageReport(boolean detailed, Bundle dict)535     private String getHTMLLanguageReport(boolean detailed, Bundle dict) {
536         StringBuffer buffer = new StringBuffer();
537         buffer.append("\n<H2>Language: " + (dict.language == null ? dict.encoding : dict.language));
538         buffer.append(dict.country == null ? "" : " - Country: " + dict.country);
539         buffer.append(dict.variant == null ? "" : " - Variant: " + dict.variant);
540         buffer.append("</H2>\n");
541         buffer.append("<BLOCKQUOTE>\n");
542 
543         buffer.append("<P>Number of NLS items in the file: " + String.valueOf(dict.allItems.size()) + "</P>\n");
544         int untranslated = 0;
545         Enumeration items = dict.allItems.elements();
546         StringBuffer innerBuffer = new StringBuffer();
547         while (items.hasMoreElements()) {
548             BundleItem tempItem = (BundleItem)items.nextElement();
549             if (tempItem.isTranslated()) continue;
550             untranslated++;
551             innerBuffer.append("<LI>" + tempItem.getKey() + "</LI>\n");
552         }
553         buffer.append("<P>Number of NLS items not translated: " + String.valueOf(untranslated) + "</P>\n");
554         if (detailed) {
555             buffer.append("<UL>Untranslated NLS keys:\n");
556             buffer.append(innerBuffer.toString());
557             buffer.append("</UL>\n");
558         }
559 
560         buffer.append("</BLOCKQUOTE>\n");
561         return buffer.toString();
562     }
563 
564     /**
565      * Returns an XML formatted report on the status of the currently open resource bundle
566      */
567 
getXMLReportz(boolean detailed)568     public Document getXMLReportz(boolean detailed) {
569         Document xml = new DocumentImpl();
570         Element root = xml.createElement("REPORT");
571         root.setAttribute("BASECLASS", rbm.getBaseClass());
572         root.setAttribute("DATE", (new Date()).toString());
573         xml.appendChild(root);
574 
575         Vector bundles = rbm.getBundles();
576         for (int i=0; i < bundles.size(); i++) {
577             root.appendChild(getXMLLanguageReportz(xml, detailed, (Bundle)bundles.elementAt(i)));
578         }
579         return xml;
580     }
581 
582     /**
583      * Returns an XML formatted report as a String object on the status of the currently open resource bundle
584      */
585 
getXMLReport(boolean detailed)586     public String getXMLReport(boolean detailed) {
587         StringBuffer buffer = new StringBuffer();
588         buffer.append("<?xml version=\"1.0\"?>\n");
589         buffer.append("<REPORT BASECLASS=\"" + rbm.getBaseClass() + "\" DATE=\"" + (new Date()).toString() + "\">\n");
590 
591         Vector bundles = rbm.getBundles();
592         for (int i=0; i < bundles.size(); i++) {
593             buffer.append(getXMLLanguageReport(detailed, (Bundle)bundles.elementAt(i)));
594         }
595         buffer.append("</REPORT>");
596         return buffer.toString();
597     }
598 
getXMLLanguageReportz(Document xml, boolean detailed, Bundle dict)599     private Element getXMLLanguageReportz(Document xml, boolean detailed, Bundle dict) {
600         Element lang_report_elem = xml.createElement("LANGUAGE_REPORT");
601         Element locale_elem = xml.createElement("LOCALE");
602         locale_elem.setAttribute("LANGUAGE", (dict.language == null ? dict.encoding : dict.language));
603         locale_elem.setAttribute("COUNTRY", (dict.country == null ? "" : dict.country));
604         locale_elem.setAttribute("VARIANT", (dict.variant == null ? "" : dict.variant));
605         Element nls_total_elem = xml.createElement("NLS_TOTAL");
606         Text    nls_total_text = xml.createTextNode(String.valueOf(dict.allItems.size()));
607         Element untranslated_total_elem = xml.createElement("UNTRANSLATED_TOTAL");
608         Element untranslated_elem = xml.createElement("UNTRANSLATED");
609 
610         nls_total_elem.appendChild(nls_total_text);
611         lang_report_elem.appendChild(locale_elem);
612         lang_report_elem.appendChild(nls_total_elem);
613         lang_report_elem.appendChild(untranslated_total_elem);
614         if (detailed) lang_report_elem.appendChild(untranslated_elem);
615 
616         int untranslated = 0;
617         Enumeration items = dict.allItems.elements();
618         while (items.hasMoreElements()) {
619             BundleItem tempItem = (BundleItem)items.nextElement();
620             if (tempItem.isTranslated()) continue;
621             untranslated++;
622             Element resource_elem = xml.createElement("RESOURCEKEY");
623             Text    resource_text = xml.createTextNode(tempItem.getKey());
624             resource_elem.appendChild(resource_text);
625             untranslated_elem.appendChild(resource_elem);
626         }
627         Text untranslated_total_text = xml.createTextNode(String.valueOf(untranslated));
628         untranslated_total_elem.appendChild(untranslated_total_text);
629 
630         return lang_report_elem;
631     }
632 
getXMLLanguageReport(boolean detailed, Bundle dict)633     private String getXMLLanguageReport(boolean detailed, Bundle dict) {
634         StringBuffer buffer = new StringBuffer();
635         buffer.append("<LANGUAGE_REPORT>\n");
636 
637         buffer.append("\n\t<LOCALE LANGUAGE=\"" + (dict.language == null ? dict.encoding : dict.language));
638         buffer.append("\" COUNTRY=\"" + (dict.country == null ? "" : dict.country));
639         buffer.append("\" VARIANT=\"" + (dict.variant == null ? "" : dict.variant) + "\"/>\n");
640 
641         buffer.append("\t<NLS_TOTAL>" + String.valueOf(dict.allItems.size()) + "</NLS_TOTAL>\n");
642         int untranslated = 0;
643         Enumeration items = dict.allItems.elements();
644         StringBuffer innerBuffer = new StringBuffer();
645         while (items.hasMoreElements()) {
646             BundleItem tempItem = (BundleItem)items.nextElement();
647             if (tempItem.isTranslated()) continue;
648             untranslated++;
649             innerBuffer.append("\t\t<RESOURCEKEY>" + tempItem.getKey() + "</RESOURCEKEY>\n");
650         }
651         buffer.append("\t<UNTRANSLATED_TOTAL>" + String.valueOf(untranslated) + "</UNTRANSLATED_TOTAL>\n");
652         if (detailed) {
653             buffer.append("\t<UNTRANSLATED>\n");
654             buffer.append(innerBuffer.toString());
655             buffer.append("\t</UNTRANSLATED>\n");
656         }
657 
658         buffer.append("</LANGUAGE_REPORT>\n");
659         return buffer.toString();
660     }
661 
updateDateFields()662 	private void updateDateFields() {
663 		if (nextReport == null) nextReportLabel.setText(Resources.getTranslation("reporter_next_report", "--"));
664 		else nextReportLabel.setText(Resources.getTranslation("reporter_next_report", nextReport.toString()));
665 		if (lastReport == null) lastReportLabel.setText(Resources.getTranslation("reporter_last_report", "--"));
666 		else lastReportLabel.setText(Resources.getTranslation("reporter_last_report", lastReport.toString()));
667 	}
668 
updateStatusComponents()669 	private void updateStatusComponents() {
670 		if (running) {
671 			statusLabel.setText(Resources.getTranslation("reporter_status_running"));
672 			statusLabel.setForeground(Color.green);
673 			statusButton.setText(Resources.getTranslation("reporter_button_stop"));
674 		} else {
675 			statusLabel.setText(Resources.getTranslation("reporter_status_stopped"));
676 			statusLabel.setForeground(Color.red);
677 			statusButton.setText(Resources.getTranslation("reporter_button_start"));
678 		}
679 	}
680 
setComponentsToDefaults()681 	private void setComponentsToDefaults() {
682 		if ((running && Preferences.getPreference("reporter_enabled").equals("No")) ||
683 			(!running && Preferences.getPreference("reporter_enabled").equals("Yes"))) toggleStatus();
684 		if (Preferences.getPreference("reporter_format_text_enabled") != null)
685 			textCheck.setSelected(Preferences.getPreference("reporter_format_text_enabled").equals("Yes"));
686 		if (Preferences.getPreference("reporter_format_html_enabled") != null)
687 			htmlCheck.setSelected(Preferences.getPreference("reporter_format_html_enabled").equals("Yes"));
688 		if (Preferences.getPreference("reporter_format_xml_enabled") != null)
689 				xmlCheck.setSelected(Preferences.getPreference("reporter_format_xml_enabled").equals("Yes"));
690 		if (Preferences.getPreference("reporter_format_text_file") != null &&
691 			!Preferences.getPreference("reporter_format_text_file").equals(""))
692 			textField.setText(Preferences.getPreference("reporter_format_text_file"));
693 		if (Preferences.getPreference("reporter_format_html_file") != null &&
694 			!Preferences.getPreference("reporter_format_html_file").equals(""))
695 			htmlField.setText(Preferences.getPreference("reporter_format_html_file"));
696 		if (Preferences.getPreference("reporter_format_xml_file") != null &&
697 			!Preferences.getPreference("reporter_format_xml_file").equals(""))
698 			xmlField.setText(Preferences.getPreference("reporter_format_xml_file"));
699 		if (Preferences.getPreference("reporter_format_text_detail") != null &&
700 			!Preferences.getPreference("reporter_format_text_detail").equals(""))
701 			selectComboValue(textCombo, Preferences.getPreference("reporter_format_text_detail"));
702 		if (Preferences.getPreference("reporter_format_html_detail") != null &&
703 			!Preferences.getPreference("reporter_format_html_detail").equals(""))
704 			selectComboValue(htmlCombo, Preferences.getPreference("reporter_format_html_detail"));
705 		if (Preferences.getPreference("reporter_format_xml_detail") != null &&
706 			!Preferences.getPreference("reporter_format_xml_detail").equals(""))
707 			selectComboValue(xmlCombo, Preferences.getPreference("reporter_format_xml_detail"));
708 		if (Preferences.getPreference("reporter_interval").equals("Sequential"))
709 			sequentialRadio.setSelected(true);
710 		else definedRadio.setSelected(true);
711 		if (Preferences.getPreference("reporter_interval_sequential_value") != null &&
712 			!Preferences.getPreference("reporter_interval_sequential_value").equals(""))
713 			selectComboValue(valueCombo, Preferences.getPreference("reporter_interval_sequential_value"));
714 		if (Preferences.getPreference("reporter_interval_sequential_units") != null &&
715 			!Preferences.getPreference("reporter_interval_sequential_units").equals(""))
716 			selectComboValue(valueCombo, Preferences.getPreference("reporter_interval_sequential_units"));
717 		if (Preferences.getPreference("reporter_interval_defined_hour") != null &&
718 			!Preferences.getPreference("reporter_interval_defined_hour").equals(""))
719 			selectComboValue(hourCombo, Preferences.getPreference("reporter_interval_defined_hour"));
720 		if (Preferences.getPreference("reporter_interval_defined_day") != null &&
721 			!Preferences.getPreference("reporter_interval_defined_day").equals(""))
722 			selectComboValue(dayCombo, Preferences.getPreference("reporter_interval_defined_day"));
723 		if (Preferences.getPreference("reporter_interval_defined_minute") != null &&
724 			!Preferences.getPreference("reporter_interval_defined_minute").equals(""))
725 			selectComboValue(minuteCombo, Preferences.getPreference("reporter_interval_defined_minute"));
726 		if (Preferences.getPreference("reporter_scan_file") != null &&
727 			!Preferences.getPreference("reporter_scan_file").equals(""))
728 			scanField.setText(Preferences.getPreference("reporter_scan_file"));
729 		if (Preferences.getPreference("reporter_perform_scan") != null)
730 			scanCheck.setSelected(Preferences.getPreference("reporter_perform_scan").equals("Yes"));
731 	}
732 
selectComboValue(JComboBox box, String value)733 	private static void selectComboValue(JComboBox box, String value) {
734 		for (int i=0; i < box.getItemCount(); i++) {
735 			if (box.getItemAt(i).toString().equals(value)) {
736 				box.setSelectedIndex(i);
737 				break;
738 			}
739 		}
740 	}
741 
saveDefaults()742 	private void saveDefaults() {
743 		// Save format options
744 		Preferences.setPreference("reporter_format_text_enabled", (textCheck.isSelected() ? "Yes" : "No"));
745 		Preferences.setPreference("reporter_format_text_file", textField.getText());
746 		Preferences.setPreference("reporter_format_text_detail", textCombo.getSelectedItem().toString());
747 		Preferences.setPreference("reporter_format_html_enabled", (htmlCheck.isSelected() ? "Yes" : "No"));
748 		Preferences.setPreference("reporter_format_html_file", htmlField.getText());
749 		Preferences.setPreference("reporter_format_html_detail", htmlCombo.getSelectedItem().toString());
750 		Preferences.setPreference("reporter_format_xml_enabled", (xmlCheck.isSelected() ? "Yes" : "No"));
751 		Preferences.setPreference("reporter_format_xml_file", xmlField.getText());
752 		Preferences.setPreference("reporter_format_xml_detail", xmlCombo.getSelectedItem().toString());
753 		Preferences.setPreference("reporter_scan_file", scanField.getText());
754 		Preferences.setPreference("reporter_perform_scan", (scanCheck.isSelected() ? "Yes" : "No"));
755 		// Save interval options
756 		Preferences.setPreference("reporter_interval", (sequentialRadio.isSelected() ? "Sequential" : "Defined"));
757 		Preferences.setPreference("reporter_interval_sequential_value", valueCombo.getSelectedItem().toString());
758 		Preferences.setPreference("reporter_interval_sequential_units", unitCombo.getSelectedItem().toString());
759 		Preferences.setPreference("reporter_interval_defined_hour", hourCombo.getSelectedItem().toString());
760 		Preferences.setPreference("reporter_interval_defined_minute", minuteCombo.getSelectedItem().toString());
761 		Preferences.setPreference("reporter_interval_defined_day", dayCombo.getSelectedItem().toString());
762 		// Save system options
763 		Preferences.setPreference("reporter_enabled", (running ? "Yes" : "No"));
764 		// Write the preferences
765 		try {
766 			Preferences.savePreferences();
767 		} catch (IOException ioe) {
768 			// TODO: Warn of error through JOptionPane
769 			ioe.printStackTrace();
770 		}
771 	}
772 
toggleStatus()773 	private void toggleStatus() {
774 		if (running) {
775 			running = false;
776 		} else {
777 			running = true;
778 		}
779 		updateStatusComponents();
780 	}
781 
initComponents()782 	private void initComponents() {
783 
784 		// File choosers
785 		bundleFileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
786 			public boolean accept(File f) {
787 				if (f.isDirectory()) return true;
788 
789 				String name = f.getName();
790 				if (!(name.toLowerCase().endsWith(".properties"))) return false;
791 				if (name.indexOf("_") > 0) return false;
792 				return true;
793 			}
794 
795 			public String getDescription() {
796 				return Resources.getTranslation("dialog_file_filter_description");
797 			}
798 		});
799 		bundleFileChooser.setSelectedFile(new File(Preferences.getPreference("reporter_base_class_file")));
800 
801 		directoryFileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
802 			public boolean accept(File f) {
803 				if (f.isDirectory()) return true;
804 				return false;
805 			}
806 
807 			public String getDescription() {
808 				return Resources.getTranslation("directory");
809 			}
810 		});
811 		directoryFileChooser.setSelectedFile(new File(Preferences.getPreference("reporter_output_directory")));
812 
813 		scanFileChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
814 			public boolean accept(File f) {
815 				if (f.isDirectory()) return true;
816 				if (f.getName().endsWith(".xml")) return true;
817 				return false;
818 			}
819 
820 			public String getDescription() {
821 				return Resources.getTranslation("dialog_file_filter_description_scan");
822 			}
823 		});
824 		scanFileChooser.setSelectedFile(new File(Preferences.getPreference("reporter_scan_file")));
825 
826 		// New top level components
827 		JPanel statusPanel = new JPanel();
828 		JPanel intervalPanel = new JPanel();
829 		JPanel optionsPanel = new JPanel();
830 		JPanel formatPanel = new JPanel();
831 		Box mainBox = new Box(BoxLayout.Y_AXIS);
832 		int width = 600;
833 		int height = 600;
834 		int compHeight = 20;
835 		Dimension mainDim = new Dimension(width,height);
836 
837 		statusPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
838 															   Resources.getTranslation("reporter_panel_status")));
839 		intervalPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
840 															   Resources.getTranslation("reporter_panel_interval")));
841 		optionsPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
842 															   Resources.getTranslation("reporter_panel_options")));
843 		formatPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
844 															   Resources.getTranslation("reporter_panel_output_format")));
845 
846 		// ** STATUS PANEL SETUP **
847 		JButton nowButton = new JButton(Resources.getTranslation("reporter_button_now"));
848 		Box     statusBox = new Box(BoxLayout.Y_AXIS);
849 		JPanel  statusPanel1 = new JPanel();
850 		JPanel  statusPanel2 = new JPanel();
851 		JPanel  statusPanel3 = new JPanel();
852 		JPanel  statusPanel4 = new JPanel();
853 		statusButton = new JButton(Resources.getTranslation("reporter_button_start"));
854 		statusLabel = new JLabel(Resources.getTranslation("reporter_status_stopped"));
855 		nextReportLabel = new JLabel(Resources.getTranslation("reporter_next_report", "--"));
856 		lastReportLabel = new JLabel(Resources.getTranslation("reporter_last_report", "--"));
857 		statusLabel.setFont(new Font("serif",Font.BOLD,14));
858 		statusLabel.setForeground(Color.red);
859 		statusPanel2.setLayout(new FlowLayout(FlowLayout.LEFT));
860 		statusPanel3.setLayout(new FlowLayout(FlowLayout.LEFT));
861 		statusPanel.setLayout(new BorderLayout());
862 
863 		nowButton.addActionListener(new ActionListener() {
864 			public void actionPerformed(ActionEvent ev) {
865 				try {
866 					generateReports();
867 				} catch (Exception e) {
868 					JOptionPane.showMessageDialog(null, e.getMessage(), Resources.getTranslation("error"),
869 												  JOptionPane.ERROR_MESSAGE);
870 					RBManagerGUI.debugMsg(e.toString());
871 					if (RBManagerGUI.debug) e.printStackTrace(System.err);
872 				}
873 			}
874 		});
875 
876 		statusButton.addActionListener(new ActionListener() {
877 			public void actionPerformed(ActionEvent ev) {
878 				toggleStatus();
879 			}
880 		});
881 
882 		statusPanel1.add(statusLabel);
883 		statusPanel2.add(nextReportLabel);
884 		statusPanel3.add(lastReportLabel);
885 		statusPanel4.add(nowButton);
886 		statusPanel4.add(Box.createHorizontalStrut(7));
887 		statusPanel4.add(statusButton);
888 		statusBox.add(statusPanel1);
889 		statusBox.add(Box.createVerticalStrut(7));
890 		//statusBox.add(Box.createHorizontalGlue());
891 		statusBox.add(statusPanel2);
892 		//statusBox.add(Box.createHorizontalGlue());
893 		statusBox.add(statusPanel3);
894 		statusBox.add(Box.createVerticalStrut(7));
895 		statusBox.add(statusPanel4);
896 		statusPanel.add(statusBox, BorderLayout.CENTER);
897 
898 		// ** OPTIONS PANEL SETUP **
899 		JLabel  inputLabel    = new JLabel(Resources.getTranslation("reporter_input_bundle"));
900 		JLabel  outputLabel   = new JLabel(Resources.getTranslation("reporter_output_directory"));
901 		JButton inputButton   = new JButton(Resources.getTranslation("reporter_button_choose"));
902 		JButton outputButton  = new JButton(Resources.getTranslation("reporter_button_choose"));
903 		JButton scanButton    = new JButton(Resources.getTranslation("reporter_button_choose"));
904 		JButton defaultButton = new JButton(Resources.getTranslation("reporter_button_save_defaults"));
905 		JLabel  textLabel     = new JLabel(Resources.getTranslation("reporter_output_file"));
906 		JLabel  htmlLabel     = new JLabel(Resources.getTranslation("reporter_output_file"));
907 		JLabel  xmlLabel      = new JLabel(Resources.getTranslation("reporter_output_file"));
908 		JLabel  textLabel2    = new JLabel(Resources.getTranslation("reporter_detail_level"));
909 		JLabel  htmlLabel2    = new JLabel(Resources.getTranslation("reporter_detail_level"));
910 		JLabel  xmlLabel2     = new JLabel(Resources.getTranslation("reporter_detail_level"));
911 		JPanel  optionsPanel1 = new JPanel();
912 		JPanel  optionsPanel2 = new JPanel();
913 		JPanel  optionsPanelA = new JPanel();
914 		JPanel  optionsPanel3 = new JPanel();
915 		JPanel  optionsPanel4 = new JPanel();
916 		JPanel  optionsPanel5 = new JPanel();
917 		JPanel  optionsPanel6 = new JPanel();
918 		Box     optionsBox    = new Box(BoxLayout.Y_AXIS);
919 		Box     outputBox     = new Box(BoxLayout.Y_AXIS);
920 
921 		bundleField    = new JTextField(Preferences.getPreference("reporter_base_class_file"));
922 		directoryField = new JTextField(Preferences.getPreference("reporter_output_directory"));
923 		textCheck      = new JCheckBox(Resources.getTranslation("reporter_format_text"));
924 		htmlCheck      = new JCheckBox(Resources.getTranslation("reporter_format_html"));
925 		xmlCheck       = new JCheckBox(Resources.getTranslation("reporter_format_xml"));
926 		scanCheck      = new JCheckBox(Resources.getTranslation("reporter_perform_scan"), false);
927 		textField      = new JTextField("report.txt");
928 		htmlField      = new JTextField("report.html");
929 		xmlField       = new JTextField("report.xml");
930 		scanField      = new JTextField();
931 		String [] detailLevels = {Resources.getTranslation("reporter_detail_high"),
932 								  Resources.getTranslation("reporter_detail_normal")};
933 		textCombo      = new JComboBox(detailLevels);
934 		htmlCombo      = new JComboBox(detailLevels);
935 		xmlCombo       = new JComboBox(detailLevels);
936 
937 		bundleField.setColumns(30);
938 		directoryField.setColumns(30);
939 		scanField.setColumns(30);
940 		textField.setColumns(15);
941 		htmlField.setColumns(15);
942 		xmlField.setColumns(15);
943 		Dimension checkDim = new Dimension(55,compHeight);
944 		textCheck.setPreferredSize(checkDim);
945 		htmlCheck.setPreferredSize(checkDim);
946 		xmlCheck.setPreferredSize(checkDim);
947 		optionsPanel1.setLayout(new FlowLayout(FlowLayout.RIGHT));
948 		optionsPanel2.setLayout(new FlowLayout(FlowLayout.RIGHT));
949 		optionsPanelA.setLayout(new FlowLayout(FlowLayout.RIGHT));
950 
951 		inputButton.addActionListener(new ActionListener() {
952 			public void actionPerformed(ActionEvent ev) {
953 				setInputBundle();
954 			}
955 		});
956 
957 		outputButton.addActionListener(new ActionListener() {
958 			public void actionPerformed(ActionEvent ev) {
959 				setOutputBundle();
960 			}
961 		});
962 
963 		scanButton.addActionListener(new ActionListener(){
964 			public void actionPerformed(ActionEvent ev) {
965 				setScanFile();
966 			}
967 		});
968 
969 		defaultButton.addActionListener(new ActionListener() {
970 			public void actionPerformed(ActionEvent ev) {
971 				saveDefaults();
972 			}
973 		});
974 
975 		optionsPanel6.add(defaultButton);
976 		optionsPanel3.add(textCheck);
977 		optionsPanel3.add(Box.createHorizontalStrut(5));
978 		optionsPanel3.add(textLabel);
979 		optionsPanel3.add(Box.createHorizontalStrut(5));
980 		optionsPanel3.add(textField);
981 		optionsPanel3.add(Box.createHorizontalStrut(5));
982 		optionsPanel3.add(textLabel2);
983 		optionsPanel3.add(Box.createHorizontalStrut(5));
984 		optionsPanel3.add(textCombo);
985 		optionsPanel4.add(htmlCheck);
986 		optionsPanel4.add(Box.createHorizontalStrut(5));
987 		optionsPanel4.add(htmlLabel);
988 		optionsPanel4.add(Box.createHorizontalStrut(5));
989 		optionsPanel4.add(htmlField);
990 		optionsPanel4.add(Box.createHorizontalStrut(5));
991 		optionsPanel4.add(htmlLabel2);
992 		optionsPanel4.add(Box.createHorizontalStrut(5));
993 		optionsPanel4.add(htmlCombo);
994 		optionsPanel5.add(xmlCheck);
995 		optionsPanel5.add(Box.createHorizontalStrut(5));
996 		optionsPanel5.add(xmlLabel);
997 		optionsPanel5.add(Box.createHorizontalStrut(5));
998 		optionsPanel5.add(xmlField);
999 		optionsPanel5.add(Box.createHorizontalStrut(5));
1000 		optionsPanel5.add(xmlLabel2);
1001 		optionsPanel5.add(Box.createHorizontalStrut(5));
1002 		optionsPanel5.add(xmlCombo);
1003 		outputBox.add(optionsPanel3);
1004 		outputBox.add(optionsPanel4);
1005 		outputBox.add(optionsPanel5);
1006 		formatPanel.add(outputBox);
1007 		optionsPanel1.add(inputLabel);
1008 		optionsPanel1.add(Box.createHorizontalStrut(5));
1009 		optionsPanel1.add(bundleField);
1010 		optionsPanel1.add(Box.createHorizontalStrut(5));
1011 		optionsPanel1.add(inputButton);
1012 		optionsPanel2.add(outputLabel);
1013 		optionsPanel2.add(Box.createHorizontalStrut(5));
1014 		optionsPanel2.add(directoryField);
1015 		optionsPanel2.add(Box.createHorizontalStrut(5));
1016 		optionsPanel2.add(outputButton);
1017 		optionsPanelA.add(scanCheck);
1018 		optionsPanelA.add(Box.createHorizontalStrut(5));
1019 		optionsPanelA.add(scanField);
1020 		optionsPanelA.add(Box.createHorizontalStrut(5));
1021 		optionsPanelA.add(scanButton);
1022 		optionsBox.add(optionsPanel1);
1023 		optionsBox.add(optionsPanel2);
1024 		optionsBox.add(optionsPanelA);
1025 		optionsBox.add(formatPanel);
1026 		optionsBox.add(optionsPanel6);
1027 		optionsPanel.add(optionsBox);
1028 
1029 		// ** INTERVAL PANEL SETUP **
1030 		String boxArray1[] = {"1","2","3","4","5","6","7","8","9","10","11","12","15","20","24","25","30"};
1031 		String boxArray2[] = {Resources.getTranslation("reporter_time_minutes"),
1032 							  Resources.getTranslation("reporter_time_hours"),
1033 							  Resources.getTranslation("reporter_time_days")};
1034 		String boxArray3[] = {"1","2","3","4","5","6","7","8","9","10","11","12",
1035 							  "13","14","15","16","17","18","19","20","21","22","23","0"};
1036 		String boxArray4[] = {"00","15","30","45"};
1037 		String boxArray5[] = {Resources.getTranslation("reporter_time_everyday"),
1038 							  Resources.getTranslation("reporter_time_monday"),
1039 							  Resources.getTranslation("reporter_time_tuesday"),
1040 							  Resources.getTranslation("reporter_time_wednesday"),
1041 							  Resources.getTranslation("reporter_time_thursday"),
1042 							  Resources.getTranslation("reporter_time_friday"),
1043 							  Resources.getTranslation("reporter_time_saturday"),
1044 							  Resources.getTranslation("reporter_time_sunday")};
1045 
1046 		JLabel colonLabel = new JLabel(":");
1047 		sequentialRadio = new JRadioButton(Resources.getTranslation("reporter_interval_sequential"));
1048 		definedRadio = new JRadioButton(Resources.getTranslation("reporter_interval_defined"), true);
1049 		valueCombo = new JComboBox(boxArray1);
1050 		unitCombo = new JComboBox(boxArray2);
1051 		hourCombo = new JComboBox(boxArray3);
1052 		minuteCombo = new JComboBox(boxArray4);
1053 		dayCombo = new JComboBox(boxArray5);
1054 		JPanel intervalPanel1 = new JPanel();
1055 		JPanel intervalPanel2 = new JPanel();
1056 		intervalPanel1.setLayout(new FlowLayout(FlowLayout.LEFT));
1057 		intervalPanel2.setLayout(new FlowLayout(FlowLayout.LEFT));
1058 		Box intervalBox = new Box(BoxLayout.Y_AXIS);
1059 		intervalPanel.setLayout(new BorderLayout());
1060 
1061 		ButtonGroup bg = new ButtonGroup();
1062 		bg.add(sequentialRadio);
1063 		bg.add(definedRadio);
1064 
1065 		intervalPanel1.add(sequentialRadio);
1066 		intervalPanel1.add(Box.createHorizontalStrut(5));
1067 		intervalPanel1.add(valueCombo);
1068 		intervalPanel1.add(Box.createHorizontalStrut(5));
1069 		intervalPanel1.add(unitCombo);
1070 		intervalPanel2.add(definedRadio);
1071 		intervalPanel2.add(Box.createHorizontalStrut(5));
1072 		intervalPanel2.add(hourCombo);
1073 		intervalPanel2.add(colonLabel);
1074 		intervalPanel2.add(minuteCombo);
1075 		intervalPanel2.add(Box.createHorizontalStrut(5));
1076 		intervalPanel2.add(dayCombo);
1077 		intervalBox.add(intervalPanel1);
1078 		intervalBox.add(intervalPanel2);
1079 		intervalPanel.add(intervalBox, BorderLayout.WEST);
1080 
1081 		// ** MAINBOX SETUP **
1082 		mainBox.removeAll();
1083 		mainBox.add(statusPanel);
1084 		mainBox.add(intervalPanel);
1085 		mainBox.add(optionsPanel);
1086 
1087 		// ** MAIN FRAME SETUP **
1088 		setLocation(new java.awt.Point(25, 25));
1089 		setSize(mainDim);
1090 		//((JComponent)getContentPane()).setMaximumSize(dimMainMax);
1091 		//((JComponent)getContentPane()).setMinimumSize(dimMainMin);
1092 		//setJMenuBar(jMenuBarMain);
1093 		getContentPane().setLayout(new BorderLayout());
1094 		getContentPane().removeAll();
1095 		getContentPane().add(mainBox, BorderLayout.CENTER);
1096 		setTitle(Resources.getTranslation("resource_bundle_reporter"));
1097 		//validateTree();
1098 		setComponentsToDefaults();
1099 		nextReport = generateNextReportDate();
1100 		updateDateFields();
1101 		repaint();
1102 
1103 		addWindowListener(new java.awt.event.WindowAdapter() {
1104 			public void windowClosing(java.awt.event.WindowEvent ev) {
1105 				thisWindowClosing(ev);
1106 			}
1107 		});
1108 	}
1109 
thisWindowClosing(WindowEvent ev)1110 	public void thisWindowClosing(WindowEvent ev) {
1111 		setVisible(false);
1112 		dispose();
1113 		System.exit(0);
1114 	}
1115 
setInputBundle()1116 	private void setInputBundle() {
1117 		int result = bundleFileChooser.showOpenDialog(this);
1118 		if (result == JFileChooser.APPROVE_OPTION) {
1119 			File f = bundleFileChooser.getSelectedFile();
1120 			if (f != null) {
1121 				bundleField.setText(f.getAbsolutePath());
1122 				Preferences.setPreference("reporter_base_class_file",f.getAbsolutePath());
1123 				try {Preferences.savePreferences();} catch (IOException ioe) {}
1124 			}
1125 		}
1126 	}
1127 
setOutputBundle()1128 	private void setOutputBundle() {
1129 		int result = directoryFileChooser.showOpenDialog(this);
1130 		if (result == JFileChooser.APPROVE_OPTION) {
1131 			File f = directoryFileChooser.getSelectedFile();
1132 			if (!f.isDirectory()) f = new File(f.getParent());
1133 			if (f != null) {
1134 				directoryField.setText(f.getAbsolutePath());
1135 				Preferences.setPreference("reporter_output_directory",f.getAbsolutePath());
1136 				try {Preferences.savePreferences();} catch (IOException ioe) {}
1137 			}
1138 		}
1139 	}
1140 
setScanFile()1141 	private void setScanFile() {
1142 		int result = scanFileChooser.showOpenDialog(this);
1143 		if (result == JFileChooser.APPROVE_OPTION) {
1144 			File f = scanFileChooser.getSelectedFile();
1145 			if (f != null) {
1146 				scanField.setText(f.getAbsolutePath());
1147 				Preferences.setPreference("reporter_scan_file",f.getAbsolutePath());
1148 				try {Preferences.savePreferences();} catch (IOException ioe) {}
1149 			}
1150 		}
1151 	}
1152 
getUsage()1153 	private static String getUsage() {
1154 		return "\nRBReporter Command Line Usage:\n\n" +
1155 			   "Default Usage (GUI):   java com.ibm.rbm.RBReporter\n" +
1156 			   "Options Usage:         java com.ibm.rbm.RBReporter [-gui | -now | -line]\n\n" +
1157 			   "Options:               -gui     Run the Graphical User Interface\n" +
1158 			   "                       -now     Execute the Report Generation Immediately\n" +
1159 			   "                       -line    Run the Reporter without the GUI";
1160 	}
1161 
main(String args[])1162 	public static void main(String args[]) {
1163 	    RBReporter reporter;
1164 		if (args.length == 1) {
1165 			if (args[0].equals("-gui")) {
1166 			    reporter = new RBReporter(true);
1167 			} else if (args[0].equals("-now")) {
1168 				reporter = new RBReporter(false);
1169 				try {
1170 					reporter.generateReports();
1171 					System.out.println("RBReporter: Generation of reports successful. " + new Date());
1172 				} catch (IOException ioe) {
1173 					System.out.println("There was an error generating the reports...\n\n\t" + ioe.getMessage());
1174 				}
1175 				reporter.thisWindowClosing(null);
1176 			} else if (args[0].equals("-line")) {
1177 				reporter = new RBReporter(false);
1178 				if (!reporter.running)
1179 				    reporter.toggleStatus();
1180 				System.out.println("RBReporter: Next Report at " + reporter.nextReport.toString());
1181 			} else {
1182 				System.out.println(getUsage());
1183 			}
1184 		} else if (args.length == 0) {
1185 			reporter = new RBReporter(true);
1186 		} else {
1187 			System.out.println(getUsage());
1188 		}
1189 	}
1190 
1191 }