config.java
来自「cwbbs 云网论坛源码」· Java 代码 · 共 143 行
JAVA
143 行
package cn.js.fan.web;import cn.js.fan.util.XMLProperties;import java.net.URL;import org.jdom.Element;import org.apache.log4j.Logger;import org.jdom.Document;import java.io.FileInputStream;import org.jdom.input.SAXBuilder;import java.util.List;import java.util.Iterator;import java.util.Vector;import cn.js.fan.security.SecurityUtil;import cn.js.fan.kernel.ISchedulerUnit;import cn.js.fan.kernel.Scheduler;import java.net.URLDecoder;public class Config { private XMLProperties properties; private final String CONFIG_FILENAME = "config_cws.xml"; private final String ADMIN_PWD = "Application.admin_pwd"; private String cfgpath; Logger logger; Document doc = null; Element root = null; public Config() { URL cfgURL = getClass().getClassLoader().getResource("/" + CONFIG_FILENAME); cfgpath = cfgURL.getFile(); cfgpath = URLDecoder.decode(cfgpath); properties = new XMLProperties(cfgpath); logger = Logger.getLogger(Config.class.getName()); SAXBuilder sb = new SAXBuilder(); try { FileInputStream fin = new FileInputStream(cfgpath); doc = sb.build(fin); root = doc.getRootElement(); fin.close(); } catch (org.jdom.JDOMException e) { logger.error("Config:" + e.getMessage()); } catch (java.io.IOException e) { logger.error("Config:" + e.getMessage()); } } public String getProperty(String name) { return properties.getProperty(name); } public void setProperty(String name, String value) { properties.setProperty(name, value); } public String getAdminPwdMD5() { return properties.getProperty(ADMIN_PWD); } public boolean setAdminPwdMD5(String pwd) { try { pwd = SecurityUtil.MD5(pwd); } catch (Exception e) { logger.error(e.getMessage()); } properties.setProperty(ADMIN_PWD, pwd); return true; } public void initScheduler() { Scheduler.getInstance().ClearUnits(); Element which = root.getChild("scheduler"); if (which == null) return; List list = which.getChildren(); Iterator ir = list.iterator(); while (ir.hasNext()) { Element e = (Element) ir.next(); String className = e.getTextTrim(); try { Class cls = Class.forName(className); ISchedulerUnit isu = (ISchedulerUnit)cls.newInstance(); isu.registSelf(); } catch (Exception e1) { e1.printStackTrace(); logger.error("initScheduler:" + e1.getMessage()); } } } public Vector getDBInfos() { Element which = root.getChild("DataBase"); if (which == null) return new Vector(); Vector v = new Vector(); List list = which.getChildren("db"); Iterator ir = list.iterator(); while (ir.hasNext()) { Element e = (Element) ir.next(); DBInfo di = new DBInfo(); di.name = e.getChildTextTrim("name"); String strDefault = e.getChildTextTrim("Default"); if (strDefault.equals("true")) di.isDefault = true; else di.isDefault = false; di.DBDriver = e.getChildTextTrim("DBDriver"); di.ConnStr = e.getChildTextTrim("ConnStr"); di.PoolName = e.getChildTextTrim("PoolName"); String UsePool = e.getChildTextTrim("UsePool"); if (UsePool.equals("true")) di.isUsePool = true; else di.isUsePool = false; v.addElement(di); } return v; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?