OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 132
Line 15... Line 15...
15
 * Créé le 15 nov. 2004
15
 * Créé le 15 nov. 2004
16
 */
16
 */
17
package org.openconcerto.odtemplate;
17
package org.openconcerto.odtemplate;
18
 
18
 
19
import org.openconcerto.odtemplate.engine.OGNLDataModel;
19
import org.openconcerto.odtemplate.engine.OGNLDataModel;
20
import org.openconcerto.openoffice.XMLVersion;
-
 
21
import org.openconcerto.openoffice.ODPackage;
20
import org.openconcerto.openoffice.ODPackage;
22
import org.openconcerto.openoffice.ODSingleXMLDocument;
21
import org.openconcerto.openoffice.ODSingleXMLDocument;
23
import org.openconcerto.openoffice.generation.DocumentGenerator;
22
import org.openconcerto.openoffice.generation.DocumentGenerator;
24
import org.openconcerto.openoffice.generation.ReportGeneration;
23
import org.openconcerto.openoffice.generation.ReportGeneration;
25
import org.openconcerto.utils.ExceptionUtils;
24
import org.openconcerto.utils.ExceptionUtils;
Line 39... Line 38...
39
 * @param <R> type of generation
38
 * @param <R> type of generation
40
 */
39
 */
41
public class TemplateGenerator<R extends ReportGeneration<?>> extends DocumentGenerator<R> {
40
public class TemplateGenerator<R extends ReportGeneration<?>> extends DocumentGenerator<R> {
42
 
41
 
43
    private final File file;
42
    private final File file;
-
 
43
    private final ODPackage pkg;
44
 
44
 
45
    public TemplateGenerator(final R rg, final File f) {
45
    public TemplateGenerator(final R rg, final File f) {
-
 
46
        this(rg, f, null);
-
 
47
    }
-
 
48
 
-
 
49
    public TemplateGenerator(final R rg, final ODPackage pkg) {
-
 
50
        this(rg, null, pkg);
-
 
51
    }
-
 
52
 
-
 
53
    private TemplateGenerator(final R rg, final File f, final ODPackage pkg) {
46
        super(rg);
54
        super(rg);
-
 
55
        if ((f == null) == (pkg == null))
-
 
56
            throw new IllegalArgumentException();
47
        this.file = f;
57
        this.file = f;
-
 
58
        this.pkg = pkg;
48
    }
59
    }
49
 
60
 
-
 
61
    @Override
50
    public final ODSingleXMLDocument generate() throws IOException, InterruptedException {
62
    public final ODSingleXMLDocument generate() throws IOException, InterruptedException {
51
        return this.substitute(this.getAllData());
63
        return this.substitute(this.getAllData());
52
    }
64
    }
53
 
65
 
54
    protected final Map<String, Object> getAllData() throws IOException, InterruptedException {
66
    protected final Map<String, Object> getAllData() throws IOException, InterruptedException {
Line 61... Line 73...
61
 
73
 
62
    protected Map<String, Object> getData() throws InterruptedException {
74
    protected Map<String, Object> getData() throws InterruptedException {
63
        return new HashMap<String, Object>();
75
        return new HashMap<String, Object>();
64
    }
76
    }
65
 
77
 
66
    private final ODSingleXMLDocument substitute(Map data) throws FileNotFoundException, IOException {
78
    private final ODSingleXMLDocument substitute(Map<String, Object> data) throws FileNotFoundException, IOException {
67
        final XMLVersion reportVersion = this.getRg().getCommon().getOOVersion();
-
 
68
        final ODPackage pkg = new ODPackage(this.file);
79
        final ODPackage pkg = this.pkg == null ? new ODPackage(this.file) : this.pkg;
69
        if (pkg.getVersion() != reportVersion)
-
 
70
            throw new IllegalArgumentException("version mismatch");
-
 
71
        try {
80
        try {
72
            this.transform(pkg.toSingle());
81
            this.transform(pkg.toSingle());
73
            // MAYBE fireStatusChange with the number of tag done out of the total
82
            // MAYBE fireStatusChange with the number of tag done out of the total
74
            return new Template(pkg).createDocument(new OGNLDataModel(data));
83
            return new Template(pkg).createDocument(new OGNLDataModel(data));
75
        } catch (Exception exn) {
84
        } catch (Exception exn) {
Line 78... Line 87...
78
    }
87
    }
79
 
88
 
80
    protected void transform(ODSingleXMLDocument single) throws Exception {
89
    protected void transform(ODSingleXMLDocument single) throws Exception {
81
    }
90
    }
82
 
91
 
-
 
92
    @Override
83
    public String toString() {
93
    public String toString() {
84
        return this.getClass() + " with file " + this.file;
94
        return this.getClass() + (this.file != null ? (" with file " + this.file) : (" with package " + this.pkg));
85
    }
95
    }
86
 
96
 
87
}
97
}