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.InternalModuleServiceCall; |
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.8% |
Uncovered Elements: 14 (115) |
Complexity: 31 |
Complexity Density: 0.38 |
|
42 |
|
public class GenerateUtf8Test extends QedeqBoTestCase { |
43 |
|
|
44 |
|
|
45 |
|
private static final Class CLASS = GenerateUtf8Test.class; |
46 |
|
private InternalModuleServiceCall call; |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
48 |
10
|
protected void tearDown() throws Exception {... |
49 |
10
|
endServiceCall(call); |
50 |
10
|
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", 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", 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", 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", 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", 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", 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", 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", 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", true); |
100 |
|
} catch (SourceFileExceptionList e) { |
101 |
|
|
102 |
1
|
assertEquals(8, e.size()); |
103 |
|
} |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
106 |
1
|
public void testGeneration7() throws Exception {... |
107 |
1
|
generate(getIndir(), "proof/proof_003.xml", true); |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@param |
116 |
|
@param |
117 |
|
@param |
118 |
|
@throws |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 5 |
Complexity Density: 0.45 |
|
120 |
10
|
public void generate(final File dir, final String xml, final boolean onlyEn) throws Exception {... |
121 |
10
|
final File destinationDirectory = new File(getGenDir(), "doc"); |
122 |
10
|
final SourceFileExceptionList sfe = new SourceFileExceptionList(); |
123 |
10
|
try { |
124 |
10
|
generate(dir, xml, "en", destinationDirectory); |
125 |
|
} catch (SourceFileExceptionList e) { |
126 |
4
|
sfe.add(e); |
127 |
|
} |
128 |
10
|
if (!onlyEn) { |
129 |
8
|
try { |
130 |
8
|
generate(dir, xml, "de", destinationDirectory); |
131 |
|
} catch (SourceFileExceptionList e) { |
132 |
3
|
sfe.add(e); |
133 |
|
} |
134 |
|
} |
135 |
10
|
if (sfe.size() > 0) { |
136 |
4
|
throw sfe; |
137 |
|
} |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
@param |
144 |
|
@param |
145 |
|
@param |
146 |
|
@param |
147 |
|
|
|
|
| 76.2% |
Uncovered Elements: 10 (42) |
Complexity: 8 |
Complexity Density: 0.29 |
|
148 |
18
|
public void generate(final File dir, final String xml, final String language,... |
149 |
|
final File destinationDirectory) throws IOException, SourceFileExceptionList, InterruptException { |
150 |
18
|
final File xmlFile = new File(dir, xml); |
151 |
18
|
final ModuleAddress address = getServices().getModuleAddress( |
152 |
|
UrlUtility.toUrl(xmlFile)); |
153 |
18
|
final KernelQedeqBo prop = (KernelQedeqBo) getServices().loadModule( |
154 |
|
address); |
155 |
18
|
if (prop.hasErrors()) { |
156 |
0
|
throw prop.getErrors(); |
157 |
|
} |
158 |
18
|
getServices().loadRequiredModules(prop.getModuleAddress()); |
159 |
18
|
if (prop.hasErrors()) { |
160 |
0
|
throw prop.getErrors(); |
161 |
|
} |
162 |
18
|
getServices().checkWellFormedness(prop.getModuleAddress()); |
163 |
18
|
if (prop.hasErrors()) { |
164 |
0
|
throw prop.getErrors(); |
165 |
|
} |
166 |
18
|
if (prop.hasErrors()) { |
167 |
0
|
throw prop.getErrors(); |
168 |
|
} |
169 |
|
|
170 |
18
|
final String web = "http://www.qedeq.org/" |
171 |
18
|
+ getInternalServices().getKernelVersionDirectory() + (!xml.startsWith("sample") ? "/doc/" : "/") + xml; |
172 |
18
|
final ModuleAddress webAddress = new DefaultModuleAddress(web); |
173 |
18
|
getInternalServices().getLocalFilePath(webAddress); |
174 |
18
|
IoUtility.copyFile(xmlFile, getInternalServices().getLocalFilePath(webAddress)); |
175 |
|
|
176 |
18
|
getServices().checkWellFormedness(webAddress); |
177 |
18
|
final QedeqBo webBo = getServices().getQedeqBo(webAddress); |
178 |
18
|
final File utfFile = new File(destinationDirectory, xml.substring(0, xml.lastIndexOf('.')) |
179 |
|
+ "_" + language + ".txt"); |
180 |
18
|
System.out.println(utfFile); |
181 |
18
|
generate((KernelQedeqBo) webBo, utfFile, language, "1"); |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
18
|
final File xmlCopy = new File(destinationDirectory, xml); |
186 |
18
|
IoUtility.copyFile(xmlFile, xmlCopy); |
187 |
18
|
if (webBo.hasErrors()) { |
188 |
0
|
throw webBo.getErrors(); |
189 |
|
} |
190 |
18
|
if (webBo.hasWarnings()) { |
191 |
7
|
throw webBo.getWarnings(); |
192 |
|
} |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
@param |
199 |
|
@param |
200 |
|
@param |
201 |
|
@param |
202 |
|
@return |
203 |
|
@throws |
204 |
|
|
|
|
| 83.3% |
Uncovered Elements: 4 (24) |
Complexity: 3 |
Complexity Density: 0.14 |
|
205 |
18
|
public String generate(final KernelQedeqBo prop, final File to, final String language,... |
206 |
|
final String level) throws SourceFileExceptionList, InterruptException { |
207 |
18
|
final String method = "generate(String, String, String, String)"; |
208 |
18
|
try { |
209 |
18
|
Trace.begin(CLASS, method); |
210 |
18
|
Trace.param(CLASS, method, "prop", prop); |
211 |
18
|
Trace.param(CLASS, method, "to", to); |
212 |
18
|
Trace.param(CLASS, method, "language", language); |
213 |
18
|
Trace.param(CLASS, method, "level", level); |
214 |
18
|
final Map parameters = new HashMap(); |
215 |
18
|
parameters.put("info", "true"); |
216 |
18
|
parameters.put("brief", "false"); |
217 |
18
|
parameters.put("maximumColumn", "80"); |
218 |
18
|
call = createServiceCall("generate UTF-8", prop); |
219 |
18
|
final String source =(new Qedeq2Utf8Executor(new Qedeq2Utf8Plugin(), prop, new Parameters(parameters))) |
220 |
|
.generateUtf8(call.getInternalServiceProcess(), language, "1"); |
221 |
18
|
if (to != null) { |
222 |
18
|
IoUtility.createNecessaryDirectories(to); |
223 |
18
|
IoUtility.copyFile(new File(source), to); |
224 |
18
|
return to.getCanonicalPath(); |
225 |
|
} |
226 |
0
|
return prop.getName(); |
227 |
|
} catch (IOException e) { |
228 |
0
|
Trace.trace(CLASS, method, e); |
229 |
0
|
throw new RuntimeException(e); |
230 |
|
} finally { |
231 |
18
|
endServiceCall(call); |
232 |
18
|
Trace.end(CLASS, method); |
233 |
|
} |
234 |
|
} |
235 |
|
|
236 |
|
} |