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:com.openedit.users.filesystem.XmlUserArchive.java
License:Open Source License
public void saveGroup(Group inGroup) throws UserManagerException { Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement("group"); if (inGroup.getId() == null) { int id = getUserIdCounter().incrementCount(); String inAccount = String.valueOf(id); inGroup.setId(inAccount);//from www.j a v a 2 s .c o m } root.addAttribute("id", inGroup.getId()); Element groupNameElem = root.addElement("group-name"); groupNameElem.setText(inGroup.getName()); Element permissionsElem = root.addElement("permissions"); for (Iterator iter = inGroup.getPermissions().iterator(); iter.hasNext();) { Object permission = (Object) iter.next(); Element permissionElem = permissionsElem.addElement("permission"); permissionElem.setText(permission.toString()); } MapPropertyContainer map = (MapPropertyContainer) inGroup.getPropertyContainer(); if (map != null) { Element propertiesElem = map.createPropertiesElement("properties"); root.add(propertiesElem); } File file = loadGroupFile(inGroup.getId()); getXmlUtil().saveXml(doc, file); getGroupIdToGroupMap().remove(inGroup.getId()); }
From source file:com.orange.atk.atkUI.corecli.Campaign.java
License:Apache License
/** * Save current campaign in .mcl file//from ww w . jav a 2 s. c o m * * @param clFileName * @throws IOException */ public static void save(String clFileName, Campaign camp) { Document document = DocumentHelper.createDocument(); Element root = document.addElement("campaign"); if (camp.getName() != null) root.addAttribute("name", camp.getName()); if (camp.getAuthor() != null) root.addAttribute("author", camp.getAuthor()); if (camp.getDate() != null) root.addAttribute("date", camp.getDate()); if (camp.getDescription() != null) root.addAttribute("description", camp.getDescription()); int stepNumber = 0; for (Step step : camp) { step.save(root, stepNumber); stepNumber++; } OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(clFileName), format); writer.write(document); writer.close(); } catch (IOException e) { Alert.raise(e, "Unable to save check-list in a file."); } }
From source file:com.orange.atk.atkUI.coregui.PhoneConfigurationWizard.java
License:Apache License
/** * call when user has changed configuration in interface */// w w w. j av a 2s. c o m private void saveconfig() { //build xml Logger.getLogger(this.getClass()).debug("save config"); Document configxml = DocumentHelper.createDocument(); Element root = configxml.addElement("confile"); Element graphlist = root.addElement("graphlist"); //global graph for (int i = 0; i < graphs.getSize(); i++) { graphlist.addElement("graph").addAttribute("name", graphs.getName(i)) .addAttribute("color", graphs.getColor(i)).addAttribute("xcomment", graphs.getcommentX(i)) .addAttribute("ycomment", graphs.getcommentY(i)).addAttribute("unit", graphs.getunit(i)) .addAttribute("scale", graphs.getscale(i)).addAttribute("sampled", graphs.getsampled(i)); } //table Graph if (tablemodel != null) for (int i = 0; i < tablemodel.getRowCount(); i++) { //don't save non-fill row String processname = (String) tablemodel.getValueAt(i, 0); String type = (String) tablemodel.getValueAt(i, 1); String color = (String) tablemodel.getValueAt(i, 2); if ("process".equals(processname) || "color".equals(color) || "Cpu or Mem".equals(type)) { JOptionPane.showMessageDialog(null, "You must select the process, the color AND the type! \nThe line will be ignored."); continue; } String unit = ""; String scale = "1"; if (type.equals("Cpu")) unit = "%"; else if (type.equals("Memory")) { unit = "KBytes"; } else if (type.equals("Data sent")) { unit = "KBytes"; scale = "1000"; } else if (type.equals("Data received")) { unit = "KBytes"; scale = "1000"; } graphlist.addElement("graph").addAttribute("name", type + "_" + processname) .addAttribute("color", color).addAttribute("xcomment", "time (min)") .addAttribute("ycomment", type + " " + processname).addAttribute("unit", unit) .addAttribute("scale", scale).addAttribute("sampled", "true"); } //marker Element markerlist = root.addElement("markerlist"); for (int i = 0; i < events.getSize(); i++) markerlist.addElement("marker").addAttribute("name", events.getName(i)).addAttribute("color", "gray") .addAttribute("position", events.getPosition(i).toString()); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(configpath), format); writer.write(configxml); // // XMLWriter out = new XMLWriter(System.out,format); // out.write(configxml); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (writer != null) try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.orange.atk.phone.android.wizard.AndroidWizard.java
License:Apache License
public void printReport() { String configXmlFileName = configFileName + ".xml"; Document configxml = DocumentHelper.createDocument(); configxml.addComment(" " + phone.getName() + " configuration file "); configxml.addComment(" Screen resolution " + screenWidth + "x" + screenHeight + " "); Element root = configxml.addElement("Android-config"); Element canalPattern = root.addElement("CanalPattern"); //keyboards//from ww w.ja v a 2 s . c om if (!keyboard.equals("")) printKeyMapping("keyboard", keyboard, canalPattern, root); if (!keyboard2.equals("")) printKeyMapping("keyboard2", keyboard2, canalPattern, root); if (!keyboard3.equals("")) printKeyMapping("keyboard3", keyboard3, canalPattern, root); Set<String> softKeySet = softKeyMap.keySet(); Element keyMapping = root.addElement("SoftKeyMapping"); for (String key : softKeySet) { keyMapping.addElement("Key").addAttribute("name", key) .addAttribute("avgX", "" + softKeyMap.get(key).getX()) .addAttribute("avgY", "" + softKeyMap.get(key).getY()); } //touchscreen if (!touchscreen.equals("")) { canalPattern.addElement("Pattern").addAttribute("canal", "touchscreen").addAttribute("value", touchscreen.replace("\"", "")); Element Touchscreen = root.addElement("Touchscreen"); Touchscreen.addComment("!!! THIS IS JUST TOUCHSCREEN Elements TEMPLATE !!!"); Touchscreen .addComment("!!! SEE ATK User Guide - Configuration section - and UPDATE following values !!!"); if (codeX != -1 && codeY != -1) { Touchscreen.addComment("!!! Please check following X Y ratioX and ratioY patterns"); Touchscreen.addElement("Pattern").addAttribute("name", "X").addAttribute("value", "3 " + codeX + " "); Touchscreen.addElement("Pattern").addAttribute("name", "Y").addAttribute("value", "3 " + codeY + " "); long ratio = maxX * 100 / screenWidth; Touchscreen.addElement("Pattern").addAttribute("name", "ratioX").addAttribute("value", String.valueOf((double) ratio / 100.0)); ratio = maxY * 100 / screenHeight; Touchscreen.addElement("Pattern").addAttribute("name", "ratioY").addAttribute("value", String.valueOf((double) ratio / 100.0)); Touchscreen.addComment("!!! Please update following patterns"); } else { Touchscreen.addElement("Pattern").addAttribute("name", "X").addAttribute("value", "0 0 "); Touchscreen.addElement("Pattern").addAttribute("name", "Y").addAttribute("value", "0 0 "); Touchscreen.addElement("Pattern").addAttribute("name", "ratioX").addAttribute("value", "1.0"); Touchscreen.addElement("Pattern").addAttribute("name", "ratioY").addAttribute("value", "1.0"); } Touchscreen.addElement("Pattern").addAttribute("name", "down").addAttribute("value", "0 0 0"); Touchscreen.addElement("Pattern").addAttribute("name", "downmax").addAttribute("value", "0 0 0"); Touchscreen.addElement("Pattern").addAttribute("name", "up").addAttribute("value", "0 0 0"); Touchscreen.addElement("Pattern").addAttribute("name", "flush").addAttribute("value", "0 0 0"); Touchscreen.addElement("Pattern").addAttribute("name", "flush2").addAttribute("value", "0 2 0"); Touchscreen.addElement("Threshold").addAttribute("name", "move").addAttribute("value", "15"); Touchscreen.addElement("Option").addAttribute("name", "sendMouseDownForMove").addAttribute("value", "true"); Touchscreen.addElement("Option").addAttribute("name", "sendMouseEventFirst").addAttribute("value", "true"); Touchscreen.addElement("Option").addAttribute("name", "useMonkeyForPress").addAttribute("value", "true"); } //Write the file. OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(configXmlFileName), format); writer.write(configxml); writer.close(); } catch (IOException e) { e.printStackTrace(); } //Show a confirm dialog and exit the wizard JOptionPane.showConfirmDialog(this, "A template of the config file has been created under \n" + configXmlFileName + "\n" + "See ATK User guide to configure the Touchscreen section of this template\n", "Success", JOptionPane.CLOSED_OPTION); exit(true); }
From source file:com.org.dms.action.service.claimmng.WorkDispatchMngAction.java
/** * /*from w w w . ja v a 2 s . co m*/ * @param type 2? 1 * @param remark * @param type workId * @return */ public String dispatchResult(String type, Map<String, String> map) { Document domresult = DocumentFactory.getInstance().createDocument(); Element root = domresult.addElement("DBSET"); Element r = root.addElement("R"); Element c01 = r.addElement("C"); c01.addAttribute("N", "BACK_ID");//???ID if (map.get("workId") != null && !"".equals(map.get("workId"))) { c01.addText(map.get("workId")); } Element c02 = r.addElement("C"); c02.addAttribute("N", "JOBORDER_PK");//400? if (map.get("joborderPk") != null && !"".equals(map.get("joborderPk"))) { c02.addText(map.get("joborderPk")); } Element c03 = r.addElement("C"); c03.addAttribute("N", "JOBORDER_CODE");//400?? if (map.get("joborderCoe") != null && !"".equals(map.get("joborderCoe"))) { c03.addText(map.get("joborderCoe")); } Element c04 = r.addElement("C"); c04.addAttribute("N", "BACK_TYPE");//??12 c04.addText(type); Element c05 = r.addElement("C"); c05.addAttribute("N", "BACK_MSG");// if (map.get("remarks") != null && !"".equals(map.get("remarks"))) { c05.addText(map.get("remarks")); } Element c06 = r.addElement("C"); c06.addAttribute("N", "JOBORDER_DNAME");//???(??) if (map.get("orgCode") != null && !"".equals(map.get("orgCode"))) { c06.addText(map.get("orgCode")); } Element c07 = r.addElement("C"); c07.addAttribute("N", "JOBORDER_OUT");//? if (map.get("ifout") != null && !"".equals(map.get("ifout"))) { c07.addText(map.get("ifout")); } Element c08 = r.addElement("C"); c08.addAttribute("N", "REPAIRER_NAME");//?? if (map.get("userName") != null && !"".equals(map.get("userName"))) { c08.addText(map.get("userName")); } Element c09 = r.addElement("C"); c09.addAttribute("N", "REPAIRER_CONTACT");//?? if (map.get("mobils") != null && !"".equals(map.get("mobils"))) { c09.addText(map.get("mobils")); } Element c10 = r.addElement("C"); c10.addAttribute("N", "VEHICLE_FLAG");//VEHICLE_FLAG ??10? if (map.get("ifVehicle") != null && !"".equals(map.get("ifVehicle"))) { c10.addText(map.get("ifVehicle")); } Element c11 = r.addElement("C"); c11.addAttribute("N", "VEHICLE_NUMBER");//? if (map.get("licensePlate") != null && !"".equals(map.get("licensePlate"))) { c11.addText(map.get("licensePlate")); } Element c12 = r.addElement("C"); c12.addAttribute("N", "JOBORDER_DTIME");//(YYYY-MM-DD HH24:MI:SS) if (map.get("dtime") != null && !"".equals(map.get("dtime"))) { c12.addText(Pub.getCurrentDate().toLocaleString()); } else { c12.addText(Pub.getCurrentDate().toLocaleString()); } Element c13 = r.addElement("C"); c13.addAttribute("N", "REMARK");// if (map.get("remarks") != null && !"".equals(map.get("remarks"))) { c13.addText(map.get("remarks")); } return domresult.getRootElement().asXML(); }
From source file:com.oubeichen.gefexp.ShapesEditor.java
License:Open Source License
private void createRawOutput(ByteArrayOutputStream out) throws IOException { /*StringBuffer sb = new StringBuffer(); Iterator it = getModel().getChildren() .iterator(), conit;// w w w.j a v a2 s .co m HashSet<Connection> hs = new HashSet<Connection>(); sb.append("Shapes:\n" + getModel().getChildren() .size() + "\n");// shape while (it.hasNext()) { Shape sp = (Shape) it.next(); sb.append(sp.toString() + "\n"); sb.append("height:\n" + sp.getSize().height + "\nwidth:\n" + sp.getSize().width + "\n"); sb.append("location:\n" + sp.getLocation().x + " " + sp.getLocation().y + "\n"); conit = sp.getSourceConnections() .iterator(); while (conit.hasNext()) { hs.add((Connection) conit.next()); } conit = sp.getTargetConnections() .iterator(); while (conit.hasNext()) { hs.add((Connection) conit.next()); } sb.append("\n");// ? } sb.append("Connections:\n" + hs.size() + "\n"); it = hs.iterator(); while (it.hasNext()) { Connection con = (Connection) it .next(); sb.append(con.getSource() .toString() + "\n"); sb.append(con.getTarget() .toString() + "\n"); sb.append("\n");// ? } out.write(sb.toString().getBytes());*/ Document document = DocumentHelper.createDocument(); Element root = document.addElement("diagram");// Element shaperoot = root.addElement("shapes"); Iterator it = getModel().getChildren().iterator(), conit; HashSet<Connection> hs = new HashSet<Connection>(); while (it.hasNext()) {//shape Shape sp = (Shape) it.next(); Element shapeElm = shaperoot.addElement("shape"); shapeElm.addElement("name").addText(sp.toString()); shapeElm.addElement("height").addText(String.valueOf(sp.getSize().height)); shapeElm.addElement("width").addText(String.valueOf(sp.getSize().width)); shapeElm.addElement("locx").addText(String.valueOf(sp.getLocation().x)); shapeElm.addElement("locy").addText(String.valueOf(sp.getLocation().y)); conit = sp.getSourceConnections().iterator(); while (conit.hasNext()) { hs.add((Connection) conit.next()); } conit = sp.getTargetConnections().iterator(); while (conit.hasNext()) { hs.add((Connection) conit.next()); } } Element connroot = root.addElement("connections"); it = hs.iterator(); while (it.hasNext()) { Element connElm = connroot.addElement("connection"); Connection con = (Connection) it.next(); connElm.addElement("source").addText(con.getSource().toString()); connElm.addElement("target").addText(con.getTarget().toString()); } OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); // XML? XMLWriter writer; try { writer = new XMLWriter(out, format); writer.write(document); writer.close(); } catch (IOException ex) { System.err.println("Cannot create output file!"); ex.printStackTrace(); } out.close(); }
From source file:com.poka.util.XmlSax.java
public String getZCXDFileNameL() { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); if (rootElm == null) { rootElm = doc.addElement("root"); }//w ww .j a v a2s . co m Element root1Elm = rootElm.element("zcxdL"); if (root1Elm == null) { root1Elm = rootElm.addElement("zcxdL"); root1Elm.setText("[0-9]{8}_[0-9A-Za-z]*_[0-9]*_1_(CNY)[.]FSN$"); writeToXml(doc, bankFile); return "[0-9]{8}_[0-9A-Za-z]*_[0-9]*_1_(CNY)[.]FSN$"; } else { return root1Elm.getTextTrim(); } }
From source file:com.poka.util.XmlSax.java
public String getZCXDFileNameC() { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); if (rootElm == null) { rootElm = doc.addElement("root"); }/* ww w .j a va 2 s. c o m*/ Element root1Elm = rootElm.element("zcxdC"); if (root1Elm == null) { root1Elm = rootElm.addElement("zcxdC"); root1Elm.setText("[0-9]{8}_[0-9A-Za-z]*_[0-9]*_2_(CNY)[.]FSN$"); writeToXml(doc, bankFile); return "[0-9]{8}_[0-9A-Za-z]*_[0-9]*_2_(CNY)[.]FSN$"; } else { return root1Elm.getTextTrim(); } }
From source file:com.poka.util.XmlSax.java
public String getGDFileNameL() { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); if (rootElm == null) { rootElm = doc.addElement("root"); }/*from w ww . j a va 2s . com*/ Element root1Elm = rootElm.element("dgL"); if (root1Elm == null) { root1Elm = rootElm.addElement("dgL"); root1Elm.setText("[0-9A-Za-z]*_[0-9]{14}_[0-9A-Za-z]{8}_[0-9]*_(1|2|3)[.]FSN$"); writeToXml(doc, bankFile); return "[0-9A-Za-z]*_[0-9]{14}_[0-9A-Za-z]{8}_[0-9]*_(1|2|3)[.]FSN$"; } else { return root1Elm.getTextTrim(); } }
From source file:com.poka.util.XmlSax.java
public String getGDFileNameC() { Document doc = load(bankFile, false); Element rootElm = doc.getRootElement(); if (rootElm == null) { rootElm = doc.addElement("root"); }/* w w w. j ava2 s . c o m*/ Element root1Elm = rootElm.element("dgC"); if (root1Elm == null) { root1Elm = rootElm.addElement("dgC"); root1Elm.setText("[0-9A-Za-z]*_[0-9]{14}_[0-9A-Za-z]{8}_[0-9]*_(4|8|12)[.]FSN$"); writeToXml(doc, bankFile); return "[0-9A-Za-z]*_[0-9]{14}_[0-9A-Za-z]{8}_[0-9]*_(4|8|12)[.]FSN$"; } else { return root1Elm.getTextTrim(); } }