1 17 18 19 package org.apache.catalina.startup; 20 21 import java.io.File ; 22 import java.io.FileInputStream ; 23 import java.io.InputStream ; 24 import java.net.URL ; 25 import java.util.Enumeration ; 26 import java.util.Properties ; 27 28 29 35 36 public class CatalinaProperties { 37 38 39 41 private static org.apache.commons.logging.Log log= 42 org.apache.commons.logging.LogFactory.getLog( CatalinaProperties.class ); 43 44 private static Properties properties = null; 45 46 47 static { 48 49 loadProperties(); 50 51 } 52 53 54 56 57 60 public static String getProperty(String name) { 61 62 return properties.getProperty(name); 63 64 } 65 66 67 70 public static String getProperty(String name, String defaultValue) { 71 72 return properties.getProperty(name, defaultValue); 73 74 } 75 76 77 79 80 83 private static void loadProperties() { 84 85 InputStream is = null; 86 Throwable error = null; 87 88 try { 89 String configUrl = getConfigUrl(); 90 if (configUrl != null) { 91 is = (new URL (configUrl)).openStream(); 92 } 93 } catch (Throwable t) { 94 } 96 97 if (is == null) { 98 try { 99 File home = new File (getCatalinaBase()); 100 File conf = new File (home, "conf"); 101 File properties = new File (conf, "catalina.properties"); 102 is = new FileInputStream (properties); 103 } catch (Throwable t) { 104 } 106 } 107 108 if (is == null) { 109 try { 110 is = CatalinaProperties.class.getResourceAsStream 111 ("/org/apache/catalina/startup/catalina.properties"); 112 } catch (Throwable t) { 113 } 115 } 116 117 if (is != null) { 118 try { 119 properties = new Properties (); 120 properties.load(is); 121 is.close(); 122 } catch (Throwable t) { 123 error = t; 124 } 125 } 126 127 if ((is == null) || (error != null)) { 128 log.warn("Failed to load catalina.properties", error); 130 properties=new Properties (); 132 } 133 134 Enumeration enumeration = properties.propertyNames(); 136 while (enumeration.hasMoreElements()) { 137 String name = (String ) enumeration.nextElement(); 138 String value = properties.getProperty(name); 139 if (value != null) { 140 System.setProperty(name, value); 141 } 142 } 143 144 } 145 146 147 150 private static String getCatalinaHome() { 151 return System.getProperty("catalina.home", 152 System.getProperty("user.dir")); 153 } 154 155 156 159 private static String getCatalinaBase() { 160 return System.getProperty("catalina.base", getCatalinaHome()); 161 } 162 163 164 167 private static String getConfigUrl() { 168 return System.getProperty("catalina.config"); 169 } 170 171 172 } 173 | Popular Tags |