Line 22... |
Line 22... |
22 |
import org.openconcerto.sql.Configuration;
|
22 |
import org.openconcerto.sql.Configuration;
|
23 |
import org.openconcerto.sql.model.SQLRow;
|
23 |
import org.openconcerto.sql.model.SQLRow;
|
24 |
import org.openconcerto.utils.ExceptionHandler;
|
24 |
import org.openconcerto.utils.ExceptionHandler;
|
25 |
import org.openconcerto.utils.StreamUtils;
|
25 |
import org.openconcerto.utils.StreamUtils;
|
26 |
import org.openconcerto.utils.StringUtils;
|
26 |
import org.openconcerto.utils.StringUtils;
|
- |
|
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 60... |
Line 64... |
60 |
try {
|
64 |
try {
|
61 |
InputStream xmlConfiguration = TemplateManager.getInstance().getTemplateConfiguration(templateId, rowLanguage != null ? rowLanguage.getString("CHEMIN") : null, null);
|
65 |
InputStream xmlConfiguration = TemplateManager.getInstance().getTemplateConfiguration(templateId, rowLanguage != null ? rowLanguage.getString("CHEMIN") : null, null);
|
62 |
if (xmlConfiguration == null) {
|
66 |
if (xmlConfiguration == null) {
|
63 |
throw new IllegalStateException("Template configuration " + templateId + " not found (" + TemplateManager.getInstance().getClass().getName() + ")");
|
67 |
throw new IllegalStateException("Template configuration " + templateId + " not found (" + TemplateManager.getInstance().getClass().getName() + ")");
|
64 |
}
|
68 |
}
|
- |
|
69 |
final BufferedReader xmlConfigurationReader = new BufferedReader(new InputStreamReader(xmlConfiguration, Charset.forName("UTF8")));
|
- |
|
70 |
BOMSkipper.skip(xmlConfigurationReader);
|
65 |
Document doc = builder.build(xmlConfiguration);
|
71 |
final Document doc = builder.build(xmlConfigurationReader);
|
- |
|
72 |
xmlConfigurationReader.close();
|
- |
|
73 |
xmlConfiguration.close();
|
66 |
|
74 |
|
67 |
// On initialise un nouvel élément racine avec l'élément racine du
|
75 |
// On initialise un nouvel élément racine avec l'élément racine du
|
68 |
// document.
|
76 |
// document.
|
69 |
final Element racine = doc.getRootElement();
|
77 |
final Element racine = doc.getRootElement();
|
70 |
|
78 |
|
Line 72... |
Line 80... |
72 |
final InputStream template = TemplateManager.getInstance().getTemplate(templateId, rowLanguage != null ? rowLanguage.getString("CHEMIN") : null, null);
|
80 |
final InputStream template = TemplateManager.getInstance().getTemplate(templateId, rowLanguage != null ? rowLanguage.getString("CHEMIN") : null, null);
|
73 |
if (template == null) {
|
81 |
if (template == null) {
|
74 |
throw new IllegalStateException("Template " + templateId + " not found (" + TemplateManager.getInstance().getClass().getName() + ")");
|
82 |
throw new IllegalStateException("Template " + templateId + " not found (" + TemplateManager.getInstance().getClass().getName() + ")");
|
75 |
}
|
83 |
}
|
76 |
final SpreadSheet spreadSheet = new ODPackage(template).getSpreadSheet();
|
84 |
final SpreadSheet spreadSheet = new ODPackage(template).getSpreadSheet();
|
- |
|
85 |
|
77 |
Sheet sheet0 = spreadSheet.getSheet(0);
|
86 |
Sheet sheet0 = spreadSheet.getSheet(0);
|
78 |
if (sheetName != null && sheetName.size() > 0) {
|
87 |
if (sheetName != null && sheetName.size() > 0) {
|
79 |
for (int i = 1; i < sheetName.size(); i++) {
|
88 |
for (int i = 1; i < sheetName.size(); i++) {
|
80 |
sheet0.copy(i, (sheetName != null) ? sheetName.get(i) : "Feuille " + i);
|
89 |
sheet0.copy(i, (sheetName != null) ? sheetName.get(i) : "Feuille " + i);
|
81 |
}
|
90 |
}
|
82 |
spreadSheet.getSheet(0).setName(sheetName.get(0));
|
91 |
spreadSheet.getSheet(0).setName(sheetName.get(0));
|
83 |
}
|
92 |
}
|
84 |
|
93 |
|
85 |
for (Integer i : liste.keySet()) {
|
94 |
for (Integer i : liste.keySet()) {
|
- |
|
95 |
final Sheet sheet;
|
- |
|
96 |
try {
|
86 |
final Sheet sheet = spreadSheet.getSheet(i);
|
97 |
sheet = spreadSheet.getSheet(i);
|
- |
|
98 |
} catch (Exception e) {
|
- |
|
99 |
throw new InvalidTemplateException("La feuille numéro " + i + " n'est pas dans le modèle", e);
|
- |
|
100 |
}
|
87 |
List children = racine.getChildren("element" + i);
|
101 |
List children = racine.getChildren("element" + i);
|
88 |
if (children.size() == 0) {
|
102 |
if (children.size() == 0) {
|
89 |
children = racine.getChildren("element");
|
103 |
children = racine.getChildren("element");
|
90 |
}
|
104 |
}
|
91 |
parseElementsXML(children, sheet, values.get(i));
|
105 |
parseElementsXML(children, sheet, values.get(i));
|
Line 94... |
Line 108... |
94 |
child = racine.getChild("table");
|
108 |
child = racine.getChild("table");
|
95 |
}
|
109 |
}
|
96 |
parseListeXML(child, liste.get(i), sheet, mapStyle.get(i));
|
110 |
parseListeXML(child, liste.get(i), sheet, mapStyle.get(i));
|
97 |
}
|
111 |
}
|
98 |
cacheStyle.clear();
|
112 |
cacheStyle.clear();
|
- |
|
113 |
|
99 |
// Sauvegarde du fichier
|
114 |
// Sauvegarde du fichier
|
100 |
return saveSpreadSheet(spreadSheet, pathDest, fileDest, templateId, rowLanguage);
|
115 |
return saveSpreadSheet(spreadSheet, pathDest, fileDest, templateId, rowLanguage);
|
101 |
|
116 |
|
102 |
} catch (JDOMException e) {
|
117 |
} catch (JDOMException e) {
|
103 |
ExceptionHandler.handle("Erreur lors de la génération du fichier " + fileDest, e);
|
118 |
ExceptionHandler.handle("Erreur lors de la génération du fichier " + fileDest, e);
|
Line 553... |
Line 568... |
553 |
|
568 |
|
554 |
e.printStackTrace();
|
569 |
e.printStackTrace();
|
555 |
}
|
570 |
}
|
556 |
|
571 |
|
557 |
// Copie de l'odsp
|
572 |
// Copie de l'odsp
|
558 |
try {
|
- |
|
559 |
File odspOut = new File(pathDest, fileName + ".odsp");
|
573 |
File odspOut = new File(pathDest, fileName + ".odsp");
|
560 |
InputStream odspIn = TemplateManager.getInstance().getTemplatePrintConfiguration(templateId, rowLanguage != null ? rowLanguage.getString("CHEMIN") : null, null);
|
574 |
try (final InputStream odspIn = TemplateManager.getInstance().getTemplatePrintConfiguration(templateId, rowLanguage != null ? rowLanguage.getString("CHEMIN") : null, null);) {
|
561 |
if (odspIn != null) {
|
575 |
if (odspIn != null) {
|
562 |
StreamUtils.copy(odspIn, odspOut);
|
576 |
StreamUtils.copy(odspIn, odspOut);
|
563 |
}
|
577 |
}
|
564 |
} catch (FileNotFoundException e) {
|
578 |
} catch (FileNotFoundException e) {
|
565 |
System.err.println("Le fichier odsp n'existe pas.");
|
579 |
System.err.println("Le fichier odsp n'existe pas.");
|