PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 34ms app.codeStats 0ms

/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 */
17package mpv5.utils.export;
18
19import ag.ion.bion.officelayer.document.IDocument;
20import enoa.connection.NoaConnection;
21import enoa.handler.DocumentHandler;
22import java.io.IOException;
23import java.util.HashMap;
24import java.util.Iterator;
25import mpv5.logging.Log;
26
27/**
28 *
29 *
30 */
31public class ODTFile extends Exportable {
32
33    private static final long serialVersionUID = 1L;
34    private NoaConnection nc;
35    private DocumentHandler dh;
36
37    public ODTFile(String pathToFile) {
38        super(pathToFile);
39        if (!exists()) {
40            try {
41                createNewFile();
42            } catch (IOException ex) {
43                Log.Debug(ex);
44            }
45        }
46        try {
47            nc = NoaConnection.getConnection();
48            dh = new DocumentHandler(nc);
49            dh.loadDocument(this, false);
50            Log.Debug(this, "Loaded odt file: " + this);
51        } catch (Exception ex) {
52            Log.Debug(ex);
53        }
54    }
55
56    @Override
57    public void run() {
58
59        Log.Debug(this, "run: ");
60        mpv5.YabsViewProxy.instance().setWaiting(true);
61
62        Log.Debug(this, "All fields:");
63        for (Iterator<String> it = getData().keySet().iterator(); it.hasNext();) {
64            String k = it.next();
65            Log.Debug(this, "Key: " + k + " [" + getData().get(k) + "]");
66        }
67
68        try {
69            dh.clear();
70            HashMap<String, Object> d = getData();
71            d.putAll(getTemplate().getData());
72            dh.fillPlaceholderFields(d);
73//            dh.fillTextVariableFields((ITextDocument) df, getData());//Omitted for performance reasons
74            dh.fillTables(getData(), getTemplate());
75            dh.setImages(getData());
76            dh.saveAs(getTarget());
77            dh.close();
78        } catch (Exception ex) {
79            Log.Debug(ex);
80        } finally {
81            mpv5.YabsViewProxy.instance().setWaiting(false);
82        }
83    }
84}