package org.greenstone.gsdl3.util; import java.util.Properties; import java.io.File; import java.io.InputStream; import org.apache.log4j.*; /** holds some global properties for the application. Read from a properties file */ public class GlobalProperties { static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.GlobalProperties.class.getName()); private static Properties properties = null; private static String properties_filename = "global.properties"; private static String gsdl3_home = null; private static String gsdl3_web_address = null; // Note, that if the servlet is reloadable, then it is reloaded each time the file is changed. static { //load in the properties properties = new Properties(); reload(); } /** get the value of the property 'key'. returns null if not found */ public static String getProperty(String key) { return properties.getProperty(key); } /** get the value of the property 'key'. * returns default_value if not found */ public static String getProperty(String key, String default_value) { return properties.getProperty(key, default_value); } /** some special ones */ public static String getGSDL3Home() { return gsdl3_home; } public static String getGSDL3WebAddress() { return gsdl3_web_address; } public static void reload() { try { InputStream in = Class.forName("org.greenstone.gsdl3.util.GlobalProperties").getClassLoader().getResourceAsStream(properties_filename); if (in != null) { logger.error("loading global properties"); properties.load(in); in.close(); } else { logger.error("couldn't load global properties!"); } gsdl3_home = properties.getProperty("gsdl3.home"); // make sure the path separators are correct File gs3_file = new File(gsdl3_home); gsdl3_home = gs3_file.getPath(); gsdl3_web_address = "http://"+ properties.getProperty("tomcat.server")+":"+ properties.getProperty("tomcat.port")+"/"+properties.getProperty("tomcat.context"); } catch (Exception e) { logger.error("Exception trying to reload global.properties: "+e); } } }