List of usage examples for org.dom4j Element 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:com.adspore.splat.xep0060.PubSubEngine.java
License:Open Source License
private static IQ getSubscriptions(PubSubService service, IQ iq, Element childElement) { // TODO Assuming that owner is the bare JID (as defined in the JEP). This can be replaced with an explicit owner specified in the packet JID owner = new JID(iq.getFrom().getNode(), iq.getFrom().getDomain(), null, true); Element subscriptionsElement = childElement.element("subscriptions"); String nodeID = subscriptionsElement.attributeValue("node"); Collection<NodeSubscription> subscriptions = new ArrayList<NodeSubscription>(); if (nodeID == null) { // Collect subscriptions of owner for all nodes at the service for (Node node : service.getNodes()) { subscriptions.addAll(node.getSubscriptions(owner)); }//w ww . ja v a 2 s .c om } else { subscriptions.addAll(service.getNode(nodeID).getSubscriptions(owner)); } // Create reply to send IQ reply = IQ.createResultIQ(iq); Element replyChildElement = childElement.createCopy(); reply.setChildElement(replyChildElement); Element affiliationsElement = replyChildElement.element("subscriptions"); // Add information about subscriptions including existing affiliations for (NodeSubscription subscription : subscriptions) { Element subElement = affiliationsElement.addElement("subscription"); Node node = subscription.getNode(); NodeAffiliate nodeAffiliate = subscription.getAffiliate(); // Do not include the node id when node is the root collection node // or the results are for a specific node if (!node.isRootCollectionNode() && (nodeID == null)) { subElement.addAttribute("node", node.getNodeID()); } subElement.addAttribute("jid", subscription.getJID().toString()); subElement.addAttribute("subscription", subscription.getState().name()); if (node.isMultipleSubscriptionsEnabled()) { subElement.addAttribute("subid", subscription.getID()); } } return reply; }
From source file:com.adspore.splat.xep0060.PubSubEngine.java
License:Open Source License
private static IQ getAffiliations(PubSubService service, IQ iq, Element childElement) { // TODO Assuming that owner is the bare JID (as defined in the JEP). This can be replaced with an explicit owner specified in the packet JID owner = new JID(iq.getFrom().getNode(), iq.getFrom().getDomain(), null, true); // Collect affiliations of owner for all nodes at the service Collection<NodeAffiliate> affiliations = new ArrayList<NodeAffiliate>(); for (Node node : service.getNodes()) { NodeAffiliate nodeAffiliate = node.getAffiliate(owner); if (nodeAffiliate != null) { affiliations.add(nodeAffiliate); }// w w w. j av a 2 s . co m } // Create reply to send IQ reply = IQ.createResultIQ(iq); Element replyChildElement = childElement.createCopy(); reply.setChildElement(replyChildElement); if (affiliations.isEmpty()) { // User does not have any affiliation or subscription with the pubsub service reply.setError(PacketError.Condition.item_not_found); } else { Element affiliationsElement = replyChildElement.element("affiliations"); // Add information about affiliations without subscriptions for (NodeAffiliate affiliate : affiliations) { Element affiliateElement = affiliationsElement.addElement("affiliation"); // Do not include the node id when node is the root collection node if (!affiliate.getNode().isRootCollectionNode()) { affiliateElement.addAttribute("node", affiliate.getNode().getNodeID()); } affiliateElement.addAttribute("jid", affiliate.getJID().toString()); affiliateElement.addAttribute("affiliation", affiliate.getAffiliation().name()); } } return reply; }
From source file:com.adspore.splat.xep0060.PubSubEngine.java
License:Open Source License
private static IQ createNode(PubSubService service, IQ iq, Element childElement, Element createElement) { // Get sender of the IQ packet JID from = iq.getFrom();//from w w w . j a va 2 s . c o m // Verify that sender has permissions to create nodes if (!service.canCreateNode(from)) { // The user is not allowed to create nodes so return an error return createErrorPacket(iq, PacketError.Condition.forbidden, null); } DataForm completedForm = null; CollectionNode parentNode = null; String nodeID = createElement.attributeValue("node"); String newNodeID = nodeID; if (nodeID == null) { // User requested an instant node if (!service.isInstantNodeSupported()) { // Instant nodes creation is not allowed so return an error Element pubsubError = DocumentHelper .createElement(QName.get("nodeid-required", "http://jabber.org/protocol/pubsub#errors")); return createErrorPacket(iq, PacketError.Condition.not_acceptable, pubsubError); } do { // Create a new nodeID and make sure that the random generated string does not // match an existing node. Probability to match an existing node are very very low // but they exist :) newNodeID = StringUtils.randomString(15); } while (service.getNode(newNodeID) != null); } boolean collectionType = false; // Check if user requested to configure the node (using a data form) Element configureElement = childElement.element("configure"); if (configureElement != null) { // Get the data form that contains the parent nodeID completedForm = getSentConfigurationForm(configureElement); if (completedForm != null) { // Calculate newNodeID when new node is affiliated with a Collection FormField field = completedForm.getField("pubsub#collection"); if (field != null) { List<String> values = field.getValues(); if (!values.isEmpty()) { String parentNodeID = values.get(0); Node tempNode = service.getNode(parentNodeID); if (tempNode == null) { // Requested parent node was not found so return an error return createErrorPacket(iq, PacketError.Condition.item_not_found, null); } else if (!tempNode.isCollectionNode()) { // Requested parent node is not a collection node so return an error return createErrorPacket(iq, PacketError.Condition.not_acceptable, null); } parentNode = (CollectionNode) tempNode; } } field = completedForm.getField("pubsub#node_type"); if (field != null) { // Check if user requested to create a new collection node List<String> values = field.getValues(); if (!values.isEmpty()) { collectionType = "collection".equals(values.get(0)); } } } } // If no parent was defined then use the root collection node if (parentNode == null && service.isCollectionNodesSupported()) { parentNode = service.getRootCollectionNode(); } // Check that the requested nodeID does not exist Node existingNode = service.getNode(newNodeID); if (existingNode != null) { // There is a conflict since a node with the same ID already exists return createErrorPacket(iq, PacketError.Condition.conflict, null); } if (collectionType && !service.isCollectionNodesSupported()) { // Cannot create a collection node since the service doesn't support it Element pubsubError = DocumentHelper .createElement(QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors")); pubsubError.addAttribute("feature", "collections"); return createErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError); } if (parentNode != null && !collectionType) { // Check if requester is allowed to add a new leaf child node to the parent node if (!parentNode.isAssociationAllowed(from)) { // User is not allowed to add child leaf node to parent node. Return an error. return createErrorPacket(iq, PacketError.Condition.forbidden, null); } // Check if number of child leaf nodes has not been exceeded if (parentNode.isMaxLeafNodeReached()) { // Max number of child leaf nodes has been reached. Return an error. Element pubsubError = DocumentHelper .createElement(QName.get("max-nodes-exceeded", "http://jabber.org/protocol/pubsub#errors")); return createErrorPacket(iq, PacketError.Condition.conflict, pubsubError); } } // Create and configure the node boolean conflict = false; Node newNode = null; try { // TODO Assumed that the owner of the subscription is the bare JID of the subscription JID. Waiting StPeter answer for explicit field. JID owner = new JID(from.getNode(), from.getDomain(), null, true); synchronized (newNodeID.intern()) { if (service.getNode(newNodeID) == null) { // Create the node if (collectionType) { newNode = new CollectionNode(service, parentNode, newNodeID, from); } else { newNode = new LeafNode(service, parentNode, newNodeID, from); } // Add the creator as the node owner newNode.addOwner(owner); // Configure and save the node to the backend store if (completedForm != null) { newNode.configure(completedForm); } else { newNode.saveToDB(); } } else { conflict = true; } } if (conflict) { // There is a conflict since a node with the same ID already exists return createErrorPacket(iq, PacketError.Condition.conflict, null); } else { // Return success to the node owner IQ reply = IQ.createResultIQ(iq); // Include new nodeID if it has changed from the original nodeID if (!newNode.getNodeID().equals(nodeID)) { Element elem = reply.setChildElement("pubsub", "http://jabber.org/protocol/pubsub"); elem.addElement("create").addAttribute("node", newNode.getNodeID()); } return reply; } } catch (NotAcceptableException e) { // Node should have at least one owner. Return not-acceptable error. return createErrorPacket(iq, PacketError.Condition.not_acceptable, null); } }
From source file:com.adspore.splat.xep0060.PubSubEngine.java
License:Open Source License
private static IQ modifyNodeAffiliations(PubSubService service, IQ iq, Element entitiesElement) { String nodeID = entitiesElement.attributeValue("node"); if (nodeID == null) { // NodeID was not provided. Return bad-request error. return createErrorPacket(iq, PacketError.Condition.bad_request, null); }/*from w ww.j a v a2s. c o m*/ Node node = service.getNode(nodeID); if (node == null) { // Node does not exist. Return item-not-found error. return createErrorPacket(iq, PacketError.Condition.item_not_found, null); } if (!node.isAdmin(iq.getFrom())) { // Requesting entity is prohibited from getting affiliates list. Return forbidden error. return createErrorPacket(iq, PacketError.Condition.forbidden, null); } IQ reply = IQ.createResultIQ(iq); Collection<JID> invalidAffiliates = new ArrayList<JID>(); // Process modifications or creations of affiliations for (Iterator it = entitiesElement.elementIterator("affiliation"); it.hasNext();) { Element affiliation = (Element) it.next(); JID owner = new JID(affiliation.attributeValue("jid")); String newAffiliation = affiliation.attributeValue("affiliation"); // Get current affiliation of this user (if any) NodeAffiliate affiliate = node.getAffiliate(owner); // Check that we are not removing the only owner of the node if (affiliate != null && !affiliate.getAffiliation().name().equals(newAffiliation)) { // Trying to modify an existing affiliation if (affiliate.getAffiliation() == NodeAffiliate.Affiliation.owner && node.getOwners().size() == 1) { // Trying to remove the unique owner of the node. Include in error answer. invalidAffiliates.add(owner); continue; } } // Owner is setting affiliations for new entities or modifying // existing affiliations if ("owner".equals(newAffiliation)) { node.addOwner(owner); } else if ("publisher".equals(newAffiliation)) { node.addPublisher(owner); } else if ("none".equals(newAffiliation)) { node.addNoneAffiliation(owner); } else { node.addOutcast(owner); } } // Process invalid entities that tried to remove node owners. Send original affiliation // of the invalid entities. if (!invalidAffiliates.isEmpty()) { reply.setError(PacketError.Condition.not_acceptable); Element child = reply.setChildElement("pubsub", "http://jabber.org/protocol/pubsub#owner"); Element entities = child.addElement("affiliations"); if (!node.isRootCollectionNode()) { entities.addAttribute("node", node.getNodeID()); } for (JID affiliateJID : invalidAffiliates) { NodeAffiliate affiliate = node.getAffiliate(affiliateJID); Element entity = entities.addElement("affiliation"); entity.addAttribute("jid", affiliate.getJID().toString()); entity.addAttribute("affiliation", affiliate.getAffiliation().name()); } } return reply; }
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);//from w w w . j a v a 2s.c om 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;/* w w w . j a 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"; 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;//from w w w . 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"; // 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;//from w ww . j a v a 2 s . c o m 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;//from w w w.ja v a 2 s . co m 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) {//from w w w.j a v a 2s . c o 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()); } } } }