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