/src/mpv5/utils/export/ODTFile.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/ · Java · 84 lines · 55 code · 8 blank · 21 comment · 2 complexity · caba3d925d431a023ba5b8c8f71731fa MD5 · raw file

  1. /*
  2. * This file is part of YaBS.
  3. *
  4. * YaBS is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * YaBS is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package mpv5.utils.export;
  18. import ag.ion.bion.officelayer.document.IDocument;
  19. import enoa.connection.NoaConnection;
  20. import enoa.handler.DocumentHandler;
  21. import java.io.IOException;
  22. import java.util.HashMap;
  23. import java.util.Iterator;
  24. import mpv5.logging.Log;
  25. /**
  26. *
  27. *
  28. */
  29. public class ODTFile extends Exportable {
  30. private static final long serialVersionUID = 1L;
  31. private NoaConnection nc;
  32. private DocumentHandler dh;
  33. public ODTFile(String pathToFile) {
  34. super(pathToFile);
  35. if (!exists()) {
  36. try {
  37. createNewFile();
  38. } catch (IOException ex) {
  39. Log.Debug(ex);
  40. }
  41. }
  42. try {
  43. nc = NoaConnection.getConnection();
  44. dh = new DocumentHandler(nc);
  45. dh.loadDocument(this, false);
  46. Log.Debug(this, "Loaded odt file: " + this);
  47. } catch (Exception ex) {
  48. Log.Debug(ex);
  49. }
  50. }
  51. @Override
  52. public void run() {
  53. Log.Debug(this, "run: ");
  54. mpv5.YabsViewProxy.instance().setWaiting(true);
  55. Log.Debug(this, "All fields:");
  56. for (Iterator<String> it = getData().keySet().iterator(); it.hasNext();) {
  57. String k = it.next();
  58. Log.Debug(this, "Key: " + k + " [" + getData().get(k) + "]");
  59. }
  60. try {
  61. dh.clear();
  62. HashMap<String, Object> d = getData();
  63. d.putAll(getTemplate().getData());
  64. dh.fillPlaceholderFields(d);
  65. // dh.fillTextVariableFields((ITextDocument) df, getData());//Omitted for performance reasons
  66. dh.fillTables(getData(), getTemplate());
  67. dh.setImages(getData());
  68. dh.saveAs(getTarget());
  69. dh.close();
  70. } catch (Exception ex) {
  71. Log.Debug(ex);
  72. } finally {
  73. mpv5.YabsViewProxy.instance().setWaiting(false);
  74. }
  75. }
  76. }