List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:com.sun.syndication.io.WireFeedOutput.java
License:Open Source License
/** * Writes to an Writer the XML representation for the given WireFeed. * <p>/*from w w w . j ava2 s . co m*/ * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility * of the developer to ensure the Writer instance is using the same charset encoding. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match * the type given to the FeedOuptut constructor. * @param writer Writer to write the XML representation for the given WireFeed. * @param prettyPrint pretty-print XML (true) oder collapsed * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. * @throws IOException thrown if there was some problem writing to the Writer. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public void output(WireFeed feed, Writer writer, boolean prettyPrint) throws IllegalArgumentException, IOException, FeedException { Document doc = outputJDom(feed); String encoding = feed.getEncoding(); Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat(); if (encoding != null) { format.setEncoding(encoding); } XMLOutputter outputter = new XMLOutputter(format); outputter.output(doc, writer); }
From source file:com.tactfactory.harmony.utils.XMLUtils.java
License:Open Source License
/** * Write an XML Document to the given file. * @param doc The XML document to write/*w ww .ja va 2 s . co m*/ * @param xmlFileName The name of the file */ public static void writeXMLToFile(final Document doc, final String xmlFileName) { try { final File xmlFile = TactFileUtils.makeFile(xmlFileName); final XMLOutputter xmlOutput = new XMLOutputter(); // Write to File // Make beautiful file with indent !!! xmlOutput.setFormat(Format.getPrettyFormat().setIndent("\t")); xmlOutput.setXMLOutputProcessor(new TactXMLOutputter()); FileOutputStream fos = new FileOutputStream(xmlFile.getAbsoluteFile()); xmlOutput.output(doc, new OutputStreamWriter(fos, TactFileUtils.DEFAULT_ENCODING)); fos.close(); } catch (IOException e) { ConsoleUtils.displayError(e); } }
From source file:com.thoughtworks.go.util.XmlUtils.java
License:Apache License
private static XMLOutputter xmlOutputer() { Format format = Format.getPrettyFormat().setEncoding("utf-8").setLineSeparator("\n"); return new XMLOutputter(format); }
From source file:com.webfront.model.Config.java
public void setConfig() { FileWriter writer = null;/* ww w .ja v a 2 s .co m*/ File defaultStartupFile = new File(home + fileSep + defaultConfigFileName); try (FileWriter defaultWriter = new FileWriter(defaultStartupFile)) { defaultWriter.write(installDir); } catch (IOException ex) { Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } try { xmlDoc = new Document(); Element rootElement = new Element(root); Element systemNode = new Element("system"); systemNode.addContent(new Element("installDir").addContent(getInstallDir())); // systemNode.addContent(new Element("tmpDir").addContent(tmpDir)); String tmp = tmpDir; tmp.replaceAll("/", "\\/"); systemNode.addContent(new Element("tmpDir").addContent(tmp)); rootElement.addContent(systemNode); xmlDoc.setRootElement(rootElement); writer = new FileWriter(getInstallDir() + getFileSep() + configFileName); XMLOutputter xml = new XMLOutputter(); xml.setFormat(Format.getPrettyFormat()); writer.write(xml.outputString(xmlDoc)); } catch (IOException ex) { Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (writer != null) { writer.close(); } } catch (IOException ex) { Logger.getLogger(Config.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.xebialabs.overcast.support.libvirt.JDomUtil.java
License:Apache License
public static String documentToString(Document xml) throws IOException { return documentToString(xml, Format.getPrettyFormat()); }
From source file:com.xebialabs.overcast.support.libvirt.JDomUtil.java
License:Apache License
public static String elementToString(Element element) throws IOException { return elementToString(element, Format.getPrettyFormat()); }
From source file:compile.util.XMLUtil.java
public void save() { _document.setContent(_racine);/*from w w w . j av a 2 s. c o m*/ try { FileWriter writer = new FileWriter(_strPath); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(_document, writer); writer.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Contabilidad.CodeBase64.java
public void limpia(String ruta) { try {//from ww w . j ava 2 s . co m org.jdom2.Document doc = new SAXBuilder().build(ruta); Element rootNode = doc.getRootElement(); List list = rootNode.getContent(); for (int i = 0; i < list.size(); i++) { Content elementos = (Content) list.get(i); if (elementos.getCType() == Content.CType.Element) { Element aux = (Element) elementos; if (aux.getName().compareToIgnoreCase("Addenda") == 0) { List list2 = aux.getContent(); for (int j = 0; j < list2.size(); j++) { Content elementos2 = (Content) list2.get(j); if (elementos2.getCType() == Content.CType.Element) { Element aux2 = (Element) elementos2; if (aux2.getName().compareToIgnoreCase("FactDocMX") == 0) { list2.remove(aux2); } if (aux2.getName().compareToIgnoreCase("ECFD") == 0) { Namespace NP = Namespace.getNamespace("", ""); aux2.setNamespace(NP); List list3 = aux2.getContent(); for (int k = 0; k < list3.size(); k++) { Content elementos3 = (Content) list3.get(k); if (elementos3.getCType() == Content.CType.Element) { Element aux3 = (Element) elementos3; aux3.setNamespace(NP); List list4 = aux3.getContent(); for (int l = 0; l < list4.size(); l++) { Content elementos4 = (Content) list4.get(l); if (elementos4.getCType() == Content.CType.Element) { Element aux4 = (Element) elementos4; aux4.setNamespace(NP); List list5 = aux4.getContent(); for (int m = 0; m < list5.size(); m++) { Content elementos5 = (Content) list5.get(m); if (elementos5.getCType() == Content.CType.Element) { Element aux5 = (Element) elementos5; aux5.setNamespace(NP); List list6 = aux5.getContent(); for (int n = 0; n < list6.size(); n++) { Content elementos6 = (Content) list6.get(n); if (elementos6 .getCType() == Content.CType.Element) { Element aux6 = (Element) elementos6; aux6.setNamespace(NP); List list7 = aux6.getContent(); for (int p = 0; p < list7.size(); p++) { Content elementos7 = (Content) list7.get(p); if (elementos7 .getCType() == Content.CType.Element) { Element aux7 = (Element) elementos7; aux7.setNamespace(NP); List list8 = aux7.getContent(); for (int q = 0; q < list8.size(); q++) { Content elementos8 = (Content) list8 .get(q); if (elementos8 .getCType() == Content.CType.Element) { Element aux8 = (Element) elementos8; aux8.setNamespace(NP); } } } } } } } } } } } } List atributos = aux2.getAttributes(); for (int a = 0; a < atributos.size(); a++) { Attribute at = (Attribute) atributos.get(a); if (at.getName().compareToIgnoreCase("schemaLocation") == 0) aux2.removeAttribute(at); } } } } } } } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { outputter.output(doc, new FileOutputStream(ruta)); } catch (IOException e) { System.out.println(e); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Contabilidad.javaToXML.java
public boolean creaAndValidaXML(TFactDocMX comprobante, String nombre) { boolean response = false; generaRaiz(comprobante);//from ww w .ja va 2 s.com XMLOutputter outputter = new XMLOutputter(); File folder = new File("nativos"); folder.mkdirs(); Format formato = Format.getPrettyFormat(); formato.setEncoding("UTF-8"); outputter.setFormat(formato); File archivoXml = new File(nombre); try { //Writer write = new FileWriter(archivoXml); FileOutputStream fop = new FileOutputStream(archivoXml); outputter.output(getXml(), fop); } catch (IOException e) { System.err.println("e1:" + e); return response; } //se instancia la clase que validara el XSD SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true); builder.setFeature("http://apache.org/xml/features/validation/schema", true); builder.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); builder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", COMPROBANTE_SCHEMA_XSD); builder.setValidation(true); //se imprime el documento si se logro cumplir con el XSD try { Document document = builder.build(archivoXml); //outputter.output(document, System.out); response = true; } catch (JDOMException e) { System.out.println("e2:"); error = e.toString(); e.printStackTrace(); } catch (IOException e) { System.out.println("e3"); error = e.toString(); e.printStackTrace(); } return response; }
From source file:controller.MobilePartnerController.java
public void createXML() throws Exception { Element root = new Element("dbconf"); Document doc = new Document(); Element child1 = new Element("url"); child1.addContent("jdbc:mysql://localhost:3306/mobile_partner"); child1.setAttribute("name", "javax.persistence.jdbc.url"); Element child2 = new Element("user"); child2.addContent("root"); child2.setAttribute("name", "javax.persistence.jdbc.user"); Element child3 = new Element("driver"); child3.addContent("com.mysql.jdbc.Driver"); child3.setAttribute("name", "javax.persistence.jdbc.driver"); Element child4 = new Element("password"); child4.addContent("nbuser"); child4.setAttribute("name", "javax.persistence.jdbc.password"); root.addContent(child1);// www .jav a 2s . co m root.addContent(child2); root.addContent(child3); root.addContent(child4); doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); outter.output(doc, new FileWriter(new File(DIR + "\\dbconf.xml"))); }