25 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
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
|
|
|
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.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.generationDoc;
|
|
|
15 |
|
|
|
16 |
import java.io.File;
|
|
|
17 |
import java.io.FileInputStream;
|
|
|
18 |
import java.io.FileNotFoundException;
|
|
|
19 |
import java.io.InputStream;
|
|
|
20 |
|
|
|
21 |
public abstract class AbstractLocalTemplateProvider implements TemplateProvider {
|
|
|
22 |
|
|
|
23 |
@Override
|
|
|
24 |
public InputStream getTemplate(String templateId, String langage, String type) {
|
|
|
25 |
try {
|
|
|
26 |
final File templateFile = getTemplateFile(templateId, langage, type);
|
|
|
27 |
if (templateFile == null || !templateFile.exists()) {
|
|
|
28 |
return null;
|
|
|
29 |
}
|
|
|
30 |
return new FileInputStream(templateFile);
|
|
|
31 |
} catch (FileNotFoundException e) {
|
|
|
32 |
return null;
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
@Override
|
|
|
37 |
public InputStream getTemplatePrintConfiguration(String templateId, String langage, String type) {
|
|
|
38 |
final File t = getTemplateFile(templateId, langage, type);
|
|
|
39 |
final String name = t.getName();
|
|
|
40 |
if (name.toLowerCase().endsWith(".ods")) {
|
|
|
41 |
final File file = new File(t.getParent(), name.substring(0, name.length() - 4) + ".odsp");
|
|
|
42 |
try {
|
|
|
43 |
return new FileInputStream(file);
|
|
|
44 |
} catch (FileNotFoundException e) {
|
|
|
45 |
System.err.println("No print configuration " + file.getAbsolutePath() + " for template id: " + templateId);
|
|
|
46 |
e.printStackTrace();
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
return null;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
@Override
|
|
|
53 |
public InputStream getTemplateConfiguration(String templateId, String langage, String type) {
|
|
|
54 |
final File t = getTemplateFile(templateId, langage, type);
|
|
|
55 |
final String name = t.getName();
|
|
|
56 |
if (name.toLowerCase().endsWith(".ods")) {
|
|
|
57 |
final File file = new File(t.getParent(), name.substring(0, name.length() - 4) + ".xml");
|
|
|
58 |
try {
|
|
|
59 |
return new FileInputStream(file);
|
|
|
60 |
} catch (FileNotFoundException e) {
|
|
|
61 |
System.err.println("No template configuration " + file.getAbsolutePath() + " for template id: " + templateId);
|
|
|
62 |
e.printStackTrace();
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
return null;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
public abstract File getTemplateFile(String templateId, String langage, String type);
|
|
|
69 |
|
|
|
70 |
@Override
|
|
|
71 |
public abstract String getTemplatePath(String templateId, String langage, String type);
|
|
|
72 |
|
|
|
73 |
}
|