List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:rezeptsuperpos.RecipeGUI.java
License:Open Source License
private String element2String(Element element) { Format format = Format.getPrettyFormat(); XMLOutputter xmlOutputter = new XMLOutputter(); xmlOutputter.setFormat(format);/* w w w. j a v a 2 s . co m*/ return xmlOutputter.outputString(element); }
From source file:rodrigorar.data.IOManager.java
License:Open Source License
public void printDocument(String file, Document xmlDocument) { try {/*from ww w .j ava 2s . c o m*/ XMLOutputter xmlOutput = new XMLOutputter(); xmlOutput.setFormat(Format.getPrettyFormat()); xmlOutput.output(xmlDocument, new FileWriter(file)); } catch (IOException exception) { exception.printStackTrace(); } }
From source file:se.miun.itm.input.tuning.converter.SpotDesignInitializer.java
License:Open Source License
public SpotDesignInitializer() throws InPUTException { outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); importer = new InputStreamImporter(); }
From source file:segunda.progra.Servidor.java
/** * Este mtodo se usa para guardar los productos del servidor en un archivo .xml a salvo * @param XML El nombre del XML donde se desea guardar los productos *//*from w w w. j a v a 2 s.c o m*/ private void guardarProductosXML(String XML) { //Defino una nueva etiqueta con cabecera para guardar los productos Element root = new Element("Productos"); //recorro toda la lista de productos para guardar los productos for (int i = 0; i < productos.size(); i++) { Producto get = productos.get(i); //El elemento que va a contener todos los datos del producto Element producto = new Element(colocaUnderScores(get.getNombre())); //Ahora llenar los datos del producto dentro de su elemento Element codigo = new Element("Codigo"); codigo.addContent(get.getCodigo()); producto.addContent(codigo); Element descripcion = new Element("Descripcion"); descripcion.addContent(get.getDescripcion()); producto.addContent(descripcion); Element tamanhoPorcion = new Element("TamanhoPorcion"); tamanhoPorcion.addContent(String.valueOf(get.getTamanhoPorcion())); producto.addContent(tamanhoPorcion); Element piezaPorPorcion = new Element("PiezasPorPorcion"); piezaPorPorcion.addContent(String.valueOf(get.getPiezasPorcion())); producto.addContent(piezaPorPorcion); Element caloriasEnUnaPorcion = new Element("CaloriasEnUnaPorcion"); caloriasEnUnaPorcion.addContent(String.valueOf(get.getCaloriasPorcion())); producto.addContent(caloriasEnUnaPorcion); Element caloriasPorPieza = new Element("CaloriasPorPieza"); caloriasPorPieza.addContent(String.valueOf(get.getCaloriasPieza())); producto.addContent(caloriasPorPieza); Element precio = new Element("Precio"); precio.addContent(String.valueOf(get.getPrecio())); producto.addContent(precio); //agrego el producto a la raz del XML root.addContent(producto); } //ahora slo falta guardarlo XMLOutputter outputterXML = new XMLOutputter(Format.getPrettyFormat()); try { outputterXML.output(new Document(root), new FileOutputStream(XML)); } catch (IOException e) { System.out.println("Ocurri un error a la hora de guardar el XML"); } }
From source file:sistemaVendas.AlterarClienteProcurado.java
private void btnAlterarClienteProcuradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarClienteProcuradoActionPerformed if (verificarCPf()) { File diretorio = new File("Bancos de Dados"); File arquivo = new File(diretorio, "BancoCliente.xml"); String id = txtIdClienteProcurado.getText(); String nome = txtNomeClienteProcurado.getText(); String sexo = (String) cbxSexoProcurado.getSelectedItem(); String idade = txtIdadeProcurado.getText(); String fone = txtFoneProcurado.getText(); String cpf = txtCpfProcurado.getText(); try {/*from w w w . ja v a 2s. c o m*/ SAXBuilder builder = new SAXBuilder(); doc = builder.build(arquivo); root = (Element) doc.getRootElement(); List<Element> clientes = root.getChildren(); for (int i = 0; i < clientes.size(); i++) { Element cliente = clientes.get(i); if (cliente.getAttributeValue("id").equals(id)) { if (!cliente.getChildText("nome").equals(nome)) { cliente.getChild("nome").setText(nome); } if (!cliente.getChildText("sexo").equals(sexo)) { cliente.getChild("sexo").setText(sexo); } if (!cliente.getChildText("idade").equals(idade)) { cliente.getChild("idade").setText(idade); } if (!cliente.getChildText("telefone").equals(fone)) { cliente.getChild("telefone").setText(fone); } if (!cliente.getChildText("cpf").equals(cpf)) { cliente.getChild("cpf").setText(cpf); } } } XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); OutputStream out = new FileOutputStream(new File(diretorio, "BancoCLiente.xml")); xout.output(doc, out); out.close(); } catch (JDOMException | IOException e) { } JOptionPane.showMessageDialog(null, "DADOS ALTERADOS COM SUCESSO!", "Sucesso", JOptionPane.INFORMATION_MESSAGE); this.dispose(); } else { JOptionPane.showMessageDialog(null, "CPF INV?LIDO! DIGITE NOVAMENTE!", "ERRO", JOptionPane.ERROR_MESSAGE); } }
From source file:sistemaVendas.AlterarClienteProcurado.java
private void btnDeletarClienteProcuradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeletarClienteProcuradoActionPerformed File diretorio = new File("Bancos de Dados"); File arquivo = new File(diretorio, "BancoCliente.xml"); String id = txtIdClienteProcurado.getText(); try {/*from w w w .jav a2 s .c om*/ SAXBuilder builder = new SAXBuilder(); doc = builder.build(arquivo); root = (Element) doc.getRootElement(); List<Element> clientes = root.getChildren(); for (int i = 0; i < clientes.size(); i++) { Element cliente = clientes.get(i); if (cliente.getAttributeValue("id").equals(id)) { cliente.getParent().removeContent(cliente); } } XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); OutputStream out = new FileOutputStream(new File(diretorio, "BancoCLiente.xml")); xout.output(doc, out); out.close(); } catch (JDOMException | IOException e) { } JOptionPane.showMessageDialog(null, "CLIENTE REMOVIDO COM SUCESSO!", "Sucesso", JOptionPane.INFORMATION_MESSAGE); this.dispose(); }
From source file:sistemaVendas.AlterarProdutoProcurado.java
private void btnOkProdutoProcuradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkProdutoProcuradoActionPerformed File diretorio = new File("Bancos de Dados"); File arquivo = new File(diretorio, "BancoProduto.xml"); String id = txtIdProdutoProcurado.getText(); String nome = txtNomeProdutoProcurado.getText(); String tipo = (String) cbxTipoProdutoProcurado.getSelectedItem(); String qtde = txtQtdeEstoqueProcurado.getText(); String preco = ftxtPrecoUnitProdutoProcurado.getText(); String descricao = txtDescricaoProcurado.getText(); try {//from w ww . j a v a 2 s. co m SAXBuilder builder = new SAXBuilder(); doc = builder.build(arquivo); root = doc.getRootElement(); List<Element> produtos = root.getChildren(); for (int i = 0; i < produtos.size(); i++) { Element produto = produtos.get(i); if (produto.getAttributeValue("id").equals(id)) { if (!produto.getChildText("nome").equals(nome)) { produto.getChild("nome").setText(nome); } if (!produto.getChild("nome").getAttributeValue("tipo").equals(tipo)) { produto.getChild("nome").setAttribute("tipo", tipo); } if (!produto.getChildText("qtde").equals(qtde)) { produto.getChild("qtde").setText(qtde); } if (!produto.getChildText("preoUnitrio").equals(preco)) { produto.getChild("preoUnitrio").setText(preco); } if (!produto.getChildText("descrio").equals(descricao)) { produto.getChild("descrio").setText(descricao); } } } XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); OutputStream out = new FileOutputStream(new File(diretorio, "BancoProduto.xml")); xout.output(doc, out); out.close(); } catch (JDOMException | IOException e) { } JOptionPane.showMessageDialog(null, "DADOS ALTERADOS COM SUCESSO!", "Sucesso", JOptionPane.INFORMATION_MESSAGE); this.dispose(); }
From source file:sistemaVendas.AlterarProdutoProcurado.java
private void btnDeletarProdutoProcuradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeletarProdutoProcuradoActionPerformed File diretorio = new File("Bancos de Dados"); File arquivo = new File(diretorio, "BancoProduto.xml"); String id = txtIdProdutoProcurado.getText(); try {/*from w w w .j av a 2s .c o m*/ SAXBuilder builder = new SAXBuilder(); doc = builder.build(arquivo); root = doc.getRootElement(); List<Element> produtos = root.getChildren(); for (int i = 0; i < produtos.size(); i++) { Element produto = produtos.get(i); if (produto.getAttributeValue("id").equals(id)) { produto.getParent().removeContent(produto); } } XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); OutputStream out = new FileOutputStream(new File(diretorio, "BancoProduto.xml")); xout.output(doc, out); out.close(); } catch (JDOMException | IOException e) { } JOptionPane.showMessageDialog(null, "PRODUTO REMOVIDO COM SUCESSO!", "Sucesso", JOptionPane.INFORMATION_MESSAGE); this.dispose(); }
From source file:sistemaVendas.CadastroCliente.java
public boolean criarXml() { String cpf = txtCpf.getText(); String nome = txtNomeCliente.getText().toUpperCase(); String idade = txtIdade.getText(); String telefone = txtFone.getText(); String sexo = (String) cbxSexo.getSelectedItem(); int id = 1;//from w w w . j av a 2 s. c om if (!(arquivo.exists())) { root = new Element("BancoCliente"); doc = new Document(root); id = 1; } /*Se existir faz uma copia do original e acrescenta novas informaes*/ try { if (arquivo.exists()) { SAXBuilder builder = new SAXBuilder(); doc = builder.build(arquivo); root = (Element) doc.getRootElement(); id = idverificador(); } } catch (IOException e) { e.printStackTrace(); } catch (JDOMException e) { e.printStackTrace(); } Element cliente = new Element("cliente"); Attribute idd = new Attribute("id", "" + id); cliente.setAttribute(idd); Element name = new Element("nome"); name.setText(nome); Element sex = new Element("sexo"); sex.setText(sexo); Element age = new Element("idade"); age.setText(idade); Element fone = new Element("telefone"); fone.setText(telefone); Element cpfxml = new Element("cpf"); cpfxml.setText(cpf); cliente.addContent(name); cliente.addContent(sex); cliente.addContent(age); cliente.addContent(fone); cliente.addContent(cpfxml); root.addContent(cliente); try { XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); OutputStream out = new FileOutputStream(new File(diretorio, "BancoCLiente.xml")); xout.output(doc, out); out.close(); } catch (IOException e) { e.printStackTrace(); } return (true); }
From source file:sistemaVendas.CadastroProduto.java
public boolean criarXml() { String nome = txtNomeProduto.getText().toUpperCase(); String tipoProduto = (String) cbxTipoProduto.getSelectedItem(); String qtde = txtQtdeEstoque.getText(); String precoUnit = ftxtPrecoUnitProduto.getText(); String descricao = txtDescricao.getText(); int id = 1;// www. j a v a 2 s . co m if (!arquivo.exists()) { root = new Element("BancoProduto"); doc = new Document(root); } try { if (arquivo.exists()) { SAXBuilder builder = new SAXBuilder(); doc = builder.build(arquivo); root = (Element) doc.getRootElement(); id = idVerificador(); } } catch (IOException | JDOMException e) { return false; } Element produto = new Element("produto"); Attribute idd = new Attribute("id", "" + id); produto.setAttribute(idd); Element name = new Element("nome"); name.setText(nome); Attribute tipo = new Attribute("tipo", tipoProduto); name.setAttribute(tipo); Element descricaoXml = new Element("descrio"); descricaoXml.setText(descricao); Element precoUnitario = new Element("preoUnitrio"); precoUnitario.setText(precoUnit); Element qtdeXml = new Element("qtde"); qtdeXml.setText(qtde); produto.addContent(name); produto.addContent(descricaoXml); produto.addContent(precoUnitario); produto.addContent(qtdeXml); root.addContent(produto); try { XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); OutputStream out = new FileOutputStream(new File(diretorio, "BancoProduto.xml")); xout.output(doc, out); out.close(); } catch (IOException e) { return false; } return true; }