📄 rollercontext.java
字号:
{ mLogger.warn(e); } } //------------------------------------------------------------------------ /** * Initialize the configured PagePlugins * @param mContext */ private void setupPagePlugins() { if (mLogger.isDebugEnabled()) { mLogger.debug("Initialize PagePlugins"); } ContextLoader.initializePagePlugins(mContext); } /** * Add TurnoverReferersTask to run on a schedule. */ private void setupRefererManager(Roller roller) { try { // Check for turnover when we first start final RefererManager refManager = roller.getRefererManager(); refManager.checkForTurnover(false, null); // Schedule a check every day, starting at end of today //TurnoverReferersTask task = new TurnoverReferersTask(); //task.init(roller, mContext.getRealPath("/")); //roller.getThreadManager().scheduleDailyTimerTask(task); } catch (RollerException e) { mLogger.warn("Couldn't schedule referer turnover task", e); } } //------------------------------------------------------------------------ private void setupIndexManager(Roller roller) throws RollerException { roller.getIndexManager(); } public void sessionCreated(HttpSessionEvent se) { if (mMemDebug) { mSessionCount.increment(); mContext.log( "Roller:SESSION_CREATED:count=" + mSessionCount + ":freemem=" + Runtime.getRuntime().freeMemory() + ":totmem=" + Runtime.getRuntime().totalMemory()); } } //------------------------------------------------------------------------ public void sessionDestroyed(HttpSessionEvent se) { if (mMemDebug) { mSessionCount.decrement(); mContext.log( "Roller:SESSION_DESTROY:count=" + mSessionCount + ":freemem=" + Runtime.getRuntime().freeMemory() + ":totalmem=" + Runtime.getRuntime().totalMemory()); } } //------------------------------------------------------------------------ /** * Get an instance of Roller from the RollerFactory. * If one does not exist, tell Factory to create new one. */ public static Roller getRoller(HttpServletRequest req) { return RollerFactory.getRoller(); } //------------------------------------------------------------------------ /** * Get authenticator */ public Authenticator getAuthenticator() { if (mAuthenticator == null) { try { Class authClass = Class.forName(RollerConfig.getProperty("authenticator.classname")); mAuthenticator = (Authenticator) authClass.newInstance(); } catch (Exception e) { // this isn't an ERROR if no authenticatorClass was specified if (!(e instanceof NullPointerException)) { mLogger.error("ERROR creating authenticator, using default", e); } else { mLogger.debug("No authenticator specified, using DefaultAuthenticator"); } mAuthenticator = new DefaultAuthenticator(); } } return mAuthenticator; } //----------------------------------------------------------------------- /** * Returns RollerConfig object. Changed so that it always tries * to fetch from the database first. If it should error, return * the stored copy. */ /* not available anymore ... use the new config classes instead -- Allen G public RollerConfigData getRollerConfig() { if (mConfig == null) { try { mConfig = getRoller(null).getConfigManager().getRollerConfig(); } catch (RollerException e) { mLogger.error("Unable to get RollerConfig from database"); } } return mConfig; } */ //----------------------------------------------------------------------- /** * Gets the hard-drive location of the upload directory. */ public static String getUploadDir(ServletContext app) { // ACK ... this really isn't the right place for this lookup!! String uploaddir = null; try { uploaddir = RollerFactory.getRoller().getFileManager().getUploadDir(); } catch(Exception e) {} return uploaddir; } //----------------------------------------------------------------------- /** * Gets the base url for the upload directory. */ public static String getUploadPath(ServletContext app) { // ACK ... why do this here?? String uploadurl = null; try { uploadurl = RollerFactory.getRoller().getFileManager().getUploadUrl(); } catch(Exception e) {} return uploadurl; } //----------------------------------------------------------------------- /** * Read Roller configuration parameters from roller-config.xml. */ /* no longer needed now that we have a new config system -- Allen G. private void setupRollerConfig() throws RollerException { mConfig = getRoller(null).getConfigManager().getRollerConfig(); if (mConfig == null) { // No entry in the rollerconfig table means that we are upgading to // Roller 0.9.9. To upgrade, we need to read the values from the // existing roller-config.xml and write them to the rollerconfig table. String configPath = getConfigPath(); mConfig = getRoller(null).getConfigManager().readFromFile(configPath); // Roller 0.9.9 uses roles for security, so create an admin role for // each of the admin users listed in the roller-config.xml file. String adminUsers[] = mConfig.adminUsersArray(); for (int i=0; i<adminUsers.length; i++) { UserData user = getRoller(null).getUserManager().getUser(adminUsers[i]); if (user != null) { RoleData role = new RoleData(null, user, "admin"); role.save(); } } // By setting the database version to null here, we ensure that the // rest of the database tables will be upgraded to 0.9.9. mConfig.setDatabaseVersion(null); saveRollerConfig(mConfig); } } */ //----------------------------------------------------------------------- /* Unused method ... this is the wrong place for this anyways -- Allen G. public void saveRollerConfig(RollerConfigData rConfig) throws RollerException { mConfig = rConfig; // save database copy //getRoller(null).begin(); // begin already called by RequestFilter getRoller(null).getConfigManager().storeRollerConfig(rConfig); getRoller(null).commit(); // save file copy OldRollerConfig rConfigFile = new OldRollerConfig(rConfig); rConfigFile.writeConfig(getConfigPath()); } */ //----------------------------------------------------------------------- /** * Determine where we should read/write roller-config.xml to. * A file in ${user.home} overrides one in WEB-INF. */ /* Unused old method -- Allen G. public String getConfigPath() { String configPath = System.getProperty("user.home") + File.separator + "roller-config.xml"; if (mLogger.isDebugEnabled()) { mLogger.debug( "Looking for roller-config.xml at '" + configPath + "'"); } boolean configFoundInHomeDir; try { configFoundInHomeDir = new File(configPath).exists(); } catch (SecurityException se) { configFoundInHomeDir = false; mLogger.info("Permission denied at '" + configPath + "'"); } if (!configFoundInHomeDir) { // No config found in user.home, store it in WEB-INF instead. if (mLogger.isDebugEnabled()) { mLogger.debug("File not found: '" + configPath); } String root = mContext.getRealPath("/"); configPath = root + File.separator + "WEB-INF" + File.separator + "roller-config.xml"; } mLogger.info("Using roller-config.xml at '" + configPath + "'"); return configPath; } */ //----------------------------------------------------------------------- /** * RollerSpellCheck must be initialized with a dictionary file * so that it can return valid a SpellChecker. */ private void setupSpellChecker() { InputStream is = null; try { is = mContext.getResourceAsStream("/WEB-INF/english.0"); RollerSpellCheck.init(is); } catch (Exception e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -