List of usage examples for org.jdom2.output XMLOutputter XMLOutputter
public XMLOutputter()
XMLOutputter
with a default Format and XMLOutputProcessor . From source file:AIR.Common.xml.XmlElement.java
License:Open Source License
public String getOuterXml() { XMLOutputter outp = new XMLOutputter(); outp.setFormat(Format.getCompactFormat()); String returnString = ""; try (StringWriter sw = new StringWriter()) { if (_element instanceof Element) outp.output((Element) _element, sw); else {//w w w . j a v a 2 s . c om // TODO: What to do for other types of Content? // Note: Document is not derived from Content. } returnString = sw.getBuffer().toString(); } catch (IOException e1) { e1.printStackTrace(); } return returnString; }
From source file:AIR.Common.xml.XmlElement.java
License:Open Source License
public String getInnerXml() { XMLOutputter outp = new XMLOutputter(); outp.setFormat(Format.getCompactFormat()); try (StringWriter sw = new StringWriter()) { if (_element instanceof Element) outp.outputElementContent((Element) _element, sw); else {//w ww.j a va 2 s . c o m // TODO: What to do for other types of Content? } return sw.toString(); } catch (IOException e1) { e1.printStackTrace(); throw new XmlReaderException(e1); } }
From source file:arquivo.Arquivo.java
public String remove(String nome, String nomeE) { SAXBuilder builder = new SAXBuilder(); List<Element> retorna = new LinkedList<>(); try {//from w ww . ja v a 2 s . c o m Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); List<Element> removido = buscaInterna(root, true, nome, nomeE); root.removeContent(removido.get(0)); XMLOutputter xout = new XMLOutputter(); OutputStream out = new FileOutputStream(arquivo); xout.output(doc, out); return "Documento alterado com sucesso!"; } catch (Exception e) { e.printStackTrace(); } return "n foi possivel remover " + nome; }
From source file:arquivo.ArquivoF.java
public ArquivoF() { super(new File("empregados.xml")); if (!arquivo.exists()) { try {//from w w w .j a v a 2s .co m Document doc = new Document(); Element root = new Element("list"); doc.setRootElement(root); XMLOutputter xout = new XMLOutputter(); xout.output(doc, new FileOutputStream(arquivo)); System.out.println("Documento criado com sucesso!"); } catch (Exception e) { // TODO: handle exception } } }
From source file:arquivo.ArquivoF.java
public String add(String confSenha, String loing, String senha, String nome) { if (confSenha.equals(senha) && !loing.equals("") && !nome.equals("") && !senha.equals("")) { if (0 != busca(nome, true, "funcinario").size() && buscaLong(loing).size() != 0) return "erro nome ja cadastrado"; SAXBuilder builder = new SAXBuilder(); try {/*w w w . j a va2 s. c om*/ Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); Element funcionario = new Element("funcinario"); Attribute nomeE = new Attribute("nome", nome); funcionario.setAttribute(nomeE); Element loingE = new Element("loing"); loingE.setText(loing); funcionario.addContent(loingE); Element senhaE = new Element("senha"); senhaE.setText(senha); funcionario.addContent(senhaE); root.addContent(funcionario); XMLOutputter xout = new XMLOutputter(); OutputStream out = new FileOutputStream(arquivo); xout.output(doc, out); System.out.println("Documento alterado com sucesso!"); return "cadastrado com suceso"; } catch (Exception e) { } } else return "preemcha os compos corretamente"; return "erro cadastral"; }
From source file:arquivo.ArquivoF.java
public String edita(String confSenha, String loing, String senha, String nome) { if (confSenha.equals(senha) && !loing.equals("") && !senha.equals("")) { if (0 == busca(nome, true, "funcinario").size() && buscaLong(loing).size() != 0) return "erro nome nao cadastrado"; SAXBuilder builder = new SAXBuilder(); try {//from w w w . jav a 2 s. c om Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); List<Element> funcinario = super.buscaInterna(root, true, nome, "funcinario"); if (!loing.equals("")) funcinario.get(0).getChild("loing").setText(loing); if (!senha.equals("")) funcinario.get(0).getChild("senha").setText(senha); XMLOutputter xout = new XMLOutputter(); OutputStream out = new FileOutputStream(arquivo); xout.output(doc, out); System.out.println("Documento alterado com sucesso!"); return "cadastrado com suceso"; } catch (Exception e) { } } else return "preemcha os compos corretamente"; return "erro cadastral"; }
From source file:arquivo.ArquivoFilme.java
public ArquivoFilme() { super(new File("filmes.xml")); if (!arquivo.exists()) { try {//w w w . ja v a2s .com Document doc = new Document(); Element root = new Element("list"); doc.setRootElement(root); XMLOutputter xout = new XMLOutputter(); xout.output(doc, new FileOutputStream(arquivo)); System.out.println("Documento criado com sucesso!"); } catch (Exception e) { // TODO: handle exception } } }
From source file:arquivo.ArquivoFilme.java
public String add(String nome, String faixa, String tipo) { if (0 != busca(nome, true, "filme").size()) return "erro nome ja cadastrado"; SAXBuilder builder = new SAXBuilder(); try {//from w w w . ja v a 2s .com Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); Element filmeE = new Element("filme"); Attribute nomeE = new Attribute("nome", nome); filmeE.setAttribute(nomeE); Attribute tipoE = new Attribute("tipo", tipo); filmeE.setAttribute(tipoE); Attribute faixaE = new Attribute("faixa", faixa); filmeE.setAttribute(faixaE); root.addContent(filmeE); XMLOutputter xout = new XMLOutputter(); OutputStream out = new FileOutputStream(arquivo); xout.output(doc, out); System.out.println("Documento alterado com sucesso!"); return "cadastrado com suceso"; } catch (Exception e) { e.printStackTrace(); } return "erro cadastral"; }
From source file:arquivo.ArquivoFilme.java
public String edita(String nome, String novoNome, String faixa, String tipo) { String retorno = "erro"; if (!nome.equals("")) { if (0 == busca(nome, true, "funcinario").size()) return "erro nao nome ja cadastrado"; SAXBuilder builder = new SAXBuilder(); try {/*from w w w. j av a 2 s . c o m*/ Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); List<Element> filme = super.buscaInterna(root, true, nome, "filme"); if (!novoNome.equals("")) filme.get(0).setAttribute("nome", novoNome); if (!faixa.equals("")) filme.get(0).setAttribute("faixa", faixa); if (!tipo.equals("")) filme.get(0).setAttribute("tipo", tipo); XMLOutputter xout = new XMLOutputter(); OutputStream out = new FileOutputStream(arquivo); xout.output(doc, out); System.out.println("Documento alterado com sucesso!"); retorno = "cadastrado com suceso"; } catch (Exception e) { } } else retorno = "preemcha os compos corretamente"; return retorno; }
From source file:arquivo.ArquivoFilme.java
public String addSesao(String nome, int numeroSala, int horaI, int mimI, int horaF, int mimF) { String retorno = "erro"; if (!nome.equals("")) { if (this.confirnaSesao(numeroSala, horaI, mimI, horaF, mimF)) { SAXBuilder builder = new SAXBuilder(); try { Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); List<Element> filme = super.buscaInterna(root, true, nome, "filme"); if (filme.size() == 0) { return "erro filme n registrado"; }//w ww. ja v a2s. c om List<Element> salas = filme.get(0).getChildren("sala"); Element secao = new Element("secao"); secao.setAttribute(new Attribute("horaI", "" + horaI)); secao.setAttribute(new Attribute("mimI", "" + mimI)); secao.setAttribute(new Attribute("horaF", "" + horaF)); secao.setAttribute(new Attribute("mimF", "" + mimF)); boolean confirna = false; for (int i = 0; i < salas.size(); i++) { if (salas.get(i).getAttributeValue("numeroSala").equals("" + numeroSala)) { confirna = true; salas.get(i).addContent(secao); break; } } if (!confirna) { Element sala = new Element("sala"); sala.addContent(secao); filme.get(0).addContent(sala); } XMLOutputter xout = new XMLOutputter(); OutputStream out = new FileOutputStream(arquivo); xout.output(doc, out); System.out.println("Documento alterado com sucesso!"); retorno = "cadastrado com suceso"; } catch (Exception e) { } } else retorno = "nesse horario a sala estara ocupada"; } return retorno; }