1 package net.sourceforge.tracelog.config; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.FileOutputStream ; 6 import java.io.ObjectInputStream ; 7 import java.io.ObjectOutputStream ; 8 import java.util.LinkedList ; 9 import java.util.List ; 10 11 12 import org.apache.log4j.Logger; 13 import org.eclipse.swt.SWT; 14 15 21 public class OldConfigFile extends ConfigFile { 22 private static Logger log = Logger.getLogger(OldConfigFile.class); 23 24 27 OldConfigFile() { 28 super(); 29 super.configFile = new File (System.getProperty("user.home") + projectProperties.getOldConfigFilePath()); 30 } 31 32 37 @SuppressWarnings ("unchecked") 38 public List <LogBean> getConfig() { 39 40 List <LogBean> logBeanList = null; 41 42 if (super.isConfigFileExists()) { 44 try { 45 ObjectInputStream ois = new ObjectInputStream (new FileInputStream (configFile)); 46 logBeanList = (List ) ois.readObject(); 47 ois.close(); 48 } 49 catch (Exception e) { 50 log.error("Cannot read log file: " + e.getMessage()); 51 } 52 } 53 else { 54 try { 55 configFile.getParentFile().mkdirs(); 57 58 configFile.createNewFile(); 60 } 61 catch (Exception e) { 62 log.error("Cannot create configuration folder: " + e.getMessage()); 63 } 64 } 65 66 if (logBeanList == null) { 70 logBeanList = getDefaultServerLogConfiguration(); 71 saveConfig(logBeanList); 72 } 73 74 return logBeanList; 75 } 76 77 83 public void saveConfig(List <LogBean> logBeanList) { 84 try { 85 ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream (configFile)); 86 oos.writeObject(logBeanList); 87 oos.close(); 88 } 89 catch (Exception e) { 90 e.printStackTrace(); 91 } 92 } 93 94 99 private List <LogBean> getDefaultServerLogConfiguration() { 100 List <LogBean> logBeanList = new LinkedList <LogBean>(); 101 102 String [] sampleServerConfigs = projectProperties.getSampleServerConfigs(); 103 104 for (int i = 0; i < sampleServerConfigs.length; ++i) { 105 String logName = sampleServerConfigs[i].substring(0, sampleServerConfigs[i].indexOf("|")); 106 String logPath = sampleServerConfigs[i].substring(sampleServerConfigs[i].indexOf("|") + 1); 107 logBeanList.add(new LogBean((i + 1), logName, logPath, SWT.COLOR_BLACK, SWT.COLOR_WHITE)); 108 } 109 110 return logBeanList; 111 } 113 114 @Override 115 public UserConfig getUserConfig() { 116 try { 117 throw new Exception ("Not implemented"); 118 } 119 catch (Exception e) { 120 log.error(e); 121 e.printStackTrace(); 122 } 123 124 return null; 125 } 126 127 @Override 128 public void saveUserConfig(UserConfig userConfig) { 129 try { 130 throw new Exception ("Not implemented"); 131 } 132 catch (Exception e) { 133 log.error(e); 134 e.printStackTrace(); 135 } 136 } 137 138 } 139 | Popular Tags |