|
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.StringTokenizer; |
|
21 |
| |
|
22 |
| import org.qedeq.kernel.bo.control.Context; |
|
23 |
| import org.qedeq.kernel.log.Trace; |
|
24 |
| import org.qedeq.kernel.utility.ReplaceUtility; |
|
25 |
| import org.qedeq.kernel.xml.tracker.SimpleXPath; |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| public final class Context2XPath { |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
0
| private Context2XPath() {
|
|
39 |
| |
|
40 |
| } |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
1
| public static final String getFileName(final Context context) {
|
|
49 |
1
| return context.getModuleLocation();
|
|
50 |
| } |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
402
| public static final String getXPath(final Context context) {
|
|
59 |
402
| final String method = "getXPath(String)";
|
|
60 |
402
| String xpath = context.getLocationWithinModule();
|
|
61 |
402
| Trace.traceParam(Context2XPath.class, method, "context", xpath);
|
|
62 |
402
| xpath = ReplaceUtility.replace(xpath, ".get(", "[");
|
|
63 |
402
| xpath = ReplaceUtility.replace(xpath, "()", "");
|
|
64 |
402
| xpath = ReplaceUtility.replace(xpath, ")", "]");
|
|
65 |
402
| xpath = ReplaceUtility.replace(xpath, ".get", "/");
|
|
66 |
402
| xpath = ReplaceUtility.replace(xpath, "get", "/Qedeq/");
|
|
67 |
| |
|
68 |
402
| xpath = incrementNumbers(xpath);
|
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
402
| xpath = ReplaceUtility.replace(xpath, "Title", "Title/Latex");
|
|
74 |
| |
|
75 |
402
| xpath = ReplaceUtility.replace(xpath, "Definition/FormulaOrTerm", "Definition/Formula");
|
|
76 |
402
| xpath = ReplaceUtility.replace(xpath, "AuthorList", "Authors/Author");
|
|
77 |
402
| xpath = ReplaceUtility.replace(xpath, "ImportList", "Imports/Import");
|
|
78 |
402
| xpath = ReplaceUtility.replace(xpath, "UsedByList", "UsedBy/Specification");
|
|
79 |
402
| xpath = ReplaceUtility.replace(xpath, "ChapterList", "Chapter");
|
|
80 |
402
| xpath = ReplaceUtility.replace(xpath, "SectionList", "Section");
|
|
81 |
402
| xpath = ReplaceUtility.replace(xpath, "SubsectionList", "Subsections/*");
|
|
82 |
402
| xpath = ReplaceUtility.replace(xpath, "VariableList", "VARLIST/VAR");
|
|
83 |
402
| xpath = ReplaceUtility.replace(xpath, "List", "s");
|
|
84 |
402
| xpath = ReplaceUtility.replace(xpath, "/NodeType", "");
|
|
85 |
402
| xpath = ReplaceUtility.replace(xpath, "Summary", "Abstract/Latex");
|
|
86 |
402
| xpath = ReplaceUtility.replace(xpath, "Introduction", "Introduction/Latex");
|
|
87 |
402
| xpath = ReplaceUtility.replace(xpath, "PrecedingText", "PRECEDING/Latex");
|
|
88 |
402
| xpath = ReplaceUtility.replace(xpath, "SucceedingText", "SUCCEEDING/Latex");
|
|
89 |
402
| xpath = ReplaceUtility.replace(xpath, "Element", "*");
|
|
90 |
402
| xpath = ReplaceUtility.replace(xpath, "Proposition", "Theorem");
|
|
91 |
402
| xpath = ReplaceUtility.replace(xpath, "/Proofs", "");
|
|
92 |
| |
|
93 |
| |
|
94 |
402
| xpath = ReplaceUtility.replace(xpath, "/NonFormalProof", "/Proof/Latex");
|
|
95 |
| |
|
96 |
402
| xpath = xpath.toUpperCase();
|
|
97 |
| |
|
98 |
402
| SimpleXPath sxp = new SimpleXPath(xpath);
|
|
99 |
| |
|
100 |
402
| final String beforeLast = sxp.getBeforeLastElement();
|
|
101 |
402
| final String last = sxp.getLastElement();
|
|
102 |
402
| if ("EMAIL".equals(last)) {
|
|
103 |
3
| sxp.deleteLastElement();
|
|
104 |
3
| sxp.setAttribute("email");
|
|
105 |
399
| } else if ("LABEL".equals(last)) {
|
|
106 |
4
| sxp.deleteLastElement();
|
|
107 |
4
| sxp.setAttribute("label");
|
|
108 |
395
| } else if ("ID".equals(last)) {
|
|
109 |
7
| sxp.deleteLastElement();
|
|
110 |
7
| sxp.setAttribute("id");
|
|
111 |
388
| } else if ("SPECIFICATION".equals(beforeLast) && "NAME".equals(last)) {
|
|
112 |
5
| sxp.deleteLastElement();
|
|
113 |
5
| sxp.setAttribute("name");
|
|
114 |
383
| } else if ("SPECIFICATION".equals(beforeLast) && "RULEVERSION".equals(last)) {
|
|
115 |
5
| sxp.deleteLastElement();
|
|
116 |
5
| sxp.setAttribute("ruleVersion");
|
|
117 |
378
| } else if ("CHAPTER".equals(beforeLast) && "NONUMBER".equals(last)) {
|
|
118 |
3
| sxp.deleteLastElement();
|
|
119 |
3
| sxp.setAttribute("noNumber");
|
|
120 |
375
| } else if ("SECTION".equals(beforeLast) && "NONUMBER".equals(last)) {
|
|
121 |
0
| sxp.deleteLastElement();
|
|
122 |
0
| sxp.setAttribute("noNumber");
|
|
123 |
375
| } else if ("*".equals(beforeLast) && "LATEX".equals(last)) {
|
|
124 |
20
| sxp.deleteLastElement();
|
|
125 |
20
| sxp.addElement("TEXT");
|
|
126 |
20
| sxp.addElement("LATEX");
|
|
127 |
355
| } else if ("DEFINITION".equals(beforeLast) && "TYPE".equals(last)) {
|
|
128 |
4
| sxp.deleteLastElement();
|
|
129 |
4
| sxp.setAttribute("kind");
|
|
130 |
351
| } else if ("DEFINITION".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
|
|
131 |
4
| sxp.deleteLastElement();
|
|
132 |
4
| sxp.setAttribute("arguments");
|
|
133 |
347
| } else if ("DEFINITION".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
|
|
134 |
0
| sxp.deleteLastElement();
|
|
135 |
0
| sxp.setAttribute("arguments");
|
|
136 |
347
| } else if ("*".equals(beforeLast) && "LEVEL".equals(last)) {
|
|
137 |
1
| sxp.deleteLastElement();
|
|
138 |
1
| sxp.setAttribute("level");
|
|
139 |
346
| } else if ("*".equals(beforeLast) && "NONUMBER".equals(last)) {
|
|
140 |
0
| sxp.deleteLastElement();
|
|
141 |
0
| sxp.setAttribute("noNumber");
|
|
142 |
346
| } else if ("*".equals(beforeLast) && "NAME".equals(last)) {
|
|
143 |
18
| final int len = sxp.getElementOccurrence(sxp.size() - 1);
|
|
144 |
18
| sxp.deleteLastElement();
|
|
145 |
18
| sxp.addElement("NAME");
|
|
146 |
18
| sxp.addElement("LATEX", len);
|
|
147 |
| } |
|
148 |
| |
|
149 |
402
| xpath = sxp.toString();
|
|
150 |
402
| Trace.traceParam(Context2XPath.class, method, "xpath", xpath);
|
|
151 |
402
| return xpath;
|
|
152 |
| } |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
402
| private static String incrementNumbers(final String xpath) {
|
|
161 |
402
| final StringTokenizer tokenizer = new StringTokenizer(xpath, "/", true);
|
|
162 |
402
| String newXpath = "";
|
|
163 |
402
| while (tokenizer.hasMoreTokens()) {
|
|
164 |
3562
| String token = tokenizer.nextToken();
|
|
165 |
3562
| if (token.indexOf('[') >= 0) {
|
|
166 |
977
| final StringTokenizer getnu = new StringTokenizer(token, "[]");
|
|
167 |
977
| newXpath += getnu.nextToken() + "[";
|
|
168 |
977
| newXpath += ((new Integer(getnu.nextToken())).intValue() + 1) + "]";
|
|
169 |
| } else { |
|
170 |
2585
| newXpath += token;
|
|
171 |
| } |
|
172 |
| } |
|
173 |
402
| return newXpath;
|
|
174 |
| } |
|
175 |
| |
|
176 |
| } |