📄 excelconfigutil.java
字号:
package cn.capitek.TorchRelay.util;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.digester.Digester;
import org.xml.sax.SAXException;
/**
* 用于处理系统配置的工具类
* 它的作用是解析配置文件,生成配置对象
*
* @author cellen
*
*/
public class ExcelConfigUtil
{
// 缺省配置文件的名称
public static final String DEFAULT_CONFI_FILE = "ExcelConfig.xml";
// 配置对象的实例
public static final ExcelXmlConfig MESSAGE_CONFIG;
static
{
// 创建Digester对象的实例
Digester digester = new Digester();
digester.setValidating(false);
// 初始化根配置对象
digester.addObjectCreate("config", "cn.capitek.TorchRelay.util.ExcelXmlConfig");
digester.addSetProperties("config");
//add
digester.addObjectCreate("config/excel",
"cn.capitek.TorchRelay.util.ExcelConfig");
digester.addSetProperties("config/excel");
digester.addSetNext("config/excel", "addExcelConfig",
"cn.capitek.TorchRelay.util.ExcelConfig");
// 设置ExcelConfig对象的配置参数
digester.addObjectCreate("config/excel/exceltype",
"cn.capitek.TorchRelay.util.ExcelType");
digester.addSetProperties("config/excel/exceltype");
digester.addSetNext("config/excel/exceltype", "addExcelType",
"cn.capitek.TorchRelay.util.ExcelType");
// 设置ExcelType对象的配置参数
digester.addObjectCreate("config/excel/exceltype/property",
"cn.capitek.TorchRelay.util.Property");
digester.addSetProperties("config/excel/exceltype/property");
digester.addSetNext("config/excel/exceltype/property", "addProperty",
"cn.capitek.TorchRelay.util.Property");
//end add
// 读取配置文件
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
InputStream in = classLoader.getResourceAsStream(DEFAULT_CONFI_FILE);
ExcelXmlConfig config = null;
try
{
// 解析配置文件,生成根配置对象
if (in != null)
config = (ExcelXmlConfig) digester.parse(in);
} catch (IOException e)
{
e.printStackTrace();
} catch (SAXException e)
{
e.printStackTrace();
}
MESSAGE_CONFIG = config;
}
/**
* 读取根配置对象
*
* @return 根配置对象
*/
public static ExcelXmlConfig getConfig()
{
return ExcelConfigUtil.MESSAGE_CONFIG;
}
/**
* 读取ExcelConfig的配置对象
*
* @return ExcelConfig的配置对象
*/
public static ExcelConfig getExcelConfig()
{
return MESSAGE_CONFIG.getExcelConfig();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -