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

📄 initplugin.java

📁 用jbuilder写的源程序
💻 JAVA
字号:
/**
 * Copyright 2003-2006 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jdon.strutsutil;

import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.PlugInConfig;

import com.jdon.container.config.app.AppConfigureCollection;
import com.jdon.container.startup.ContainerSetupScript;
import com.jdon.util.FileLocator;
import com.jdon.util.StringUtil;

/**
 * Struts应用框架初始化
 *
 *
 * 需要在struts_config.xml中加入:
 *   <plug-in className="com.jdon.strutsutil.InitPlugIn"/>
 *
 * 设置本初始化,可使用对象池等技术配置
 *
 * <p>Copyright: Jdon.com Copyright (c) 2003</p>
 * <p></p>
 * @author banq
 * @version 1.0
 */

public class InitPlugIn implements PlugIn {
	public final static String module = InitPlugIn.class.getName();

	private ContainerSetupScript css = new ContainerSetupScript();

	private FileLocator fileLocator = new FileLocator();

	private ActionServlet servlet = null;

	private ModuleConfig config = null;

	public void init(ActionServlet servlet, ModuleConfig config)
			throws ServletException {
		// Remember our associated configuration and servlet
		this.config = config;
		this.servlet = servlet;

		ServletContext sc = servlet.getServletContext();

		String config_file = "";
		PlugInConfig[] plugInConfigs = config.findPlugInConfigs();
		int length = plugInConfigs.length;
		for (int i = 0; i < length; i++) {
			Set entries = plugInConfigs[i].getProperties().entrySet();
			Iterator iter = entries.iterator();
			while (iter.hasNext()) {
				Map.Entry entry = (Map.Entry) iter.next();
				if (AppConfigureCollection.CONFIG_NAME.equals(entry.getKey())) { //可能有多个配置
					config_file = (String) entry.getValue();
					String[] configs = StringUtil.split(config_file, ",");
					for (int j = 0; j < configs.length; j++) {
						if (checkExsit(configs[j])) {
							css.prepare(configs[j], sc);
						}
					}

				}
			}
		}
	}

	public boolean checkExsit(String config_file) {
		boolean ret = false;
		InputStream xmlFile = null;
		try {
			xmlFile = fileLocator.getConfPathXmlStream(config_file);
			if (xmlFile != null)
				ret = true;
		} catch (Exception ex) {

		}
		return ret;
	}

	public void destroy() {
		css.destroyed(servlet.getServletContext());
		config = null;
		servlet = null;
	}

}

⌨️ 快捷键说明

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