Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. // Gerando Arquivo Xml Para Exportação.
  2. private File GerarXmlFuncionarios() {
  3.  
  4. List<FuncionarioModel> funcionariosModel = funcionarioRepository.todos();
  5.  
  6. List<PessoaModel> pessoasModel = pessoaRepository.todas();
  7.  
  8. // Nome do Elemento Raiz do Xml
  9. Element elementDados = new Element("funcionarios");
  10.  
  11. Document documentoFuncionarios = new Document(elementDados);
  12.  
  13. funcionariosModel.forEach(funcionario -> {
  14. pessoasModel.forEach(pessoa -> {
  15. // Campos dos Xml com os Seus Valores
  16. Element elementFuncionario = new Element("funcionario");
  17. elementFuncionario.addContent(new Element("codigo").setText(pessoa.getCodigo().toString()));
  18. elementFuncionario.addContent(new Element("nome").setText(pessoa.getNome()));
  19. elementFuncionario.addContent(new Element("cargo").setText(funcionario.getCargo()));
  20.  
  21. elementDados.addContent(elementFuncionario);
  22. });
  23. });
  24.  
  25. XMLOutputter xmlGerado = new XMLOutputter();
  26. xmlGerado.setFormat(Format.getPrettyFormat().setEncoding("ISO-8859-1"));
  27.  
  28. try {
  29.  
  30. // Gera o Nome do Arquivo
  31. String nomeArquivo = "funcionarios_".concat(java.util.UUID.randomUUID().toString()).concat(".xml");
  32.  
  33. // Caminho que o Arquivo Sera Salvo
  34. File arquivo = new File("C:/Amarildo/Sistema_Web/".concat(nomeArquivo));
  35.  
  36. FileWriter fileWriter = new FileWriter(arquivo);
  37.  
  38. xmlGerado.output(documentoFuncionarios, fileWriter);
  39.  
  40. return arquivo;
  41.  
  42. } catch (Exception ex) {
  43.  
  44. ex.printStackTrace();
  45. }
  46.  
  47. return null;
  48. }
  49.  
  50. public List<PessoaModel> todas() {
  51. TypedQuery<PessoaModel> query = manager.createQuery("from PessoaModel", PessoaModel.class);
  52. return query.getResultList();
  53. }
  54.  
  55.  
  56. public List<FuncionarioModel> todos() {
  57. TypedQuery<FuncionarioModel> query = manager.createQuery("from FuncionarioModel", FuncionarioModel.class);
  58. return query.getResultList();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement