List of usage examples for org.dom4j.io XMLWriter write
public void write(Object object) throws IOException
From source file:io.mashin.oep.model.Workflow.java
License:Open Source License
@Override public void write(org.dom4j.Element parent) { Document document = parent.getDocument(); parent.detach();//w w w . j a va2 s .co m Element rootElement = document.addElement("workflow-app"); Element graphicalInfoElement = DocumentHelper.createElement("workflow"); XMLWriteUtils.writeWorkflowSchemaVersion(getSchemaVersion(), rootElement); XMLWriteUtils.writeSLAVersion(this, rootElement); XMLWriteUtils.writeTextPropertyAsAttribute(name, rootElement, "name"); XMLWriteUtils.writePropertiesCollection(parameters, rootElement, "parameters", "property"); XMLWriteUtils.writeGlobalProperty(global, rootElement); XMLWriteUtils.writeCredentialsCollection(credentials, rootElement); startNode.write(rootElement); for (Node node : nodes) { if (!(node.equals(startNode) || node.equals(endNode))) { node.write(rootElement); } graphicalInfoElement.addElement("node").addAttribute("name", node.getName()) .addAttribute("x", node.getPosition().x + "").addAttribute("y", node.getPosition().y + ""); } endNode.write(rootElement); XMLWriteUtils.writeSLAProperty(this, sla, rootElement); Comment graphicalInfoNode = null; try { StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()); writer.write(graphicalInfoElement); writer.flush(); graphicalInfoNode = DocumentHelper.createComment(stringWriter.toString()); } catch (Exception e) { graphicalInfoNode = DocumentHelper.createComment(graphicalInfoElement.asXML()); } document.add(graphicalInfoNode); }
From source file:io.mashin.oep.parts.WorkflowNodeEditPart.java
License:Open Source License
private void performOpen() { if (getCastedModel() instanceof CustomActionNode) { CustomActionNode customActionNode = (CustomActionNode) getCastedModel(); String customActionNodeXML = ""; try {//w ww . ja v a 2 s . c o m StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()); writer.write(DocumentHelper .parseText((String) customActionNode.getPropertyValue(CustomActionNode.PROP_XML)) .getRootElement()); writer.flush(); customActionNodeXML = stringWriter.toString(); } catch (Exception e) { e.printStackTrace(); customActionNodeXML = (String) customActionNode.getPropertyValue(CustomActionNode.PROP_XML); } XMLEditor.getInstance().open(customActionNode, customActionNodeXML, customActionNode.getName(), xml -> getViewer().getEditDomain().getCommandStack() .execute(new CustomActionNodeXMLEditCommand(customActionNode, xml))); } }
From source file:io.mashin.oep.ui.editor.WorkflowEditor.java
License:Open Source License
private String writeModel() { try {/*from ww w .j a v a 2 s .com*/ Document document = DocumentHelper.createDocument(); workflow.write(document.addElement("dummy")); OutputFormat format = OutputFormat.createPrettyPrint(); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); writer.write(document); stringWriter.flush(); String hpdl = stringWriter.toString(); hpdl = XMLUtils.schemaVersionToXmlns(hpdl); //hpdl = XMLUtils.slaVersionToXmlnsSLA(hpdl); return hpdl; } catch (IOException e) { e.printStackTrace(); return ""; } }
From source file:iqq.app.service.impl.IMResourceServiceImpl.java
License:Apache License
@Override public void writeXml(Document document, File xmlFile) { try {// w ww . j ava2s . com OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML? outputFormat.setEncoding("UTF-8");// XML? outputFormat.setIndent(true);// ? outputFormat.setIndent(" ");// TAB? outputFormat.setNewlines(true);// ?? XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(xmlFile), outputFormat); xmlWriter.write(document); xmlWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:iqq.app.util.XmlUtils.java
License:Apache License
/** * XML/*from w w w .ja v a 2s . c om*/ * * @param document * @param xmlFile * @throws IOException */ public static void writeXml(String filename, Document document) throws IOException { LOG.debug("XML: " + filename); OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML? outputFormat.setEncoding("UTF-8");// XML? outputFormat.setIndent(true);// ? outputFormat.setIndent(" ");// TAB? outputFormat.setNewlines(true);// ?? synchronized (document) { XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(filename), outputFormat); xmlWriter.write(document); xmlWriter.close(); } }
From source file:it.eng.qbe.datasource.configuration.dao.fileimpl.CalculatedFieldsDAOFileImpl.java
License:Mozilla Public License
private void guardedWrite(Document document, File file) { Writer out;//from w ww. ja v a2 s. c om OutputFormat format; XMLWriter writer; logger.debug("IN"); out = null; writer = null; try { logger.debug("acquiring lock..."); getLock(); logger.debug("Lock acquired"); out = null; try { out = new FileWriter(file); } catch (IOException e) { throw new DAOException("Impossible to open file [" + file + "]", e); } Assert.assertNotNull(out, "Output stream cannot be null"); format = OutputFormat.createPrettyPrint(); format.setEncoding("ISO-8859-1"); format.setIndent(" "); writer = new XMLWriter(out, format); try { writer.write(document); writer.flush(); } catch (IOException e) { throw new DAOException("Impossible to write to file [" + file + "]", e); } } catch (Throwable t) { if (t instanceof DAOException) throw (DAOException) t; throw new DAOException("An unpredicetd error occurred while writing on file [" + file + "]"); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { throw new DAOException("Impossible to properly close stream to file file [" + file + "]", e); } } logger.debug("releasing lock..."); releaseLock(); logger.debug("lock released"); logger.debug("OUT"); } }
From source file:it.pdfsam.env.EnvWorker.java
License:Open Source License
/** * Saves the environment//from w ww.j ava 2 s .c o m * */ public void saveJob() { try { file_chooser.setApproveButtonText(GettextResource.gettext(i18n_messages, "Save job")); int return_val = file_chooser.showOpenDialog(null); File chosen_file = null; if (return_val == JFileChooser.APPROVE_OPTION) { chosen_file = file_chooser.getSelectedFile(); if (chosen_file != null) { try { Document document = DocumentHelper.createDocument(); Element root = document.addElement("pdfsam_saved_jobs"); root.addAttribute("version", MainGUI.NAME); root.addAttribute("savedate", new SimpleDateFormat("dd-MMM-yyyy").format(new Date())); for (int i = 0; i < pl_panel.length; i++) { Element node = (Element) root.addElement("plugin"); node.addAttribute("class", pl_panel[i].getClass().getName()); node.addAttribute("name", pl_panel[i].getPluginName()); pl_panel[i].getJobNode(node); fireLogPropertyChanged(GettextResource.gettext(i18n_messages, pl_panel[i].getPluginName() + " job node loaded."), LogPanel.LOG_DEBUG); } FileWriter file_writer = new FileWriter(chosen_file); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter xml_file_writer = new XMLWriter(file_writer, format); xml_file_writer.write(document); xml_file_writer.flush(); xml_file_writer.close(); fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Job saved."), LogPanel.LOG_INFO); } catch (Exception ex) { fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Error: ") + ex.getMessage(), LogPanel.LOG_ERROR); } } } } catch (RuntimeException re) { fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "RuntimeError:") + " Unable to load environment. " + re.getMessage(), LogPanel.LOG_ERROR); } catch (Exception e) { fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Error:") + " Unable to load environment. " + e.getMessage(), LogPanel.LOG_ERROR); } }
From source file:it.pdfsam.util.XMLParser.java
License:Open Source License
/** * Write the DOM to the xml file/*from w w w .ja va 2s . c o m*/ * * @param domDoc Document to write * @param full_path Full path to the xml file to write * @throws Exception */ public static void writeXmlFile(Document domDoc, String full_path) throws Exception { FileWriter file_writer = new FileWriter(full_path); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter xml_file_writer = new XMLWriter(file_writer, format); xml_file_writer.write(domDoc); xml_file_writer.flush(); xml_file_writer.close(); }
From source file:it.pdfsam.utils.XMLParser.java
License:Open Source License
/** * Write the DOM to the xml file// w w w .j a v a 2 s . c om * @param domDoc Document to write * @param full_path Full path to the xml file to write * @throws Exception */ public static void writeXmlFile(Document domDoc, String full_path) throws Exception { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(full_path)); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter xml_file_writer = new XMLWriter(bos, format); xml_file_writer.write(domDoc); xml_file_writer.flush(); xml_file_writer.close(); }
From source file:it.unibz.inf.xmlssd.metadator.helpers.Exporter.java
License:Apache License
/** * Export method which exports all the stored data as a XML document. * @throws IOException/*from w w w. j av a 2 s .com*/ */ public void export() throws IOException { OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(aFile.getCanonicalPath()), format); SQLiteManager sqlite = new SQLiteManager(); writer.write(sqlite.get()); writer.close(); }