Ejemplo n.º 1
0
  public void init(ServletConfig config) throws ServletException {
    super.init(config);

    try {
      String appPath = config.getServletContext().getRealPath("");
      // 是否为开发mode
      debug = "true".equals(config.getInitParameter("development"));
      // 读取log4j.xml配置文件
      DOMConfigurator.configure(appPath + "/WEB-INF/log4j.xml");

      logger.info("Starting JForum. Debug mode is " + debug);
      //
      ConfigLoader.startSystemglobals(appPath);
      // 启动缓存引擎
      ConfigLoader.startCacheEngine();

      // Configure the template engine
      Configuration templateCfg = new Configuration();
      templateCfg.setTemplateUpdateDelay(2);
      templateCfg.setSetting("number_format", "#");
      templateCfg.setSharedVariable("startupTime", new Long(new Date().getTime()));

      // Create the default template loader
      String defaultPath = SystemGlobals.getApplicationPath() + "/templates";
      FileTemplateLoader defaultLoader = new FileTemplateLoader(new File(defaultPath));

      String extraTemplatePath = SystemGlobals.getValue(ConfigKeys.FREEMARKER_EXTRA_TEMPLATE_PATH);

      if (StringUtils.isNotBlank(extraTemplatePath)) {
        // An extra template path is configured, we need a MultiTemplateLoader
        FileTemplateLoader extraLoader = new FileTemplateLoader(new File(extraTemplatePath));
        TemplateLoader[] loaders = new TemplateLoader[] {extraLoader, defaultLoader};
        MultiTemplateLoader multiLoader = new MultiTemplateLoader(loaders);
        templateCfg.setTemplateLoader(multiLoader);
      } else {
        // An extra template path is not configured, we only need the default loader
        templateCfg.setTemplateLoader(defaultLoader);
      }
      // 载入模块
      ModulesRepository.init(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR));

      this.loadConfigStuff();

      if (!this.debug) {
        templateCfg.setTemplateUpdateDelay(3600);
      }

      JForumExecutionContext.setTemplateConfig(templateCfg);
    } catch (Exception e) {
      throw new ForumStartupException("Error while starting JForum", e);
    }
  }