|
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.module.ModuleDataException; |
|
26 |
| import org.qedeq.kernel.bo.module.ModuleProperties; |
|
27 |
| import org.qedeq.kernel.bo.module.QedeqBo; |
|
28 |
| import org.qedeq.kernel.common.SourceFileExceptionList; |
|
29 |
| import org.qedeq.kernel.context.KernelContext; |
|
30 |
| import org.qedeq.kernel.trace.Trace; |
|
31 |
| import org.qedeq.kernel.utility.IoUtility; |
|
32 |
| import org.qedeq.kernel.utility.TextOutput; |
|
33 |
| import org.qedeq.kernel.xml.mapper.ModuleDataException2XmlFileException; |
|
34 |
| import org.qedeq.kernel.xml.parser.DefaultSourceFileExceptionList; |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| public final class Xml2Latex { |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
0
| private Xml2Latex() {
|
|
49 |
| |
|
50 |
| } |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
21
| public static String generate(final ModuleProperties prop, final File to, final String language,
|
|
63 |
| final String level) throws SourceFileExceptionList { |
|
64 |
21
| final String method = "generate(String, String, String, String)";
|
|
65 |
21
| File destination = null;
|
|
66 |
21
| QedeqBo qedeqBo = null;
|
|
67 |
21
| try {
|
|
68 |
21
| Trace.begin(Xml2Latex.class, method);
|
|
69 |
21
| Trace.param(Xml2Latex.class, method, "prop", prop);
|
|
70 |
21
| Trace.param(Xml2Latex.class, method, "to", to);
|
|
71 |
21
| Trace.param(Xml2Latex.class, method, "language", language);
|
|
72 |
21
| Trace.param(Xml2Latex.class, method, "level", level);
|
|
73 |
21
| if (to == null) {
|
|
74 |
9
| String tex = prop.getModuleAddress().localizeInFileSystem(prop.getModuleAddress()
|
|
75 |
| .getURL()); |
|
76 |
9
| if (tex.toLowerCase().endsWith(".xml")) {
|
|
77 |
9
| tex = tex.substring(0, tex.length() - 4);
|
|
78 |
| } |
|
79 |
9
| if (language != null && language.length() > 0) {
|
|
80 |
6
| tex = tex + "_" + language;
|
|
81 |
| } |
|
82 |
| |
|
83 |
| |
|
84 |
9
| destination = new File(KernelContext.getInstance().getConfig()
|
|
85 |
| .getGenerationDirectory(), tex + ".tex").getCanonicalFile(); |
|
86 |
| } else { |
|
87 |
12
| destination = to;
|
|
88 |
| } |
|
89 |
| } catch (IOException e) { |
|
90 |
0
| Trace.trace(Xml2Latex.class, method, e);
|
|
91 |
0
| throw new DefaultSourceFileExceptionList(e);
|
|
92 |
| } |
|
93 |
21
| TextOutput printer = null;
|
|
94 |
21
| try {
|
|
95 |
21
| qedeqBo = prop.getModule();
|
|
96 |
21
| IoUtility.createNecessaryDirectories(destination);
|
|
97 |
21
| final OutputStream outputStream = new FileOutputStream(destination);
|
|
98 |
21
| printer = new TextOutput(destination.getName(), outputStream);
|
|
99 |
| |
|
100 |
| |
|
101 |
21
| Qedeq2Latex.print(prop.getUrl(), qedeqBo, printer,
|
|
102 |
| language, level); |
|
103 |
21
| return destination.getCanonicalPath();
|
|
104 |
| } catch (IOException e) { |
|
105 |
0
| Trace.trace(Xml2Latex.class, method, e);
|
|
106 |
0
| throw new DefaultSourceFileExceptionList(e);
|
|
107 |
| } catch (RuntimeException e) { |
|
108 |
0
| Trace.trace(Xml2Latex.class, method, e);
|
|
109 |
0
| throw new DefaultSourceFileExceptionList(e);
|
|
110 |
| } catch (ModuleDataException e) { |
|
111 |
0
| Trace.trace(Xml2Latex.class, method, e);
|
|
112 |
0
| Trace.param(Xml2Latex.class, method, "context", e.getContext());
|
|
113 |
0
| throw ModuleDataException2XmlFileException.createXmlFileExceptionList(e,
|
|
114 |
| qedeqBo.getQedeq()); |
|
115 |
| } finally { |
|
116 |
21
| if (printer != null) {
|
|
117 |
21
| printer.close();
|
|
118 |
| } |
|
119 |
21
| Trace.end(Xml2Latex.class, method);
|
|
120 |
| } |
|
121 |
| } |
|
122 |
| |
|
123 |
| } |