1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.bo.service.unicode; |
17 |
|
|
18 |
|
import java.io.File; |
19 |
|
import java.io.IOException; |
20 |
|
import java.util.HashMap; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
import org.qedeq.base.io.IoUtility; |
24 |
|
import org.qedeq.base.io.Parameters; |
25 |
|
import org.qedeq.base.io.UrlUtility; |
26 |
|
import org.qedeq.base.trace.Trace; |
27 |
|
import org.qedeq.kernel.bo.common.QedeqBo; |
28 |
|
import org.qedeq.kernel.bo.module.InternalServiceCall; |
29 |
|
import org.qedeq.kernel.bo.module.KernelQedeqBo; |
30 |
|
import org.qedeq.kernel.bo.test.QedeqBoTestCase; |
31 |
|
import org.qedeq.kernel.se.common.DefaultModuleAddress; |
32 |
|
import org.qedeq.kernel.se.common.ModuleAddress; |
33 |
|
import org.qedeq.kernel.se.common.SourceFileExceptionList; |
34 |
|
import org.qedeq.kernel.se.visitor.InterruptException; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@author |
41 |
|
|
|
|
| 87.7% |
Uncovered Elements: 14 (114) |
Complexity: 30 |
Complexity Density: 0.37 |
|
42 |
|
public class GenerateUtf8Test extends QedeqBoTestCase { |
43 |
|
|
44 |
|
|
45 |
|
private static final Class CLASS = GenerateUtf8Test.class; |
46 |
|
private InternalServiceCall call; |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
48 |
9
|
protected void tearDown() throws Exception {... |
49 |
9
|
endServiceCall(call); |
50 |
9
|
super.tearDown(); |
51 |
|
} |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
53 |
1
|
public void testGeneration1() throws Exception {... |
54 |
1
|
try { |
55 |
1
|
generate(getDocDir(), "math/qedeq_logic_v1.xml", getGenDir(), false); |
56 |
|
} catch (SourceFileExceptionList e) { |
57 |
1
|
assertEquals(4, e.size()); |
58 |
|
} |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
61 |
1
|
public void testGeneration1b() throws Exception {... |
62 |
1
|
generate(getDocDir(), "math/qedeq_formal_logic_v1.xml", getGenDir(), false); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
65 |
1
|
public void testGeneration2() throws Exception {... |
66 |
1
|
try { |
67 |
1
|
generate(getDocDir(), "sample/qedeq_sample1.xml", getGenDir(), false); |
68 |
|
} catch (SourceFileExceptionList e) { |
69 |
1
|
assertEquals(4, e.size()); |
70 |
|
} |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
73 |
1
|
public void testGeneration3() throws Exception {... |
74 |
1
|
generate(getDocDir(), "sample/qedeq_sample2.xml", getGenDir(), false); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
77 |
1
|
public void testGeneration3b() throws Exception {... |
78 |
1
|
generate(getDocDir(), "sample/qedeq_sample3.xml", getGenDir(), false); |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
81 |
1
|
public void testGeneration3c() throws Exception {... |
82 |
1
|
generate(getDocDir(), "sample/qedeq_sample4.xml", getGenDir(), false); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
85 |
1
|
public void testGeneration4() throws Exception {... |
86 |
1
|
generate(getDocDir(), "math/qedeq_set_theory_v1.xml", getGenDir(), false); |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
89 |
1
|
public void testGeneration5() throws Exception {... |
90 |
1
|
try { |
91 |
1
|
generate(getDocDir(), "project/qedeq_basic_concept.xml", getGenDir(), false); |
92 |
|
} catch (SourceFileExceptionList e) { |
93 |
1
|
assertEquals(14, e.size()); |
94 |
|
} |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
1
PASS
|
|
97 |
1
|
public void testGeneration6() throws Exception {... |
98 |
1
|
try { |
99 |
1
|
generate(getDocDir(), "project/qedeq_logic_language.xml", getGenDir(), true); |
100 |
|
} catch (SourceFileExceptionList e) { |
101 |
|
|
102 |
1
|
assertEquals(8, e.size()); |
103 |
|
} |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
@param |
111 |
|
@param |
112 |
|
@param |
113 |
|
@param |
114 |
|
@throws |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
116 |
9
|
public void generate(final File dir, final String xml, final File destinationDirectory,... |
117 |
|
final boolean onlyEn) throws Exception { |
118 |
9
|
final SourceFileExceptionList sfe = new SourceFileExceptionList(); |
119 |
9
|
try { |
120 |
9
|
generate(dir, xml, "en", destinationDirectory); |
121 |
|
} catch (SourceFileExceptionList e) { |
122 |
4
|
sfe.add(e); |
123 |
|
} |
124 |
9
|
if (!onlyEn) { |
125 |
8
|
try { |
126 |
8
|
generate(dir, xml, "de", destinationDirectory); |
127 |
|
} catch (SourceFileExceptionList e) { |
128 |
3
|
sfe.add(e); |
129 |
|
} |
130 |
|
} |
131 |
9
|
if (sfe.size() > 0) { |
132 |
4
|
throw sfe; |
133 |
|
} |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
@param |
140 |
|
@param |
141 |
|
@param |
142 |
|
@param |
143 |
|
|
|
|
| 77.3% |
Uncovered Elements: 10 (44) |
Complexity: 8 |
Complexity Density: 0.27 |
|
144 |
17
|
public void generate(final File dir, final String xml, final String language,... |
145 |
|
final File destinationDirectory) throws IOException, SourceFileExceptionList, InterruptException { |
146 |
17
|
final File xmlFile = new File(dir, xml); |
147 |
17
|
final ModuleAddress address = getServices().getModuleAddress( |
148 |
|
UrlUtility.toUrl(xmlFile)); |
149 |
17
|
final KernelQedeqBo prop = (KernelQedeqBo) getServices().loadModule( |
150 |
|
address); |
151 |
17
|
if (prop.hasErrors()) { |
152 |
0
|
throw prop.getErrors(); |
153 |
|
} |
154 |
17
|
getServices().loadRequiredModules(prop.getModuleAddress()); |
155 |
17
|
if (prop.hasErrors()) { |
156 |
0
|
throw prop.getErrors(); |
157 |
|
} |
158 |
17
|
getServices().checkWellFormedness(prop.getModuleAddress()); |
159 |
17
|
if (prop.hasErrors()) { |
160 |
0
|
throw prop.getErrors(); |
161 |
|
} |
162 |
17
|
if (prop.hasErrors()) { |
163 |
0
|
throw prop.getErrors(); |
164 |
|
} |
165 |
|
|
166 |
17
|
final String web = "http://www.qedeq.org/" |
167 |
17
|
+ getInternalServices().getKernelVersionDirectory() + (!xml.startsWith("sample") ? "/doc/" : "/") + xml; |
168 |
17
|
final ModuleAddress webAddress = new DefaultModuleAddress(web); |
169 |
17
|
getInternalServices().getLocalFilePath(webAddress); |
170 |
17
|
IoUtility.copyFile(xmlFile, getInternalServices().getLocalFilePath(webAddress)); |
171 |
|
|
172 |
17
|
getServices().checkWellFormedness(webAddress); |
173 |
17
|
final QedeqBo webBo = getServices().getQedeqBo(webAddress); |
174 |
17
|
final File texFile = new File(destinationDirectory, xml.substring(0, xml.lastIndexOf('.')) |
175 |
|
+ "_" + language + ".txt"); |
176 |
17
|
generate((KernelQedeqBo) webBo, texFile, language, "1"); |
177 |
17
|
final File texCopy = new File(dir, new File(new File(xml).getParent(), texFile.getName()) |
178 |
|
.getPath()); |
179 |
17
|
final File xmlCopy = new File(destinationDirectory, xml); |
180 |
17
|
IoUtility.createNecessaryDirectories(xmlCopy); |
181 |
17
|
IoUtility.copyFile(xmlFile, xmlCopy); |
182 |
17
|
IoUtility.copyFile(texFile, texCopy); |
183 |
17
|
if (webBo.hasErrors()) { |
184 |
0
|
throw webBo.getErrors(); |
185 |
|
} |
186 |
17
|
if (webBo.hasWarnings()) { |
187 |
7
|
throw webBo.getWarnings(); |
188 |
|
} |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
@param |
195 |
|
@param |
196 |
|
@param |
197 |
|
@param |
198 |
|
@return |
199 |
|
@throws |
200 |
|
|
|
|
| 83.3% |
Uncovered Elements: 4 (24) |
Complexity: 3 |
Complexity Density: 0.14 |
|
201 |
17
|
public String generate(final KernelQedeqBo prop, final File to, final String language,... |
202 |
|
final String level) throws SourceFileExceptionList, InterruptException { |
203 |
17
|
final String method = "generate(String, String, String, String)"; |
204 |
17
|
try { |
205 |
17
|
Trace.begin(CLASS, method); |
206 |
17
|
Trace.param(CLASS, method, "prop", prop); |
207 |
17
|
Trace.param(CLASS, method, "to", to); |
208 |
17
|
Trace.param(CLASS, method, "language", language); |
209 |
17
|
Trace.param(CLASS, method, "level", level); |
210 |
17
|
final Map parameters = new HashMap(); |
211 |
17
|
parameters.put("info", "true"); |
212 |
17
|
parameters.put("brief", "false"); |
213 |
17
|
parameters.put("maximumColumn", "80"); |
214 |
17
|
call = createServiceCall("generate latex", prop); |
215 |
17
|
final String source =(new Qedeq2Utf8Executor(new Qedeq2Utf8Plugin(), prop, new Parameters(parameters))) |
216 |
|
.generateUtf8(call.getInternalServiceProcess(), language, "1"); |
217 |
17
|
if (to != null) { |
218 |
17
|
IoUtility.createNecessaryDirectories(to); |
219 |
17
|
IoUtility.copyFile(new File(source), to); |
220 |
17
|
return to.getCanonicalPath(); |
221 |
|
} |
222 |
0
|
return prop.getName(); |
223 |
|
} catch (IOException e) { |
224 |
0
|
Trace.trace(CLASS, method, e); |
225 |
0
|
throw new RuntimeException(e); |
226 |
|
} finally { |
227 |
17
|
endServiceCall(call); |
228 |
17
|
Trace.end(CLASS, method); |
229 |
|
} |
230 |
|
} |
231 |
|
|
232 |
|
} |