1 43 package net.jforum; 44 45 import java.io.File ; 46 import java.util.Date ; 47 48 import javax.servlet.ServletConfig ; 49 import javax.servlet.ServletException ; 50 import javax.servlet.http.HttpServlet ; 51 52 import net.jforum.exceptions.ForumStartupException; 53 import net.jforum.repository.BBCodeRepository; 54 import net.jforum.repository.ModulesRepository; 55 import net.jforum.repository.Tpl; 56 import net.jforum.util.I18n; 57 import net.jforum.util.bbcode.BBCodeHandler; 58 import net.jforum.util.preferences.ConfigKeys; 59 import net.jforum.util.preferences.SystemGlobals; 60 61 import org.apache.log4j.Logger; 62 import org.apache.log4j.xml.DOMConfigurator; 63 64 import freemarker.template.Configuration; 65 66 70 public class JForumBaseServlet extends HttpServlet 71 { 72 private static Logger logger = Logger.getLogger(JForumBaseServlet.class); 73 74 protected boolean debug; 75 76 protected void startFrontController() 77 { 78 try { 79 SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_GENERIC)); 80 SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_DRIVER)); 81 82 ConfigLoader.loadDaoImplementation(); 83 ConfigLoader.listenForChanges(); 84 ConfigLoader.startSearchIndexer(); 85 ConfigLoader.startSummaryJob(); 86 } 87 catch (Exception e) { 88 throw new ForumStartupException("Error while starting JForum", e); 89 } 90 } 91 92 public void init(ServletConfig config) throws ServletException 93 { 94 super.init(config); 95 96 try { 97 String appPath = config.getServletContext().getRealPath(""); 98 debug = "true".equals(config.getInitParameter("development")); 99 100 DOMConfigurator.configure(appPath + "/WEB-INF/log4j.xml"); 101 102 logger.info("Starting JForum. Debug mode is " + debug); 103 104 ConfigLoader.startSystemglobals(appPath); 105 ConfigLoader.startCacheEngine(); 106 107 Configuration templateCfg = new Configuration(); 109 templateCfg.setDirectoryForTemplateLoading(new File (SystemGlobals.getApplicationPath() + "/templates")); 110 templateCfg.setTemplateUpdateDelay(2); 111 templateCfg.setSetting("number_format", "#"); 112 templateCfg.setSharedVariable("startupTime", new Long (new Date ().getTime())); 113 114 ModulesRepository.init(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR)); 115 116 this.loadConfigStuff(); 117 118 if (!this.debug) { 119 templateCfg.setTemplateUpdateDelay(3600); 120 } 121 122 JForumExecutionContext.setTemplateConfig(templateCfg); 123 } 124 catch (Exception e) { 125 throw new ForumStartupException("Error while starting JForum", e); 126 } 127 } 128 129 protected void loadConfigStuff() throws Exception 130 { 131 ConfigLoader.loadUrlPatterns(); 132 I18n.load(); 133 Tpl.load(SystemGlobals.getValue(ConfigKeys.TEMPLATES_MAPPING)); 134 135 BBCodeRepository.setBBCollection(new BBCodeHandler().parse()); 137 } 138 } 139 | Popular Tags |