1 43 package net.jforum; 44 45 import java.io.File ; 46 import java.io.FileInputStream ; 47 import java.io.IOException ; 48 import java.util.Iterator ; 49 import java.util.Map ; 50 import java.util.Properties ; 51 52 import net.jforum.cache.CacheEngine; 53 import net.jforum.cache.Cacheable; 54 import net.jforum.dao.DataAccessDriver; 55 import net.jforum.exceptions.CacheEngineStartupException; 56 import net.jforum.summary.SummaryScheduler; 57 import net.jforum.util.FileMonitor; 58 import net.jforum.util.preferences.ConfigKeys; 59 import net.jforum.util.preferences.QueriesFileListener; 60 import net.jforum.util.preferences.SystemGlobals; 61 import net.jforum.util.preferences.SystemGlobalsListener; 62 import net.jforum.util.search.SearchFacade; 63 64 import org.apache.log4j.Logger; 65 import org.quartz.SchedulerException; 66 67 73 public class ConfigLoader 74 { 75 private static final Logger logger = Logger.getLogger(ConfigLoader.class); 76 private static CacheEngine cache; 77 78 87 public static void startSystemglobals(String appPath) throws Exception 88 { 89 SystemGlobals.initGlobals(appPath, appPath + "/WEB-INF/config/SystemGlobals.properties"); 90 SystemGlobals.loadAdditionalDefaults(SystemGlobals.getValue(ConfigKeys.DATABASE_DRIVER_CONFIG)); 91 92 if (new File (SystemGlobals.getValue(ConfigKeys.INSTALLATION_CONFIG)).exists()) { 93 SystemGlobals.loadAdditionalDefaults(SystemGlobals.getValue(ConfigKeys.INSTALLATION_CONFIG)); 94 } 95 } 96 97 104 public static Properties loadModulesMapping(String baseConfigDir) throws IOException 105 { 106 Properties modulesMapping = new Properties (); 107 modulesMapping.load(new FileInputStream (baseConfigDir + "/modulesMapping.properties")); 108 109 return modulesMapping; 110 } 111 112 118 public static void loadUrlPatterns() throws IOException { 119 Properties p = new Properties (); 120 p.load(new FileInputStream (SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) 121 + "/urlPattern.properties")); 122 123 Iterator iter = p.entrySet().iterator(); 124 while (iter.hasNext()) { 125 Map.Entry entry = (Map.Entry ) iter.next(); 126 127 ActionServletRequest.addUrlPattern((String )entry.getKey(), (String )entry.getValue()); 128 } 129 } 130 131 137 public static void listenForChanges() 138 { 139 int fileChangesDelay = SystemGlobals.getIntValue(ConfigKeys.FILECHANGES_DELAY); 140 141 if (fileChangesDelay > 0) { 142 FileMonitor.getInstance().addFileChangeListener(new QueriesFileListener(), 144 SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_GENERIC), fileChangesDelay); 145 146 FileMonitor.getInstance().addFileChangeListener(new QueriesFileListener(), 147 SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_DRIVER), fileChangesDelay); 148 149 FileMonitor.getInstance().addFileChangeListener(new SystemGlobalsListener(), 151 SystemGlobals.getValue(ConfigKeys.DEFAULT_CONFIG), fileChangesDelay); 152 153 ConfigLoader.listenInstallationConfig(); 154 } 155 } 156 157 public static void listenInstallationConfig() 158 { 159 int fileChangesDelay = SystemGlobals.getIntValue(ConfigKeys.FILECHANGES_DELAY); 160 161 if (fileChangesDelay > 0) { 162 if (new File (SystemGlobals.getValue(ConfigKeys.INSTALLATION_CONFIG)).exists()) { 163 FileMonitor.getInstance().addFileChangeListener(new SystemGlobalsListener(), 164 SystemGlobals.getValue(ConfigKeys.INSTALLATION_CONFIG), fileChangesDelay); 165 } 166 } 167 } 168 169 public static void loadDaoImplementation() throws Exception 170 { 171 172 String driver = SystemGlobals.getValue(ConfigKeys.DAO_DRIVER); 174 175 logger.info("Loading JDBC driver " + driver); 176 177 Class c = Class.forName(driver); 178 DataAccessDriver d = (DataAccessDriver)c.newInstance(); 179 DataAccessDriver.init(d); 180 } 181 182 public static void startCacheEngine() 183 { 184 try { 185 String cacheImplementation = SystemGlobals.getValue(ConfigKeys.CACHE_IMPLEMENTATION); 186 logger.info("Using cache engine: " + cacheImplementation); 187 188 cache = (CacheEngine)Class.forName(cacheImplementation).newInstance(); 189 cache.init(); 190 191 String s = SystemGlobals.getValue(ConfigKeys.CACHEABLE_OBJECTS); 192 if (s == null || s.trim().equals("")) { 193 logger.warn("Cannot find Cacheable objects to associate the cache engine instance."); 194 return; 195 } 196 197 String [] cacheableObjects = s.split(","); 198 for (int i = 0; i < cacheableObjects.length; i++) { 199 logger.info("Creating an instance of " + cacheableObjects[i]); 200 Object o = Class.forName(cacheableObjects[i].trim()).newInstance(); 201 202 if (o instanceof Cacheable) { 203 ((Cacheable)o).setCacheEngine(cache); 204 } 205 else { 206 logger.error(cacheableObjects[i] + " is not an instance of net.jforum.cache.Cacheable"); 207 } 208 } 209 } 210 catch (Exception e) { 211 throw new CacheEngineStartupException("Error while starting the cache engine", e); 212 } 213 } 214 215 public static void stopCacheEngine() 216 { 217 if (cache != null) { 218 cache.stop(); 219 } 220 } 221 222 public static void startSearchIndexer() 223 { 224 SearchFacade.init(); 225 } 226 227 232 public static void startSummaryJob() throws SchedulerException, IOException { 233 SummaryScheduler.startJob(); 234 } 235 } 236 | Popular Tags |