1 7 package org.enhydra.convert; 8 9 import java.io.File ; 10 import java.io.IOException ; 11 import java.io.FileInputStream ; 12 import com.lutris.util.ConfigException; 13 14 20 public class Converter { 21 22 private File confFile; 23 private File xmlFile; 24 25 public Converter(){ 26 confFile = null; 27 xmlFile = null; 28 } 29 30 public static void main(String [] args) { 31 32 System.out.println("Initialization of configuration instances, please wait ..."); 33 34 ConfigFile confF = null; 35 XMLFile xmlF = new XMLFile(); 36 37 Converter converter = new Converter(); 38 39 for (int i=0; i<args.length; i++) { 40 if (args[i].equalsIgnoreCase("-in")){ 41 converter.confFile = new File (args[i+1]); 42 }else if (args[i].equalsIgnoreCase("-out")){ 43 converter.xmlFile = new File (args[i+1]); 44 }else if (args[i].equalsIgnoreCase("-desc")){ 45 if (args[i+1].equalsIgnoreCase("OFF")) 46 xmlF.setDescription(false); 47 }else if (args[i].equalsIgnoreCase("-enc")){ 48 xmlF.setEncoding(args[i+1]); 49 } 50 } 51 52 if (converter.confFile!=null && converter.xmlFile!=null){ 53 System.out.println("CONF file configuration initialization ..."); 54 try { 55 FileInputStream fInputStream = new FileInputStream (converter.confFile); 56 confF = new ConfigFile(fInputStream); 57 } catch (ConfigException ex){ 58 System.out.println("CONF configuration file has to be properly defined!"); 59 }catch (IOException ex){ 60 System.out.println("CONF configuration file doesn't exist!"); 61 } 62 if (confF!=null){ 63 System.out.println("CONF file configuration succeeded!"); 64 65 if (converter.xmlFile.exists()){ 66 System.out.println("Reading existing XML configuration ..."); 67 xmlF.read(converter.xmlFile); 68 } 69 System.out.println("Loading CONF file configuration ..."); 70 xmlF.sinhronize(confF); 71 System.out.println("Writing XML configuration file ..."); 72 xmlF.write(converter.xmlFile); 73 74 System.out.println("Configuration conversion succeeded!!!"); 75 } 76 }else { 77 System.out.println("" + 78 "Usage: conf2xml [-options]\n" + 79 "where options include:\n" + 80 "-in input CONF file\n" + 81 "-out output XML file\n" + 82 "-desc wheter to include (or not)\n" + 83 " parameter descriptions (ON/OFF)\n" + 84 " Default value is ON!\n" + 85 "-enc encoding of output XML file\n" + 86 " Default value is ISO-8859-1!"); 87 } 88 } 89 } 90 | Popular Tags |