List of usage examples for org.dom4j Document addElement
Element addElement(String name);
Element
node with the given name to this branch and returns a reference to the new node. From source file:cmcc.gz.adc.message.CorpBindRsp.java
public String toString() { try {/*w w w. j a va 2 s .com*/ Document document = DocumentHelper.createDocument(); Element root = document.addElement("CorpBindRsp"); Element head = root.addElement("HEAD"); head.addElement("CODE").addText(header.getCode()); head.addElement("SID").addText(header.getSid()); head.addElement("TIMESTAMP").addText(header.getTimestamp()); head.addElement("SERVICEID").addText(header.getServiceId()); root.addElement("BODY").setText(encodeBody()); return root.asXML(); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:cmcc.gz.adc.message.CorpBindRsp.java
private String encodeBody() { Document document = DocumentHelper.createDocument(); try {//from ww w. j av a 2 s.c om Element root = document.addElement("BODY"); root.addElement("RESULTCODE").addText(resultcode); root.addElement("RESULTMSG").addText(resultmsg); root.addElement("URL").addText(url); return SecurityTool.encrypt(root.asXML()); } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:cn.buk.api.service.CtripHotelServiceImpl.java
License:LGPL
private Element createRequestHeaderElement(Document document, String requestType) { Element returnElement = document.addElement("Request"); Element element = returnElement.addElement("Header"); element.addAttribute("AllianceID", this.allianceId); element.addAttribute("SID", this.sid); long timestamp = SignatureUtils.GetTimeStamp(); String signature = null;// w ww. j a v a 2 s. com try { signature = SignatureUtils.CalculationSignature(timestamp + "", this.allianceId, this.secretKey, this.sid, requestType); } catch (Exception e) { logger.error(e.getMessage()); } element.addAttribute("TimeStamp", timestamp + ""); element.addAttribute("Signature", signature); element.addAttribute("RequestType", requestType); return returnElement; }
From source file:cn.com.sunjiesh.wechat.helper.WechatMessageConvertDocumentHelper.java
/** * ?XML/*w ww .j a va 2 s .c o m*/ * * @param toUserName ??OpenID * @param fromUserName ?? * @param msgType ? * @return XML */ private static Document initRespDoc(final String toUserName, final String fromUserName, final String msgType) { Document respDoc = DocumentHelper.createDocument(); Element rootEle = respDoc.addElement("xml"); Element toUserNameEle = rootEle.addElement("ToUserName"); Element fromUserNameEle = rootEle.addElement("FromUserName"); Element createTimeEle = rootEle.addElement("CreateTime"); Element msgTypeEle = rootEle.addElement("MsgType"); toUserNameEle.setText(toUserName); fromUserNameEle.setText(fromUserName); createTimeEle.setText(String.valueOf(System.currentTimeMillis())); msgTypeEle.setText(msgType); return respDoc; }
From source file:com.aesirteam.smep.adc.simulator.TransletServlet.java
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { String message = ""; boolean body_flag = "on".equals(arg0.getParameter("body_flag")) ? true : false; arg0.setCharacterEncoding("GBK"); String tb_endpoint = arg0.getParameter("tb_endpoint"); String tb_secret = arg0.getParameter("teb_secret"); String tb_code = arg0.getParameter("tb_code"); Util util = new Util(); util.setEndpoint(tb_endpoint);// w ww.java 2 s.c o m util.setSecret(tb_secret); if ("CorpBind".equals(tb_code)) { try { Document document = DocumentHelper.createDocument(); Element root = document.addElement("CorpBindReq"); //PUD Element head = root.addElement("HEAD"); head.addElement("CODE").addText("CorpBind"); head.addElement("SID").addText(arg0.getParameter("tb_sid")); head.addElement("TIMESTAMP").addText(arg0.getParameter("tb_timestamp")); head.addElement("SERVICEID").addText(arg0.getParameter("tb_serviceid")); //PDU Document bodydocument = DocumentHelper.createDocument(); Element body = bodydocument.addElement("BODY"); body.addElement("CORPNAME").addText(arg0.getParameter("tb_corpname")); body.addElement("CORPACCOUNT").addText(arg0.getParameter("tb_corpaccount")); body.addElement("LICENSE").addText(arg0.getParameter("tb_license")); body.addElement("OPTYPE").addText(arg0.getParameter("tb_optype")); body.addElement("OPNOTE").addText(arg0.getParameter("tb_opnote")); Element paramlist = body.addElement("PARAMLIST"); String[] plist = arg0.getParameterValues("lb_paramlist"); if (null != plist && 1 <= plist.length) { for (int i = 0; i < plist.length; i++) { //System.out.println(plist[i]); String[] ppv = plist[i].split(":"); Element parammap = paramlist.addElement("PARAMMAP"); parammap.addElement("PARAMNAME").addText(ppv[0]); if (1 < ppv.length) parammap.addElement("PARAMVALUE").addText(ppv[1]); else parammap.addElement("PARAMVALUE"); } } Element corpinfolist = body.addElement("CORPINFOLIST"); String[] clist = arg0.getParameterValues("lb_corpinfolist"); if (null != clist && 1 <= clist.length) { for (int i = 0; i < clist.length; i++) { //System.out.println(clist[i]); String[] ppv = clist[i].split(":"); Element corpinfomap = corpinfolist.addElement("CORPINFOMAP"); corpinfomap.addElement("CORPINFONAME").addText(ppv[0]); if (1 < ppv.length) corpinfomap.addElement("CORPINFOVALUE").addText(ppv[1]); else corpinfomap.addElement("CORPINFOVALUE"); } } Element pointlist = body.addElement("POINTLIST"); String[] ilist = arg0.getParameterValues("lb_pointlist"); if (null != ilist && 1 <= ilist.length) { for (int i = 0; i < ilist.length; i++) { String[] ppv = ilist[i].split(":"); Element orderpointmap = pointlist.addElement("ORDERPOINTMAP"); orderpointmap.addElement("POINTNAME").addText(ppv[0]); if (1 < ppv.length) orderpointmap.addElement("POINTVALUE").addText(ppv[1]); else orderpointmap.addElement("POINTVALUE"); } } if (!body_flag) { root.addElement("BODY").setText(util.encrypt(util.getXmlText(bodydocument))); String rsqstr = util.soapHttpClient("CorpBinding", util.getXmlText(document)); message = util.decrypt(rsqstr); } else { message = util.getXmlText(bodydocument); } util = null; } catch (Exception ex) { ex.printStackTrace(); } } else if ("DeptBind".equals(tb_code)) { try { Document document = DocumentHelper.createDocument(); Element root = document.addElement("DeptBindReq"); //PUD Element head = root.addElement("HEAD"); head.addElement("CODE").addText("DeptBind"); head.addElement("SID").addText(arg0.getParameter("tb_sid")); head.addElement("TIMESTAMP").addText(arg0.getParameter("tb_timestamp")); head.addElement("SERVICEID").addText(arg0.getParameter("tb_serviceid")); //PDU Document bodydocument = DocumentHelper.createDocument(); Element body = bodydocument.addElement("BODY"); body.addElement("CORPACCOUNT").addText(arg0.getParameter("tb_corpaccount")); Element deptinfo = body.addElement("DEPS"); deptinfo.addElement("DEPTID").addText(arg0.getParameter("tb_deptid")); deptinfo.addElement("PARENTID").addText(arg0.getParameter("tb_parentid")); deptinfo.addElement("DEPNAME").addText(arg0.getParameter("tb_depname")); deptinfo.addElement("DEPDES").addText(arg0.getParameter("tb_depdes")); deptinfo.addElement("DEPADDRESS").addText(arg0.getParameter("tb_depaddress")); deptinfo.addElement("DEPTELNO").addText(arg0.getParameter("tb_deptelno")); deptinfo.addElement("DEPFAXNO").addText(arg0.getParameter("tb_depfaxno")); deptinfo.addElement("DEPMNGID").addText(arg0.getParameter("tb_depmngid")); deptinfo.addElement("BUILDTIME").addText(arg0.getParameter("tb_buildtime")); deptinfo.addElement("UPDATEDATE").addText(arg0.getParameter("tb_updatedate")); deptinfo.addElement("OPTYPE").addText(arg0.getParameter("tb_optype")); Element deptinfomaplist = deptinfo.addElement("DEPTINFOMAPLIST"); String[] diml = arg0.getParameterValues("lb_deptinfomaplist"); if (null != diml && 1 <= diml.length) { for (int i = 0; i < diml.length; i++) { //System.out.println(diml[i]); String[] ppv = diml[i].split(":"); Element deptinfomap = deptinfomaplist.addElement("DEPTINFOMAP"); deptinfomap.addElement("DEPTINFONAME").addText(ppv[0]); if (1 < ppv.length) deptinfomap.addElement("DEPTINFOVALUE").addText(ppv[1]); else deptinfomap.addElement("DEPTINFOVALUE"); } } Element deptinfo1 = body.addElement("DEPS"); deptinfo1.addElement("DEPTID").addText(arg0.getParameter("tb_deptid1")); deptinfo1.addElement("PARENTID").addText(arg0.getParameter("tb_parentid1")); deptinfo1.addElement("DEPNAME").addText(arg0.getParameter("tb_depname1")); deptinfo1.addElement("DEPDES").addText(arg0.getParameter("tb_depdes1")); deptinfo1.addElement("DEPADDRESS").addText(arg0.getParameter("tb_depaddress1")); deptinfo1.addElement("DEPTELNO").addText(arg0.getParameter("tb_deptelno1")); deptinfo1.addElement("DEPFAXNO").addText(arg0.getParameter("tb_depfaxno1")); deptinfo1.addElement("DEPMNGID").addText(arg0.getParameter("tb_depmngid1")); deptinfo1.addElement("BUILDTIME").addText(arg0.getParameter("tb_buildtime1")); deptinfo1.addElement("UPDATEDATE").addText(arg0.getParameter("tb_updatedate1")); deptinfo1.addElement("OPTYPE").addText(arg0.getParameter("tb_optype1")); Element deptinfomaplist1 = deptinfo1.addElement("DEPTINFOMAPLIST"); String[] diml1 = arg0.getParameterValues("lb_deptinfomaplist1"); if (null != diml1 && 1 <= diml1.length) { for (int i = 0; i < diml1.length; i++) { //System.out.println(diml1[i]); String[] ppv = diml1[i].split(":"); Element deptinfomap = deptinfomaplist1.addElement("DEPTINFOMAP"); deptinfomap.addElement("DEPTINFONAME").addText(ppv[0]); if (1 < ppv.length) deptinfomap.addElement("DEPTINFOVALUE").addText(ppv[1]); else deptinfomap.addElement("DEPTINFOVALUE"); } } if (!body_flag) { root.addElement("BODY").setText(util.encrypt(util.getXmlText(bodydocument))); String rsqstr = util.soapHttpClient("DeptBinding", util.getXmlText(document)); message = util.decrypt(rsqstr); } else { message = util.getXmlText(bodydocument); } util = null; } catch (Exception ex) { ex.printStackTrace(); } } else if ("StaffBind".equals(tb_code)) { try { Document document = DocumentHelper.createDocument(); Element root = document.addElement("StaffBindReq"); //PUD Element head = root.addElement("HEAD"); head.addElement("CODE").addText("StaffBind"); head.addElement("SID").addText(arg0.getParameter("tb_sid")); head.addElement("TIMESTAMP").addText(arg0.getParameter("tb_timestamp")); head.addElement("SERVICEID").addText(arg0.getParameter("tb_serviceid")); //PDU Document bodydocument = DocumentHelper.createDocument(); Element body = bodydocument.addElement("BODY"); body.addElement("CORPACCOUNT").addText(arg0.getParameter("tb_corpaccount")); Element stafflist = body.addElement("STAFFLIST"); Element staffinfo = stafflist.addElement("STAFFINFO"); staffinfo.addElement("UFID").addText(arg0.getParameter("tb_ufid")); staffinfo.addElement("USERTYPE").addText(arg0.getParameter("tb_usertype")); staffinfo.addElement("STAFFNAME").addText(arg0.getParameter("tb_staffname")); staffinfo.addElement("STAFFMOBILE").addText(arg0.getParameter("tb_staffmobile")); staffinfo.addElement("OPTYPE").addText(arg0.getParameter("tb_optype")); staffinfo.addElement("OPNOTE").addText(arg0.getParameter("tb_opnote")); Element userinfomaplist = staffinfo.addElement("USERINFOMAPLIST"); String[] ufml = arg0.getParameterValues("lb_userinfomaplist"); //System.out.println(diml.length); if (null != ufml && 1 <= ufml.length) { for (int i = 0; i < ufml.length; i++) { //System.out.println(diml[i]); String[] ppv = ufml[i].split(":"); Element userinfomap = userinfomaplist.addElement("USERINFOMAP"); userinfomap.addElement("USERINFONAME").addText(ppv[0]); if (1 < ppv.length) userinfomap.addElement("USERINFOVALUE").addText(ppv[1]); else userinfomap.addElement("USERINFOVALUE"); } } Element staffinfo1 = stafflist.addElement("STAFFINFO"); staffinfo1.addElement("UFID").addText(arg0.getParameter("tb_ufid1")); staffinfo1.addElement("USERTYPE").addText(arg0.getParameter("tb_usertype1")); staffinfo1.addElement("STAFFNAME").addText(arg0.getParameter("tb_staffname1")); staffinfo1.addElement("STAFFMOBILE").addText(arg0.getParameter("tb_staffmobile1")); staffinfo1.addElement("OPTYPE").addText(arg0.getParameter("tb_optype1")); staffinfo1.addElement("OPNOTE").addText(arg0.getParameter("tb_opnote1")); Element userinfomaplist1 = staffinfo1.addElement("USERINFOMAPLIST"); String[] ufml1 = arg0.getParameterValues("lb_userinfomaplist1"); if (null != ufml1 && 1 <= ufml1.length) { for (int i = 0; i < ufml1.length; i++) { //System.out.println(diml1[i]); String[] ppv = ufml1[i].split(":"); Element userinfomap = userinfomaplist1.addElement("USERINFOMAP"); userinfomap.addElement("USERINFONAME").addText(ppv[0]); if (1 < ppv.length) userinfomap.addElement("USERINFOVALUE").addText(ppv[1]); else userinfomap.addElement("USERINFOVALUE"); } } if (!body_flag) { root.addElement("BODY").setText(util.encrypt(util.getXmlText(bodydocument))); String rsqstr = util.soapHttpClient("StaffBinding", util.getXmlText(document)); message = util.decrypt(rsqstr); } else { message = util.getXmlText(bodydocument); } util = null; } catch (Exception ex) { ex.printStackTrace(); } } printPage(arg1, message); }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void backupDomainTable(String strPath, String strDomainName, String strTableName) { Connection con = null;/*from w ww .ja v a 2s . c o m*/ XMLWriter output = null; ResultSet rsTable = null; Statement stTable = null; try { if (!(strPath.substring(strPath.length() - 1).equals(File.separator) || strPath.substring(strPath.length() - 1).equals("/"))) { strPath = strPath + File.separatorChar; } // Class.forName("org.postgresql.Driver").newInstance(); // // String strUrl = "jdbc:postgresql://localhost:5432/hm"; // // String strUsr = "hivemanager"; // // String strPsd = "aerohive"; AhBackupNewTool oTool = new AhBackupNewTool(); con = oTool.initCon(); try { stTable = con.createStatement(); String strSql; int intFileCount = 0; int intRecordNum; while (true) { intRecordNum = 0; strSql = "select * from " + strTableName + " where domainname='" + strDomainName + "'" + " limit " + 5000 + " offset " + intFileCount * 5000; if (!AhBackupNewTool.isValidCoon(con)) { con = oTool.initCon(); stTable = con.createStatement(); } rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); ResultSetMetaData rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { intRecordNum++; Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } if (1 == intRecordNum) { row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)) .addAttribute("value", newStr); } else { row.addElement("field").addAttribute("value", newStr); } } } if (intRecordNum <= 0 && 0 != intFileCount) break; File file; if (intFileCount == 0) { file = new File(strPath + strTableName.toLowerCase() + ".xml"); } else { file = new File(strPath + strTableName.toLowerCase() + "_" + intFileCount + ".xml"); } intFileCount++; output = new XMLWriter(new FileOutputStream(file)); output.write(document); output.close(); if (5000 > intRecordNum) break; } rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } } catch (Exception ex) { // add the debug msg BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != con) { try { con.close(); } catch (Exception conex) { BeLogTools.restoreLog(BeLogTools.ERROR, conex.getMessage()); } } if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void backup1table(String strPath, String strTableName) { Connection con = null;/*w w w .ja v a 2 s. c o m*/ XMLWriter output = null; ResultSet rsTable = null; Statement stTable = null; try { if (!(strPath.substring(strPath.length() - 1).equals(File.separator) || strPath.substring(strPath.length() - 1).equals("/"))) { strPath = strPath + File.separatorChar; } // Class.forName("org.postgresql.Driver").newInstance(); // // String strUrl = "jdbc:postgresql://localhost:5432/hm"; // // String strUsr = "hivemanager"; // // String strPsd = "aerohive"; // con = DriverManager // .getConnection(strUrl, strUsr, strPsd); AhBackupNewTool oTool = new AhBackupNewTool(); con = oTool.initCon(); //String strTableName = AhBackupTool.ahLicenseHistory.toLowerCase(); try { stTable = con.createStatement(); // String strSql = "select count(*) from " + strTableName; // // rsTable = stTable.executeQuery(strSql); // // rsTable = stTable.executeQuery(strSql); // // rsTable.next(); // // int iRowCount = rsTable.getInt(1); // // rsTable.close(); //int intFileCount = 1; String strSql; int intFileCount = 0; int intRecordNum; //for (int i = 0; i < iRowCount || i == 0; i = i + 5000) { while (true) { intRecordNum = 0; strSql = "select * from " + strTableName + " limit " + 5000 + " offset " + intFileCount * 5000; if (!AhBackupNewTool.isValidCoon(con)) { con = oTool.initCon(); stTable = con.createStatement(); } rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); ResultSetMetaData rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { intRecordNum++; Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } if (1 == intRecordNum) { row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)) .addAttribute("value", newStr); } else { row.addElement("field").addAttribute("value", newStr); } } } if (intRecordNum <= 0 && 0 != intFileCount) break; File file; if (intFileCount == 0) { file = new File(strPath + strTableName.toLowerCase() + ".xml"); } else { file = new File(strPath + strTableName.toLowerCase() + "_" + intFileCount + ".xml"); } intFileCount++; output = new XMLWriter(new FileOutputStream(file)); output.write(document); output.close(); if (5000 > intRecordNum) break; } rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } } catch (Exception ex) { // add the debug msg BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != con) { try { con.close(); } catch (Exception conex) { BeLogTools.restoreLog(BeLogTools.ERROR, conex.getMessage()); } } if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void storeBriefDomainInfo(String strXmlPath, HmDomain oDomain) { String strDomainTable = AhBackupTool.ahDomain.toLowerCase(); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strDomainTable); File fDomain = new File(strXmlPath + strDomainTable.toLowerCase() + ".xml"); XMLWriter output = null;/* w w w .j av a2s . c om*/ try { output = new XMLWriter(new FileOutputStream(fDomain)); Element row = table.addElement("row"); String strDomainId = oDomain.getId().toString(); String strDomainName = oDomain.getDomainName(); row.addElement("field").addAttribute("name", "id").addAttribute("value", strDomainId); row.addElement("field").addAttribute("name", "domainname").addAttribute("value", strDomainName); output.write(document); output.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void storeDomainTable(String strTableName, String strPath, HmDomain oDomain, Connection conTable) { String strSql = "select * from " + strTableName; XMLWriter output = null;/* w w w. ja va 2s . c om*/ ResultSet rsTable = null; Statement stTable = null; try { stTable = conTable.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); File file = new File(strPath + strTableName.toLowerCase() + ".xml"); output = new XMLWriter(new FileOutputStream(file)); ResultSetMetaData rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)).addAttribute("value", newStr); } } output.write(document); output.close(); rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }
From source file:com.ah.be.admin.adminBackupUnit.AhBackupTool.java
private void storeCertainDomainTable(String strTableName, String strPath, HmDomain oDomain, Connection conTable) {/* ww w. ja v a 2 s. co m*/ String strSql = "select * from " + strTableName + " where domainname=" + "'" + oDomain.getDomainName() + "'"; XMLWriter output = null; ResultSet rsTable = null; Statement stTable = null; try { stTable = conTable.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); rsTable = stTable.executeQuery(strSql); Document document = DocumentHelper.createDocument(); Element table = document.addElement("table").addAttribute("schema", strTableName); File file = new File(strPath + strTableName.toLowerCase() + ".xml"); output = new XMLWriter(new FileOutputStream(file)); ResultSetMetaData rsmd = rsTable.getMetaData(); int iCount = rsmd.getColumnCount(); while (rsTable.next()) { Element row = table.addElement("row"); for (int icol = 1; icol <= iCount; icol++) { String newStr; if (rsTable.getString(icol) == null) { newStr = "NULL"; } else if ("null".equalsIgnoreCase(rsTable.getString(icol))) { newStr = "_" + rsTable.getString(icol) + "_"; } else { newStr = rsTable.getString(icol); } row.addElement("field").addAttribute("name", rsmd.getColumnName(icol)).addAttribute("value", newStr); } } output.write(document); output.close(); rsTable.close(); stTable.close(); } catch (Exception ex) { BeLogTools.restoreLog(BeLogTools.ERROR, ex.getMessage()); } finally { if (null != output) { try { output.close(); } catch (Exception outex) { BeLogTools.restoreLog(BeLogTools.ERROR, outex.getMessage()); } } if (null != rsTable) { try { rsTable.close(); } catch (Exception rsex) { BeLogTools.restoreLog(BeLogTools.ERROR, rsex.getMessage()); } } if (null != stTable) { try { stTable.close(); } catch (Exception stex) { BeLogTools.restoreLog(BeLogTools.ERROR, stex.getMessage()); } } } }