⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 butorcontextlistener.java

📁 一个实用工具类
💻 JAVA
字号:
/* * Copyright (C) butor.com. All rights reserved. * * This software is published under the terms of the GNU Library General * Public License (GNU LGPL), a copy of which has been included with this * distribution in the LICENSE.txt file.  */package org.butor.web.listener;import java.io.File;import java.io.IOException;import javax.servlet.ServletContext;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;import javax.servlet.ServletException;import org.butor.config.ConfigFactory;import org.butor.config.IConfig;import org.butor.fwService.starter.FwServiceStarter;import org.butor.helper.PropertiesHelper;import org.butor.log.Log;/** * @author sawanai * */public class ButorContextListener implements ServletContextListener {	// System arguments.	public static final String PARAM_APP_CONFIG = "butor_app_config";	public static final String DEFAULT_APP_CONFIG_FILENAME =		"WEB-INF/conf/app-config.xml";	protected FwServiceStarter f_serviceStarter = null;	protected static String f_contextBase = null;	protected static String f_contextName = null;	protected IConfig f_config = null;	/**	 * 	 */	public ButorContextListener() {		super();	}	/* (non-Javadoc)	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)	 */	public void contextInitialized(ServletContextEvent arg0) {		try {			PropertiesHelper.loadSystemProperties();						startServices(arg0.getServletContext());		} catch (ServletException e) {			Log.logException(this, Log.LOG_TYPE_ERROR, "contextInitialized()", e);		}	}	/* (non-Javadoc)	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)	 */	public void contextDestroyed(ServletContextEvent arg0) {		stopServices();				f_serviceStarter = null;		f_contextBase = null;		f_contextName = null;		f_config = null;	}	/**	 * Start this webapp services.	 *	 * @exception ServletException if we cannot configure ourselves correctly	 */	protected void startServices(ServletContext context)		throws ServletException {		Log.logStr(this, Log.LOG_TYPE_INFO, "startServices()", "Starting services ...");		f_contextBase = context.getRealPath(File.separator);		int pos = f_contextBase.lastIndexOf(File.separator);		f_contextBase = f_contextBase.substring(0, pos);		pos = f_contextBase.lastIndexOf(File.separator);		f_contextName = f_contextBase.substring(pos + 1);		loadConfig();		f_serviceStarter = new FwServiceStarter(f_config);		if (Log.shouldLog(this.getClass().getName(), Log.LOG_LEVEL_LOW)) {			Log.logStr(this, Log.LOG_TYPE_INFO, "startServices()", 				"Final config: " +f_config);		}	}	/**	 * 	 */	protected void stopServices() {		Log.logStr(this, Log.LOG_TYPE_INFO, "stopServices()", "Stopping services ...");		if (f_serviceStarter != null) {			f_serviceStarter.shutdown();		}	}	/**	 * Init config.	 */	protected void loadConfig() throws ServletException {		f_config = null;		String confFile = System.getProperty(PARAM_APP_CONFIG, DEFAULT_APP_CONFIG_FILENAME);		Log.logStr(this, Log.LOG_TYPE_INFO, "loadConfig()", 			"Got system parameters: " + PARAM_APP_CONFIG +"=[" +System.getProperty(PARAM_APP_CONFIG) +"]");		confFile = f_contextBase				+ (confFile.startsWith(File.separator) ? "" : File.separator)				+ confFile;		String[] externalConfSuffixes = getConfigSuffixes();		try {			f_config = ConfigFactory.loadConfigFile(confFile, f_contextBase, 					ConfigFactory.getAlternateConfDir(), ConfigFactory.getLogDir(),					externalConfSuffixes);			} catch (IOException e) {			throw new ServletException(e);		}	}	/**	 * Get webapp config file suffixes	 */	public static String[] getConfigSuffixes() {		return ConfigFactory.getConfigSuffixes(f_contextName);	}	/**	 * get context directory	 */	public static String getContextDir() {		return f_contextBase;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -