|
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.ModuleContext; |
|
59 |
| import org.qedeq.kernel.bo.module.ModuleDataException; |
|
60 |
| import org.qedeq.kernel.bo.visitor.AbstractModuleVisitor; |
|
61 |
| import org.qedeq.kernel.bo.visitor.QedeqNotNullTraverser; |
|
62 |
| import org.qedeq.kernel.dto.list.Enumerator; |
|
63 |
| import org.qedeq.kernel.trace.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 static final Class CLASS = Context2SimpleXPath.class; |
|
91 |
| |
|
92 |
| |
|
93 |
| private QedeqNotNullTraverser traverser; |
|
94 |
| |
|
95 |
| |
|
96 |
| private Qedeq qedeq; |
|
97 |
| |
|
98 |
| |
|
99 |
| private final ModuleContext find; |
|
100 |
| |
|
101 |
| |
|
102 |
| private SimpleXPath current; |
|
103 |
| |
|
104 |
| |
|
105 |
| private final List elements; |
|
106 |
| |
|
107 |
| |
|
108 |
| private int level; |
|
109 |
| |
|
110 |
| |
|
111 |
| private boolean matching; |
|
112 |
| |
|
113 |
| |
|
114 |
| private String matchingBegin; |
|
115 |
| |
|
116 |
| |
|
117 |
| private SimpleXPath matchingPath; |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
32025
| private Context2SimpleXPath(final ModuleContext find, final Qedeq qedeq) {
|
|
126 |
32025
| this.qedeq = qedeq;
|
|
127 |
32025
| traverser = new QedeqNotNullTraverser(find.getModuleLocation(), this);
|
|
128 |
32025
| this.find = find;
|
|
129 |
32025
| elements = new ArrayList(20);
|
|
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 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
32025
| public static SimpleXPath getXPath(final ModuleContext find, final Qedeq qedeq)
|
|
158 |
| throws ModuleDataException { |
|
159 |
32025
| final Context2SimpleXPath converter = new Context2SimpleXPath(find, qedeq);
|
|
160 |
32025
| return converter.find();
|
|
161 |
| } |
|
162 |
| |
|
163 |
32025
| private final SimpleXPath find() throws ModuleDataException {
|
|
164 |
32025
| final String method = "find()";
|
|
165 |
32025
| Trace.paramInfo(CLASS, this, method, "find", find);
|
|
166 |
32025
| elements.clear();
|
|
167 |
32025
| level = 0;
|
|
168 |
32025
| current = new SimpleXPath();
|
|
169 |
32025
| try {
|
|
170 |
32025
| traverser.accept(qedeq);
|
|
171 |
| } catch (LocationFoundException e) { |
|
172 |
32025
| Trace.paramInfo(CLASS, this, method, "location found", current);
|
|
173 |
32025
| return current;
|
|
174 |
| } |
|
175 |
0
| Trace.param(CLASS, this, method, "level", level);
|
|
176 |
0
| Trace.info(CLASS, this, method, "location was not found");
|
|
177 |
0
| throw new LocationNotFoundException(find);
|
|
178 |
| } |
|
179 |
| |
|
180 |
32025
| public final void visitEnter(final Qedeq qedeq) throws ModuleDataException {
|
|
181 |
32025
| enter("QEDEQ");
|
|
182 |
32025
| final String method = "visitEnter(Qedeq)";
|
|
183 |
32025
| Trace.param(CLASS, this, method, "current", current);
|
|
184 |
32025
| checkMatching(method);
|
|
185 |
| } |
|
186 |
| |
|
187 |
0
| public final void visitLeave(final Qedeq qedeq) {
|
|
188 |
0
| leave();
|
|
189 |
| } |
|
190 |
| |
|
191 |
32023
| public final void visitEnter(final Header header) throws ModuleDataException {
|
|
192 |
32023
| enter("HEADER");
|
|
193 |
32023
| final String method = "visitEnter(Header)";
|
|
194 |
32023
| Trace.param(CLASS, this, method, "current", current);
|
|
195 |
32023
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
196 |
32023
| checkMatching(method);
|
|
197 |
| |
|
198 |
32010
| traverser.setLocationWithinModule(context + ".getEmail()");
|
|
199 |
32010
| current.setAttribute("email");
|
|
200 |
32010
| checkIfFound();
|
|
201 |
| } |
|
202 |
| |
|
203 |
31569
| public final void visitLeave(final Header header) {
|
|
204 |
31569
| leave();
|
|
205 |
| } |
|
206 |
| |
|
207 |
549
| public final void visitEnter(final Specification specification) throws ModuleDataException {
|
|
208 |
549
| enter("SPECIFICATION");
|
|
209 |
549
| final String method = "visitEnter(Specification)";
|
|
210 |
549
| Trace.param(CLASS, this, method, "current", current);
|
|
211 |
549
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
212 |
549
| checkMatching(method);
|
|
213 |
| |
|
214 |
501
| traverser.setLocationWithinModule(context + ".getName()");
|
|
215 |
501
| current.setAttribute("name");
|
|
216 |
501
| checkIfFound();
|
|
217 |
| |
|
218 |
479
| traverser.setLocationWithinModule(context + ".getRuleVersion()");
|
|
219 |
479
| current.setAttribute("ruleVersion");
|
|
220 |
479
| checkIfFound();
|
|
221 |
| } |
|
222 |
| |
|
223 |
325
| public final void visitLeave(final Specification specification) {
|
|
224 |
325
| leave();
|
|
225 |
| } |
|
226 |
| |
|
227 |
174060
| public final void visitEnter(final LatexList latexList) throws ModuleDataException {
|
|
228 |
174060
| final String method = "visitEnter(LatexList)";
|
|
229 |
174060
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
230 |
174060
| final String name;
|
|
231 |
174060
| if (context.endsWith(".getTitle()")) {
|
|
232 |
74004
| name = "TITLE";
|
|
233 |
100056
| } else if (context.endsWith(".getSummary()")) {
|
|
234 |
279
| name = "ABSTRACT";
|
|
235 |
99777
| } else if (context.endsWith(".getIntroduction()")) {
|
|
236 |
60954
| name = "INTRODUCTION";
|
|
237 |
38823
| } else if (context.endsWith(".getName()")) {
|
|
238 |
12539
| name = "NAME";
|
|
239 |
26284
| } else if (context.endsWith(".getPrecedingText()")) {
|
|
240 |
25510
| name = "PRECEDING";
|
|
241 |
774
| } else if (context.endsWith(".getSucceedingText()")) {
|
|
242 |
284
| name = "SUCCEEDING";
|
|
243 |
490
| } else if (context.endsWith(".getLatex()")) {
|
|
244 |
166
| name = "TEXT";
|
|
245 |
324
| } else if (context.endsWith(".getDescription()")) {
|
|
246 |
160
| name = "DESCRIPTION";
|
|
247 |
164
| } else if (context.endsWith(".getNonFormalProof()")) {
|
|
248 |
66
| name = null;
|
|
249 |
98
| } else if (context.endsWith(".getItem()")) {
|
|
250 |
98
| name = null;
|
|
251 |
| } else { |
|
252 |
0
| throw new IllegalArgumentException("unknown LatexList " + context);
|
|
253 |
| } |
|
254 |
174060
| Trace.param(CLASS, this, method, "name", name);
|
|
255 |
174060
| if (name != null) {
|
|
256 |
173896
| enter(name);
|
|
257 |
| } |
|
258 |
174060
| Trace.param(CLASS, this, method, "current", current);
|
|
259 |
| |
|
260 |
174060
| checkMatching(method);
|
|
261 |
| } |
|
262 |
| |
|
263 |
168670
| public final void visitLeave(final LatexList latexList) {
|
|
264 |
168670
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
265 |
168670
| if (!context.endsWith(".getNonFormalProof()")
|
|
266 |
| && !context.endsWith(".getItem()")) { |
|
267 |
168670
| leave();
|
|
268 |
| } |
|
269 |
| } |
|
270 |
| |
|
271 |
4133
| public final void visitEnter(final Latex latex) throws ModuleDataException {
|
|
272 |
4133
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
273 |
4133
| if (context.indexOf(".getAuthorList().get(") >= 0) {
|
|
274 |
13
| enter("NAME");
|
|
275 |
| } |
|
276 |
4133
| enter("LATEX");
|
|
277 |
4133
| final String method = "visitEnter(Latex)";
|
|
278 |
4133
| Trace.param(CLASS, this, method, "current", current);
|
|
279 |
4133
| checkMatching(method);
|
|
280 |
| |
|
281 |
1298
| traverser.setLocationWithinModule(context + ".getLanguage()");
|
|
282 |
1298
| current.setAttribute("language");
|
|
283 |
1298
| checkIfFound();
|
|
284 |
| |
|
285 |
1298
| traverser.setLocationWithinModule(context + ".getLatex()");
|
|
286 |
1298
| current.setAttribute(null);
|
|
287 |
1298
| checkIfFound();
|
|
288 |
| } |
|
289 |
| |
|
290 |
1298
| public final void visitLeave(final Latex latex) {
|
|
291 |
| |
|
292 |
1298
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
293 |
1298
| if (context.indexOf(".getAuthorList().get(") >= 0) {
|
|
294 |
0
| leave();
|
|
295 |
| } |
|
296 |
1298
| leave();
|
|
297 |
| } |
|
298 |
| |
|
299 |
132
| public final void visitEnter(final LocationList locationList) throws ModuleDataException {
|
|
300 |
132
| enter("LOCATIONS");
|
|
301 |
132
| final String method = "visitEnter(LocationList)";
|
|
302 |
132
| Trace.param(CLASS, this, method, "current", current);
|
|
303 |
132
| checkMatching(method);
|
|
304 |
| |
|
305 |
| } |
|
306 |
| |
|
307 |
0
| public final void visitLeave(final LocationList locationList) {
|
|
308 |
0
| leave();
|
|
309 |
| } |
|
310 |
| |
|
311 |
98
| public final void visitEnter(final Location location) throws ModuleDataException {
|
|
312 |
98
| enter("LOCATION");
|
|
313 |
98
| final String method = "visitEnter(Location)";
|
|
314 |
98
| Trace.param(CLASS, this, method, "current", current);
|
|
315 |
98
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
316 |
98
| checkMatching(method);
|
|
317 |
| |
|
318 |
40
| traverser.setLocationWithinModule(context + ".getLocation()");
|
|
319 |
40
| current.setAttribute("value");
|
|
320 |
40
| checkIfFound();
|
|
321 |
| } |
|
322 |
| |
|
323 |
14
| public final void visitLeave(final Location location) {
|
|
324 |
14
| leave();
|
|
325 |
| } |
|
326 |
| |
|
327 |
233
| public final void visitEnter(final AuthorList authorList) throws ModuleDataException {
|
|
328 |
233
| enter("AUTHORS");
|
|
329 |
233
| final String method = "visitEnter(AuthorList)";
|
|
330 |
233
| Trace.param(CLASS, this, method, "current", current);
|
|
331 |
233
| checkMatching(method);
|
|
332 |
| } |
|
333 |
| |
|
334 |
161
| public final void visitLeave(final AuthorList authorList) {
|
|
335 |
161
| leave();
|
|
336 |
| } |
|
337 |
| |
|
338 |
48
| public final void visitEnter(final Author author) throws ModuleDataException {
|
|
339 |
48
| enter("AUTHOR");
|
|
340 |
48
| final String method = "visitEnter(Author)";
|
|
341 |
48
| Trace.param(CLASS, this, method, "current", current);
|
|
342 |
48
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
343 |
48
| checkMatching(method);
|
|
344 |
| |
|
345 |
24
| traverser.setLocationWithinModule(context + ".getEmail()");
|
|
346 |
24
| current.setAttribute("email");
|
|
347 |
24
| checkIfFound();
|
|
348 |
| } |
|
349 |
| |
|
350 |
0
| public final void visitLeave(final Author author) {
|
|
351 |
0
| leave();
|
|
352 |
| } |
|
353 |
| |
|
354 |
139
| public final void visitEnter(final ImportList importList) throws ModuleDataException {
|
|
355 |
139
| enter("IMPORTS");
|
|
356 |
139
| final String method = "visitEnter(ImportList)";
|
|
357 |
139
| Trace.param(CLASS, this, method, "current", current);
|
|
358 |
139
| checkMatching(method);
|
|
359 |
| } |
|
360 |
| |
|
361 |
33
| public final void visitLeave(final ImportList importList) {
|
|
362 |
33
| leave();
|
|
363 |
| } |
|
364 |
| |
|
365 |
106
| public final void visitEnter(final Import imp) throws ModuleDataException {
|
|
366 |
106
| enter("IMPORT");
|
|
367 |
106
| final String method = "visitEnter(Import)";
|
|
368 |
106
| Trace.param(CLASS, this, method, "current", current);
|
|
369 |
106
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
370 |
106
| checkMatching(method);
|
|
371 |
| |
|
372 |
92
| traverser.setLocationWithinModule(context + ".getLabel()");
|
|
373 |
92
| current.setAttribute("label");
|
|
374 |
92
| checkIfFound();
|
|
375 |
| } |
|
376 |
| |
|
377 |
12
| public final void visitLeave(final Import imp) {
|
|
378 |
12
| leave();
|
|
379 |
| } |
|
380 |
| |
|
381 |
55
| public final void visitEnter(final UsedByList usedByList) throws ModuleDataException {
|
|
382 |
55
| enter("USEDBY");
|
|
383 |
55
| final String method = "visitEnter(UsedByList)";
|
|
384 |
55
| Trace.param(CLASS, this, method, "current", current);
|
|
385 |
55
| checkMatching(method);
|
|
386 |
| } |
|
387 |
| |
|
388 |
0
| public final void visitLeave(final UsedByList usedByList) {
|
|
389 |
0
| leave();
|
|
390 |
| } |
|
391 |
| |
|
392 |
31569
| public final void visitEnter(final ChapterList chapterList) throws ModuleDataException {
|
|
393 |
31569
| final String method = "visitEnter(ChapterList)";
|
|
394 |
| |
|
395 |
| |
|
396 |
31569
| checkMatching(method);
|
|
397 |
| } |
|
398 |
| |
|
399 |
170
| public final void visitLeave(final ChapterList chapterList) {
|
|
400 |
170
| traverser.setBlocked(false);
|
|
401 |
| } |
|
402 |
| |
|
403 |
139181
| public final void visitEnter(final Chapter chapter) throws ModuleDataException {
|
|
404 |
139181
| enter("CHAPTER");
|
|
405 |
139181
| final String method = "visitEnter(Chapter)";
|
|
406 |
139181
| Trace.param(CLASS, this, method, "current", current);
|
|
407 |
139181
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
408 |
139181
| checkMatching(method);
|
|
409 |
| |
|
410 |
139056
| traverser.setLocationWithinModule(context + ".getNoNumber()");
|
|
411 |
139056
| current.setAttribute("noNumber");
|
|
412 |
139056
| checkIfFound();
|
|
413 |
| } |
|
414 |
| |
|
415 |
107794
| public final void visitLeave(final Chapter chapter) {
|
|
416 |
107794
| leave();
|
|
417 |
| } |
|
418 |
| |
|
419 |
30761
| public final void visitEnter(final SectionList sectionList) throws ModuleDataException {
|
|
420 |
30761
| final String method = "visitEnter(SectionList)";
|
|
421 |
| |
|
422 |
| |
|
423 |
30761
| checkMatching(method);
|
|
424 |
| } |
|
425 |
| |
|
426 |
0
| public final void visitLeave(final SectionList sectionList) {
|
|
427 |
0
| traverser.setBlocked(false);
|
|
428 |
| } |
|
429 |
| |
|
430 |
74894
| public final void visitEnter(final Section section) throws ModuleDataException {
|
|
431 |
74894
| enter("SECTION");
|
|
432 |
74894
| final String method = "visitEnter(Section)";
|
|
433 |
74894
| Trace.param(CLASS, this, method, "current", current);
|
|
434 |
74894
| final String context = traverser.getCurrentContext().getLocationWithinModule();
|
|
435 |
74894
| checkMatching(method);
|
|
436 |
| |
|
437 |
74661
| traverser.setLocationWithinModule(context + ".getNoNumber()");
|
|
438 |
74661
| current.setAttribute("noNumber");
|