OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 149 Rev 156
Line 22... Line 22...
22
import org.openconcerto.openoffice.spreadsheet.Table;
22
import org.openconcerto.openoffice.spreadsheet.Table;
23
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.Configuration;
24
import org.openconcerto.sql.model.SQLRow;
24
import org.openconcerto.sql.model.SQLRow;
25
import org.openconcerto.utils.ExceptionHandler;
25
import org.openconcerto.utils.ExceptionHandler;
26
import org.openconcerto.utils.StreamUtils;
26
import org.openconcerto.utils.StreamUtils;
-
 
27
import org.openconcerto.utils.io.BOMSkipper;
27
 
28
 
28
import java.awt.Point;
29
import java.awt.Point;
-
 
30
import java.io.BufferedReader;
29
import java.io.File;
31
import java.io.File;
30
import java.io.FileNotFoundException;
32
import java.io.FileNotFoundException;
31
import java.io.IOException;
33
import java.io.IOException;
32
import java.io.InputStream;
34
import java.io.InputStream;
-
 
35
import java.io.InputStreamReader;
-
 
36
import java.nio.charset.Charset;
33
import java.util.HashMap;
37
import java.util.HashMap;
34
import java.util.Iterator;
38
import java.util.Iterator;
35
import java.util.List;
39
import java.util.List;
36
import java.util.Map;
40
import java.util.Map;
37
 
41
 
Line 44... Line 48...
44
import org.jdom2.input.SAXBuilder;
48
import org.jdom2.input.SAXBuilder;
45
 
49
 
