?? webconfig.java
字號:
package com.easyjf.web.config;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.easyjf.web.FormConfig;
import com.easyjf.web.Globals;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
/**
*
* <p>
* Title:配置信息
* </p>
* <p>
* Description:調用配置信息處理類,處理并存放easyjf-web.xml中的配置信息
* </p>
* <p>
* Copyright: Copyright (c) 2006
* </p>
* <p>
* Company: www.easyjf.com
* </p>
*
* @author 蔡世友
* @version 1.0
*/
public class WebConfig {
private final static Map modules = new HashMap();
private final static Map forms = new HashMap();
private final static Map pages = new HashMap();
private final static List initApps = new ArrayList();
private final static Map interceptors = new HashMap();
private static String TemplateBasePath;
private static boolean debug = false;
private static int maxUploadFileSize = 1024 * 1024 * 5;
private static int uploadSizeThreshold = 1024 * 30;
private static WebConfig config;
private static final Logger logger = (Logger) Logger
.getLogger(WebConfig.class.getName());
private WebConfig() {
}
public static WebConfig getInstance() {
if (config == null) {
config = new WebConfig();
// config.init();
}
return config;
}
public void init() {
if (modules != null)
modules.clear();
if (forms != null)
forms.clear();
if (pages != null)
pages.clear();
if (initApps != null)
initApps.clear();
if (interceptors != null)
interceptors.clear();
TemplateBasePath = "";
try {
System.out.println("系統初始化!");
IConfigFactory icf = (IConfigFactory) Class.forName(
Globals.CONFIG_FACTORY_CLASS).newInstance();
icf.initForm(forms);
icf.initModule(modules);
icf.initPage(pages);
Map map = icf.initOther();
if (map != null) {
if (map.get("TemplateBasePath") != null)
TemplateBasePath = (String) map.get("TemplateBasePath");
if (map.get(IConfigFactory.DEBUG) != null) {
debug = Boolean.valueOf(
(String) map.get(IConfigFactory.DEBUG))
.booleanValue();
}
if (map.get(IConfigFactory.MaxUploadFileSize) != null) {
int maxSize = Integer.valueOf(
(String) map.get(IConfigFactory.MaxUploadFileSize))
.intValue();
if (maxSize > 0)
maxUploadFileSize = maxSize;
}
if (map.get(IConfigFactory.UploadSizeThreshold) != null) {
int maxSize = Integer.valueOf(
(String) map
.get(IConfigFactory.UploadSizeThreshold))
.intValue();
if (maxSize > 0)
uploadSizeThreshold = maxSize;
}
List list = (List) icf.initOther().get("initApp");
logger.info("list.size:" + list.size());
if (list != null) {
for (int i = 0; i < list.size(); i++) {
// logger.info((String) list.get(i));
String[] appParms = ((String) list.get(i)).split(";");
String classname = appParms[0];
String initmethod = appParms[1];
String destroymethod = appParms[2];
// logger.info(classname + " " + initmethod + " "
// + destroymethod);
Object obj = null;
Method init_method = null;
Map app = new HashMap();
if (!"".equals(classname)) {
obj = Class.forName(appParms[0]).newInstance();
app.put("classname", obj);
}
if (!"".equals(initmethod)
&& !initmethod.equals("null")) {
init_method = obj.getClass().getMethod(initmethod,
null);
app.put("init", init_method);
}
if (!"".equals(destroymethod)
&& !destroymethod.equals("null")) {
Method destroy_method = obj.getClass().getMethod(
destroymethod, null);
app.put("destroy", destroy_method);
}
// logger.info("an app add");
initApps.add(app);
// logger.info("initApps.size:" + initApps.size());
}
}
list = (List) icf.initOther().get("interceptors");
if (list != null) {
for (int i = 0; i < list.size(); i++) {
try {
Map app = (Map) list.get(i);
String name = (String) app.get("name");
Object obj = Class.forName(
(String) app.get("class")).newInstance();
if (name == null || "".equals(name))
name = obj.getClass().getName();
interceptors.put(name, obj);
} catch (Exception e) {
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public Page findPage(String s) {
return (Page) pages.get(s);
}
public FormConfig findForm(String s) {
return (FormConfig) forms.get(s);
}
public Module findModule(String s) {
return (Module) modules.get(s);
}
public String getTemplateBasePath() {
return TemplateBasePath;
}
public void setTemplateBasePath(String templateBasePath) {
TemplateBasePath = templateBasePath;
}
public boolean isDebug() {
return debug;
}
public void setDebug(boolean debug) {
WebConfig.debug = debug;
}
public Map getForms() {
return forms;
}
public Map getModules() {
return modules;
}
public Map getPages() {
return pages;
}
public List getInitApps() {
return initApps;
}
public Map getInterceptors() {
return interceptors;
}
public static int getMaxUploadFileSize() {
return maxUploadFileSize;
}
public static void setMaxUploadFileSize(int maxUploadFileSize) {
WebConfig.maxUploadFileSize = maxUploadFileSize;
}
public static int getUploadSizeThreshold() {
return uploadSizeThreshold;
}
public static void setUploadSizeThreshold(int uploadSizeThreshold) {
WebConfig.uploadSizeThreshold = uploadSizeThreshold;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -