|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.xml.mapper; |
|
19 |
| |
|
20 |
| import java.util.ArrayList; |
|
21 |
| import java.util.HashMap; |
|
22 |
| import java.util.List; |
|
23 |
| import java.util.Map; |
|
24 |
| |
|
25 |
| import org.qedeq.kernel.base.list.ElementList; |
|
26 |
| import org.qedeq.kernel.base.module.Author; |
|
27 |
| import org.qedeq.kernel.base.module.AuthorList; |
|
28 |
| import org.qedeq.kernel.base.module.Axiom; |
|
29 |
| import org.qedeq.kernel.base.module.Chapter; |
|
30 |
| import org.qedeq.kernel.base.module.ChapterList; |
|
31 |
| import org.qedeq.kernel.base.module.Formula; |
|
32 |
| import org.qedeq.kernel.base.module.FunctionDefinition; |
|
33 |
| import org.qedeq.kernel.base.module.Header; |
|
34 |
| import org.qedeq.kernel.base.module.Import; |
|
35 |
| import org.qedeq.kernel.base.module.ImportList; |
|
36 |
| import org.qedeq.kernel.base.module.Latex; |
|
37 |
| import org.qedeq.kernel.base.module.LatexList; |
|
38 |
| import org.qedeq.kernel.base.module.LinkList; |
|
39 |
| import org.qedeq.kernel.base.module.LiteratureItem; |
|
40 |
| import org.qedeq.kernel.base.module.LiteratureItemList; |
|
41 |
| import org.qedeq.kernel.base.module.Location; |
|
42 |
| import org.qedeq.kernel.base.module.LocationList; |
|
43 |
| import org.qedeq.kernel.base.module.Node; |
|
44 |
| import org.qedeq.kernel.base.module.PredicateDefinition; |
|
45 |
| import org.qedeq.kernel.base.module.Proof; |
|
46 |
| import org.qedeq.kernel.base.module.ProofList; |
|
47 |
| import org.qedeq.kernel.base.module.Proposition; |
|
48 |
| import org.qedeq.kernel.base.module.Qedeq; |
|
49 |
| import org.qedeq.kernel.base.module.Rule; |
|
50 |
| import org.qedeq.kernel.base.module.Section; |
|
51 |
| import org.qedeq.kernel.base.module.SectionList; |
|
52 |
| import org.qedeq.kernel.base.module.Specification; |
|
53 |
| import org.qedeq.kernel.base.module.Subsection; |
|
54 |
| import org.qedeq.kernel.base.module.SubsectionList; |
|
55 |
| import org.qedeq.kernel.base.module.Term; |
|
56 |
| import org.qedeq.kernel.base.module.UsedByList; |
|
57 |
| import org.qedeq.kernel.base.module.VariableList; |
|
58 |
| import org.qedeq.kernel.bo.module.ModuleDataException; |
|
59 |
| import org.qedeq.kernel.bo.visitor.AbstractModuleVisitor; |
|
60 |
| import org.qedeq.kernel.bo.visitor.QedeqNotNullTransverser; |
|
61 |
| import org.qedeq.kernel.context.ModuleContext; |
|
62 |
| import org.qedeq.kernel.dto.list.Enumerator; |
|
63 |
| import org.qedeq.kernel.log.Trace; |
|
64 |
| import org.qedeq.kernel.xml.tracker.SimpleXPath; |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| public final class Context2SimpleXPath extends AbstractModuleVisitor { |
|
88 |
| |
|
89 |
| |
|
90 |
| private QedeqNotNullTransverser transverser; |
|
91 |
| |
|
92 |
| |
|
93 |
| private Qedeq qedeq; |
|
94 |
| |
|
95 |
| |
|
96 |
| private final ModuleContext find; |
|
97 |
| |
|
98 |
| |
|
99 |
| private SimpleXPath current; |
|
100 |
| |
|
101 |
| |
|
102 |
| private final List elements; |
|
103 |
| |
|
104 |
| |
|
105 |
| private int level; |
|
106 |
| |
|
107 |
| |
|
108 |
| private boolean matching; |
|
109 |
| |
|
110 |
| |
|
111 |
| private String matchingBegin; |
|
112 |
| |
|
113 |
| |
|
114 |
| private SimpleXPath matchingPath; |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
26546
| private Context2SimpleXPath(final ModuleContext find, final Qedeq qedeq) {
|
|
123 |
26546
| this.qedeq = qedeq;
|
|
124 |
26546
| transverser = new QedeqNotNullTransverser(find.getModuleLocation(), this);
|
|
125 |
26546
| this.find = find;
|
|
126 |
26546
| elements = new ArrayList(20);
|
|
127 |
| } |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
26546
| public static SimpleXPath getXPath(final ModuleContext find, final Qedeq qedeq)
|
|
155 |
| throws ModuleDataException { |
|
156 |
26546
| final Context2SimpleXPath converter = new Context2SimpleXPath(find, qedeq);
|
|
157 |
26546
| return converter.find();
|
|
158 |
| } |
|
159 |
| |
|
160 |
26546
| private final SimpleXPath find() throws ModuleDataException {
|
|
161 |
26546
| final String method = "find()";
|
|
162 |
26546
| Trace.paramInfo(this, method, "find", find);
|
|
163 |
26546
| elements.clear();
|
|
164 |
26546
| level = 0;
|
|
165 |
26546
| current = new SimpleXPath();
|
|
166 |
26546
| try {
|
|
167 |
26546
| transverser.accept(qedeq);
|
|
168 |
| } catch (LocationFoundException e) { |
|
169 |
26546
| Trace.paramInfo(this, method, "location found", current);
|
|
170 |
26546
| return current;
|
|
171 |
| } |
|
172 |
0
| Trace.param(this, method, "level", level);
|
|
173 |
0
| Trace.info(this, method, "location was not found");
|
|
174 |
0
| throw new LocationNotFoundException(find);
|
|
175 |
| } |
|
176 |
| |
|
177 |
26546
| public final void visitEnter(final Qedeq qedeq) throws ModuleDataException {
|
|
178 |
26546
| enter("QEDEQ");
|
|
179 |
26546
| final String method = "visitEnter(Qedeq)";
|
|
180 |
26546
| Trace.param(this, method, "current", current);
|
|
181 |
26546
| checkMatching(method);
|
|
182 |
| } |
|
183 |
| |
|
184 |
0
| public final void visitLeave(final Qedeq qedeq) {
|
|
185 |
0
| leave();
|
|
186 |
| } |
|
187 |
| |
|
188 |
26544
| public final void visitEnter(final Header header) throws ModuleDataException {
|
|
189 |
26544
| enter("HEADER");
|
|
190 |
26544
| final String method = "visitEnter(Header)";
|
|
191 |
26544
| Trace.param(this, method, "current", current);
|
|
192 |
26544
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
193 |
26544
| checkMatching(method);
|
|
194 |
| |
|
195 |
26531
| transverser.setLocationWithinModule(context + ".getEmail()");
|
|
196 |
26531
| current.setAttribute("email");
|
|
197 |
26531
| checkIfFound();
|
|
198 |
| } |
|
199 |
| |
|
200 |
26080
| public final void visitLeave(final Header header) {
|
|
201 |
26080
| leave();
|
|
202 |
| } |
|
203 |
| |
|
204 |
563
| public final void visitEnter(final Specification specification) throws ModuleDataException {
|
|
205 |
563
| enter("SPECIFICATION");
|
|
206 |
563
| final String method = "visitEnter(Specification)";
|
|
207 |
563
| Trace.param(this, method, "current", current);
|
|
208 |
563
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
209 |
563
| checkMatching(method);
|
|
210 |
| |
|
211 |
511
| transverser.setLocationWithinModule(context + ".getName()");
|
|
212 |
511
| current.setAttribute("name");
|
|
213 |
511
| checkIfFound();
|
|
214 |
| |
|
215 |
487
| transverser.setLocationWithinModule(context + ".getRuleVersion()");
|
|
216 |
487
| current.setAttribute("ruleVersion");
|
|
217 |
487
| checkIfFound();
|
|
218 |
| } |
|
219 |
| |
|
220 |
335
| public final void visitLeave(final Specification specification) {
|
|
221 |
335
| leave();
|
|
222 |
| } |
|
223 |
| |
|
224 |
138062
| public final void visitEnter(final LatexList latexList) throws ModuleDataException {
|
|
225 |
138062
| final String method = "visitEnter(LatexList)";
|
|
226 |
138062
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
227 |
138062
| final String name;
|
|
228 |
138062
| if (context.endsWith(".getTitle()")) {
|
|
229 |
58305
| name = "TITLE";
|
|
230 |
79757
| } else if (context.endsWith(".getSummary()")) {
|
|
231 |
289
| name = "ABSTRACT";
|
|
232 |
79468
| } else if (context.endsWith(".getIntroduction()")) {
|
|
233 |
50106
| name = "INTRODUCTION";
|
|
234 |
29362
| } else if (context.endsWith(".getName()")) {
|
|
235 |
7582
| name = "NAME";
|
|
236 |
21780
| } else if (context.endsWith(".getPrecedingText()")) {
|
|
237 |
21072
| name = "PRECEDING";
|
|
238 |
708
| } else if (context.endsWith(".getSucceedingText()")) {
|
|
239 |
276
| name = "SUCCEEDING";
|
|
240 |
432
| } else if (context.endsWith(".getLatex()")) {
|
|
241 |
156
| name = "TEXT";
|
|
242 |
276
| } else if (context.endsWith(".getDescription()")) {
|
|
243 |
114
| name = "DESCRIPTION";
|
|
244 |
162
| } else if (context.endsWith(".getNonFormalProof()")) {
|
|
245 |
64
| name = null;
|
|
246 |
98
| } else if (context.endsWith(".getItem()")) {
|
|
247 |
98
| name = null;
|
|
248 |
| } else { |
|
249 |
0
| throw new IllegalArgumentException("unknown LatexList " + context);
|
|
250 |
| } |
|
251 |
138062
| Trace.param(this, method, "name", name);
|
|
252 |
138062
| if (name != null) {
|
|
253 |
137900
| enter(name);
|
|
254 |
| } |
|
255 |
138062
| Trace.param(this, method, "current", current);
|
|
256 |
| |
|
257 |
138062
| checkMatching(method);
|
|
258 |
| } |
|
259 |
| |
|
260 |
133190
| public final void visitLeave(final LatexList latexList) {
|
|
261 |
133190
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
262 |
133190
| if (!context.endsWith(".getNonFormalProof()")
|
|
263 |
| && !context.endsWith(".getItem()")) { |
|
264 |
133190
| leave();
|
|
265 |
| } |
|
266 |
| } |
|
267 |
| |
|
268 |
3757
| public final void visitEnter(final Latex latex) throws ModuleDataException {
|
|
269 |
3757
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
270 |
3757
| if (context.indexOf(".getAuthorList().get(") >= 0) {
|
|
271 |
13
| enter("NAME");
|
|
272 |
| } |
|
273 |
3757
| enter("LATEX");
|
|
274 |
3757
| final String method = "visitEnter(Latex)";
|
|
275 |
3757
| Trace.param(this, method, "current", current);
|
|
276 |
3757
| checkMatching(method);
|
|
277 |
| |
|
278 |
1176
| transverser.setLocationWithinModule(context + ".getLanguage()");
|
|
279 |
1176
| current.setAttribute("language");
|
|
280 |
1176
| checkIfFound();
|
|
281 |
| |
|
282 |
1176
| transverser.setLocationWithinModule(context + ".getLatex()");
|
|
283 |
1176
| current.setAttribute(null);
|
|
284 |
1176
| checkIfFound();
|
|
285 |
| } |
|
286 |
| |
|
287 |
1176
| public final void visitLeave(final Latex latex) {
|
|
288 |
| |
|
289 |
1176
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
290 |
1176
| if (context.indexOf(".getAuthorList().get(") >= 0) {
|
|
291 |
0
| leave();
|
|
292 |
| } |
|
293 |
1176
| leave();
|
|
294 |
| } |
|
295 |
| |
|
296 |
128
| public final void visitEnter(final LocationList locationList) throws ModuleDataException {
|
|
297 |
128
| enter("LOCATIONS");
|
|
298 |
128
| final String method = "visitEnter(LocationList)";
|
|
299 |
128
| Trace.param(this, method, "current", current);
|
|
300 |
128
| checkMatching(method);
|
|
301 |
| |
|
302 |
| } |
|
303 |
| |
|
304 |
0
| public final void visitLeave(final LocationList locationList) {
|
|
305 |
0
| leave();
|
|
306 |
| } |
|
307 |
| |
|
308 |
76
| public final void visitEnter(final Location location) throws ModuleDataException {
|
|
309 |
76
| enter("LOCATION");
|
|
310 |
76
| final String method = "visitEnter(Location)";
|
|
311 |
76
| Trace.param(this, method, "current", current);
|
|
312 |
76
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
313 |
76
| checkMatching(method);
|
|
314 |
| |
|
315 |
24
| transverser.setLocationWithinModule(context + ".getLocation()");
|
|
316 |
24
| current.setAttribute("value");
|
|
317 |
24
| checkIfFound();
|
|
318 |
| } |
|
319 |
| |
|
320 |
0
| public final void visitLeave(final Location location) {
|
|
321 |
0
| leave();
|
|
322 |
| } |
|
323 |
| |
|
324 |
243
| public final void visitEnter(final AuthorList authorList) throws ModuleDataException {
|
|
325 |
243
| enter("AUTHORS");
|
|
326 |
243
| final String method = "visitEnter(AuthorList)";
|
|
327 |
243
| Trace.param(this, method, "current", current);
|
|
328 |
243
| checkMatching(method);
|
|
329 |
| } |
|
330 |
| |
|
331 |
171
| public final void visitLeave(final AuthorList authorList) {
|
|
332 |
171
| leave();
|
|
333 |
| } |
|
334 |
| |
|
335 |
48
| public final void visitEnter(final Author author) throws ModuleDataException {
|
|
336 |
48
| enter("AUTHOR");
|
|
337 |
48
| final String method = "visitEnter(Author)";
|
|
338 |
48
| Trace.param(this, method, "current", current);
|
|
339 |
48
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
340 |
48
| checkMatching(method);
|
|
341 |
| |
|
342 |
24
| transverser.setLocationWithinModule(context + ".getEmail()");
|
|
343 |
24
| current.setAttribute("email");
|
|
344 |
24
| checkIfFound();
|
|
345 |
| } |
|
346 |
| |
|
347 |
0
| public final void visitLeave(final Author author) {
|
|
348 |
0
| leave();
|
|
349 |
| } |
|
350 |
| |
|
351 |
149
| public final void visitEnter(final ImportList importList) throws ModuleDataException {
|
|
352 |
149
| enter("IMPORTS");
|
|
353 |
149
| final String method = "visitEnter(ImportList)";
|
|
354 |
149
| Trace.param(this, method, "current", current);
|
|
355 |
149
| checkMatching(method);
|
|
356 |
| } |
|
357 |
| |
|
358 |
33
| public final void visitLeave(final ImportList importList) {
|
|
359 |
33
| leave();
|
|
360 |
| } |
|
361 |
| |
|
362 |
140
| public final void visitEnter(final Import imp) throws ModuleDataException {
|
|
363 |
140
| enter("IMPORT");
|
|
364 |
140
| final String method = "visitEnter(Import)";
|
|
365 |
140
| Trace.param(this, method, "current", current);
|
|
366 |
140
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
367 |
140
| checkMatching(method);
|
|
368 |
| |
|
369 |
122
| transverser.setLocationWithinModule(context + ".getLabel()");
|
|
370 |
122
| current.setAttribute("label");
|
|
371 |
122
| checkIfFound();
|
|
372 |
| } |
|
373 |
| |
|
374 |
36
| public final void visitLeave(final Import imp) {
|
|
375 |
36
| leave();
|
|
376 |
| } |
|
377 |
| |
|
378 |
55
| public final void visitEnter(final UsedByList usedByList) throws ModuleDataException {
|
|
379 |
55
| enter("USEDBY");
|
|
380 |
55
| final String method = "visitEnter(UsedByList)";
|
|
381 |
55
| Trace.param(this, method, "current", current);
|
|
382 |
55
| checkMatching(method);
|
|
383 |
| } |
|
384 |
| |
|
385 |
0
| public final void visitLeave(final UsedByList usedByList) {
|
|
386 |
0
| leave();
|
|
387 |
| } |
|
388 |
| |
|
389 |
26080
| public final void visitEnter(final ChapterList chapterList) throws ModuleDataException {
|
|
390 |
26080
| final String method = "visitEnter(ChapterList)";
|
|
391 |
| |
|
392 |
| |
|
393 |
26080
| checkMatching(method);
|
|
394 |
| } |
|
395 |
| |
|
396 |
170
| public final void visitLeave(final ChapterList chapterList) {
|
|
397 |
170
| transverser.setBlocked(false);
|
|
398 |
| } |
|
399 |
| |
|
400 |
105308
| public final void visitEnter(final Chapter chapter) throws ModuleDataException {
|
|
401 |
105308
| enter("CHAPTER");
|
|
402 |
105308
| final String method = "visitEnter(Chapter)";
|
|
403 |
105308
| Trace.param(this, method, "current", current);
|
|
404 |
105308
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
405 |
105308
| checkMatching(method);
|
|
406 |
| |
|
407 |
105191
| transverser.setLocationWithinModule(context + ".getNoNumber()");
|
|
408 |
105191
| current.setAttribute("noNumber");
|
|
409 |
105191
| checkIfFound();
|
|
410 |
| } |
|
411 |
| |
|
412 |
79410
| public final void visitLeave(final Chapter chapter) {
|
|
413 |
79410
| leave();
|
|
414 |
| } |
|
415 |
| |
|
416 |
25306
| public final void visitEnter(final SectionList sectionList) throws ModuleDataException {
|
|
417 |
25306
| final String method = "visitEnter(SectionList)";
|
|
418 |
| |
|
419 |
| |
|
420 |
25306
| checkMatching(method);
|
|
421 |
| } |
|
422 |
| |
|
423 |
0
| public final void visitLeave(final SectionList sectionList) {
|
|
424 |
0
| transverser.setBlocked(false);
|
|
425 |
| } |
|
426 |
| |
|
427 |
66845
| public final void visitEnter(final Section section) throws ModuleDataException {
|
|
428 |
66845
| enter("SECTION");
|
|
429 |
66845
| final String method = "visitEnter(Section)";
|
|
430 |
66845
| Trace.param(this, method, "current", current);
|
|
431 |
66845
| final String context = transverser.getCurrentContext().getLocationWithinModule();
|
|
432 |
66845
| checkMatching(method);
|
|
433 |
| |
|
434 |
66632
| transverser.setLocationWithinModule(context + ".getNoNumber()");
|
|
435 |
66632
| current.setAttribute("noNumber");
|
|
436 |
66632
| checkIfFound();
|
|
437 |
| } |
|
438 |
| |
|
439 |
|