| 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 |
|
|
| 22 |
|
|
| 23 |
0 |
public class ConvertMain { |
| 24 |
|
|
| 25 |
|
private static void print(PrintStream ps, String msg){ |
| 26 |
0 |
ps.println(msg); |
| 27 |
0 |
} |
| 28 |
|
|
| 29 |
|
private static String getHelpText(){ |
| 30 |
0 |
String help = "Give following arguments:\n" |
| 31 |
|
+ "\t1. XML input filename\n" |
| 32 |
|
+ "\t2. XLS output filename\n"; |
| 33 |
0 |
return help; |
| 34 |
|
} |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
public static void main(String[] arg) { |
| 40 |
84 |
if(arg.length == 1){ |
| 41 |
0 |
if("-h".equals(arg[0]) || "--help".equals(arg[0])){ |
| 42 |
0 |
print(System.out, getHelpText()); |
| 43 |
0 |
System.exit(0); |
| 44 |
0 |
} else if("--colors".equals(arg[0])){ |
| 45 |
0 |
print(System.out, "The colors supported: \n"); |
| 46 |
0 |
Collection<String> colors = POIColor.getInstance().getSupportedColors(); |
| 47 |
0 |
for(String color: colors){ |
| 48 |
0 |
print(System.out, color); |
| 49 |
0 |
} |
| 50 |
0 |
System.exit(0); |
| 51 |
0 |
} else{ |
| 52 |
0 |
print(System.err, getHelpText()); |
| 53 |
0 |
System.exit(-1); |
| 54 |
0 |
} |
| 55 |
69 |
} else if(arg.length != 2){ |
| 56 |
0 |
print(System.err, getHelpText()); |
| 57 |
0 |
System.exit(-1); |
| 58 |
15 |
} |
| 59 |
0 |
|
| 60 |
0 |
try{ |
| 61 |
69 |
XML2SpreadSheet.convert(new FileInputStream(arg[0]), |
| 62 |
57 |
new FileOutputStream(arg[1])); |
| 63 |
0 |
} catch(FileNotFoundException fnfe){ |
| 64 |
72 |
print(System.err, "FileNotFoundException occurred!"); |
| 65 |
72 |
fnfe.printStackTrace(System.err); |
| 66 |
57 |
} catch(IOException ioe){ |
| 67 |
15 |
print(System.err, "IOException occurred!"); |
| 68 |
15 |
ioe.printStackTrace(System.err); |
| 69 |
15 |
} catch(XML2XLSFatalException e){ |
| 70 |
0 |
print(System.err, "Error occurred: "+e.getMessage()); |
| 71 |
0 |
e.printStackTrace(System.err); |
| 72 |
12 |
} |
| 73 |
12 |
} |
| 74 |
0 |
} |
| 75 |
0 |
|