List of usage examples for org.jdom2 Attribute Attribute
public Attribute(final String name, final String value)
Attribute
with the specified (local) name and value, and does not place the attribute in a Namespace
. 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;/* w w w . j a v a 2s .co m*/ 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;//from ww w . ja 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; }
From source file:sistemaVendas.RealizarVenda.java
public boolean criarXml() { File diretorio2 = new File("Bancos de Dados"); File arquivo2 = new File(diretorio2, "BancoNotas.xml"); String cpf = lblCpfClienteVenda.getText().replaceAll("CPF:", " "); String nome = lblNomeClienteVenda.getText().replaceAll("Nome: ", " "); String telefone = lblFoneClienteVenda.getText().replaceAll("Fone:", " "); String data = formatarData(); String valorNota = txtTotalItens.getText(); String valorPagar = txtTotalPagar.getText(); String tipoPagamento = ""; if (rbAvista.isSelected()) tipoPagamento = "? Vista"; else if (rbDebito.isSelected()) tipoPagamento = "Dbito"; else if (rbCredito.isSelected()) tipoPagamento = "Crdito Parcelado de " + cbxNumParcela.getSelectedItem() + "x"; int numeracao = 1; if (!(arquivo2.exists())) { root2 = new Element("BancoNotas"); doc2 = new Document(root2); numeracao = 1;/*w w w .j av a 2s . c o m*/ numeroDaUltimaNota = "" + numeracao; } /*Se existir faz uma copia do original e acrescenta novas informaes*/ try { if (arquivo2.exists()) { SAXBuilder builder = new SAXBuilder(); doc2 = builder.build(arquivo2); root2 = (Element) doc2.getRootElement(); numeracao = idverificador(); numeroDaUltimaNota = "" + numeracao; } } catch (IOException e) { e.printStackTrace(); } catch (JDOMException e) { e.printStackTrace(); } Element nota = new Element("Nota"); Attribute numer = new Attribute("Numeracao", "" + numeracao); nota.setAttribute(numer); Attribute date = new Attribute("Data", "" + data); nota.setAttribute(date); root2.addContent(nota); Element cliente = new Element("Cliente"); Element name = new Element("Nome"); name.setText(nome); Element fone = new Element("Telefone"); fone.setText(telefone); Element cPf = new Element("CPF"); cPf.setText(cpf); cliente.addContent(name); cliente.addContent(fone); cliente.addContent(cPf); nota.addContent(cliente); Element produto = new Element("Produto"); for (int i = 0; i < tabItensVenda.getRowCount(); i++) { Element iten = new Element("Item"); String auxitem = (String) tabItensVenda.getValueAt(i, 1); iten.setText(auxitem); String auxquant = (String) tabItensVenda.getValueAt(i, 3); Attribute qtde = new Attribute("Quantidade", "" + auxquant); iten.setAttribute(qtde); String auxprecouni = (String) tabItensVenda.getValueAt(i, 2); Attribute precoUni = new Attribute("PrecoUnitario", "" + auxprecouni); iten.setAttribute(precoUni); String auxtotalpecas = (String) tabItensVenda.getValueAt(i, 4); Attribute pecastotal = new Attribute("PrecoTotal", "" + auxtotalpecas); iten.setAttribute(pecastotal); produto.addContent(iten); } nota.addContent(produto); Element pagament = new Element("Pagamento"); Element valort = new Element("ValorTotal"); valort.setText(valorPagar); Element valornot = new Element("ValorTotalNota"); valornot.setText(valorNota); Element modoPag = new Element("ModoPagamento"); modoPag.setText(tipoPagamento); pagament.addContent(valort); pagament.addContent(valornot); pagament.addContent(modoPag); nota.addContent(pagament); try { XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat()); OutputStream out = new FileOutputStream(new File(diretorio2, "BancoNotas.xml")); xout.output(doc2, out); out.close(); } catch (IOException e) { e.printStackTrace(); } return (true); }
From source file:strategies.HeldStock.java
public void AddToXml(Element rootElement) { Element heldElement = new Element("heldStock"); heldElement.setAttribute(new Attribute("ticker", tickerSymbol)); for (StockPurchase purchase : purchases) { purchase.AddToXml(heldElement);//from w w w .j a v a 2 s . c om } rootElement.addContent(heldElement); }
From source file:strategies.StockPurchase.java
void AddToXml(Element heldElement) { Element purchaseElement = new Element("purchase"); purchaseElement.setAttribute(new Attribute("priceForOne", TradeFormatter.toString(priceForOne))); purchaseElement.setAttribute(new Attribute("position", Integer.toString(position))); purchaseElement.setAttribute(new Attribute("portions", Integer.toString(portions))); purchaseElement.setAttribute(new Attribute("date", date.toString())); heldElement.addContent(purchaseElement); }
From source file:uno.gpt.generator.XMLWriter.java
License:Open Source License
/** * write a plan/* ww w . ja v a 2 s . c o m*/ * @param pl The target plan * @param parent The goal to achieve */ public void writePlan(PlanNode pl, Element parent) { Element plan = new Element("Plan"); plan.setAttribute(new Attribute("name", pl.getName())); // precondition ArrayList<Literal> st = pl.getPre(); if (st == null || st.size() == 0) { plan.setAttribute(new Attribute("precondition", "null")); } else { String pre = ""; for (int i = 0; i < st.size(); i++) { pre += st.get(i).toString(); } plan.setAttribute(new Attribute("precondition", pre)); } // in-condition st = pl.getInc(); if (st == null || st.size() == 0) { plan.setAttribute(new Attribute("in-condition", "null")); } else { String inc = ""; for (int i = 0; i < st.size(); i++) { inc += st.get(i).toString(); } plan.setAttribute(new Attribute("in-condition", inc)); } // write all actions, subgoals and parallel compositions it contains for (int i = 0; i < pl.getPlanBody().size(); i++) { if (pl.getPlanBody().get(i) instanceof ActionNode) { ActionNode act = (ActionNode) pl.getPlanBody().get(i); writeAction(act, plan); } if (pl.getPlanBody().get(i) instanceof GoalNode) { GoalNode gl = (GoalNode) pl.getPlanBody().get(i); writeGoal(gl, plan); } if (pl.getPlanBody().get(i) instanceof ParallelNode) { ParallelNode pn = (ParallelNode) pl.getPlanBody().get(i); writeParallel(pn, plan); } } parent.addContent(plan); }
From source file:uno.gpt.generator.XMLWriter.java
License:Open Source License
/** * write action//from ww w . j a v a2 s . c om * @param act The target action * @param parent The plan which contain this action */ public void writeAction(ActionNode act, Element parent) { Element action = new Element("Action"); action.setAttribute(new Attribute("name", act.getName())); // pre-condition ArrayList<Literal> st = act.getPreC(); if (st == null || st.size() == 0) { action.setAttribute(new Attribute("precondition", "null")); } else { String pre = ""; for (int i = 0; i < st.size(); i++) { pre = pre + st.get(i).toString(); } action.setAttribute(new Attribute("precondition", pre)); } // in-condition st = act.getInC(); if (st == null || st.size() == 0) { action.setAttribute(new Attribute("in-condition", "null")); } else { String inc = ""; for (int i = 0; i < st.size(); i++) { inc = inc + st.get(i).toString(); } action.setAttribute(new Attribute("in-condition", inc)); } // postcondition st = act.getPostC(); if (st == null) { action.setAttribute(new Attribute("postcondition", "null")); } else { String post = ""; for (int i = 0; i < st.size(); i++) { post = post + st.get(i).toString(); } action.setAttribute(new Attribute("postcondition", post)); } parent.addContent(action); }
From source file:uno.gpt.generator.XMLWriter.java
License:Open Source License
/** * write goal//ww w. j a v a 2s . c om * @param gl The target goal * @param parent the Plan which contain this goal */ public void writeGoal(GoalNode gl, Element parent) { Element goal = new Element("Goal"); goal.setAttribute(new Attribute("name", gl.getName())); // in-condition ArrayList<Literal> st = gl.getInC(); if (st == null || st.size() == 0) { goal.setAttribute(new Attribute("in-condition", "null")); } else { String inc = ""; for (int i = 0; i < st.size(); i++) { inc = inc + st.get(i).toString(); } goal.setAttribute(new Attribute("in-condition", inc)); } for (int i = 0; i < gl.getPlans().size(); i++) { PlanNode pl = gl.getPlans().get(i); writePlan(pl, goal); } parent.addContent(goal); }
From source file:uno.gpt.generator.XMLWriter.java
License:Open Source License
/** * write parallel composition//from ww w . j a v a2 s . c om * @param pn The target parallel composition * @param parent The plan which contain this parallel composition */ public void writeParallel(ParallelNode pn, Element parent) { Element parallel = new Element("Parallel_composition"); parallel.setAttribute(new Attribute("name", pn.getName())); for (int i = 0; i < pn.getParallel().size(); i++) { if (pn.getParallel().get(i) instanceof ActionNode) { ActionNode act = (ActionNode) pn.getParallel().get(i); writeAction(act, parallel); } if (pn.getParallel().get(i) instanceof GoalNode) { GoalNode gl = (GoalNode) pn.getParallel().get(i); writeGoal(gl, parallel); } } parent.addContent(parallel); }
From source file:xmlproject.TraitementEtudiant.java
public void addEtudiant(String nom, String prenom, String code, String departement, String moyenne) throws IOException { Attribute id = new Attribute("id", code); this.etudiant.setAttribute(id); racine.addContent(etudiant);//from www. j av a 2 s . c o m this.nom = new Element("nom"); this.nom.setText(nom); this.prenom = new Element("prenom"); this.prenom.setText(prenom); this.code = new Element("code"); this.code.setText(code); this.departement = new Element("departement"); this.departement.setText(departement); this.moyenne = new Element("moyenne"); this.moyenne.setText(moyenne); this.etudiant.addContent(this.nom); this.etudiant.addContent(this.prenom); this.etudiant.addContent(this.code); this.etudiant.addContent(this.departement); this.etudiant.addContent(this.moyenne); }