List of usage examples for org.dom4j.io XMLWriter flush
public void flush() throws IOException
From source file:it.pdfsam.utils.XMLParser.java
License:Open Source License
/** * Write the DOM to the xml file/*from 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:jp.aegif.alfresco.online_webdav.WebDAVMethod.java
License:Open Source License
/** * Flushes all XML written so far to the response * //w w w. j a v a2 s. c om * @param xml XMLWriter that should be flushed */ protected final void flushXML(XMLWriter writer) throws IOException { if (shouldFlushXMLWriter()) { writer.flush(); } m_response.getWriter().write(m_xmlWriter.toCharArray()); m_xmlWriter.reset(); }
From source file:net.bpfurtado.tas.runner.savegame.SaveGamePersister.java
License:Open Source License
public static void write(Document xml, File saveGameFile, SaveGameListener saveGameListener) { try {/*from www .j a va2 s .c o m*/ saveGameListener.log("Saving game to file: [" + saveGameFile + "]..."); OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("ISO-8859-1"); format.setNewlines(true); format.setLineSeparator(System.getProperty("line.separator")); XMLWriter writer = new XMLWriter(new FileWriter(saveGameFile), format); writer.write(xml); writer.flush(); writer.close(); saveGameListener.log("Game saved!"); } catch (Exception e) { throw new AdventureException("Error writing Save Game", e); } }
From source file:net.erdfelt.android.sdkfido.project.FilteredFileUtil.java
License:Apache License
public static void write(Document pom, File outputFile) throws OutputProjectException { XMLWriter writer = null; FileOutputStream out = null;// ww w .ja v a 2 s . com try { out = new FileOutputStream(outputFile); OutputFormat pretty = OutputFormat.createPrettyPrint(); pretty.setIndentSize(2); writer = new XMLWriter(out, pretty); writer.write(pom); writer.flush(); } catch (UnsupportedEncodingException e) { throw new OutputProjectException("Unable to write xml to file: " + outputFile, e); } catch (IOException e) { throw new OutputProjectException("Unable to write xml to file: " + outputFile, e); } finally { IOUtils.closeQuietly(out); } }
From source file:net.nikr.eve.jeveasset.io.local.update.Update.java
License:Open Source License
void setVersion(final File xml, final int newVersion) throws DocumentException { SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(xml); XPath xpathSelector = DocumentHelper.createXPath("/settings"); List<?> results = xpathSelector.selectNodes(doc); for (Iterator<?> iter = results.iterator(); iter.hasNext();) { Element element = (Element) iter.next(); Attribute attr = element.attribute("version"); if (attr == null) { element.add(new DefaultAttribute("version", String.valueOf(newVersion))); } else {/*ww w . j av a 2 s . c om*/ attr.setText(String.valueOf(newVersion)); } } try { FileOutputStream fos = new FileOutputStream(xml); OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-16"); XMLWriter writer = new XMLWriter(fos, outformat); writer.write(doc); writer.flush(); } catch (IOException ioe) { LOG.error("Failed to update the serttings.xml version number", ioe); throw new RuntimeException(ioe); } }
From source file:net.nikr.eve.jeveasset.io.local.update.updates.Update1To2.java
License:Open Source License
@Override public void performUpdate(final String path) { LOG.info("Performing update from v1 to v2"); LOG.info(" - modifies files:"); LOG.info(" - settings.xml"); try {//from www .j av a2s .c o m // We need to update the settings // current changes are: // 1. XPath: /settings/filters/filter/row[@mode] // changed from (e.g.) "Contains" to the enum value name in AssetFilter.Mode // 2. settings/marketstat[@defaultprice] --> another enum: Asset.PriceMode // 3. settings/columns/column --> settings/tables/table/column // settings/flags/flag --> removed two flags (now in settings/tables/table) SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(path); convertDefaultPriceModes(doc); convertModes(doc); convertTableSettings(doc); FileOutputStream fos = new FileOutputStream(path); OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-16"); XMLWriter writer = new XMLWriter(fos, outformat); writer.write(doc); writer.flush(); } catch (IOException ex) { LOG.error("", ex); throw new RuntimeException(ex); } catch (DocumentException ex) { LOG.error("", ex); throw new RuntimeException(ex); } }
From source file:net.sf.ginp.setup.SetupManagerImpl.java
License:Open Source License
/** * @param visit/* w w w. j ava2 s. com*/ * @param outputDocument * @throws UnsupportedEncodingException * @throws IOException generally, and specifically * FileNotFoundException and UnsupportedEncodingException */ public final boolean writeConfig(final SetupVisit visit, final Document outputDocument) throws IOException { FileOutputStream outputStream = null; XMLWriter write = null; boolean success = false; try { String confFileLocation = Configuration.getConfigfilelocation(); if (confFileLocation == null) { log.warn("Configuration.getConfigfilelocation() is NULL!"); } // make sure directory exists and be verbose about this to log. File configDir = new File(Configuration.getConfigfilelocationPath()); if (!configDir.exists()) { if (configDir.mkdirs()) { log.info("Config directory created at: " + configDir.getAbsolutePath()); } else { log.error("Can not create config directory at: " + configDir.getAbsolutePath()); } } else { if (log.isDebugEnabled()) { log.debug("Config dir exists at:" + configDir.getAbsolutePath()); } } // warn about overwrite File configFile = new File(confFileLocation); if (configFile.exists()) { log.warn("Overwriting config file at: " + configFile.getAbsolutePath()); } outputStream = new FileOutputStream(configFile, false); OutputFormat format = OutputFormat.createPrettyPrint(); write = new XMLWriter(outputStream, format); write.write(outputDocument); success = configFile.exists(); } catch (Exception ex) { log.error("Error writing config.", ex); } finally { if (write != null) { write.flush(); write.close(); } if (outputStream != null) { outputStream.flush(); outputStream.close(); } } return success; }
From source file:net.sf.jguard.core.util.XMLUtils.java
License:Open Source License
/** * write the updated configuration to the XML file in the UTF-8 format. * * @param url URL of the file to write * @param document dom4j Document/*from w w w .j a v a 2 s.c o m*/ * @throws IOException */ public static void write(URL url, Document document) throws IOException { OutputFormat outFormat = OutputFormat.createPrettyPrint(); if (document.getXMLEncoding() != null) { outFormat.setEncoding(document.getXMLEncoding()); } else { outFormat.setEncoding(UTF_8); } XMLWriter out = new XMLWriter(new BufferedOutputStream(new FileOutputStream(url.getPath())), outFormat); out.write(document); out.flush(); out.close(); }
From source file:net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager.java
License:Open Source License
public void writeAsXML(OutputStream outputStream, String encodingScheme) throws IOException { OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding(encodingScheme); XMLWriter writer = new XMLWriter(outputStream, outformat); writer.write(this.document); writer.flush(); }
From source file:net.sf.jvifm.model.AppStatus.java
License:Open Source License
public static boolean writeAppStatus() { try {/* w w w . j ava 2s. co m*/ String[][] currentPath = Main.fileManager.getAllCurrentPath(); Document document = DocumentHelper.createDocument(); Element root = document.addElement("tabs"); for (int i = 0; i < currentPath.length; i++) { Element tabElement = root.addElement("tab"); tabElement.addAttribute("left", currentPath[i][0]); tabElement.addAttribute("right", currentPath[i][1]); } FileOutputStream fos = new FileOutputStream(appStatusPath); OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); BufferedOutputStream out = new BufferedOutputStream(fos); XMLWriter writer = new XMLWriter(out, outformat); writer.write(document); writer.flush(); writer.close(); } catch (Exception e) { e.printStackTrace(); return false; } return true; }