1
2
3
4
5
6
7 package org.wiztools.xml2spreadsheet;
8
9 import org.wiztools.xml2spreadsheet.exception.XML2XLSFatalException;
10 import org.wiztools.xml2spreadsheet.poiimpl.POIColor;
11 import java.io.FileInputStream;
12 import java.io.FileNotFoundException;
13 import java.io.FileOutputStream;
14 import java.io.IOException;
15 import java.io.PrintStream;
16 import java.util.Collection;
17
18
19 /***
20 *
21 * @author subhash
22 */
23 public class ConvertMain {
24
25 private static void print(PrintStream ps, String msg){
26 ps.println(msg);
27 }
28
29 private static String getHelpText(){
30 String help = "Give following arguments:\n"
31 + "\t1. XML input filename\n"
32 + "\t2. XLS output filename\n";
33 return help;
34 }
35
36 /***
37 * The main method
38 */
39 public static void main(String[] arg) {
40 if(arg.length == 1){
41 if("-h".equals(arg[0]) || "--help".equals(arg[0])){
42 print(System.out, getHelpText());
43 System.exit(0);
44 } else if("--colors".equals(arg[0])){
45 print(System.out, "The colors supported: \n");
46 Collection<String> colors = POIColor.getInstance().getSupportedColors();
47 for(String color: colors){
48 print(System.out, color);
49 }
50 System.exit(0);
51 } else{
52 print(System.err, getHelpText());
53 System.exit(-1);
54 }
55 } else if(arg.length != 2){
56 print(System.err, getHelpText());
57 System.exit(-1);
58 }
59
60 try{
61 XML2SpreadSheet.convert(new FileInputStream(arg[0]),
62 new FileOutputStream(arg[1]));
63 } catch(FileNotFoundException fnfe){
64 print(System.err, "FileNotFoundException occurred!");
65 fnfe.printStackTrace(System.err);
66 } catch(IOException ioe){
67 print(System.err, "IOException occurred!");
68 ioe.printStackTrace(System.err);
69 } catch(XML2XLSFatalException e){
70 print(System.err, "Error occurred: "+e.getMessage());
71 e.printStackTrace(System.err);
72 }
73 }
74 }
75