List of usage examples for org.jdom2.input SAXBuilder build
@Override public Document build(final String systemId) throws JDOMException, IOException
This builds a document from the supplied URI.
From source file:arquivo.Arquivo.java
public List busca(String nome, boolean completa, String nomeE) { SAXBuilder builder = new SAXBuilder(); List<Element> retorna = new LinkedList<>(); try {/*from w ww . ja va2 s . c o m*/ Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); retorna = this.buscaInterna(root, completa, nome, nomeE); } catch (Exception e) { } return retorna; }
From source file:arquivo.Arquivo.java
public String remove(String nome, String nomeE) { SAXBuilder builder = new SAXBuilder(); List<Element> retorna = new LinkedList<>(); try {// w ww.java 2s . 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 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 {//from w w w. j ava 2 s . c o m 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 . j a va2s . co m*/ 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.ArquivoF.java
public List buscaLong(String loing) { List<Element> loings = new LinkedList<>(); SAXBuilder builder = new SAXBuilder(); try {/* w w w. j a v a2 s . c o m*/ Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); List<Element> funcinario = super.buscaInterna(root, false, "", "funcinario"); for (int i = 0; i < funcinario.size(); i++) { if (funcinario.get(i).getChildText("loing").equals(loing)) loings.add(funcinario.get(i)); } } catch (Exception e) { } return loings; }
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 2 s. c om*/ 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 {/* ww w .j av a2 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"; }/* www . j a va 2 s. c o m*/ 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; }
From source file:arquivo.ArquivoFilme.java
public boolean confirnaSesao(int numeroSala, int horaI, int mimI, int horaF, int mimF) { SAXBuilder builder = new SAXBuilder(); try {//from w w w . j a v a 2 s . c o m Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); List<Element> filme = root.getChildren("filme"); for (int i = 0; i < filme.size(); i++) { List<Element> salas = filme.get(i).getChildren("sala"); for (int j = 0; j < salas.size(); j++) { if (salas.get(j).getAttribute("numeroSala").equals("" + numeroSala)) { List<Element> secoes = salas.get(j).getChildren("secao"); for (int d = 0; d < secoes.size(); d++) { int horaEF = Integer.parseInt(secoes.get(d).getAttributeValue("horaF")); int mimEF = Integer.parseInt(secoes.get(d).getAttributeValue("mimF")); if (horaI >= horaEF && mimI > mimEF + 15) { return true; } int horaIF = Integer.parseInt(secoes.get(d).getAttributeValue("horaI")); int mimIF = Integer.parseInt(secoes.get(d).getAttributeValue("mimI")); if (horaF <= horaIF && mimF < mimIF + 15) { return true; } } } } } } catch (Exception e) { } return false; }
From source file:arquivo.ArquivoFilme.java
public List buscaSalas(String nome) { List<Element> salas = new LinkedList<>(); SAXBuilder builder = new SAXBuilder(); try {//w w w . j av a2 s . c o m Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); List<Element> filme = super.buscaInterna(root, true, nome, "filme"); if (filme.size() != 0) salas = filme.get(0).getChildren("sala"); } catch (Exception e) { } return salas; }