|
/**
* Read xml file
*
* @param realPath:
* web path
*/
public Document procConfig(String realPath) {
realPath += cfgFile;
this.file = new File(realPath);
try {
SAXBuilder builder = new SAXBuilder();
doc = builder.build(new File(realPath));
return doc;
} catch (Exception e) {
System.err.println("Error creating XML parser in UsrConfig.java");
e.printStackTrace();
return null;
}
}
/**
* Read the elements in usrcfg.xml: the host's IP address, and port
*
* @param doc
*/
public void setUsrInfo(Document doc, String addr, String port,
String usrName, String usrPwd) {
Element root = doc.getRootElement();
Element host = root.getChild(UsrDef.TAG_HOST);
host.setAttribute(UsrDef.ATTR_ADDR, addr);
host.setAttribute(UsrDef.ATTR_PORT, port);
Element user = root.getChild(UsrDef.TAG_USER);
user.setAttribute(UsrDef.ATTR_NAME, usrName);
user.setAttribute(UsrDef.ATTR_PWD, usrPwd);
this.saveProperties();
}/**
* Read the elements in usrcfg.xml: user name, password, database data source, database user name and password.
*
* @param doc
* @throws Exception
*/
public void parseDBInfo(Document doc, String dbID, String dbUsrName,
String dbPwd) {
Element root = doc.getRootElement();
List dbList = root.getChildren(UsrDef.TAG_DB);
// System.out.println(dbList.size());
for (Iterator iter = dbList.iterator(); iter.hasNext();) {
Element db = (Element) iter.next();
String Id = db.getAttributeValue(UsrDef.ATTR_ID);
if (Id.equals(dbID)) {
db.setAttribute(UsrDef.ATTR_USERNAME, dbUsrName);
db.setAttribute(UsrDef.ATTR_PWD, dbPwd);
saveProperties();
}
if (Id.equals(dbID)) {
db.setAttribute(UsrDef.ATTR_USERNAME, dbUsrName);
db.setAttribute(UsrDef.ATTR_PWD, dbPwd);
saveProperties();
}
}
} |
|