|
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.context.ModuleContext; |
|
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 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| public final class Context2XPath { |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
0
| private Context2XPath() {
|
|
53 |
| |
|
54 |
| } |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
1
| public static final String getFileName(final ModuleContext context) {
|
|
63 |
1
| return context.getModuleLocation();
|
|
64 |
| } |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
3153
| public static final String getXPath(final ModuleContext context) {
|
|
73 |
3153
| final String method = "getXPath(String)";
|
|
74 |
3153
| String xpath = context.getLocationWithinModule();
|
|
75 |
3153
| Trace.param(Context2XPath.class, method, "context", xpath);
|
|
76 |
3153
| xpath = ReplaceUtility.replace(xpath, ".get(", "[");
|
|
77 |
3153
| xpath = ReplaceUtility.replace(xpath, "()", "");
|
|
78 |
3153
| xpath = ReplaceUtility.replace(xpath, ")", "]");
|
|
79 |
3153
| xpath = ReplaceUtility.replace(xpath, ".get", "/");
|
|
80 |
3153
| xpath = ReplaceUtility.replace(xpath, "get", "/Qedeq/");
|
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
3153
| xpath = ReplaceUtility.replace(xpath, "Title[", "Title/Latex[");
|
|
86 |
| |
|
87 |
3153
| xpath = ReplaceUtility.replace(xpath, "PredicateDefinition", "DEFINITION_PREDICATE");
|
|
88 |
3153
| xpath = ReplaceUtility.replace(xpath, "FunctionDefinition", "DEFINITION_FUNCTION");
|
|
89 |
3153
| xpath = ReplaceUtility.replace(xpath, "AuthorList[", "Authors/Author[");
|
|
90 |
3153
| xpath = ReplaceUtility.replace(xpath, "ImportList[", "Imports/Import[");
|
|
91 |
3153
| xpath = ReplaceUtility.replace(xpath, "LiteratureItemList[", "BIBLIOGRAPHY/ITEM[");
|
|
92 |
3153
| xpath = ReplaceUtility.replace(xpath, "LiteratureItemList", "BIBLIOGRAPHY");
|
|
93 |
3153
| xpath = ReplaceUtility.replace(xpath, "/Item[", "/Latex[");
|
|
94 |
3153
| xpath = ReplaceUtility.replace(xpath, "/Item", "/Latex");
|
|
95 |
3153
| xpath = ReplaceUtility.replace(xpath, "UsedByList[", "UsedBy/Specification[");
|
|
96 |
3153
| xpath = ReplaceUtility.replace(xpath, "ChapterList[", "Chapter[");
|
|
97 |
3153
| xpath = ReplaceUtility.replace(xpath, "AuthorList[", "Author[");
|
|
98 |
3153
| xpath = ReplaceUtility.replace(xpath, "AuthorList", "Authors");
|
|
99 |
3153
| xpath = ReplaceUtility.replace(xpath, "ImportList", "Imports");
|
|
100 |
3153
| xpath = ReplaceUtility.replace(xpath, "LocationList", "Locations");
|
|
101 |
3153
| xpath = ReplaceUtility.replace(xpath, "LinkList[", "Link[");
|
|
102 |
3153
| xpath = ReplaceUtility.replace(xpath, "SectionList[", "Section[");
|
|
103 |
3153
| xpath = ReplaceUtility.replace(xpath, "SubsectionList", "Subsections/*");
|
|
104 |
3153
| xpath = ReplaceUtility.replace(xpath, "VariableList", "VARLIST/*");
|
|
105 |
3153
| xpath = ReplaceUtility.replace(xpath, "ProofList[", "PROOF[");
|
|
106 |
3153
| xpath = ReplaceUtility.replace(xpath, "ProofList", "PROOF");
|
|
107 |
3153
| xpath = ReplaceUtility.replace(xpath, "/NodeType", "");
|
|
108 |
3153
| xpath = ReplaceUtility.replace(xpath, "Summary", "Abstract/Latex");
|
|
109 |
3153
| xpath = ReplaceUtility.replace(xpath, "Introduction", "Introduction/Latex");
|
|
110 |
3153
| xpath = ReplaceUtility.replace(xpath, "PrecedingText", "PRECEDING/Latex");
|
|
111 |
3153
| xpath = ReplaceUtility.replace(xpath, "SucceedingText", "SUCCEEDING/Latex");
|
|
112 |
3153
| xpath = ReplaceUtility.replace(xpath, "Description[", "Description/Latex[");
|
|
113 |
3153
| xpath = ReplaceUtility.replace(xpath, "Proposition", "Theorem");
|
|
114 |
3153
| xpath = ReplaceUtility.replace(xpath, "Formula/Element/", "Formula/*/");
|
|
115 |
3153
| xpath = ReplaceUtility.replace(xpath, "Element", "*");
|
|
116 |
| |
|
117 |
| |
|
118 |
3153
| xpath = ReplaceUtility.replace(xpath, "/NonFormalProof[", "/Latex[");
|
|
119 |
3153
| xpath = ReplaceUtility.replace(xpath, "/NonFormalProof", "/Latex");
|
|
120 |
| |
|
121 |
3153
| xpath = ReplaceUtility.replace(xpath, "/List", "");
|
|
122 |
3153
| xpath = ReplaceUtility.replace(xpath, "List", "");
|
|
123 |
3153
| xpath = ReplaceUtility.replace(xpath, "(", "[");
|
|
124 |
3153
| xpath = xpath.toUpperCase();
|
|
125 |
| |
|
126 |
3153
| xpath = incrementNumbers(xpath);
|
|
127 |
| |
|
128 |
| |
|
129 |
3153
| SimpleXPath sxp = new SimpleXPath(xpath);
|
|
130 |
| |
|
131 |
3153
| final String beforeLast = sxp.getBeforeLastElement();
|
|
132 |
3153
| final String last = sxp.getLastElement();
|
|
133 |
3153
| if ("EMAIL".equals(last)) {
|
|
134 |
10
| sxp.deleteLastElement();
|
|
135 |
10
| sxp.setAttribute("email");
|
|
136 |
3143
| } else if ("LABEL".equals(last)) {
|
|
137 |
14
| sxp.deleteLastElement();
|
|
138 |
14
| sxp.setAttribute("label");
|
|
139 |
3129
| } else if ("ID".equals(last)) {
|
|
140 |
103
| sxp.deleteLastElement();
|
|
141 |
103
| sxp.setAttribute("id");
|
|
142 |
3026
| } else if ("SPECIFICATION".equals(beforeLast) && "NAME".equals(last)) {
|
|
143 |
12
| sxp.deleteLastElement();
|
|
144 |
12
| sxp.setAttribute("name");
|
|
145 |
3014
| } else if ("SPECIFICATION".equals(beforeLast) && "RULEVERSION".equals(last)) {
|
|
146 |
12
| sxp.deleteLastElement();
|
|
147 |
12
| sxp.setAttribute("ruleVersion");
|
|
148 |
3002
| } else if ("CHAPTER".equals(beforeLast) && "NONUMBER".equals(last)) {
|
|
149 |
8
| sxp.deleteLastElement();
|
|
150 |
8
| sxp.setAttribute("noNumber");
|
|
151 |
2994
| } else if ("SECTION".equals(beforeLast) && "NONUMBER".equals(last)) {
|
|
152 |
0
| sxp.deleteLastElement();
|
|
153 |
0
| sxp.setAttribute("noNumber");
|
|
154 |
2994
| } else if ("*".equals(beforeLast) && "LATEX".equals(last)) {
|
|
155 |
40
| sxp.deleteLastElement();
|
|
156 |
40
| sxp.addElement("TEXT");
|
|
157 |
40
| sxp.addElement("LATEX");
|
|
158 |
2954
| } else if ("DEFINITION_PREDICATE".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
|
|
159 |
14
| sxp.deleteLastElement();
|
|
160 |
14
| sxp.setAttribute("arguments");
|
|
161 |
2940
| } else if ("DEFINITION_PREDICATE".equals(beforeLast) && "NAME".equals(last)) {
|
|
162 |
14
| sxp.deleteLastElement();
|
|
163 |
14
| sxp.setAttribute("name");
|
|
164 |
2926
| } else if ("DEFINITION_FUNCTION".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
|
|
165 |
16
| sxp.deleteLastElement();
|
|
166 |
16
| sxp.setAttribute("arguments");
|
|
167 |
2910
| } else if ("DEFINITION_FUNCTION".equals(beforeLast) && "NAME".equals(last)) {
|
|
168 |
16
| sxp.deleteLastElement();
|
|
169 |
16
| sxp.setAttribute("name");
|
|
170 |
2894
| } else if ("RULE".equals(beforeLast) && "NAME".equals(last)) {
|
|
171 |
2
| sxp.deleteLastElement();
|
|
172 |
2
| sxp.setAttribute("name");
|
|
173 |
2892
| } else if ("*".equals(beforeLast) && "LEVEL".equals(last)) {
|
|
174 |
72
| sxp.deleteLastElement();
|
|
175 |
72
| sxp.setAttribute("level");
|
|
176 |
2820
| } else if ("*".equals(beforeLast) && "NONUMBER".equals(last)) {
|
|
177 |
0
| sxp.deleteLastElement();
|
|
178 |
0
| sxp.setAttribute("noNumber");
|
|
179 |
2820
| } else if ("*".equals(beforeLast) && "NAME".equals(last)) {
|
|
180 |
196
| final int len = sxp.getElementOccurrence(sxp.size() - 1);
|
|
181 |
196
| sxp.deleteLastElement();
|
|
182 |
196
| sxp.addElement("NAME");
|
|
183 |
196
| sxp.addElement("LATEX", len);
|
|
184 |
| } |
|
185 |
| |
|
186 |
3153
| xpath = sxp.toString();
|
|
187 |
3153
| Trace.param(Context2XPath.class, method, "xpath", xpath);
|
|
188 |
3153
| return xpath;
|
|
189 |
| } |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
3153
| private static String incrementNumbers(final String xpath) {
|
|
198 |
3153
| final StringTokenizer tokenizer = new StringTokenizer(xpath, "/", true);
|
|
199 |
3153
| String newXpath = "";
|
|
200 |
3153
| while (tokenizer.hasMoreTokens()) {
|
|
201 |
36200
| String token = tokenizer.nextToken();
|
|
202 |
36200
| if (token.indexOf('[') >= 0) {
|
|
203 |
8704
| final StringTokenizer getnu = new StringTokenizer(token, "[]");
|
|
204 |
8704
| newXpath += getnu.nextToken() + "[";
|
|
205 |
8704
| newXpath += ((new Integer(getnu.nextToken())).intValue() + 1) + "]";
|
|
206 |
| } else { |
|
207 |
27496
| newXpath += token;
|
|
208 |
| } |
|
209 |
| } |
|
210 |
3153
| return newXpath;
|
|
211 |
| } |
|
212 |
| |
|
213 |
| } |