|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.latex; |
|
19 |
| |
|
20 |
| import java.io.File; |
|
21 |
| import java.io.FileOutputStream; |
|
22 |
| import java.io.IOException; |
|
23 |
| import java.io.OutputStream; |
|
24 |
| |
|
25 |
| import org.qedeq.kernel.bo.control.KernelQedeqBo; |
|
26 |
| import org.qedeq.kernel.common.DefaultSourceFileExceptionList; |
|
27 |
| import org.qedeq.kernel.common.SourceFileExceptionList; |
|
28 |
| import org.qedeq.kernel.context.KernelContext; |
|
29 |
| import org.qedeq.kernel.trace.Trace; |
|
30 |
| import org.qedeq.kernel.utility.IoUtility; |
|
31 |
| import org.qedeq.kernel.utility.TextOutput; |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| public final class Xml2Latex { |
|
41 |
| |
|
42 |
| |
|
43 |
| private static final Class CLASS = Xml2Latex.class; |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
0
| private Xml2Latex() {
|
|
49 |
| |
|
50 |
| } |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
28
| public static String generate(final KernelQedeqBo prop, final File to, final String language,
|
|
63 |
| final String level) throws SourceFileExceptionList { |
|
64 |
28
| final String method = "generate(String, String, String, String)";
|
|
65 |
28
| File destination = null;
|
|
66 |
28
| try {
|
|
67 |
28
| Trace.begin(CLASS, method);
|
|
68 |
28
| Trace.param(CLASS, method, "prop", prop);
|
|
69 |
28
| Trace.param(CLASS, method, "to", to);
|
|
70 |
28
| Trace.param(CLASS, method, "language", language);
|
|
71 |
28
| Trace.param(CLASS, method, "level", level);
|
|
72 |
28
| if (to == null) {
|
|
73 |
19
| String tex = prop.getModuleAddress().getFileName();
|
|
74 |
19
| if (tex.toLowerCase().endsWith(".xml")) {
|
|
75 |
19
| tex = tex.substring(0, tex.length() - 4);
|
|
76 |
| } |
|
77 |
19
| if (language != null && language.length() > 0) {
|
|
78 |
14
| tex = tex + "_" + language;
|
|
79 |
| } |
|
80 |
| |
|
81 |
| |
|
82 |
19
| destination = new File(KernelContext.getInstance().getConfig()
|
|
83 |
| .getGenerationDirectory(), tex + ".tex").getCanonicalFile(); |
|
84 |
| } else { |
|
85 |
9
| destination = to;
|
|
86 |
| } |
|
87 |
| } catch (IOException e) { |
|
88 |
0
| Trace.trace(CLASS, method, e);
|
|
89 |
0
| throw new DefaultSourceFileExceptionList(e);
|
|
90 |
| } |
|
91 |
28
| TextOutput printer = null;
|
|
92 |
28
| try {
|
|
93 |
28
| IoUtility.createNecessaryDirectories(destination);
|
|
94 |
28
| final OutputStream outputStream = new FileOutputStream(destination);
|
|
95 |
28
| printer = new TextOutput(destination.getName(), outputStream);
|
|
96 |
| |
|
97 |
28
| Qedeq2Latex.print(prop, printer, language, level);
|
|
98 |
28
| return destination.getCanonicalPath();
|
|
99 |
| } catch (IOException e) { |
|
100 |
0
| Trace.trace(CLASS, method, e);
|
|
101 |
0
| throw new DefaultSourceFileExceptionList(e);
|
|
102 |
| } catch (RuntimeException e) { |
|
103 |
0
| Trace.trace(CLASS, method, e);
|
|
104 |
0
| throw new DefaultSourceFileExceptionList(e);
|
|
105 |
| } finally { |
|
106 |
28
| if (printer != null) {
|
|
107 |
28
| printer.close();
|
|
108 |
| } |
|
109 |
28
| Trace.end(CLASS, method);
|
|
110 |
| } |
|
111 |
| } |
|
112 |
| |
|
113 |
| } |