22
33
44import org .w3c .dom .Document ;
5- import javax .xml .parsers .ParserConfigurationException ;
6- import javax .xml .transform .TransformerException ;
7- import java .io .IOException ;
8- import java .util .ArrayList ;
95import java .util .List ;
106import java .util .logging .Level ;
117import java .util .logging .Logger ;
@@ -23,35 +19,20 @@ public class Main {
2319public static void main (String []args ) {
2420
2521//Arg validator
26- if (args .length == 0 ) {
22+ if (args .length < 2 ) {
2723logger .log (Level .SEVERE ,"No args were specified." );
28- System .exit (0 );
24+ System .exit (1 );
2925 }
3026//Vars Initialization
3127String csvFile =args [0 ];
3228String xmlFile =args [1 ];
33- String elementName ;
34- String csvSplit =",(?=([^\" ]*\" [^\" ]*\" )*[^\" ]*$)" ;
35-
36- try {
37- elementName =args [2 ];
38- }catch (ArrayIndexOutOfBoundsException e ) {
39- logger .log (Level .INFO ,"Since you didn't specify a element name, 'element' will be the parental node." );
40- elementName ="element" ;
41- }
42-
43- try {
44- if (args [3 ] =="-s" )
45- csvSplit =";(?=([^\" ]*\" [^\" ]*\" )*[^\" ]*$)" ;
46- }catch (ArrayIndexOutOfBoundsException e ){
47- }
29+ String elementName =args .length >=3 && !args [3 ].equals ("-s" ) ?args [2 ] :"element" ;
30+ String csvSplit = (args .length >3 &&args [3 ].equals ("-s" ) ||args .length >4 &&args [4 ].equals ("-s" )) ?";(?=([^\" ]*\" [^\" ]*\" )*[^\" ]*$)" :",(?=([^\" ]*\" [^\" ]*\" )*[^\" ]*$)" ;
4831
49- List <String []>elements ;
50- elements =XMLutils .readCsvFile (csvFile ,csvSplit );
51- Document xmlDoc ;
52- xmlDoc =XMLutils .createXmlDocument (elements ,elementName );
53- XMLutils .writeXmlDocumentToFile (xmlDoc ,xmlFile );
54- }
32+ List <String []>elements =XMLutils .readCsvFile (csvFile ,csvSplit );
33+ Document xmlDoc =XMLutils .createXmlDocument (elements ,elementName );
34+ XMLutils .writeXmlDocumentToFile (xmlDoc ,xmlFile );
35+ }
5536 }
5637
5738