1 17 18 19 20 package org.apache.lenya.net; 21 22 import java.net.URL ; 23 import java.util.Properties ; 24 25 import org.apache.log4j.Category; 26 27 28 31 public class Configuration { 32 static Category log = Category.getInstance(Configuration.class); 33 public static final String DEFAULT_CONFIGURATION_FILE = "org/apache/lenya/net/conf.properties"; 34 public static final String DEFAULT_CONFIGURATION_KEY = "lenya.configuration"; 35 public static final String OVERRIDE_DEFAULT_CONFIGURATION_KEY = "override.lenya.configuration"; 36 public String configurationPath = null; 37 public String smtpHost = null; 38 public String smtpPort = null; 39 public String smtpDomain = null; 40 41 44 public Configuration() { 45 getProperties(load()); 46 } 47 48 55 public static void main(String [] args) { 56 Configuration conf = new Configuration(); 57 58 System.out.println("Proxy Manager Configuration Path: " + conf.configurationPath); 59 System.out.println("SMTP Host: " + conf.smtpHost); 60 System.out.println("SMTP Port: " + conf.smtpPort); 61 System.out.println("SMTP Domain: " + conf.smtpDomain); 62 } 63 64 69 public static Properties load() { 70 String resourcePathRelativeToClasspath = System.getProperty(OVERRIDE_DEFAULT_CONFIGURATION_KEY); 71 72 if (resourcePathRelativeToClasspath == null) { 73 resourcePathRelativeToClasspath = System.getProperty(DEFAULT_CONFIGURATION_KEY, DEFAULT_CONFIGURATION_FILE); 74 log.debug(DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath); 75 } else { 76 log.debug(OVERRIDE_DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath); 77 } 78 79 URL url = Configuration.class.getClassLoader().getResource(resourcePathRelativeToClasspath); 80 81 if (url == null) { 82 log.error(".load(): Could not find resource on classpath: " + resourcePathRelativeToClasspath); 83 } 84 85 log.debug(url); 86 87 Properties properties = new Properties (); 88 89 try { 90 properties.load(Configuration.class.getResourceAsStream("conf.properties")); 91 } catch (Exception e) { 92 log.error(e); 93 } 94 95 return properties; 96 } 97 98 103 public void getProperties(Properties properties) { 104 if (properties != null) { 105 configurationPath = getProperty(properties, "org.apache.lenya.net.ProxyManager.configurationPath"); 106 smtpHost = getProperty(properties, "org.apache.lenya.net.SMTP.host"); 107 smtpPort = getProperty(properties, "org.apache.lenya.net.SMTP.port"); 108 smtpDomain = getProperty(properties, "org.apache.lenya.net.SMTP.domain"); 109 } 110 } 111 112 120 public String getProperty(Properties properties, String key) { 121 String value = properties.getProperty(key); 122 123 if (value != null) { 124 log.debug(key + "=" + value); 125 126 return value; 127 } else { 128 log.error("No such property: " + key); 129 } 130 131 return null; 132 } 133 134 137 public static void register() { 138 } 139 } 140 | Popular Tags |