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

📄 butorcontextservices.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.helper;import java.io.File;import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import org.butor.config.ConfigFactory;import org.butor.config.IConfig;import org.butor.fwService.starter.FwServiceStarter;import org.butor.log.Log;/** * Creates and initializes the session. * Perform the following calls: * - Get user profile * - Find application servers * - Get security list *  * @author 	mateusfi */public class ButorContextServices implements Filter {	// System arguments.	public static final String PARAM_APP_CONFIG = "app_config";	public static final String DEFAULT_APP_CONFIG_FILENAME =		"WEB-INF/conf/app-config.xml";	protected FwServiceStarter f_serviceMonitor = null;	protected static String f_contextBase = null;	protected static String f_contextName = null;	protected IConfig f_config = null;	/**	 * @see Filter#init(FilterConfig)	 */	public void init(FilterConfig config) throws ServletException {		startServices(config.getServletContext());	}	/**	 * @see Filter#doFilter()	 */	public void doFilter(		ServletRequest request,		ServletResponse response,		FilterChain fc)		throws ServletException, IOException {//		SingleSignOn.keepSesionsAlive(request, response);				fc.doFilter(request, response);	}	/**	 * @see Filter#destroy()	 */	public void destroy() {				stopServices();				f_serviceMonitor = null;		f_contextBase = null;		f_contextName = null;		f_config = null;	}	/**	 * Initialize this servlet.	 *	 * @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_serviceMonitor = 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 ...");		f_serviceMonitor.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 + -