1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package inc.che.common.config;
20
21
22 import inc.che.common.resource.ResourceManager;
23 import inc.che.common.resource.StringResources;
24 import inc.che.common.string.StringUtil;
25
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.util.Date;
31 import java.util.Iterator;
32 import java.util.Properties;
33
34 import org.apache.log4j.Logger;
35
36 /***
37 * <b>Lädt uns Speichert Konfigurationsparameter aus einer Propertydatei</b>
38 * @version $Id: PropertyConfigLoader.java,v 1.1 2005/03/06 12:56:50 stevemcmee Exp $
39 * @author <address> Steve McMee <stevemcmee@users.sourceforge.net></address>
40 */
41
42 public class PropertyConfigLoader extends ConfigLoader {
43
44 /*** CVS ID of this file */
45 public static final String CVS_ID =
46 "$Id: PropertyConfigLoader.java,v 1.1 2005/03/06 12:56:50 stevemcmee Exp $";
47
48 /***
49 * logger instance for this class
50 */
51
52 private static Logger log = Logger.getLogger(PropertyConfigLoader.class);
53
54 /***
55 * The ResourceManager
56 */
57 private static ResourceManager resourceManager =
58 ResourceManager.getResourceManager(StringResources.TEXT_RESOURCES);
59
60 /***
61 * stores Properties into a File
62 *@param configFile File holds the properties
63 *@param properties Properties to store
64 */
65 public void storeProperties(File configFile, Properties properties)
66 throws IOException {
67 if (log.isDebugEnabled()) {
68 log.debug(
69 "storeProperties (" + configFile + "," + properties + ")");
70 }
71 properties.store(
72 new FileOutputStream(configFile),
73 resourceManager.getText(
74 "props_store_header",
75 new String[] {
76 new Date().toString(),
77 System.getProperty("user.name")}));
78 }
79
80 public Properties loadProperties(File configFile) throws IOException {
81 if (log.isDebugEnabled()) {
82 log.debug("loadProperties(" + configFile + ")");
83 }
84 Properties erg = new Properties();
85 Properties props = new Properties();
86 props.load(new FileInputStream(configFile));
87
88 Properties sysProps = System.getProperties();
89 String value;
90 String key;
91 String sysKey;
92 for (Iterator it = props.keySet().iterator(); it.hasNext();) {
93 key = (String) it.next();
94 value = props.getProperty(key);
95 value = StringUtil.replaceSystemProperties(value);
96 erg.setProperty(key, value);
97 }
98 return erg;
99 }
100
101 }