List of usage examples for org.dom4j.io OutputFormat createPrettyPrint
public static OutputFormat createPrettyPrint()
From source file:com.glaf.core.util.Dom4jUtils.java
License:Apache License
public static void createDoument(Document doc, String filename, String encoding, boolean createPrettyPrint) { OutputFormat format = null;//w ww . j a v a 2s . c o m if (createPrettyPrint) { format = OutputFormat.createPrettyPrint(); } else { format = new OutputFormat(); } format.setEncoding(encoding); createDoument(doc, filename, format); }
From source file:com.glaf.core.util.Dom4jUtils.java
License:Apache License
/** * XML?????XML/*w w w .j av a2 s . co m*/ * * @param doc * @param encoding * @return ? * @throws Exception */ public static byte[] getBytesFromPrettyDocument(Document doc, String encoding) { if (doc == null) { return null; } OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(encoding); return getBytesFromDocument(doc, format); }
From source file:com.globalsight.cxe.util.Dom4jUtil.java
License:Apache License
public static String formatXML(Document document, String charset) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(charset);/* www . j a v a 2 s . c o m*/ StringWriter sw = new StringWriter(); XMLWriter xw = new XMLWriter(sw, format); try { xw.write(document); xw.flush(); xw.close(); } catch (IOException e) { log.error(e.getMessage(), e); return document.asXML(); } return sw.toString(); }
From source file:com.googlecode.starflow.engine.xml.XmlFormat.java
License:Apache License
/** * dom4j'pretty'??dom.// w ww. j a v a2 s .c o m * * @param doc * ??dom. * @param encoding * ??. * @return ??XML.null,???. */ public static String getPrettyString(Document doc, String encoding) { StringWriter writer = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); if (encoding == null || "".equals(encoding.trim())) { encoding = "GBK"; } format.setEncoding(encoding); XMLWriter xmlwriter = new XMLWriter(writer, format); try { xmlwriter.write(doc); } catch (IOException e) { e.printStackTrace(); } return writer.toString(); }
From source file:com.gote.pojo.Tournament.java
License:Apache License
/** * Transform Tournament in a formatted XML * /*from w w w.j ava 2 s . c om*/ * @return XML to write as a String */ public String toXML() { // Create document Document doc = DocumentHelper.createDocument(); // Create tournament element Element root = doc.addElement(TournamentGOTEUtil.TAG_TOURNAMENT); // Add attributes root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_NAME, getTitle()); root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_SERVER, getServerType()); root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_DATESTART, getStartDate().toString()); root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_DATEEND, getEndDate().toString()); // Add rules getTournamentRules().toXML(root); // Add players Element players = root.addElement(TournamentGOTEUtil.TAG_PLAYERS); for (Player player : getParticipantsList()) { player.toXML(players); } // Add rounds Element rounds = root.addElement(TournamentGOTEUtil.TAG_ROUNDS); for (Round round : getRounds()) { round.toXML(rounds); } StringWriter out = new StringWriter(1024); XMLWriter writer; try { writer = new XMLWriter(OutputFormat.createPrettyPrint()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } writer.setWriter(out); try { writer.write(doc); } catch (IOException e) { e.printStackTrace(); } // Return the friendly XML return out.toString(); }
From source file:com.haulmont.bali.util.Dom4j.java
License:Apache License
public static void writeDocument(Document doc, boolean prettyPrint, Writer writer) { XMLWriter xmlWriter;//from w w w . j a v a2s .com try { if (prettyPrint) { OutputFormat format = OutputFormat.createPrettyPrint(); xmlWriter = new XMLWriter(writer, format); } else { xmlWriter = new XMLWriter(writer); } xmlWriter.write(doc); } catch (IOException e) { throw new RuntimeException("Unable to write XML", e); } }
From source file:com.haulmont.bali.util.Dom4j.java
License:Apache License
public static void writeDocument(Document doc, boolean prettyPrint, OutputStream stream) { XMLWriter xmlWriter;//from ww w.j av a 2 s .c o m try { if (prettyPrint) { OutputFormat format = OutputFormat.createPrettyPrint(); xmlWriter = new XMLWriter(stream, format); } else { xmlWriter = new XMLWriter(stream); } xmlWriter.write(doc); } catch (IOException e) { throw new RuntimeException("Unable to write XML", e); } }
From source file:com.haulmont.cuba.restapi.XMLConverter2.java
License:Apache License
protected String documentToString(Document document) { try {//w ww .j a v a 2 s. c o m OutputFormat format = OutputFormat.createPrettyPrint(); StringWriter sw = new StringWriter(); XMLWriter writer = new XMLWriter(sw, format); writer.write(document); return sw.toString(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlWriter.java
License:Apache License
@Override public String buildXml(Report report) { try {/*w ww. j a va 2s. c o m*/ Document document = DocumentFactory.getInstance().createDocument(); Element root = document.addElement("report"); root.addAttribute("name", report.getName()); writeTemplates(report, root); writeInputParameters(report, root); writeValueFormats(report, root); writeRootBand(report, root); StringWriter stringWriter = new StringWriter(); new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()).write(document); return stringWriter.toString(); } catch (IOException e) { throw new ReportingException(e); } }
From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java
License:Apache License
/** * XML?? XML???/* www .j ava 2 s .co m*/ * * @param document * ? * @param file * ?XML */ public void writeXml(Document document, File file) { try { //? OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter output = new XMLWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"), format); output.write(document); output.flush(); output.close(); } catch (IOException e) { log.info(e.getMessage()); } }