List of usage examples for org.dom4j Element elements
List<Element> elements(QName qName);
From source file:com.poka.util.XmlSax.java
public boolean changeBankNumXmlAtt() { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("bankInfos"); if (root1Elm == null) { root1Elm = rootElm.addElement("bankInfos"); }//from w ww . ja va 2 s . c om boolean flag = false; List nodes = root1Elm.elements("bankInfo"); for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); String attr = elm.attributeValue("id"); if (attr.equals("1")) { flag = true; elm.setAttributeValue("ip", this.ip); elm.setAttributeValue("port", this.port); elm.setAttributeValue("bankNum", this.bankNum); elm.setAttributeValue("NetWorkNum", this.networkNum); } else { continue; } } if (!flag) { Element elm = root1Elm.addElement("bankInfo"); elm.setAttributeValue("ip", this.ip); elm.setAttributeValue("port", this.port); elm.setAttributeValue("bankNum", this.bankNum); elm.setAttributeValue("NetWorkNum", this.networkNum); elm.setAttributeValue("id", "1"); } return writeToXml(doc, bankFile); }
From source file:com.poka.util.XmlSax.java
public void getBankInfo() { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("bankInfos"); if (root1Elm == null) { root1Elm = rootElm.addElement("bankInfos"); }/*w w w.ja v a 2 s. c om*/ List nodes = root1Elm.elements("bankInfo"); for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); String attr = elm.attributeValue("id"); if (attr.equals("1")) { this.setIp(elm.attributeValue("ip")); this.setPort(elm.attributeValue("port")); setBankNum(elm.attributeValue("bankNum")); setNetworkNum(elm.attributeValue("NetWorkNum")); } } }
From source file:com.poka.util.XmlSax.java
public void getMachineInfo() { this.machines = new ArrayList<MachinesCfg>(); Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("machines"); if (root1Elm == null) { root1Elm = rootElm.addElement("machines"); }/* w w w .j a v a 2 s . c om*/ List nodes = root1Elm.elements("machine"); for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); if (elm.attributeValue("type").equals("" + FsnComProperty.comBusType)) { MachinesCfg cfg = new MachinesCfg(); cfg.setIp(elm.attributeValue("ip")); cfg.setMachineType(elm.attributeValue("machineType")); cfg.setMachineNum(Integer.parseInt(elm.attributeValue("machineNum").trim())); cfg.setUser1(elm.attributeValue("user1")); cfg.setUser2(elm.attributeValue("user2")); cfg.setType(Integer.parseInt(elm.attributeValue("type").trim())); this.machines.add(cfg); } } }
From source file:com.poka.util.XmlSax.java
public MachinesCfg getMachineInfo(int type, String ip) { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("machines"); if (root1Elm == null) { root1Elm = rootElm.addElement("machines"); }/* w w w . j ava 2 s . c o m*/ List nodes = root1Elm.elements("machine"); for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); if (elm.attributeValue("type").equals("" + type) && elm.attributeValue("ip").equals(ip.trim())) { MachinesCfg cfg = new MachinesCfg(); cfg.setIp(elm.attributeValue("ip")); cfg.setMachineType(elm.attributeValue("machineType")); cfg.setMachineNum(Integer.parseInt(elm.attributeValue("machineNum").trim())); cfg.setUser1(elm.attributeValue("user1")); cfg.setUser2(elm.attributeValue("user2")); cfg.setType(Integer.parseInt(elm.attributeValue("type").trim())); return cfg; } } return null; }
From source file:com.poka.util.XmlSax.java
public void getAddMachineInfo() { this.addMachines = new ArrayList<>(); Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("machines"); if (root1Elm == null) { root1Elm = rootElm.addElement("machines"); }//from ww w . j a va2 s.c o m List nodes = root1Elm.elements("machine"); for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); if (elm.attributeValue("type").equals("" + FsnComProperty.atmAddBusType)) { MachinesCfg cfg = new MachinesCfg(); cfg.setIp(elm.attributeValue("ip")); cfg.setMachineType(elm.attributeValue("machineType")); cfg.setMachineNum(Integer.parseInt(elm.attributeValue("machineNum").trim())); cfg.setUser1(elm.attributeValue("user1")); cfg.setUser2(elm.attributeValue("user2")); cfg.setType(Integer.parseInt(elm.attributeValue("type").trim())); this.addMachines.add(cfg); } } }
From source file:com.poka.util.XmlSax.java
public void getGuaoMachineInfo() { this.guaoMachines = new ArrayList<MachinesCfg>(); Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("machines"); if (root1Elm == null) { root1Elm = rootElm.addElement("machines"); }/*from www. j ava 2 s.c o m*/ List nodes = root1Elm.elements("machine"); for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); if (elm.attributeValue("type").equals("" + FsnComProperty.guaoBusType)) { MachinesCfg cfg = new MachinesCfg(); cfg.setIp(elm.attributeValue("ip")); cfg.setMachineType(elm.attributeValue("machineType")); cfg.setMachineNum(Integer.parseInt(elm.attributeValue("machineNum").trim())); cfg.setUser1(elm.attributeValue("user1")); cfg.setUser2(elm.attributeValue("user2")); cfg.setType(Integer.parseInt(elm.attributeValue("type").trim())); this.guaoMachines.add(cfg); } } }
From source file:com.poka.util.XmlSax.java
public int updateOrAddMachineInfo(MachinesCfg cfg) { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("machines"); if (root1Elm == null) { root1Elm = rootElm.addElement("machines"); }/*from w w w. j av a2s. c o m*/ List nodes = root1Elm.elements("machine"); boolean flag = false; for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); if (elm.attributeValue("ip").trim().equals(cfg.getIp().trim()) && elm.attributeValue("type").trim().equals("" + cfg.getType())) { elm.setAttributeValue("machineType", cfg.getMachineType().trim()); elm.setAttributeValue("machineNum", "" + cfg.getMachineNum()); elm.setAttributeValue("user1", cfg.getUser1().trim()); elm.setAttributeValue("user2", cfg.getUser2().trim()); elm.setAttributeValue("type", "" + cfg.getType()); flag = true; break; } } if (!flag) { Element tem = root1Elm.addElement("machine"); tem.addAttribute("machineType", cfg.getMachineType().trim()); tem.setAttributeValue("machineNum", "" + cfg.getMachineNum()); tem.addAttribute("ip", cfg.getIp().trim()); tem.addAttribute("user1", cfg.getUser1().trim()); tem.addAttribute("user2", cfg.getUser2().trim()); tem.addAttribute("type", "" + cfg.getType()); } try { OutputFormat format = OutputFormat.createPrettyPrint(); // format.setEncoding("UTF-8"); format.setEncoding(encodingType); XMLWriter writer = new XMLWriter(new FileWriter(bankFile), format); writer.write(doc); writer.flush(); writer.close(); if (flag) {// return 0; } else {// return 1; } // return true; } catch (IOException ex) { Logger.getLogger(XmlSax.class.getName()).log(Level.SEVERE, null, ex); } return -1; }
From source file:com.poka.util.XmlSax.java
public OperationUser getUser1AndUser2(String sIp, int type) { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("machines"); if (root1Elm == null) { root1Elm = rootElm.addElement("machines"); }/*from www . j a va 2s . c o m*/ List nodes = root1Elm.elements("machine"); OperationUser usr = new OperationUser(); for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); if (elm.attributeValue("ip").trim().equals(sIp.trim()) && elm.attributeValue("type").trim().equals("" + type)) { usr.setUser1(elm.attributeValue("user1").trim()); usr.setUser2(elm.attributeValue("user2").trim()); } } return usr; }
From source file:com.poka.util.XmlSax.java
public boolean isCfgIp(String sIp, int type) { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("machines"); if (root1Elm == null) { root1Elm = rootElm.addElement("machines"); }//from w w w .ja v a 2 s .c o m List nodes = root1Elm.elements("machine"); boolean flag = false; for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); if (elm.attributeValue("ip").trim().equals(sIp.trim()) && elm.attributeValue("type").trim().equals("" + type)) { return true; } } return false; }
From source file:com.poka.util.XmlSax.java
public boolean deleteMachineInfo(MachinesCfg cfg) { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); Element root1Elm = rootElm.element("machines"); if (root1Elm == null) { root1Elm = rootElm.addElement("machines"); }/*from ww w.ja va 2 s.c o m*/ List nodes = root1Elm.elements("machine"); boolean flag = false; for (Iterator it = nodes.iterator(); it.hasNext();) { Element elm = (Element) it.next(); if (elm.attributeValue("ip").trim().equals(cfg.getIp().trim()) && elm.attributeValue("type").trim().equals("" + cfg.getType())) { root1Elm.remove(elm); break; } } return writeToXml(doc, bankFile); }