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