List of usage examples for org.jdom2.output XMLOutputter XMLOutputter
public XMLOutputter()
XMLOutputter
with a default Format and XMLOutputProcessor . From source file:compile.util.XMLUtil.java
public void save() { _document.setContent(_racine);//www. j av a 2s. 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.javaToXML.java
public boolean creaAndValidaXML(TFactDocMX comprobante, String nombre) { boolean response = false; generaRaiz(comprobante);/* w w w. j av a2s . c o m*/ 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);/*from w w w . j a v a 2 s.c o 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"))); }
From source file:core.ListComponenXml.java
@Override public void updateFile() { try {/*from ww w .ja v a 2 s . co m*/ Element root = new Element("listado"); Document document = new Document(); for (Xml xml : this.getXmls()) { Element autor = new Element("autor"); autor.addContent(new Element("nombre").setText(xml.getAutor().getNombre())); autor.addContent(new Element("descripcion").setText(xml.getAutor().getDescripcion())); autor.addContent(new Element("version").setText(xml.getAutor().getVersion())); Element cuerpo = new Element("cuerpo"); Element tipo = new Element("tipo"); Element status = new Element("status"); tipo.setAttribute("columnas", "" + xml.getCuerpo().getColumnas()); tipo.setAttribute("tipodatocolumna", String.join(",", xml.getCuerpo().getTipo_datos())); cuerpo.addContent(tipo); tipo.addContent(new Element("claseprincipal").setText(xml.getCuerpo().getMain())); status.setAttribute("active", String.valueOf(xml.getStatus().getActive())); Element parametro = new Element("parametro"); for (String dato : xml.getCuerpo().getParametros()) { parametro.addContent(new Element(dato)); } cuerpo.addContent(parametro); Element pluguin = new Element("pluguin"); pluguin.addContent(autor); pluguin.addContent(cuerpo); pluguin.addContent(status); root.addContent(pluguin); } ; document.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); String basePath = new File("").getAbsolutePath(); String ruta = basePath + "/src/configuracion/xml_configuracion.xml"; if (System.getProperty("os.name").toLowerCase().contains("windows")) { ruta = basePath + "\\src\\configuracion\\xml_configuracion.xml"; } outter.output(document, new FileWriter(new File(ruta))); } catch (IOException ex) { Logger.getLogger(ListComponenXml.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:core.utileria.java
/** * @param args the command line arguments *//* ww w . jav a 2 s . c om*/ public static void main(String[] args) throws IOException { // TODO code application logic here // File archivo = new File("/home/dark/Escritorio/aaaaaaaaaaa/a3"); // if (!archivo.exists()) // archivo.mkdir(); ListComponenXml l = new ListComponenXml(); String basePath = new File("").getAbsolutePath(); System.out.println(basePath); System.out.println(System.getProperty("os.name").toLowerCase()); String ruta = basePath + "/src/configuracion/xml_configuracion.xml"; if (System.getProperty("os.name").toLowerCase().contains("windows")) { ruta = basePath + "\\src\\configuracion\\xml_configuracion.xml"; } l.loadingFile(ruta); l.readNodeFile(); // for(Xml x : l.getXmls()){ // System.out.println(x.toString()); // } Element root = new Element("CONFIGURATION"); Document doc = new Document(); Element child1 = new Element("BROWSER"); child1.addContent("chrome"); Element child2 = new Element("BASE"); child1.addContent("http:fut"); Element child3 = new Element("EMPLOYEE"); child3.addContent(new Element("EMP_NAME").addContent("Anhorn, Irene")); root.addContent(child1); doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); outter.output(doc, new FileWriter(new File(basePath + "\\src\\configuracion\\xml_configuracion2.xml"))); }
From source file:core.WriteComponenXml.java
@Override public void writeFile(String ruta, Xml xml) { FileWriter writer = null;/*from w w w . jav a 2s. com*/ try { ValidXml vxml = new ValidXml(); System.out.println(vxml.exisFile(ruta)); System.out.println(vxml.validExtencion(ruta)); if (vxml.exisFile(ruta) && vxml.validExtencion(ruta)) { loadingFile(ruta); try { FileInputStream fis = new FileInputStream(this.getFile()); setDocument(this.getBuilder().build(fis)); this.setRootNode(getDocument().detachRootElement()); } catch (FileNotFoundException ex) { Logger.getLogger(WriteComponenXml.class.getName()).log(Level.SEVERE, null, ex); } catch (JDOMException ex) { Logger.getLogger(WriteComponenXml.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(WriteComponenXml.class.getName()).log(Level.SEVERE, null, ex); } } else { String basePath = new File("").getAbsolutePath(); ruta = basePath + "/src/configuracion/xml_configuracion.xml"; if (System.getProperty("os.name").toLowerCase().contains("windows")) { ruta = basePath + "\\src\\configuracion\\xml_configuracion.xml"; } Element root = new Element("listado"); Document doc = new Document(); doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); this.setFile(new File(ruta)); outter.output(doc, new FileWriter(this.getFile())); FileInputStream fis = new FileInputStream(this.getFile()); setDocument(this.getBuilder().build(this.getFile())); this.setRootNode(getDocument().detachRootElement()); this.setDocument(new Document()); this.setRootNode(new Element("listado")); } Element autor = new Element("autor"); System.out.println(" " + this.getDocument() + " " + this.getRootNode()); autor.addContent(new Element("nombre").setText(xml.getAutor().getNombre())); autor.addContent(new Element("descripcion").setText(xml.getAutor().getDescripcion())); autor.addContent(new Element("version").setText(xml.getAutor().getVersion())); Element cuerpo = new Element("cuerpo"); Element tipo = new Element("tipo"); Element status = new Element("status"); tipo.setAttribute("columnas", "" + xml.getCuerpo().getColumnas()); tipo.setAttribute("tipodatocolumna", String.join(",", xml.getCuerpo().getTipo_datos())); cuerpo.addContent(tipo); tipo.addContent(new Element("claseprincipal").setText(xml.getCuerpo().getMain())); status.setAttribute("active", String.valueOf(xml.getStatus().getActive())); Element parametro = new Element("parametro"); for (String dato : xml.getCuerpo().getParametros()) { parametro.addContent(new Element(dato)); } cuerpo.addContent(parametro); Element pluguin = new Element("pluguin"); pluguin.addContent(autor); pluguin.addContent(cuerpo); pluguin.addContent(status); this.getRootNode().addContent(pluguin); this.getDocument().setContent(this.getRootNode()); writer = new FileWriter(ruta); XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(this.getDocument(), writer); outputter.output(this.getDocument(), System.out); writer.close(); // close writer } catch (IOException ex) { Logger.getLogger(WriteComponenXml.class.getName()).log(Level.SEVERE, null, ex); } catch (JDOMException ex) { Logger.getLogger(WriteComponenXml.class.getName()).log(Level.SEVERE, null, ex); } finally { } }
From source file:cz.lbenda.dataman.db.ExportTableData.java
License:Apache License
/** Write rows from sql query to output stream * @param sqlQueryRows rows/* w w w.j ava 2 s . c om*/ * @param outputStream stream to which are data write */ public static void writeSqlQueryRowsToXMLv2(SQLQueryRows sqlQueryRows, OutputStream outputStream) throws IOException { Element root = new Element("export"); root.setAttribute("sql", sqlQueryRows.getSQL()); root.setAttribute("version", "2"); List<Element> rows = new ArrayList<>(sqlQueryRows.getRows().size()); sqlQueryRows.getRows().forEach(rowDesc -> { Element row = new Element("row"); List<Element> cols = new ArrayList<>(sqlQueryRows.getMetaData().getColumns().size()); sqlQueryRows.getMetaData().getColumns().forEach(columnDesc -> { Element element = new Element(columnDesc.getName()); if (rowDesc.isColumnNull(columnDesc)) { element.setAttribute("null", "true"); } else { element.setText(rowDesc.getColumnValueStr(columnDesc)); } cols.add(element); }); row.addContent(cols); rows.add(row); }); root.addContent(rows); XMLOutputter xmlOutputter = new XMLOutputter(); xmlOutputter.output(new Document(root), outputStream); }
From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java
License:Apache License
public static String storeToString() { Document doc = new Document(storeAllToElement()); XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); StringWriter sw = new StringWriter(); try {//from w ww.j a v a 2 s . co m xmlOutput.output(doc, sw); return sw.toString(); } catch (IOException e) { LOG.error("There was problem with write XML output to StringWriter", e); throw new RuntimeException("There was problem with write XML output to StringWriter", e); } }
From source file:cz.muni.fi.mir.mathmlcanonicalization.MathMLCanonicalizer.java
License:Apache License
/** * Canonicalize an input MathML stream./*ww w . j a va 2s.c o m*/ * * @param in input stream to be canonicalized * @param out canonical output stream of input * @throws JDOMException problem with DOM * @throws IOException problem with streams * @throws ModuleException some module cannot canonicalize the input */ public void canonicalize(final InputStream in, final OutputStream out) throws JDOMException, IOException, ModuleException, XMLStreamException { if (in == null) { throw new NullPointerException("in"); } if (out == null) { throw new NullPointerException("out"); } InputStream inputStream = in; if (enforcingXHTMLPlusMathMLDTD) { inputStream = DTDManipulator.injectXHTMLPlusMathMLDTD(in); } ByteArrayOutputStream outputStream = null; // calling stream modules for (StreamModule module : streamModules) { outputStream = module.execute(inputStream); if (outputStream == null) { throw new IOException("Module " + module + "returned null."); } inputStream = new ByteArrayInputStream(outputStream.toByteArray()); } if (enforcingXHTMLPlusMathMLDTD) { inputStream = DTDManipulator.removeDTD(inputStream); } // do not create the JDOM representation if there are no modules if (domModules.isEmpty()) { if (streamModules.isEmpty()) { throw new IOException("There are no modules added."); } assert outputStream != null; // nonempty streamModules + nothing thrown in for outputStream.writeTo(out); return; } // creating the JDOM representation from the stream final SAXBuilder builder = Settings.setupSAXBuilder(); final Document document = builder.build(inputStream); // calling JDOM modules for (DOMModule module : domModules) { module.execute(document); } // convertong the JDOM representation back to stream final XMLOutputter serializer = new XMLOutputter(); serializer.output(document, out); }
From source file:cz.muni.fi.pb138.scxml2voicexmlj.XmlHelper.java
public String render(Content xml) { try {//from w w w.j a v a 2s . c om XMLOutputter out = new XMLOutputter(); StringWriter writer = new StringWriter(); out.output(asList(xml), writer); return writer.toString(); } catch (IOException e) { throw new RuntimeException(e); } }