List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:com.heren.turtle.server.utils.XmlUtils.java
License:Open Source License
/** * back successful information// w ww. j a v a2 s . co m * * @return */ public static String resultMessage() { Document document = DocumentHelper.createDocument(); Element payload = DocumentHelper.createElement("payload"); document.setRootElement(payload); Element response = payload.addElement("response"); Element result = response.addElement("result"); result.setText("true"); Element resultText = response.addElement("resultText"); resultText.setText("??"); Element userId = response.addElement("userId"); userId.setText("0001"); return document.asXML(); }
From source file:com.heren.turtle.server.utils.XmlUtils.java
License:Open Source License
/** * @param params ArrayList// www . j av a 2 s.com * @return String */ public static String createResultMessage(List<Map<String, Object>> params) throws Exception { Document document; if (params != null && params.size() > 0) { document = DocumentHelper.createDocument(); Element root = document.addElement("payload"); Element response = root.addElement("response"); Element items = response.addElement("items"); for (Map<String, Object> param : params) { Element item = items.addElement("item"); param.keySet().forEach(key -> { Element element = item.addElement(key); element.setText(String.valueOf(param.get(key))); }); } Element userId = response.addElement("user_id"); userId.setText("0001"); } else { document = DocumentHelper.createDocument(); Element root = document.addElement("payload"); Element response = root.addElement("response"); Element userId = response.addElement("user_id"); userId.setText("0001"); } return document.asXML(); }
From source file:com.heren.turtle.server.utils.XmlUtils.java
License:Open Source License
/** * @param params HashMap/*ww w . j a v a 2 s. c o m*/ * @return String */ public static String createResultMessage(Map<String, Object> params) throws Exception { Document document; if (params != null) { document = DocumentHelper.createDocument(); Element root = document.addElement("payload"); Element response = root.addElement("response"); params.keySet().forEach(key -> { Element element = response.addElement(key); element.setText(String.valueOf(params.get(key))); }); Element userId = response.addElement("user_id"); userId.setText("0001"); } else { document = DocumentHelper.createDocument(); Element root = document.addElement("payload"); Element response = root.addElement("response"); Element userId = response.addElement("user_id"); userId.setText("0001"); } return document.asXML(); }
From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java
License:Apache License
/** * ?XML * * @return */ public Document CreateDocument() { Document document = DocumentHelper.createDocument(); return document; }
From source file:com.ikon.servlet.admin.StatsGraphServlet.java
License:Open Source License
/** * Convert a piechartdata to xml//from w w w . j a v a 2 s . c om * * @author puspendu.banerjee@gmail.com */ public String repoStatsXML(final String title, final DefaultPieDataset dataset) throws IOException, ServletException { Document document = DocumentHelper.createDocument(); Element root = document.addElement("RepoStats"); root.addElement("Title").addCDATA(title); Element dataSetElement = root.addElement("DataSet"); for (int i = 0; i < dataset.getItemCount(); i++) { Element itemElement = dataSetElement.addElement("Item"); itemElement.addElement("name").addCDATA(dataset.getKey(i).toString()); itemElement.addAttribute("percent", dataset.getValue(i).toString()); dataSetElement.add(itemElement); } return document.asXML(); }
From source file:com.jaspersoft.jasperserver.export.ExporterImpl.java
License:Open Source License
protected void process() { Document indexDocument = DocumentHelper.createDocument(); indexRootElement = indexDocument.addElement(getIndexRootElementName()); setOutputProperties();//from w w w .jav a2s . c o m invokeModules(); writeIndexDocument(indexDocument); }
From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java
License:Apache License
/** * ?//ww w.j av a 2 s.c om * @throws IOException */ public void generate() throws IOException { resolveFields(domainClazz); Document document = DocumentHelper.createDocument(); generateDocType(document); Element root = generateRoot(document); generateInsert(root); generateGet(root); generateUpdate(root); generateList(root); generateDelete(root); generateResultMap(root); write(document); }
From source file:com.jswiff.xml.XMLWriter.java
License:Open Source License
/** * Creates a new XMLWriter instance and generates an in-memory XML document * from the SWF document used as argument. * * @param swfDocument the SWF doc to be converted to XML *//*from w w w . ja va 2 s . c om*/ public XMLWriter(SWFDocument swfDocument) { this.swfDocument = swfDocument; xmlDocument = DocumentHelper.createDocument(); rootElement = xmlDocument.addElement("swfdocument"); writeHeader(); writeTags(); }
From source file:com.laudandjolynn.mytv.MyTvData.java
License:Apache License
public void writeData(String parent, String tag, String value) { logger.debug("write data to my tv data file: " + Constant.MY_TV_DATA_FILE_PATH); File file = new File(Constant.MY_TV_DATA_FILE_PATH); if (!file.exists()) { Document doc = DocumentHelper.createDocument(); doc.addElement(Constant.APP_NAME); try {//w ww. j av a2 s .c o m FileUtils.writeWithNIO(doc.asXML().getBytes(), Constant.MY_TV_DATA_FILE_PATH); } catch (IOException e) { throw new MyTvException( "error occur while write data to file. -- " + Constant.MY_TV_DATA_FILE_PATH); } } SAXReader reader = new SAXReader(); try { Document xmlDoc = reader.read(file); Element parentElement = xmlDoc.getRootElement(); if (parent != null) { List<?> nodes = xmlDoc.selectNodes("//" + parent); if (nodes != null && nodes.size() > 0) { parentElement = (Element) nodes.get(0); } } parentElement.addElement(tag).setText(value); try { XMLWriter writer = new XMLWriter(new FileWriter(file)); writer.write(xmlDoc); writer.close(); } catch (IOException e) { throw new MyTvException( "error occur while write data to file. -- " + Constant.MY_TV_DATA_FILE_PATH); } } catch (DocumentException e) { String msg = "can't parse xml file. -- " + Constant.MY_TV_DATA_FILE_PATH; throw new MyTvException(msg); } }
From source file:com.liferay.jbpm.WorkflowComponentImpl.java
License:Open Source License
public String getCurrentTasksXml(long instanceId, long tokenId) throws WorkflowComponentException { List tasks = getCurrentTasks(instanceId, tokenId); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("result"); if (tasks != null) { for (int i = 0; i < tasks.size(); i++) { TaskInstance task = (TaskInstance) tasks.get(i); createElement(task, root);//from w w w . ja v a2 s.c om } } return doc.asXML(); }