List of usage examples for org.dom4j.io XMLWriter close
public void close() throws IOException
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
public boolean save(OutputStream os, Document document) { boolean flag = true; XMLWriter writer = null; OutputStreamWriter outputStream = null; try {/*from w w w . j a v a 2 s . c o m*/ outputStream = new OutputStreamWriter(os, DAFAULT_CHARSET); writer = new XMLWriter(outputStream); writer.write(document); writer.flush(); } catch (Exception ex) { log.error("?xml", ex); flag = false; throw new RuntimeException(ex); } finally { try { if (null != writer) { writer.close(); } if (outputStream != null) { outputStream.close(); } } catch (IOException e) { log.error("?xml:", e); } } return flag; }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
public boolean save(File outPutFile, Document document, boolean lineAble) { boolean flag = true; XMLWriter writer = null; OutputStreamWriter outputStream = null; try {//from w w w .ja v a 2s . com outputStream = new OutputStreamWriter(new FileOutputStream(outPutFile), DAFAULT_CHARSET); final OutputFormat format = OutputFormat.createCompactFormat();//? format.setNewlines(lineAble); writer = new XMLWriter(outputStream, format); writer.write(document); writer.flush(); outputStream.close(); writer.close(); } catch (Exception ex) { log.error("?xml", ex); flag = false; } finally { try { if (null != writer) { writer.close(); } if (outputStream != null) { outputStream.close(); } } catch (IOException e) { log.error("?xml:", e); } } return flag; }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
private void writeDocument(final OutputStream out, Document document) { XMLWriter xmlWriter = null; try {// w ww.j a v a2 s . c o m xmlWriter = new XMLWriter(out); xmlWriter.write(document); xmlWriter.flush(); } catch (IOException e) { throw new RuntimeException(e); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { throw new RuntimeException(e); } } } }
From source file:com.wedian.site.common.utils.SettingUtils.java
License:Open Source License
/** * //from w w w . j a v a 2 s. c om * * @param setting * */ public static void set(Setting setting) { try { File shopxxXmlFile = new ClassPathResource(CommonAttributes.SITE_XML_PATH).getFile(); Document document = new SAXReader().read(shopxxXmlFile); List<Element> elements = document.selectNodes("/site/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(shopxxXmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.xebialabs.overthere.cifs.winrm.exception.WinRMRuntimeIOException.java
License:Open Source License
private String toString(Document doc) { if (doc == null) { return "[EMPTY]"; }//from www . j av a 2 s.c o m StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()); try { xmlWriter.write(doc); xmlWriter.close(); } catch (IOException e) { throw new RuntimeException("error ", e); } return stringWriter.toString(); }
From source file:com.xebialabs.overthere.cifs.winrm.soap.Soapy.java
License:Open Source License
public static String toString(Document doc) { StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()); try {/* w w w.ja v a 2 s .c o m*/ xmlWriter.write(doc); xmlWriter.close(); } catch (IOException e) { throw new WinRmRuntimeIOException("Cannnot convert XML to String ", e); } return stringWriter.toString(); }
From source file:com.xebialabs.overthere.cifs.winrm.WinRmRuntimeIOException.java
License:Open Source License
private static String toString(Document doc) { if (doc == null) { return "[EMPTY]"; }//from w ww .j a v a 2s . co m StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()); try { xmlWriter.write(doc); xmlWriter.close(); } catch (IOException e) { throw new RuntimeException("error ", e); } return stringWriter.toString(); }
From source file:com.xebialabs.overthere.winrm.WinRmClient.java
License:Open Source License
private static void logDocument(String caption, final Document document) { if (!logger.isTraceEnabled()) { return;//from ww w. j a v a 2 s . c o m } StringWriter text = new StringWriter(); try { XMLWriter writer = new XMLWriter(text, OutputFormat.createPrettyPrint()); writer.write(document); writer.close(); } catch (IOException e) { logger.trace("{}\n{}", caption, e); } logger.trace("{}\n{}", caption, text); }
From source file:com.xebialabs.overthere.winrm.WinRmClient.java
License:Open Source License
private static String toString(Document doc) { StringWriter stringWriter = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()); try {// w ww .java 2 s . com xmlWriter.write(doc); xmlWriter.close(); } catch (IOException exc) { throw new WinRmRuntimeIOException("Cannnot convert XML to String ", exc); } return stringWriter.toString(); }
From source file:com.xpn.xwiki.tool.xar.XarMojo.java
License:Open Source License
/** * Create and add package configuration file to the package. * //w ww .jav a 2s. c o m * @param packageFile the package when to add configuration file. * @param files the files in the package. * @throws Exception error when writing the configuration file. */ private void generatePackageXml(File packageFile, Collection<ArchiveEntry> files) throws Exception { getLog().info("Generating package.xml descriptor at [" + packageFile.getPath() + "]"); OutputFormat outputFormat = new OutputFormat("", true); outputFormat.setEncoding(this.encoding); OutputStream out = new FileOutputStream(packageFile); XMLWriter writer = new XMLWriter(out, outputFormat); writer.write(toXML(files)); writer.close(); out.close(); }