comparison export_iprscan_to_Excel/source_files/iprscanToExcel_v20/src/be/cropdesign/iprscan/Main.java @ 0:a9762cd6e2e3 draft default tip

Uploaded
author basfplant
date Tue, 05 Mar 2013 04:00:19 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a9762cd6e2e3
1 package be.cropdesign.iprscan;
2
3 import java.io.FileNotFoundException;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.util.HashMap;
7
8 //include POI 3.8-beta5 jars in classpath
9 import org.apache.poi.xssf.usermodel.XSSFCell;
10 import org.apache.poi.xssf.usermodel.XSSFRow;
11 import org.apache.poi.xssf.usermodel.XSSFSheet;
12 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
13
14 /**
15 * the .jar needs as parameters the path to the XML file with the summary tables and
16 * the .raw file with the iprscan results.
17 * Further the path and filename of the exported Excel file (.xlsx) is given as a parameter.
18 * java -jar iprscan.jar -xml $XML -raw $raw -excel $excel
19 * @author: Katrien Bernaerts and Domantas Motiejunas
20 * @date: 21/06/2012
21 * @affiliation: CropDesign N.V., a BASF Plant Science Company - Technologiepark 3, 9052 Zwijnaarde - Belgium
22 */
23 public class Main {
24
25 /**
26 * @param args
27 */
28 public static void main(String[] args) {
29 /*
30 * store the arguments and their corresponding flags in a HashMap.
31 * The availability of a HashMap with key (-flag) / value (argument) pairs makes it easier
32 * to handle the arguments and their flags.
33 */
34 HashMap<String, String> arguments = new HashMap<String, String>();
35 if (args.length == 0){
36 System.err.println("No arguments were found at the command line.");
37 } else {
38 for(int i = 0; i < args.length; i++){
39 // for the even args. args[0] is a flag, args[1] is the corresponding argument etc.
40 if (i % 2 == 0){
41 arguments.put(args[i], args[i+1]); // define key (-flag) - value (argument) pairs
42 }
43 }
44 }
45
46
47 /*
48 * fetch the argument values for each flag in the FLAGS enumeration
49 */
50 String XMLFile = arguments.get(EnumFlags.XML.getFlag());
51 String rawFile = arguments.get(EnumFlags.RAW.getFlag());
52 String xlsxName = arguments.get(EnumFlags.EXCEL.getFlag());
53
54 /*
55 * create an Excel workbook using the Apache POI library
56 * ref: http://sanjaal.com/java/105/java-file/writing-to-excel-file-using-apache-poi/
57 */
58 XSSFWorkbook wb = new XSSFWorkbook();
59 XSSFRow myRow = null;
60 XSSFCell myCell = null;
61
62 /*
63 * determine which arguments (-xml or -raw or (-xml && -raw)) were used at the command line,
64 * and execute the methods corresponding with those arguments
65 */
66 if(arguments.containsKey(EnumFlags.XML.getFlag()) && arguments.containsKey(EnumFlags.RAW.getFlag())){
67 parseXML(wb, myRow, myCell, XMLFile);
68 parseRaw(wb, myRow, myCell, rawFile);
69 } else if (arguments.containsKey(EnumFlags.XML.getFlag())) {
70 parseXML(wb, myRow, myCell, XMLFile);
71 } else if (arguments.containsKey(EnumFlags.RAW.getFlag())) {
72 parseRaw(wb, myRow, myCell, rawFile);
73 }
74
75 /*
76 * write the parsed results to Excel
77 */
78 FileOutputStream fileOut;
79 try {
80 fileOut = new FileOutputStream(xlsxName);
81 wb.write(fileOut);
82 fileOut.close();
83 } catch (FileNotFoundException fnf) {
84 System.err.println("Filenot found: " + fnf);
85 } catch (IOException io) {
86 System.err.println("Input/output error: " + io);
87 }
88 }
89
90 /**
91 * generate Excel tabsheet 2 containing the summary tables obtained by parsing the XML file
92 */
93 public static void parseXML(XSSFWorkbook wb, XSSFRow myRow, XSSFCell myCell, String XMLFile){
94 XSSFSheet sheet2 = wb.createSheet("summary tables");
95 new XMLToExcel(wb, sheet2, myRow, myCell, XMLFile);
96 }
97
98 /**
99 * generate tabsheet3: write the iprscan results in the .raw file to Excel, tabsheet "iprscan results"
100 */
101 public static void parseRaw(XSSFWorkbook wb, XSSFRow myRow, XSSFCell myCell, String rawFile){
102 XSSFSheet sheet3 = wb.createSheet("iprscan results");
103 new RawToExcel(wb, sheet3,myRow, myCell, rawFile);
104 }
105 }