📄 getproperties.java
字号:
package mmsproject.common;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.FileInputStream;
import org.w3c.dom.NodeList;
import mmsproject.FrmMMSManage;
/**
*
* <p>Title: 彩信发送接收项目</p>
*
* <p>Description: 获取配置信息 参数见配置文件注释</p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author tomato
* @version 1.0
*/
public class GetProperties {
//数据库连接信息
public static String ConnectionString = "";
public static String UserName = "";
public static String Password = "";
//全球通
public static String VASP_ID = "";
public static String VAS_ID = "";
public static String SendDelay = "";
public static String QueryDelay = "";
/**
* 获取配子文件的参数
*/
public GetProperties() {
Document doc;
DocumentBuilderFactory factory;
DocumentBuilder docBuilder;
FileInputStream in;
String fileName;
try {
//get the xml file
//fileName = System.getProperty("user.dir");
fileName = "./config/config.xml";
in = new FileInputStream(fileName);
//解析XML文件,生成document对象
factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
docBuilder = factory.newDocumentBuilder();
doc = docBuilder.parse(in);
//取得数据库连接配置
NodeList node = doc.getElementsByTagName("SQL");
int nAttributesSize = node.item(0).getAttributes().getLength();
for (int i = 0; i < nAttributesSize; i++) {
String temp = node.item(0).getAttributes().item(i).getNodeName().trim();
if (temp.equals("ConnectionString")) {
ConnectionString = node.item(0).getAttributes().item(i).getNodeValue().trim();
} else if (temp.equals("UserName")) {
UserName = node.item(0).getAttributes().item(i).getNodeValue().trim();
} else if (temp.equals("Password")) {
Password = node.item(0).getAttributes().item(i).getNodeValue().trim();
}
}
//取得sp参数
node = doc.getElementsByTagName("VAS");
nAttributesSize = node.item(0).getAttributes().getLength();
for (int i = 0; i < nAttributesSize; i++) {
String temp = node.item(0).getAttributes().item(i).getNodeName().trim();
if (temp.equals("VASP_ID")) {
VASP_ID = node.item(0).getAttributes().item(i).getNodeValue().trim();
} else if (temp.equals("VAS_ID")) {
VAS_ID = node.item(0).getAttributes().item(i).getNodeValue().trim();
}
}
//取得数据库连接配置
node = doc.getElementsByTagName("TimeConfig");
nAttributesSize = node.item(0).getAttributes().getLength();
for (int i = 0; i < nAttributesSize; i++) {
String temp = node.item(0).getAttributes().item(i).getNodeName().trim();
if (temp.equals("SendDelay")) {
SendDelay = node.item(0).getAttributes().item(i).getNodeValue().trim();
} else if (temp.equals("QueryDelay")) {
QueryDelay = node.item(0).getAttributes().item(i).getNodeValue().trim();
}
}
} catch (Exception e) {
FrmMMSManage.m_txtStatus.setText(FrmMMSManage.m_txtStatus.getText()
+ "\n"
+ "读取配置文件出错" + e.getMessage()
);
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -