struts1 配置文件扩展
来源:互联网 发布:ie浏览器无法登录淘宝 编辑:程序博客网 时间:2024/05/23 19:55
import java.io.File;
import java.io.FilenameFilter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import org.apache.commons.digester.Digester;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.ModuleConfigFactory;
public class xxxActionServlet extends ActionServlet {
/**
* 序列化id
*/
private static final long serialVersionUID = -6431294872323567188L;
/**
* 模块Struts配置文件所在目录
*/
private static final String MODULE_CONFIG_LOCATION = "config";
/**
* 模块Struts配置文件默认加载级别
*/
private static final int MODULE_CONFIG_LOAD_LEVEL = 2;
@SuppressWarnings("unchecked")
@Override
protected ModuleConfig initModuleConfig(String prefix, String paths) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + prefix + "' configuration from '" + paths + "'");
}
// Parse the configuration for this module
ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
ModuleConfig config = factoryObject.createModuleConfig(prefix);
List<URL> urls = (List<URL>) splitAndResolvePaths(paths);
// Load module struts config
if (prefix.equals("")) {
// WebRoot directory
String webRoot = getServletContext().getRealPath("/");
// Load module struts config
loadModuleStrutsConfig(urls, webRoot, MODULE_CONFIG_LOAD_LEVEL);
}
// Configure the Digester instance we will use
Digester digester = initConfigDigester();
for (Iterator i = urls.iterator(); i.hasNext();) {
URL url = (URL) i.next();
digester.push(config);
this.parseModuleConfigFile(digester, url);
}
getServletContext().setAttribute(Globals.MODULE_KEY + config.getPrefix(), config);
return config;
}
/**
* get struts config file url arraylist
*
* @param path
* @param parentModule
* @param level
* @return
* @throws ServletException
*/
private void loadModuleStrutsConfig(List<URL> configList, String moduleParentPath, int level) throws ServletException {
File moduleParentDir = new File(moduleParentPath);
String[] modules = moduleParentDir.list();
for (String module : modules) {
// WEB-INF is not a module
if (module.toUpperCase().equals("WEB-INF")) {
continue;
}
// Skip files
String moduleDirPath = moduleParentPath + File.separator + module;
if (! new File(moduleDirPath).isDirectory()) {
continue;
}
// Module struts config
String moduleConfigPath = moduleDirPath + File.separator + MODULE_CONFIG_LOCATION;
File moduleConfigDir = new File(moduleConfigPath);
if (moduleConfigDir.exists() && moduleConfigDir.isDirectory()) {
loadModuleStrutsConfig(configList, moduleConfigDir);
} else {
if (level - 1 > 0) {
loadModuleStrutsConfig(configList, moduleDirPath, level - 1);
}
}
}
}
/**
* @param moduleConfigDir
*/
private void loadModuleStrutsConfig(List<URL> configList, File moduleConfigDir) {
File[] strutsConfigFiles = moduleConfigDir.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().startsWith("struts-config-") && name.toLowerCase().endsWith(".xml");
}
});
if (strutsConfigFiles.length > 0) {
try {
File strutsConfigFile = strutsConfigFiles[0];
if (log.isInfoEnabled()) {
log.info("Load module struts config from file [" + strutsConfigFile.getAbsolutePath() + "]");
}
configList.add(strutsConfigFile.toURI().toURL());
} catch (MalformedURLException e) {
log.error("Load module struts config from file [" + strutsConfigFiles[0].getAbsolutePath() + "] failed");
}
}
}
}
- struts1 配置文件扩展
- struts1配置文件
- struts1配置文件
- Struts1配置文件
- struts1配置文件
- struts1配置文件
- Struts1 配置文件
- struts1.1 配置文件属性
- Struts1.x复习-配置文件
- struts1配置文件出错
- Struts1配置文件总结
- Struts1 配置文件详细说明
- Struts1 配置文件详细说明
- struts1的配置文件属性
- Struts1配置文件总结
- struts1.1 配置文件属性
- 学习札记--Struts1 配置文件
- struts1配置文件详解
- Xshell终端ssh连接ubuntu中文版编译服务器显示中文字符乱码
- mac connect linux
- php 函数urlencode运用解决导出中文文件名乱码
- Visual Stdio 动态库的生成
- 程序员如何在“小公司成长”和“大公司学习”
- struts1 配置文件扩展
- SIFT特征提取分析
- 用正则表达式将文字转换成表情图片
- java环境变量设置 --- 小笔记
- ActionScript 不断放大的圆
- 单例模式及c++实现
- 机器学习一张图
- hbase 远程链接
- HDFS daily maintenance,, useful command