List of usage examples for org.dom4j.io XMLWriter close
public void close() throws IOException
From source file:org.palooca.config.BaseConfig.java
License:Open Source License
public void saveConfig(Document document) { try {//from w ww. ja va2 s .co m Element root = document.getRootElement(); if (root != null) { OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter( new FileWriter(new File(URI.create(basePath + root.getName() + ".xml"))), format); writer.write(document); writer.close(); } } catch (Exception e) { } }
From source file:org.pdfsam.guiclient.business.environment.Environment.java
License:Open Source License
/** * saves and environment to the output file * /* ww w . jav a 2 s .c o m*/ * @param outFile * @param savePasswords * true save passwords informations */ public void saveEnvironment(File outFile, boolean savePasswords) { try { if (outFile != null) { synchronized (Environment.class) { Document document = DocumentHelper.createDocument(); Element root = document.addElement("pdfsam_saved_jobs"); root.addAttribute("version", GuiClient.getVersion()); root.addAttribute("savedate", new SimpleDateFormat("dd-MMM-yyyy").format(new Date())); String selection = treePanel.getSelectedPlugin(); if (selection != null && selection.length() > 0) { root.addAttribute("selection", selection); } for (AbstractPlugablePanel plugablePanel : plugins.values()) { Element node = (Element) root.addElement("plugin"); node.addAttribute("class", plugablePanel.getClass().getName()); node.addAttribute("name", plugablePanel.getPluginName()); plugablePanel.getJobNode(node, savePasswords); LOG.info(GettextResource.gettext(i18nMessages, plugablePanel.getPluginName() + " node environment loaded.")); } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile)); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter xmlWriter = new XMLWriter(bos, format); xmlWriter.write(document); xmlWriter.flush(); xmlWriter.close(); } LOG.info(GettextResource.gettext(i18nMessages, "Environment saved.")); } else { LOG.error(GettextResource.gettext(i18nMessages, "Error saving environment, output file is null.")); } } catch (Exception ex) { LOG.error(GettextResource.gettext(i18nMessages, "Error saving environment."), ex); } }
From source file:org.pdfsam.guiclient.utils.xml.XMLParser.java
License:Open Source License
/** * Write the DOM to the xml file/*from w w w. j ava2 s. c om*/ * * @param domDoc Document to write * @param outFile xml File to write * @throws Exception */ public static void writeXmlFile(Document domDoc, File outFile) throws Exception { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile)); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter xmlFileWriter = new XMLWriter(bos, format); xmlFileWriter.write(domDoc); xmlFileWriter.flush(); xmlFileWriter.close(); }
From source file:org.pdfsam.guiclient.utils.XmlUtility.java
License:Open Source License
/** * Write the DOM to the xml file// w w w .jav a2 s.co m * * @param domDoc * Document to write * @param outFile * xml File to write * @throws IOException */ public static void writeXmlFile(Document domDoc, File outFile) throws IOException { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile)); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter xmlFileWriter = new XMLWriter(bos, format); xmlFileWriter.write(domDoc); xmlFileWriter.flush(); xmlFileWriter.close(); }
From source file:org.pdfsam.plugin.merge.actions.SaveListAsXmlAction.java
License:Open Source License
/** * Save the xml file//www . ja va 2s.c o m * * @param rows * @param selectedFile * @throws Exception */ public void writeXmlFile(PdfSelectionTableItem[] rows, File selectedFile) throws Exception { if (selectedFile != null && rows != null) { Document document = DocumentHelper.createDocument(); Element root = document.addElement("filelist"); for (int i = 0; i < rows.length; i++) { PdfSelectionTableItem row = rows[i]; Element node = (Element) root.addElement("file"); node.addAttribute("value", row.getInputFile().getAbsolutePath()); String pwd = row.getPassword(); if (pwd != null && pwd.length() > 0) { node.addAttribute("password", pwd); } } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(selectedFile)); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter xmlWriter = new XMLWriter(bos, format); xmlWriter.write(document); xmlWriter.flush(); xmlWriter.close(); LOG.info(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "File xml saved.")); } else { LOG.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error saving xml file, output file is null.")); } }
From source file:org.pdfsam.plugin.merge.components.JSaveListAsXmlMenuItem.java
License:Open Source License
/** * Save the xml file// w w w .j a va2 s . co m * @param rows * @param selectedFile * @throws Exception */ public void writeXmlFile(PdfSelectionTableItem[] rows, File selectedFile) throws Exception { if (selectedFile != null && rows != null) { Document document = DocumentHelper.createDocument(); Element root = document.addElement("filelist"); for (int i = 0; i < rows.length; i++) { PdfSelectionTableItem row = rows[i]; Element node = (Element) root.addElement("file"); node.addAttribute("value", row.getInputFile().getAbsolutePath()); String pwd = row.getPassword(); if (pwd != null && pwd.length() > 0) { node.addAttribute("password", pwd); } } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(selectedFile)); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter xmlWriter = new XMLWriter(bos, format); xmlWriter.write(document); xmlWriter.flush(); xmlWriter.close(); log.info(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "File xml saved.")); } else { log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Error saving xml file, output file is null.")); } }
From source file:org.peerfact.impl.analyzer.visualization2d.util.Config.java
License:Open Source License
/** * Writes the existing structure in the XML config file *//* w w w.j ava 2 s . c o m*/ public static void writeXMLFile() { if (config != null) { // Write file only if the XML tree exists in // memory try { OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(configFile), format); writer.write(Config.config); writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.peerfact.impl.network.gnp.topology.HostMap.java
License:Open Source License
/** * saves host postion location, GNP position, groups, GNP Space, PingER * Lookup table in an xml file used within the simulation * //from w ww. ja v a 2 s .com * @param file */ public void exportToXml(File file) { log.debug("Export Hosts to an XML File"); try { OutputFormat format = OutputFormat.createPrettyPrint(); OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); XMLWriter writer = new XMLWriter(out, format); writer.write(getDocument()); writer.close(); } catch (IOException e) { log.debug(e); } }
From source file:org.pentaho.actionsequence.dom.actions.MQLAction.java
License:Open Source License
private Document prettyPrint(Document document) { try {/*from w w w . j a v a2 s. co m*/ OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(document.getXMLEncoding()); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); // XMLWriter has a bug that is avoided if we reparse the document // prior to calling XMLWriter.write() writer.write(DocumentHelper.parseText(document.asXML())); writer.close(); document = DocumentHelper.parseText(stringWriter.toString()); } catch (Exception e) { e.printStackTrace(); return (null); } return (document); }
From source file:org.pentaho.actionsequence.dom.ActionSequenceDocument.java
License:Open Source License
public static Document prettyPrint(Document document) { try {//w ww . j a va 2s. com OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(document.getXMLEncoding()); StringWriter stringWriter = new StringWriter(); XMLWriter writer = new XMLWriter(stringWriter, format); // XMLWriter has a bug that is avoided if we reparse the document // prior to calling XMLWriter.write() writer.write(DocumentHelper.parseText(document.asXML())); writer.close(); document = DocumentHelper.parseText(stringWriter.toString()); } catch (Exception e) { e.printStackTrace(); return (null); } return (document); }