99public class Main {
1010 /**
1111 * Executes the CSV to XML conversion
12- * @param args file input and output
13- *
12+ * @author Daniel Apesteguia Timoner
13+ * @param args Input file, output file and elements names.
1414 */
1515 public static void main (String [] args ){
1616 //Arg validator
@@ -24,14 +24,21 @@ public static void main(String[] args){
2424 //Vars Initialization
2525 String csvFile = args [0 ];
2626 String xmlFile = args [1 ];
27- String elementName = args [2 ];
27+ String elementName ;
28+ try {
29+ elementName = args [2 ];}
30+ catch (ArrayIndexOutOfBoundsException e ){
31+ System .out .println ("You didn't especify any element so we will fix 'element' as parental node." );
32+ elementName = "element" ;
33+ }
34+
2835
2936 //ArrayList of ArrayStrings Generation with CSV
30- ArrayList <String []> elements = null ;
37+ ArrayList <String []> elements ;
3138 elements = new Reader ().CSVtoArrayList (csvFile );
3239
3340 //XML Doc Generation with ArrayList
34- Document xmlDoc = null ;
41+ Document xmlDoc ;
3542 xmlDoc = new TabularToXMLConverter ().docBuilder (elements ,elementName );
3643 TabularToXMLConverter .transformDocToFile (xmlDoc ,xmlFile );
3744
@@ -40,7 +47,7 @@ public static void main(String[] args){
4047 System .out .println ("File wasn't found, error: " +e );
4148 }
4249 catch (TransformerException e ){
43- System .out .println ("Transformer error: " +e );;
50+ System .out .println ("Transformer error: " +e );
4451 }
4552 catch (ParserConfigurationException e ) {
4653 System .out .println ("Configuration error: " +e );
0 commit comments