source: greenstone3/trunk/src/java/org/greenstone/gsdl3/util/GlobalProperties.java@ 14641

Last change on this file since 14641 was 13270, checked in by shaoqun, 17 years ago

replace Category class which is deprecated with Logger class

  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1package org.greenstone.gsdl3.util;
2
3import java.util.Properties;
4import java.io.File;
5import java.io.InputStream;
6
7import org.apache.log4j.*;
8
9/** holds some global properties for the application. Read from a properties file */
10public class GlobalProperties {
11
12
13 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.GlobalProperties.class.getName());
14 private static Properties properties = null;
15 private static String properties_filename = "global.properties";
16 private static String gsdl3_home = null;
17 private static String gsdl3_web_address = null;
18
19 // Note, that if the servlet is reloadable, then it is reloaded each time the file is changed.
20 static {
21 //load in the properties
22 properties = new Properties();
23 reload();
24 }
25
26 /** get the value of the property 'key'. returns null if not found */
27 public static String getProperty(String key) {
28 return properties.getProperty(key);
29 }
30
31 /** get the value of the property 'key'.
32 * returns default_value if not found */
33 public static String getProperty(String key, String default_value) {
34 return properties.getProperty(key, default_value);
35 }
36
37 /** some special ones */
38 public static String getGSDL3Home() {
39 return gsdl3_home;
40 }
41
42 public static String getGSDL3WebAddress() {
43 return gsdl3_web_address;
44 }
45
46 public static void reload() {
47 try {
48 InputStream in = Class.forName("org.greenstone.gsdl3.util.GlobalProperties").getClassLoader().getResourceAsStream(properties_filename);
49 if (in != null) {
50 logger.error("loading global properties");
51 properties.load(in);
52 in.close();
53 } else {
54 logger.error("couldn't load global properties!");
55 }
56 gsdl3_home = properties.getProperty("gsdl3.home");
57 // make sure the path separators are correct
58 File gs3_file = new File(gsdl3_home);
59 gsdl3_home = gs3_file.getPath();
60 gsdl3_web_address = "http://"+ properties.getProperty("tomcat.server")+":"+ properties.getProperty("tomcat.port")+"/"+properties.getProperty("tomcat.context");
61 } catch (Exception e) {
62 logger.error("Exception trying to reload global.properties: "+e);
63 }
64
65 }
66}
Note: See TracBrowser for help on using the repository browser.