01: /**
02: * Copyright (C) 2006, 2007 David Bulmore, Software Sensation Inc.
03: * All Rights Reserved.
04: *
05: * This file is part of jCommonTk.
06: *
07: * jCommonTk is free software; you can redistribute it and/or modify it under
08: * the terms of the GNU General Public License (Version 2) as published by
09: * the Free Software Foundation.
10: *
11: * jCommonTk is distributed in the hope that it will be useful, but WITHOUT
12: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with jCommonTk; if not, write to the Free Software Foundation,
18: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19: */package jcommontk.utils;
20:
21: import java.io.FileNotFoundException;
22: import java.net.URL;
23: import java.util.Properties;
24: import java.util.Enumeration;
25: import java.util.logging.Level;
26: import java.util.logging.Logger;
27:
28: /**
29: * Contains properties from the application.properties file along with system properties.
30: * These properties are passed to the server and can be obtained within the
31: * install&update script from $script.getClientInfo().
32: */
33: public class ApplicationProperties {
34: private static Logger logger = Logger
35: .getLogger(ApplicationProperties.class.getName());
36:
37: static Properties props;
38: static URL url;
39:
40: private ApplicationProperties() {
41: }
42:
43: public static synchronized Properties getProperties() {
44: if (props == null)
45: props = loadProperties();
46:
47: return props;
48: }
49:
50: public static void setPropertiesFile(URL url) {
51: ApplicationProperties.url = url;
52: }
53:
54: public static Properties loadProperties() {
55: try {
56: if (url == null)
57: url = ClassLoader
58: .getSystemResource("application.properties");
59:
60: if (url == null)
61: throw new FileNotFoundException(
62: "application.properties");
63:
64: props = new Properties();
65: props.load(url.openStream());
66:
67: Enumeration e = System.getProperties().propertyNames();
68: String key;
69:
70: while (e.hasMoreElements()) {
71: key = (String) e.nextElement();
72: props.setProperty(key, System.getProperty(key));
73: }
74:
75: return props;
76: } catch (Exception e) {
77: logger.log(Level.SEVERE, e.toString(), e);
78: }
79:
80: return null;
81: }
82: }
|