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.apicloud.commons.model.Feature.java
License:Open Source License
public static Element saveXml3(List<Feature> features) { Document document = XMLUtil.createDocument(); Element rootElement = document.addElement("Features"); createFeatureElement3(rootElement, features); return rootElement; }
From source file:com.apicloud.commons.model.Feature.java
License:Open Source License
public static String XMLTOString2(File file) { String documentStr = ""; List<Feature> features = Feature.loadXml3(file); Document document = DocumentHelper.createDocument(); Element rootElement = document.addElement("Features"); for (Feature feature : features) { Element featureElement = rootElement.addElement("feature"); featureElement.setName(feature.getName()); if (feature.getParams().size() == 1) { Element paramElement = featureElement.addElement("param"); paramElement.addAttribute(feature.getName(), feature.getParams().get(0).getName() + ":" + feature.getParams().get(0).getValue()); } else if (feature.getParams().size() == 2) { Element paramElement = featureElement.addElement("param"); paramElement.addAttribute(feature.getParams().get(0).getName(), feature.getParams().get(0).getValue()); paramElement.addAttribute(feature.getParams().get(1).getName(), feature.getParams().get(1).getValue()); }/*from w w w. j ava 2 s . co m*/ } documentStr = document.asXML(); return documentStr; }
From source file:com.autoupdater.client.xml.creators.FileCacheXMLCreator.java
License:Apache License
/** * Creates XML document with file cache data and stores it info file. * //from ww w .j ava2 s . co m * @param destination * destination file * @param fileCache * file cache which needs to be saved * @throws IOException * thrown when error occurs during storing data to file */ public void createXML(File destination, Map<String, String> fileCache) throws IOException { logger.debug("Save file cache data at: " + destination.getCanonicalPath()); Document fileCacheXML = DocumentHelper.createDocument(); fileCacheXML.addComment(XMLCreationConfiguration.DO_NOT_EDIT_FILE_MANUALLY_WARNING); Element files = fileCacheXML.addElement(FileCacheSchema.files); addFiles(files, fileCache); Files.write(fileCacheXML.asXML(), destination, XMLCreationConfiguration.XML_ENCODING); logger.trace("Saved file cache data at: " + destination.getCanonicalPath()); }
From source file:com.beacon.wlsagent.xml.XmlWorker.java
public Document genIniXml(Map pinnedInfoMap) { Document document = DocumentHelper.createDocument(); Element root = document.addElement("MONITOR").addAttribute("Date", BeaconUtil.getStringDate()); if (pinnedInfoMap != null) { String agentVer = lic.getIp().equals("ANY") ? "- TRIAL LICENSE" : "- FORMAL LICENSE"; agentVer = "1.0 " + agentVer; root.addElement("INITBUF") .addAttribute("AdminServerName", (String) pinnedInfoMap.get("AdminServerName")) .addAttribute("DomainVersion", (String) pinnedInfoMap.get("DomainVersion")) .addAttribute("Name", (String) pinnedInfoMap.get("Name")) .addAttribute("ProductionModeEnabled", ((Boolean) pinnedInfoMap.get("ProductionModeEnabled")).toString()) .addAttribute("RootDirectory", (String) pinnedInfoMap.get("RootDirectory")) .addAttribute("Activationtime", BeaconUtil.longToDateStr((Long) pinnedInfoMap.get("ActivationTime"))) .addAttribute("JDKVendor", (String) pinnedInfoMap.get("JavaVendor")) .addAttribute("JDKVersion", (String) pinnedInfoMap.get("JavaVersion")) .addAttribute("OSVersion", (String) pinnedInfoMap.get("OSVersion")) .addAttribute("OSName", (String) pinnedInfoMap.get("OSName")) .addAttribute("ServerNum", (String) pinnedInfoMap.get("ServerNum")) .addAttribute("AgentVersion", "1.0").addAttribute("LICTYPE", lic.getIp()); ;//from www . ja v a2 s. com } return document; }
From source file:com.beacon.wlsagent.xml.XmlWorker.java
public Document genErrXml(String sysCode) { Document document = DocumentHelper.createDocument(); Element root = document.addElement("MONITOR").addAttribute("Date", BeaconUtil.getStringDate()); root.addElement("SYSTEM").addAttribute("errMsg", sysCode); return document; }
From source file:com.beacon.wlsagent.xml.XmlWorker.java
public Document genMonXml(Document document, BeaconStateCollector fsc) { Document resultDoc = null; if (fsc.isConnectedToAdmin()) { resultDoc = DocumentHelper.createDocument(); Element root = resultDoc.addElement("MONITOR").addAttribute("Date", BeaconUtil.getStringDate()); Element osEle = root.addElement("OSResource"); String cpuStr = BeaconUtil.runShell("sh bin/getCPU.sh"); String memStr = BeaconUtil.runShell("sh bin/getMEM.sh"); if ((cpuStr == "") || (memStr == "")) { cpuStr = (String) BeaconUtil.runShell().get("CPU"); memStr = (String) BeaconUtil.runShell().get("MEM"); }//from w ww . j av a 2s . c o m osEle.addAttribute("CPU", cpuStr).addAttribute("MEM", memStr); List mbeanEleList = document.selectNodes("//MBean"); ObjectName[] svrRt = fsc.getServerRT(); int svrRtCount = svrRt.length; int f = 0; for (Iterator i = mbeanEleList.iterator(); i.hasNext();) { Element mbeanEle = (Element) i.next(); String mbeanName = mbeanEle.attributeValue("name"); log.debug("Currently dealing with mbean: " + mbeanName); Iterator k = mbeanEle.elementIterator("attribute"); List al = new ArrayList(); for (; k.hasNext(); f++) { al.add(((Element) k.next()).getText()); } String mbeanAttrStrs[] = BeaconUtil.listToStrArray(al); for (int m = 0; m < svrRtCount; m++) { Map mBeanInfoMap[] = fsc.getMBeanInfoMaps(mbeanAttrStrs, mbeanName, svrRt[m]); String svrName = svrRt[m].getKeyProperty("Name"); log.debug("Currently dealing with server: " + svrRt[m]); if (mBeanInfoMap != null) { for (int g = 0; g < mBeanInfoMap.length; g++) { if (mBeanInfoMap[g] != null && mbeanAttrStrs.length > 0) { Element currItem = root.addElement(mbeanName); currItem.addAttribute("serverName", svrName); for (int j = 0; j < mbeanAttrStrs.length; j++) { String curAttr = mbeanAttrStrs[j]; Object curAttrVal = mBeanInfoMap[g].get(curAttr); if (curAttrVal != null) { currItem.addAttribute(curAttr, String.valueOf(curAttrVal)); } else { root.remove(currItem); j = mbeanAttrStrs.length; } log.debug("Attribute: " + curAttr + " Value: " + String.valueOf(mBeanInfoMap[g].get(curAttr))); } } } } } } } else { resultDoc = this.genErrXml("Happened to lose connection to WebLogic Admin. maybe shutdown"); } return resultDoc; }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
public static void main(String[] args) { try {//from w w w . j av a 2 s . c om Document document = XMLDom4jUtils.createDocument(); Element root = document.getRootElement(); String test02 = "?"; String test2 = "PHS(??)"; Document doc = XMLDom4jUtils.createDocument(); root = doc.addElement("address"); for (int i = 0; i < 1; i++) { XMLDom4jUtils.appendChild(root, "name", test02); XMLDom4jUtils.appendChild(root, "city", "nj"); } XMLDom4jUtils.appendChild(root, "state", test2); XMLDom4jUtils.appendChild(root, "sysDate", new Date()); XMLDom4jUtils.appendChild(root, "intValue", 100); XMLDom4jUtils.toXML(doc, System.out, "utf-8"); System.out.println("-------------------"); // XMLDom4jUtils.element2XML(root, System.out, "utf-8"); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.bsoft.baseframe.baseframe_utils.beanUtils.CreateXMLFile.java
License:Open Source License
/** * xml??//from w w w . jav a 2s .com * @return ?? */ public boolean createXMLFile() { String clsName = FileUtils.getClassName(tbName); String fileName = path + clsName + ".xml"; String beanName = beanPkg + "." + clsName; List<GenaBean> list = GenaBeanDBUtils.getFields(tbName); if (list.size() == 0) { return false; } StringBuffer fields = new StringBuffer(); StringBuffer values = new StringBuffer(); GenaBean gb = null; String fn = null; for (int i = 0; i < list.size(); i++) { gb = list.get(i); fn = gb.getColumnName(); fields.append(fn); if ("delflag".equals(fn)) { values.append("'0'"); } else if ("ctb1".equals(fn)) { values.append("getdate()"); } else { values.append("#").append(fn).append("#"); } if (i != list.size() - 1) { fields.append(", "); values.append(", "); } } System.out.println(fields.toString()); System.out.println(values.toString()); //Document Document document = DocumentHelper.createDocument(); // document.addDocType("sqlMap", "-//ibatis.apache.org//DTD SQL Map 2.0//EN", "http://ibatis.apache.org/dtd/sql-map-2.dtd"); // document Element rootElement = document.addElement("sqlMap"); //?? rootElement.addAttribute("namespace", clsName.toUpperCase()); //insert Element insertNode = rootElement.addElement("insert"); insertNode.addAttribute("id", "add" + clsName); insertNode.addAttribute("parameterClass", beanName); insertNode.setText("insert into " + tbName + "(" + fields + ") values (" + values + ")"); //? Element removeNode = rootElement.addElement("delete"); removeNode.addAttribute("id", "remove" + clsName); removeNode.addAttribute("parameterClass", beanName); removeNode.setText("delete from " + tbName + " where id = #id#"); // Element deleteNode = rootElement.addElement("update"); deleteNode.addAttribute("id", "del" + clsName); deleteNode.addAttribute("parameterClass", beanName); deleteNode.setText("update " + tbName + " set delflag=#delflag# where id = #id#"); //selectOne Element selectOneNode = rootElement.addElement("select"); selectOneNode.addAttribute("id", "getOne" + clsName); selectOneNode.addAttribute("parameterClass", beanName); selectOneNode.addAttribute("resultClass", beanName); selectOneNode.setText("select * from " + tbName + " where id = #id# "); //select Element selectNode = rootElement.addElement("select"); selectNode.addAttribute("id", "queryCount"); selectNode.addAttribute("resultClass", "int"); selectNode.setText("select count(*) as countnum from " + tbName + " where 1=1"); //select Element selectNode2 = rootElement.addElement("select"); selectNode2.addAttribute("id", "list" + clsName); selectNode2.addAttribute("resultClass", beanName); selectNode2.addAttribute("parameterClass", "java.util.Map"); selectNode2.setText("select * from (select top $endNum$ row_number()over(order by TT.id) as RN,* from" + "(SELECT * FROM " + tbName + " where 1=1) as TT)as H where RN > #startNum#"); //update Element updateNode = rootElement.addElement("update"); updateNode.addAttribute("id", "upSap" + clsName); updateNode.addAttribute("parameterClass", beanName); updateNode.setText("UPDATE " + tbName + " "); Element erElement = updateNode.addElement("dynamic"); erElement.addAttribute("prepend", "set"); for (int i = 0; i < list.size(); i++) { gb = list.get(i); fn = gb.getColumnName(); if (!"id".equals(fn)) { Element saElement = erElement.addElement("isNotNull"); saElement.addAttribute("property", fn); saElement.addAttribute("removeFirstPrepend", "true"); saElement.addAttribute("prepend", ","); saElement.setText(fn + "=#" + fn + "#"); } } updateNode.addText(" where "); Element terElement = updateNode.addElement("isNotNull"); terElement.addAttribute("property", "id"); terElement.setText(" id = #id# "); //update Element updateSimpleNode = rootElement.addElement("update"); updateSimpleNode.addAttribute("id", "update" + clsName); updateSimpleNode.addAttribute("parameterClass", beanName); StringBuffer sb = new StringBuffer(); sb.append("update ").append(tbName).append(" set "); for (int i = 0; i < list.size(); i++) { gb = list.get(i); fn = gb.getColumnName(); if (!"id".equals(fn)) { if ("ctb3".equals(fn)) { sb.append(fn).append("=").append("getdate()"); } else { sb.append(fn).append("=#").append(fn).append("#"); } if (i != list.size() - 1) { sb.append(", "); } } } sb.append(" where id = #id# "); updateSimpleNode.setText(sb.toString()); return FileUtils.wrieteXML2Doc(document, new File(fileName)); }
From source file:com.bullx.cacconfig.CACConfig.java
License:Open Source License
public Document getRequest() { Document doc = DocumentHelper.createDocument(); Element request = doc.addElement("request"); DOMElement configsData = getConfigs(); request.add(configsData);/* w w w. java 2 s.c o m*/ return doc; }
From source file:com.bullx.cacdata.CACData.java
License:Open Source License
public Document getRequest() { Document doc = DocumentHelper.createDocument(); Element request = doc.addElement("request"); DOMElement monitorData = getMonitorData(); request.add(monitorData);/*w w w .j a v a 2 s . c o m*/ return doc; }