1 17 18 19 20 package org.apache.lenya.xml; 21 22 import java.net.URL ; 23 import java.util.Properties ; 24 25 import org.apache.log4j.Category; 26 27 28 32 public class Configuration { 33 static Category log = Category.getInstance(Configuration.class); 34 public static final String DEFAULT_CONFIGURATION_FILE = "org/apache/lenya/xml/xpsconf.properties"; 35 public static final String DEFAULT_CONFIGURATION_KEY = "xps.configuration"; 36 public static final String OVERRIDE_DEFAULT_CONFIGURATION_KEY = "override.xps.configuration"; 37 public String cacheFolder = null; 38 public boolean cacheHTTP = false; 39 public String INCLUDE = null; 40 public String JAVA_ZONE = null; 41 public String proxyHost = null; 42 public String proxyPort = null; 43 44 47 public Configuration() { 48 getProperties(load()); 49 } 50 51 58 public static void main(String [] args) { 59 Configuration conf = new Configuration(); 60 61 System.out.println("Caching directory: " + conf.cacheFolder); 62 System.out.println("Cache xml from http connections: " + conf.cacheHTTP); 63 64 if ((conf.proxyHost != null) && (conf.proxyHost != null)) { 65 System.out.println("Proxy set:"); 66 System.out.println(conf.proxyHost); 67 System.out.println(conf.proxyPort); 68 } else { 69 System.out.println("No proxy set."); 70 } 71 } 72 73 78 public static Properties load() { 79 String resourcePathRelativeToClasspath = System.getProperty(OVERRIDE_DEFAULT_CONFIGURATION_KEY); 80 81 if (resourcePathRelativeToClasspath == null) { 82 resourcePathRelativeToClasspath = System.getProperty(DEFAULT_CONFIGURATION_KEY, 83 DEFAULT_CONFIGURATION_FILE); 84 log.debug(DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath); 85 } else { 86 log.debug(OVERRIDE_DEFAULT_CONFIGURATION_KEY + "=" + resourcePathRelativeToClasspath); 87 } 88 89 ClassLoader cl = ClassLoader.getSystemClassLoader(); 90 91 URL url = org.apache.log4j.helpers.Loader.getResource("hallo"); 93 94 if (url == null) { 95 } 97 98 log.debug(url); 99 100 Properties properties = new Properties (); 101 102 try { 103 properties.load(Configuration.class.getResourceAsStream("xpsconf.properties")); 104 } catch (Exception e) { 105 log.error(".load(): " + e); 106 } 107 108 return properties; 109 } 110 111 116 public void getProperties(Properties properties) { 117 if (properties != null) { 118 cacheFolder = getProperty(properties, 119 "org.apache.lenya.xps.XLinkInterpreter.cacheFolder"); 120 cacheHTTP = false; 121 INCLUDE = getProperty(properties, "Include"); 122 JAVA_ZONE = getProperty(properties, "JavaZone"); 123 proxyHost = null; 124 proxyPort = null; 125 } 126 } 127 128 136 public String getProperty(Properties properties, String key) { 137 String value = properties.getProperty(key); 138 139 if (value != null) { 140 log.debug(key + "=" + value); 141 142 return value; 143 } else { 144 log.debug(".getProperty(): No such property: " + key); 145 } 146 147 return null; 148 } 149 150 153 public static void register() { 154 } 155 } 156 | Popular Tags |