OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 185
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 27... Line 27...
27
import org.openconcerto.utils.ExceptionHandler;
27
import org.openconcerto.utils.ExceptionHandler;
28
import org.openconcerto.utils.StreamUtils;
28
import org.openconcerto.utils.StreamUtils;
29
 
29
 
30
import java.awt.Point;
30
import java.awt.Point;
31
import java.io.File;
31
import java.io.File;
-
 
32
import java.io.FileInputStream;
32
import java.io.FileNotFoundException;
33
import java.io.FileNotFoundException;
33
import java.io.IOException;
34
import java.io.IOException;
34
import java.io.InputStream;
35
import java.io.InputStream;
35
import java.util.ArrayList;
36
import java.util.ArrayList;
36
import java.util.Arrays;
37
import java.util.Arrays;
Line 54... Line 55...
54
    protected int nbPage, nbRowsPerPage;
55
    protected int nbPage, nbRowsPerPage;
55
    private boolean visu, impression;
56
    private boolean visu, impression;
56
    private String printer;
57
    private String printer;
57
    private boolean exportPDF;
58
    private boolean exportPDF;
58
    private Map mapReplaceText;
59
    private Map mapReplaceText;
59
    private String fODSP = null;
60
    private InputStream fODSP = null;
60
 
61
 
61
    protected static final String defaultLocationTemplate = "/Configuration/Template/Default/";
62
    protected static final String defaultLocationTemplate = "/Configuration/Template/Default/";
62
 
63
 
63
    static {
64
    static {
64
        String loc = TemplateNXProps.getInstance().getStringProperty("LocationTemplate");
65
        String loc = TemplateNXProps.getInstance().getStringProperty("LocationTemplate");
Line 75... Line 76...
75
 
76
 
76
    protected void searchStyle(Sheet sheet, Map<String, Map<Integer, String>> mapStyleDef, int colEnd, int rowEnd) {
77
    protected void searchStyle(Sheet sheet, Map<String, Map<Integer, String>> mapStyleDef, int colEnd, int rowEnd) {
77
 
78
 
78
        // on parcourt chaque ligne de la feuille pour recuperer les styles
79
        // on parcourt chaque ligne de la feuille pour recuperer les styles
79
        int columnCount = (colEnd == -1) ? sheet.getColumnCount() : (colEnd + 1);
80
        int columnCount = (colEnd == -1) ? sheet.getColumnCount() : (colEnd + 1);
-
 
81
        int endColumnSearch = Math.min(100, columnCount);
80
        System.err.println("End column search : " + columnCount);
82
        System.err.println("End column search : " + endColumnSearch);
81
 
83
 
82
        int rowCount = (rowEnd > 0) ? rowEnd : sheet.getRowCount();
84
        int rowCount = (rowEnd > 0) ? rowEnd : sheet.getRowCount();
-
 
85
        int endRowSearch = Math.min(100, rowCount);
83
        for (int i = 0; i < rowCount; i++) {
86
        for (int i = 0; i < endRowSearch; i++) {
84
            int x = 0;
87
            int x = 0;
85
            Map<Integer, String> mapCellStyle = new HashMap<Integer, String>();
88
            Map<Integer, String> mapCellStyle = new HashMap<Integer, String>();
86
            String style = "";
89
            String style = "";
87
 
90
 
88
            for (int j = 0; j < columnCount; j++) {
91
            for (int j = 0; j < endColumnSearch; j++) {
89
 
92
 
90
                if (sheet.isCellValid(j, i)) {
93
                if (sheet.isCellValid(j, i)) {
91
 
94
 
92
                    MutableCell c = sheet.getCellAt(j, i);
95
                    MutableCell c = sheet.getCellAt(j, i);
93
                    String cellStyle = c.getStyleName();
96
                    String cellStyle = c.getStyleName();
Line 181... Line 184...
181
            }
184
            }
182
        }
185
        }
183
    }
186
    }
184
 
187
 
185
    protected SpreadSheet loadTemplate() throws IOException {
188
    protected SpreadSheet loadTemplate() throws IOException {
-
 
189
 
-
 
190
        InputStream f = TemplateManager.getInstance().getTemplate(modele.replaceAll(".ods", ""));
-
 
191
        if (f == null) {
186
        InputStream f = getStreamStatic(modelDir + File.separator + this.modele);
192
            f = getStreamStatic(modelDir + File.separator + this.modele);
187
        fODSP = modelDir + File.separator + this.modele + "p";
193
            fODSP = getStreamStatic(modelDir + File.separator + this.modele + "p");
188
        if (f == null) {
194
            if (f == null) {
189
            f = getStreamStatic(defaultLocationTemplate + File.separator + this.modele);
195
                f = getStreamStatic(defaultLocationTemplate + File.separator + this.modele);
190
            fODSP = defaultLocationTemplate + File.separator + this.modele + "p";
196
                fODSP = getStreamStatic(defaultLocationTemplate + File.separator + this.modele + "p");
191
            if (f == null) {
197
                if (f == null) {
192
                ExceptionHandler.handle("Modele " + this.modele + " introuvable. Impossible de générer le document.");
198
                    ExceptionHandler.handle("Modele " + this.modele + " introuvable. Impossible de générer le document.");
193
                System.err.println("Modele introuvable : " + (defaultLocationTemplate + File.separator + this.modele));
199
                    System.err.println("Modele introuvable : " + (defaultLocationTemplate + File.separator + this.modele));
194
                fODSP = null;
200
                    fODSP = null;
195
                return null;
201
                    return null;
196
            }
202
                }
197
        }
203
            }
-
 
204
        } else {
-
 
205
            fODSP = TemplateManager.getInstance().getTemplatePrintConfiguration(modele.replaceAll(".ods", ""), null, null);
-
 
206
        }
-
 
207
 
198
        final SpreadSheet res = new ODPackage(f).getSpreadSheet();
208
        final SpreadSheet res = new ODPackage(f).getSpreadSheet();
199
        f.close();
209
        f.close();
200
        return res;
210
        return res;
201
    }
211
    }
202
 
212
 
Line 215... Line 225...
215
        }
225
        }
216
        File fTmp = new File(this.destDirOO, this.destFileName + ".ods");
226
        File fTmp = new File(this.destDirOO, this.destFileName + ".ods");
217
        fTmp.renameTo(fDest);
227
        fTmp.renameTo(fDest);
218
 
228
 
219
        fDest = new File(this.destDirOO, this.destFileName + ".ods");
229
        fDest = new File(this.destDirOO, this.destFileName + ".ods");
220
        try (final InputStream stream = getStreamStatic(fODSP)) {
-
 
221
            if (stream != null) {
230
        if (this.fODSP != null) {
222
                // Copie de l'odsp
231
            // Copie de l'odsp
223
                File odspOut = new File(this.destDirOO, this.destFileName + ".odsp");
232
            File odspOut = new File(this.destDirOO, this.destFileName + ".odsp");
224
                StreamUtils.copy(stream, odspOut);
233
            StreamUtils.copy(this.fODSP, odspOut);
225
            }
-
 
226
        }
234
        }
-
 
235
 
227
        try {
236
        try {
228
            ssheet.saveAs(fDest);
237
            ssheet.saveAs(fDest);
229
        } catch (FileNotFoundException e) {
238
        } catch (FileNotFoundException e) {
230
            final File file = fDest;
239
            final File file = fDest;
231
            SwingUtilities.invokeLater(new Runnable() {
240
            SwingUtilities.invokeLater(new Runnable() {