List of usage examples for org.dom4j.io OutputFormat createPrettyPrint
public static OutputFormat createPrettyPrint()
From source file:net.sf.ginp.config.Configuration.java
License:Open Source License
/** * Saves current settings to Disk./*w w w. ja v a 2 s.c o m*/ */ public static void writeConfig() { try { OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(configfilelocation), format); writer.write(document); writer.close(); log.info("Writen config file to disk."); // check It try { FileInputStream fis = new FileInputStream(new File(configfilelocation)); SetupManager service = ModelUtil.getSetupManager(); document = service.testValidConfig(fis); configOK = true; } catch (Exception ex) { log.error("Error parsing new config file", ex); } } catch (Exception e) { log.error("Error writing config file to disk.", e); } readConfig(); }
From source file:net.sf.ginp.setup.SetupManagerImpl.java
License:Open Source License
/** * @param visit//from w w w . j av a 2 s. c o m * @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. ja v a 2s.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();/* w w w . ja va 2s .c o m*/ }
From source file:net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager.java
License:Open Source License
public void writeAsHTML(OutputStream outputStream) throws IOException { HTMLWriter writer = new HTMLWriter(outputStream, OutputFormat.createPrettyPrint()); writer.write(this.document); writer.flush();/* w w w. j a va 2 s. com*/ }
From source file:net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager.java
License:Open Source License
public void exportAsXMLFile(String fileName) throws IOException { FileWriter fileWriter = null; try {/* w ww .jav a 2 s. c o m*/ fileWriter = new FileWriter(fileName); XMLWriter xmlWriter = new XMLWriter(fileWriter, OutputFormat.createPrettyPrint()); xmlWriter.write(document); xmlWriter.close(); } finally { if (fileWriter != null) { fileWriter.close(); } } }
From source file:net.sf.jguard.ext.authorization.manager.XmlAuthorizationManager.java
License:Open Source License
public void writeAsHTML(OutputStream outputStream) throws IOException { HTMLWriter writer = new HTMLWriter(outputStream, OutputFormat.createPrettyPrint()); writer.write(this.document); writer.flush();// w w w . j a va 2 s .com }
From source file:net.sf.jguard.ext.authorization.manager.XmlAuthorizationManager.java
License:Open Source License
public void exportAsXMLFile(String fileName) throws IOException { XMLWriter xmlWriter = null;// ww w .j a va 2 s. c o m FileWriter fileWriter = null; try { fileWriter = new FileWriter(fileName); xmlWriter = new XMLWriter(fileWriter, OutputFormat.createPrettyPrint()); xmlWriter.write(document); } finally { if (fileWriter != null) { fileWriter.close(); } if (xmlWriter != null) { xmlWriter.close(); } } }
From source file:net.sf.jvifm.model.AppStatus.java
License:Open Source License
public static boolean writeAppStatus() { try {/* w w w. j av a 2 s . c o 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; }
From source file:net.sf.jvifm.model.BookmarkManager.java
License:Open Source License
@SuppressWarnings("unchecked") public void store() { try {/* ww w .j a v a 2s . c om*/ Document document = DocumentHelper.createDocument(); Element root = document.addElement("bookmarks"); for (Iterator it = bookmarkList.iterator(); it.hasNext();) { Bookmark bm = (Bookmark) it.next(); Element bookmarkElement = root.addElement("bookmark"); bookmarkElement.addElement("name").addText(bm.getName()); bookmarkElement.addElement("path").addText(bm.getPath()); if (bm.getKey() != null) bookmarkElement.addElement("key").addText(bm.getKey()); } FileOutputStream fos = new FileOutputStream(storePath); 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(); fos.close(); } catch (Exception e) { e.printStackTrace(); } }