| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.qedeq.kernel.xml.mapper; |
| 17 |
|
|
| 18 |
|
import java.util.StringTokenizer; |
| 19 |
|
|
| 20 |
|
import org.qedeq.base.trace.Trace; |
| 21 |
|
import org.qedeq.base.utility.StringUtility; |
| 22 |
|
import org.qedeq.kernel.common.ModuleContext; |
| 23 |
|
import org.qedeq.kernel.xml.tracker.SimpleXPath; |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
@link |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@version |
| 47 |
|
@author |
| 48 |
|
@deprecated |
| 49 |
|
|
|
|
|
| 0% |
Uncovered Elements: 153 (153) |
Complexity: 35 |
Complexity Density: 0.31 |
|
| 50 |
|
public final class Context2XPathOld { |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
private static final Class CLASS = Context2XPathOld.class; |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 58 |
0
|
private Context2XPathOld() {... |
| 59 |
|
|
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
@param |
| 66 |
|
@return |
| 67 |
|
@deprecated |
| 68 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 69 |
0
|
public static final String getFileName(final ModuleContext context) {... |
| 70 |
0
|
return context.getModuleLocation().toString(); |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
@param |
| 77 |
|
@return |
| 78 |
|
@deprecated |
| 79 |
|
|
|
|
|
| 0% |
Uncovered Elements: 134 (134) |
Complexity: 30 |
Complexity Density: 0.29 |
|
| 80 |
0
|
public static final String getXPath(final ModuleContext context) {... |
| 81 |
0
|
final String method = "getXPath(String)"; |
| 82 |
0
|
String xpath = context.getLocationWithinModule(); |
| 83 |
0
|
Trace.param(CLASS, method, "context", xpath); |
| 84 |
0
|
xpath = StringUtility.replace(xpath, ".get(", "["); |
| 85 |
0
|
xpath = StringUtility.replace(xpath, "()", ""); |
| 86 |
0
|
xpath = StringUtility.replace(xpath, ")", "]"); |
| 87 |
0
|
xpath = StringUtility.replace(xpath, ".get", "/"); |
| 88 |
0
|
xpath = StringUtility.replace(xpath, "get", "/Qedeq/"); |
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
0
|
xpath = StringUtility.replace(xpath, "Title[", "Title/Latex["); |
| 94 |
|
|
| 95 |
0
|
xpath = StringUtility.replace(xpath, "PredicateDefinition", "DEFINITION_PREDICATE"); |
| 96 |
0
|
xpath = StringUtility.replace(xpath, "FunctionDefinition", "DEFINITION_FUNCTION"); |
| 97 |
0
|
xpath = StringUtility.replace(xpath, "AuthorList[", "Authors/Author["); |
| 98 |
0
|
xpath = StringUtility.replace(xpath, "ImportList[", "Imports/Import["); |
| 99 |
0
|
xpath = StringUtility.replace(xpath, "LiteratureItemList[", "BIBLIOGRAPHY/ITEM["); |
| 100 |
0
|
xpath = StringUtility.replace(xpath, "LiteratureItemList", "BIBLIOGRAPHY"); |
| 101 |
0
|
xpath = StringUtility.replace(xpath, "/Item[", "/Latex["); |
| 102 |
0
|
xpath = StringUtility.replace(xpath, "/Item", "/Latex"); |
| 103 |
0
|
xpath = StringUtility.replace(xpath, "UsedByList[", "UsedBy/Specification["); |
| 104 |
0
|
xpath = StringUtility.replace(xpath, "ChapterList[", "Chapter["); |
| 105 |
0
|
xpath = StringUtility.replace(xpath, "AuthorList[", "Author["); |
| 106 |
0
|
xpath = StringUtility.replace(xpath, "AuthorList", "Authors"); |
| 107 |
0
|
xpath = StringUtility.replace(xpath, "ImportList", "Imports"); |
| 108 |
0
|
xpath = StringUtility.replace(xpath, "LocationList", "Locations"); |
| 109 |
0
|
xpath = StringUtility.replace(xpath, "LinkList[", "Link["); |
| 110 |
0
|
xpath = StringUtility.replace(xpath, "SectionList[", "Section["); |
| 111 |
0
|
xpath = StringUtility.replace(xpath, "SubsectionList", "Subsections/*"); |
| 112 |
0
|
xpath = StringUtility.replace(xpath, "VariableList", "VARLIST/*"); |
| 113 |
0
|
xpath = StringUtility.replace(xpath, "ProofList[", "PROOF["); |
| 114 |
0
|
xpath = StringUtility.replace(xpath, "ProofList", "PROOF"); |
| 115 |
0
|
xpath = StringUtility.replace(xpath, "/NodeType", ""); |
| 116 |
0
|
xpath = StringUtility.replace(xpath, "Summary", "Abstract/Latex"); |
| 117 |
0
|
xpath = StringUtility.replace(xpath, "Introduction", "Introduction/Latex"); |
| 118 |
0
|
xpath = StringUtility.replace(xpath, "PrecedingText", "PRECEDING/Latex"); |
| 119 |
0
|
xpath = StringUtility.replace(xpath, "SucceedingText", "SUCCEEDING/Latex"); |
| 120 |
0
|
xpath = StringUtility.replace(xpath, "Description[", "Description/Latex["); |
| 121 |
0
|
xpath = StringUtility.replace(xpath, "Proposition", "Theorem"); |
| 122 |
0
|
xpath = StringUtility.replace(xpath, "Formula/Element/", "Formula/*/"); |
| 123 |
0
|
xpath = StringUtility.replace(xpath, "Element", "*"); |
| 124 |
|
|
| 125 |
0
|
xpath = StringUtility.replace(xpath, "/NonFormalProof[", "/Latex["); |
| 126 |
0
|
xpath = StringUtility.replace(xpath, "/NonFormalProof", "/Latex"); |
| 127 |
|
|
| 128 |
0
|
xpath = StringUtility.replace(xpath, "/List", ""); |
| 129 |
0
|
xpath = StringUtility.replace(xpath, "List", ""); |
| 130 |
0
|
xpath = StringUtility.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(CLASS, method, "xpath", xpath); |
| 195 |
0
|
return xpath; |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
@param |
| 202 |
|
@return |
| 203 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 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 |
|
} |