46
public class OOgenerationListeColumnXML {
50
public class OOgenerationListeColumnXML {
47
 
51
 
48
    // Cache pour la recherche des styles
52
    // Cache pour la recherche des styles
49
    private static Map<Sheet, Map<String, Map<Integer, String>>> cacheStyle = new HashMap<Sheet, Map<String, Map<Integer, String>>>();
53
    private static Map<Sheet, Map<String, Map<Integer, String>>> cacheStyle = new HashMap<>();
50
 
54
 
51
    public static File genere(String modele, File pathDest, String fileDest, Map<Integer, List<Map<String, Object>>> liste, Map<Integer, Map<String, Object>> values) {
55
    public static File genere(String modele, File pathDest, String fileDest, Map<Integer, List<Map<String, Object>>> liste, Map<Integer, Map<String, Object>> values) {
52
        return genere(modele, pathDest, fileDest, liste, values, new HashMap<Integer, Map<Integer, String>>(), null, null);
56
        return genere(modele, pathDest, fileDest, liste, values, new HashMap<Integer, Map<Integer, String>>(), null, null);
53
    }
57
    }
54
 
58
 
Line 59... Line 63...
59
        try {
63
        try {
60
            InputStream xmlConfiguration = TemplateManager.getInstance().getTemplateConfiguration(templateId, rowLanguage != null ? rowLanguage.getString("CHEMIN") : null, null);
64
            InputStream xmlConfiguration = TemplateManager.getInstance().getTemplateConfiguration(templateId, rowLanguage != null ? rowLanguage.getString("CHEMIN") : null, null);
61
            if (xmlConfiguration == null) {
65
            if (xmlConfiguration == null) {
62
                throw new IllegalStateException("Template configuration " + templateId + " not found (" + TemplateManager.getInstance().getClass().getName() + ")");
66
                throw new IllegalStateException("Template configuration " + templateId + " not found (" + TemplateManager.getInstance().getClass().getName() + ")");
63
            }
67
            }
-
 
68
            final BufferedReader xmlConfigurationReader = new BufferedReader(new InputStreamReader(xmlConfiguration, Charset.forName("UTF8")));
-
 
69
            BOMSkipper.skip(xmlConfigurationReader);
64
            Document doc = builder.build(xmlConfiguration);
70
            final Document doc = builder.build(xmlConfigurationReader);
-
 
71
            xmlConfigurationReader.close();
-
 
72
            xmlConfiguration.close();
65
 
73
 
66
            // On initialise un nouvel élément racine avec l'élément racine du
74
            // On initialise un nouvel élément racine avec l'élément racine du
67
            // document.
75
            // document.
68
            final Element racine = doc.getRootElement();
76
            final Element racine = doc.getRootElement();
69
 
77
 
Line 82... Line 90...
82
            }
90
            }
83
 
91
 
84
            for (Integer i : liste.keySet()) {
92
            for (Integer i : liste.keySet()) {
85
                final Sheet sheet = spreadSheet.getSheet(i);
93
                final Sheet sheet = spreadSheet.getSheet(i);
86
                List children = racine.getChildren("element" + i);
94
                List children = racine.getChildren("element" + i);
87
                if (children.size() == 0) {
95
                if (children.isEmpty()) {
88
                    children = racine.getChildren("element");
96
                    children = racine.getChildren("element");
89
                }
97
                }
90
                parseElementsXML(children, sheet, values.get(i));
98
                parseElementsXML(children, sheet, values.get(i));
91
                Element child = racine.getChild("table" + i);
99
                Element child = racine.getChild("table" + i);
92
                if (child == null) {
100
                if (child == null) {
Line 136... Line 144...
136
        if (liste == null || tableau == null) {
144
        if (liste == null || tableau == null) {
137
            return;
145
            return;
138
        }
146
        }
139
        Object oLastColTmp = tableau.getAttributeValue("lastColumn");
147
        Object oLastColTmp = tableau.getAttributeValue("lastColumn");
140
        int lastColumn = -1;
148
        int lastColumn = -1;
141
        int endPageLine = Integer.valueOf(tableau.getAttributeValue("endPageLine"));
149
        int endPageLine = Integer.parseInt(tableau.getAttributeValue("endPageLine"));
142
        if (oLastColTmp != null) {
150
        if (oLastColTmp != null) {
143
            lastColumn = sheet.resolveHint(oLastColTmp.toString() + 1).x + 1;
151
            lastColumn = sheet.resolveHint(oLastColTmp.toString() + 1).x + 1;
144
        }
152
        }
145
        Map<String, Map<Integer, String>> mapStyle = searchStyle(sheet, lastColumn, endPageLine);
153
        Map<String, Map<Integer, String>> mapStyle = searchStyle(sheet, lastColumn, endPageLine);
146
 
154
 
Line 200... Line 208...
200
     * @param test remplir ou non avec les valeurs
208
     * @param test remplir ou non avec les valeurs
201
     * @return le nombre de page
209
     * @return le nombre de page
202
     */
210
     */
203
    private static int fillTable(Element tableau, List<Map<String, Object>> liste, Sheet sheet, Map<String, Map<Integer, String>> mapStyle, boolean test, Map<Integer, String> style) {
211
    private static int fillTable(Element tableau, List<Map<String, Object>> liste, Sheet sheet, Map<String, Map<Integer, String>> mapStyle, boolean test, Map<Integer, String> style) {
204
 
212
 
205
        // int nbPage = 1;
-
 
206
        // int currentLineTmp = Integer.valueOf(tableau.getAttributeValue("firstLine"));
-
 
207
        // int currentLine = Integer.valueOf(tableau.getAttributeValue("firstLine"));
-
 
208
        // int endPageLine = Integer.valueOf(tableau.getAttributeValue("endPageLine"));
-
 
209
        int endLine = Integer.valueOf(tableau.getAttributeValue("endLine"));
213
        int endLine = Integer.parseInt(tableau.getAttributeValue("endLine"));
210
 
214
 
211
        List listElts = tableau.getChildren("element");
215
        List listElts = tableau.getChildren("element");
212
 
216
 
213
        Object o = null;
217
        Object o = null;
214
        // String columnSousTotal = tableau.getAttributeValue("groupSousTotalColumn");
218
        // String columnSousTotal = tableau.getAttributeValue("groupSousTotalColumn");
Line 220... Line 224...
220
        sheet.setColumnCount(liste.size() + 5);
224
        sheet.setColumnCount(liste.size() + 5);
221
        Integer firstCol = Integer.valueOf(tableau.getAttributeValue("firstLine"));
225
        Integer firstCol = Integer.valueOf(tableau.getAttributeValue("firstLine"));
222
        int currentCol = firstCol;
226
        int currentCol = firstCol;
223
        for (int i = 0; i < liste.size(); i++) {
227
        for (int i = 0; i < liste.size(); i++) {
224
            Map<String, Object> mValues = liste.get(i);
228
            Map<String, Object> mValues = liste.get(i);
225
            // System.err.println(mValues);
-
 
226
            if (currentCol != firstCol) {
229
            if (currentCol != firstCol) {
227
                for (int k = 0; k < endLine; k++) {
230
                for (int k = 0; k < endLine; k++) {
228
                    MutableCell<SpreadSheet> c1 = sheet.getCellAt(firstCol, k);
231
                    MutableCell<SpreadSheet> c1 = sheet.getCellAt(firstCol, k);
229
                    if (c1.getFormula() != null && c1.getFormula().trim().length() > 0) {
232
                    if (c1.getFormula() != null && c1.getFormula().trim().length() > 0) {
230
                        String formula = c1.getFormula();
233
                        String formula = c1.getFormula();
Line 462... Line 465...
462
 
465
 
463
            e.printStackTrace();
466
            e.printStackTrace();
464
        }
467
        }
465
 
468
 
466
        // Copie de l'odsp
469
        // Copie de l'odsp
467
        try {
-
 
468
            File odspOut = new File(pathDest, fileName + ".odsp");
470
        File odspOut = new File(pathDest, fileName + ".odsp");
469
            InputStream odspIn = TemplateManager.getInstance().getTemplatePrintConfiguration(templateId, rowLanguage != null ? rowLanguage.getString("CHEMIN") : null, null);
471
        try (final InputStream odspIn = TemplateManager.getInstance().getTemplatePrintConfiguration(templateId, rowLanguage != null ? rowLanguage.getString("CHEMIN") : null, null);) {
470
            if (odspIn != null) {
472
            if (odspIn != null) {
471
                StreamUtils.copy(odspIn, odspOut);
473
                StreamUtils.copy(odspIn, odspOut);
472
            }
474
            }
473
        } catch (FileNotFoundException e) {
475
        } catch (FileNotFoundException e) {
474
            System.err.println("Le fichier odsp n'existe pas.");
476
            System.err.println("Le fichier odsp n'existe pas.");