|
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 |
0
| public static final String getFileName(final ModuleContext context) {
|
|
69 |
0
| return context.getModuleLocation();
|
|
70 |
| } |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
0
| public static final String getXPath(final ModuleContext context) {
|
|
80 |
0
| final String method = "getXPath(String)";
|
|
81 |
0
| String xpath = context.getLocationWithinModule();
|
|
82 |
0
| Trace.param(Context2XPathOld.class, method, "context", xpath);
|
|
83 |
0
| xpath = ReplaceUtility.replace(xpath, ".get(", "[");
|
|
84 |
0
| xpath = ReplaceUtility.replace(xpath, "()", "");
|
|
85 |
0
| xpath = ReplaceUtility.replace(xpath, ")", "]");
|
|
86 |
0
| xpath = ReplaceUtility.replace(xpath, ".get", "/");
|
|
87 |
0
| xpath = ReplaceUtility.replace(xpath, "get", "/Qedeq/");
|
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
0
| xpath = ReplaceUtility.replace(xpath, "Title[", "Title/Latex[");
|
|
93 |
| |
|
94 |
0
| xpath = ReplaceUtility.replace(xpath, "PredicateDefinition", "DEFINITION_PREDICATE");
|
|
95 |
0
| xpath = ReplaceUtility.replace(xpath, "FunctionDefinition", "DEFINITION_FUNCTION");
|
|
96 |
0
| xpath = ReplaceUtility.replace(xpath, "AuthorList[", "Authors/Author[");
|
|
97 |
0
| xpath = ReplaceUtility.replace(xpath, "ImportList[", "Imports/Import[");
|
|
98 |
0
| xpath = ReplaceUtility.replace(xpath, "LiteratureItemList[", "BIBLIOGRAPHY/ITEM[");
|
|
99 |
0
| xpath = ReplaceUtility.replace(xpath, "LiteratureItemList", "BIBLIOGRAPHY");
|
|
100 |
0
| xpath = ReplaceUtility.replace(xpath, "/Item[", "/Latex[");
|
|
101 |
0
| xpath = ReplaceUtility.replace(xpath, "/Item", "/Latex");
|
|
102 |
0
| xpath = ReplaceUtility.replace(xpath, "UsedByList[", "UsedBy/Specification[");
|
|
103 |
0
| xpath = ReplaceUtility.replace(xpath, "ChapterList[", "Chapter[");
|
|
104 |
0
| xpath = ReplaceUtility.replace(xpath, "AuthorList[", "Author[");
|
|
105 |
0
| xpath = ReplaceUtility.replace(xpath, "AuthorList", "Authors");
|
|
106 |
0
| xpath = ReplaceUtility.replace(xpath, "ImportList", "Imports");
|
|
107 |
0
| xpath = ReplaceUtility.replace(xpath, "LocationList", "Locations");
|
|
108 |
0
| xpath = ReplaceUtility.replace(xpath, "LinkList[", "Link[");
|
|
109 |
0
| xpath = ReplaceUtility.replace(xpath, "SectionList[", "Section[");
|
|
110 |
0
| xpath = ReplaceUtility.replace(xpath, "SubsectionList", "Subsections/*");
|
|
111 |
0
| xpath = ReplaceUtility.replace(xpath, "VariableList", "VARLIST/*");
|
|
112 |
0
| xpath = ReplaceUtility.replace(xpath, "ProofList[", "PROOF[");
|
|
113 |
0
| xpath = ReplaceUtility.replace(xpath, "ProofList", "PROOF");
|
|
114 |
0
| xpath = ReplaceUtility.replace(xpath, "/NodeType", "");
|
|
115 |
0
| xpath = ReplaceUtility.replace(xpath, "Summary", "Abstract/Latex");
|
|
116 |
0
| xpath = ReplaceUtility.replace(xpath, "Introduction", "Introduction/Latex");
|
|
117 |
0
| xpath = ReplaceUtility.replace(xpath, "PrecedingText", "PRECEDING/Latex");
|
|
118 |
0
| xpath = ReplaceUtility.replace(xpath, "SucceedingText", "SUCCEEDING/Latex");
|
|
119 |
0
| xpath = ReplaceUtility.replace(xpath, "Description[", "Description/Latex[");
|
|
120 |
0
| xpath = ReplaceUtility.replace(xpath, "Proposition", "Theorem");
|
|
121 |
0
| xpath = ReplaceUtility.replace(xpath, "Formula/Element/", "Formula/*/");
|
|
122 |
0
| xpath = ReplaceUtility.replace(xpath, "Element", "*");
|
|
123 |
| |
|
124 |
| |
|
125 |
0
| xpath = ReplaceUtility.replace(xpath, "/NonFormalProof[", "/Latex[");
|
|
126 |
0
| xpath = ReplaceUtility.replace(xpath, "/NonFormalProof", "/Latex");
|
|
127 |
| |
|
128 |
0
| xpath = ReplaceUtility.replace(xpath, "/List", "");
|
|
129 |
0
| xpath = ReplaceUtility.replace(xpath, "List", "");
|
|
130 |
0
| xpath = ReplaceUtility.replace(xpath, "(", "[");
|
|
131 |
0
| xpath = xpath.toUpperCase();
|
|
132 |
| |
|
133 |
0
| xpath = incrementNumbers(xpath);
|
|
134 |
| |
|
135 |
| |
|
136 |
0
| SimpleXPath sxp = new SimpleXPath(xpath);
|
|
137 |
| |
|
138 |
0
| final String beforeLast = sxp.getBeforeLastElement();
|
|
139 |
0
| final String last = sxp.getLastElement();
|
|
140 |
0
| if ("EMAIL".equals(last)) {
|
|
141 |
0
| sxp.deleteLastElement();
|
|
142 |
0
| sxp.setAttribute("email");
|
|
143 |
0
| } else if ("LABEL".equals(last)) {
|
|
144 |
0
| sxp.deleteLastElement();
|
|
145 |
0
| sxp.setAttribute("label");
|
|
146 |
0
| } else if ("ID".equals(last)) {
|
|
147 |
0
| sxp.deleteLastElement();
|
|
148 |
0
| sxp.setAttribute("id");
|
|
149 |
0
| } else if ("SPECIFICATION".equals(beforeLast) && "NAME".equals(last)) {
|
|
150 |
0
| sxp.deleteLastElement();
|
|
151 |
0
| sxp.setAttribute("name");
|
|
152 |
0
| } else if ("SPECIFICATION".equals(beforeLast) && "RULEVERSION".equals(last)) {
|
|
153 |
0
| sxp.deleteLastElement();
|
|
154 |
0
| sxp.setAttribute("ruleVersion");
|
|
155 |
0
| } else if ("CHAPTER".equals(beforeLast) && "NONUMBER".equals(last)) {
|
|
156 |
0
| sxp.deleteLastElement();
|
|
157 |
0
| sxp.setAttribute("noNumber");
|
|
158 |
0
| } else if ("SECTION".equals(beforeLast) && "NONUMBER".equals(last)) {
|
|
159 |
0
| sxp.deleteLastElement();
|
|
160 |
0
| sxp.setAttribute("noNumber");
|
|
161 |
0
| } else if ("*".equals(beforeLast) && "LATEX".equals(last)) {
|
|
162 |
0
| sxp.deleteLastElement();
|
|
163 |
0
| sxp.addElement("TEXT");
|
|
164 |
0
| sxp.addElement("LATEX");
|
|
165 |
0
| } else if ("DEFINITION_PREDICATE".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
|
|
166 |
0
| sxp.deleteLastElement();
|
|
167 |
0
| sxp.setAttribute("arguments");
|
|
168 |
0
| } else if ("DEFINITION_PREDICATE".equals(beforeLast) && "NAME".equals(last)) {
|
|
169 |
0
| sxp.deleteLastElement();
|
|
170 |
0
| sxp.setAttribute("name");
|
|
171 |
0
| } else if ("DEFINITION_FUNCTION".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
|
|
172 |
0
| sxp.deleteLastElement();
|
|
173 |
0
| sxp.setAttribute("arguments");
|
|
174 |
0
| } else if ("DEFINITION_FUNCTION".equals(beforeLast) && "NAME".equals(last)) {
|
|
175 |
0
| sxp.deleteLastElement();
|
|
176 |
0
| sxp.setAttribute("name");
|
|
177 |
0
| } else if ("RULE".equals(beforeLast) && "NAME".equals(last)) {
|
|
178 |
0
| sxp.deleteLastElement();
|
|
179 |
0
| sxp.setAttribute("name");
|
|
180 |
0
| } else if ("*".equals(beforeLast) && "LEVEL".equals(last)) {
|
|
181 |
0
| sxp.deleteLastElement();
|
|
182 |
0
| sxp.setAttribute("level");
|
|
183 |
0
| } else if ("*".equals(beforeLast) && "NONUMBER".equals(last)) {
|
|
184 |
0
| sxp.deleteLastElement();
|
|
185 |
0
| sxp.setAttribute("noNumber");
|
|
186 |
0
| } else if ("*".equals(beforeLast) && "NAME".equals(last)) {
|
|
187 |
0
| final int len = sxp.getElementOccurrence(sxp.size() - 1);
|
|
188 |
0
| sxp.deleteLastElement();
|
|
189 |
0
| sxp.addElement("NAME");
|
|
190 |
0
| sxp.addElement("LATEX", len);
|
|
191 |
| } |
|
192 |
| |
|
193 |
0
| xpath = sxp.toString();
|
|
194 |
0
| Trace.param(Context2XPathOld.class, method, "xpath", xpath);
|
|
195 |
0
| 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 |
| } |