List of usage examples for org.dom4j.io OutputFormat createPrettyPrint
public static OutputFormat createPrettyPrint()
From source file:com.nokia.ant.ModelPropertiesParser.java
License:Open Source License
/** * Writes Document object as xml file/*from w ww. jav a 2 s .c om*/ */ private void writeXMLFile() { try { if (outputPath != null) { XMLWriter out = new XMLWriter(new FileOutputStream(outputPath), OutputFormat.createPrettyPrint()); out.write(doc); } } catch (FileNotFoundException e) { // We are Ignoring the errors as no need to fail the build. log.debug("Not able to write into XML Document " + e.getMessage()); } catch (UnsupportedEncodingException e) { // We are Ignoring the errors as no need to fail the build. log.debug("Not able to write into XML Document " + e.getMessage()); } catch (IOException e) { // We are Ignoring the errors as no need to fail the build. log.debug("Not able to write into XML Document " + e.getMessage()); } }
From source file:com.nokia.helium.core.ant.filters.PrettyPrintXmlFilter.java
License:Open Source License
/** * Filter the input string.// w w w . j a v a 2s . c o m * * @param string * the string to filter * @return the modified string */ public String filter(String token) { String output = token; XMLWriter writer = null; if (token.length() > 0) { try { Document doc = DocumentHelper.parseText(token); StringWriter out = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndentSize(4); writer = new XMLWriter(out, format); writer.write(doc); output = out.toString(); } catch (org.dom4j.DocumentException exc) { throw new BuildException(exc.getMessage(), exc); } catch (IOException exc) { throw new BuildException(exc.getMessage(), exc); } finally { try { if (writer != null) { writer.close(); } } catch (IOException exc) { throw new BuildException(exc.getMessage(), exc); } } } return output; }
From source file:com.nokia.helium.diamonds.XMLMerger.java
License:Open Source License
/** * Write the XML content back the file.//from ww w. j ava2 s . c om * @throws XMLMergerException */ protected void write() throws XMLMergerException { try { FileOutputStream fos = new FileOutputStream(outputFile); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(fos, format); writer.write(doc); writer.flush(); } catch (FileNotFoundException e) { throw new XMLMergerException(e.getMessage()); } catch (UnsupportedEncodingException e) { throw new XMLMergerException(e.getMessage()); } catch (IOException e) { throw new XMLMergerException(e.getMessage()); } }
From source file:com.nokia.helium.environment.EnvironmentXMLWriter.java
License:Open Source License
/** * Writes an environment definition in XML to output. * @param environment Enviroment definition. * @throws IOException If I/O error occurs. *//*ww w . j a va 2 s.c o m*/ public void write(Environment environment) throws IOException { doc = DocumentFactory.getInstance().createDocument(); doc.addElement("environment"); List<Executable> executables = environment.getExecutables(); for (Iterator<Executable> iterator = executables.iterator(); iterator.hasNext();) { Executable executable = (Executable) iterator.next(); write(executable); } XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint()); writer.write(doc); writer.close(); }
From source file:com.nokia.helium.internaldata.ant.listener.XMLRenderer.java
License:Open Source License
/** * Rendering the build node into XML string. *///from w ww.j ava 2 s .co m public String toString() { // Creating the XML document Document document = DocumentHelper.createDocument(); Element statistics = document.addElement("statistics"); statistics.addAttribute("version", "1.1"); // Creating the document content. insertDatabase(statistics); createTargets(statistics); createAsserts(statistics); createExecutionTree(statistics); createProperties(statistics); try { ByteArrayOutputStream output = new ByteArrayOutputStream(); XMLWriter out = new XMLWriter(output, OutputFormat.createPrettyPrint()); out.write(document); return output.toString(); } catch (UnsupportedEncodingException exc) { return document.asXML(); } catch (IOException exc) { return document.asXML(); } }
From source file:com.npower.dm.hibernate.management.ModelManagementBeanImpl.java
License:Open Source License
/** * //from www .j a v a 2 s. com * @param filename * @return */ public int formatXMLFile(String filename) { int returnValue = 0; try { SAXReader saxReader = new SAXReader(); Document document = saxReader.read(new File(filename)); XMLWriter writer = null; OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); writer = new XMLWriter(new FileWriter(new File(filename)), format); writer.write(document); writer.close(); returnValue = 1; } catch (Exception ex) { ex.printStackTrace(); } return returnValue; }
From source file:com.npower.dm.util.XMLPrettyFormatter.java
License:Open Source License
/** * Format the xml to pretty print format. * @return/*from w w w . ja v a 2 s . c o m*/ * @throws IOException */ public String format() throws IOException { StringWriter writer = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter xmlwriter = new XMLWriter(writer, format); xmlwriter.write(this.document); return writer.toString(); }
From source file:com.orange.atk.atkUI.corecli.Campaign.java
License:Apache License
/** * Save current campaign in .mcl file/* w w w . ja v a 2 s . c o m*/ * * @param clFileName * @throws IOException */ public static void save(String clFileName, Campaign camp) { Document document = DocumentHelper.createDocument(); Element root = document.addElement("campaign"); if (camp.getName() != null) root.addAttribute("name", camp.getName()); if (camp.getAuthor() != null) root.addAttribute("author", camp.getAuthor()); if (camp.getDate() != null) root.addAttribute("date", camp.getDate()); if (camp.getDescription() != null) root.addAttribute("description", camp.getDescription()); int stepNumber = 0; for (Step step : camp) { step.save(root, stepNumber); stepNumber++; } OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(clFileName), format); writer.write(document); writer.close(); } catch (IOException e) { Alert.raise(e, "Unable to save check-list in a file."); } }
From source file:com.orange.atk.atkUI.corecli.utils.FileUtilities.java
License:Apache License
/** * Copy a source html file into a destination file, patching the style sheet * on the fly for the given one.//from w ww. j av a 2s .c o m * * @param in * source html file * @param out * destination file * @param newStyleSheetPath * the new css style sheet absolute path * @throws Exception */ public static void copyHTMLFilePrettyPrint(File in, File out, String newStyleSheetPath) throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(in.getAbsolutePath()); Element linkElem = (Element) document.selectSingleNode("/html/head/link"); if (linkElem != null) { linkElem.addAttribute("href", newStyleSheetPath); } OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileOutputStream(out), format); writer.write(document); writer.close(); }
From source file:com.orange.atk.atkUI.corecli.utils.XMLOutput.java
License:Apache License
public void generate() { try {/*from ww w . j a v a2 s . com*/ OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); XMLWriter writer = new XMLWriter(new FileWriter(file), format); writer.write(doc); writer.close(); } catch (Exception e) { Alert.raise(e, "While generating " + file); } }