1 19 20 package org.lucane.client; 21 22 import java.util.Properties ; 23 import java.io.*; 24 25 import org.lucane.common.Logging; 26 27 35 public class LocalConfig 36 { 37 static final String CONFIG_DIRECTORY = "etc/localconfig/"; 38 39 private String app; 41 private String path; 42 private Properties properties; 43 44 50 public LocalConfig(String app) 51 { 52 this.app = app; 53 this.path = System.getProperty("user.dir") + '/' + CONFIG_DIRECTORY + 54 Client.getInstance().getMyInfos().getName() + '/' + app + ".properties"; 55 this.path = this.path.replace('\\', '/'); 56 57 this.properties = new Properties (); 58 59 try { 60 this.properties.load(new FileInputStream(this.path)); 61 } catch(FileNotFoundException fnfe) { 62 } catch(IOException ioe) { 64 Logging.getLogger().warning("Error when loading LocalConfig for " + app); 65 ioe.printStackTrace(); 66 } 67 } 68 69 75 public void set(String key, String value) 76 { 77 this.properties.setProperty(key, value); 78 } 79 80 86 public void set(String key, int value) 87 { 88 set(key, String.valueOf(value)); 89 } 90 91 97 public String get(String key) 98 { 99 return this.properties.getProperty(key); 100 } 101 102 109 public int getInt(String key, int value) 110 { 111 try { 112 return Integer.parseInt(get(key)); 113 } catch(Exception e) {} 114 115 return value; 116 } 117 118 124 public int getInt(String key) 125 { 126 return getInt(key, 0); 127 } 128 129 136 public String get(String key, String defaultValue) 137 { 138 return this.properties.getProperty(key, defaultValue); 139 } 140 141 144 public void save() 145 throws IOException 146 { 147 this.properties.store(new FileOutputStream(this.path), this.app); 148 } 149 } | Popular Tags |