Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../img/srcFileCovDistChart0.png 96% of files have more coverage
113   220   35   28.25
36   134   0.31   4
4     8.75  
1    
 
  Context2XPathOld       Line # 50 113 35 0% 0.0
 
No Tests
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
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.se.common.ModuleContext;
23    import org.qedeq.kernel.xml.tracker.SimpleXPath;
24   
25    /**
26    * This class is outdated. Worked with XSD version 0.03.01. Can not find locations
27    * within formulas or terms. Should be used for tests?
28    *
29    * <p>
30    * Map content string to SimpleXPath string. This class makes it possible to transfer an location
31    * of an {@link org.qedeq.kernel.base.module.Qedeq} object into an XPath like position description
32    * for an XML file representation of that object.
33    * <p>
34    * This class has maps something like<br>
35    * <code>
36    * getChapterList().get(4).getSectionList().get(0).getSubsectionList().get(4).getLatex().get(0)
37    * </code><br>
38    * into<br>
39    * <code>QEDEQ/CHAPTER[5]/SECTION/SUBSECTIONS/*[5]/TEXT/LATEX</code>
40    *
41    * mime 20070109: use visitor and Qedeq-Object to get XPath; this is necessary because
42    * an Atom (if it is the first in an ElementList) is always an attribute tag - therefore the
43    * XML element counting doesn't work (you have to subtract one if the first element is an
44    * Atom)
45    *
46    * @version $Revision: 1.1 $
47    * @author Michael Meyling
48    * @deprecated
49    */
 
50    public final class Context2XPathOld {
51   
52    /** This class. */
53    private static final Class CLASS = Context2XPathOld.class;
54   
55    /**
56    * Constructor.
57    */
 
58  0 toggle private Context2XPathOld() {
59    // nothing to do
60    }
61   
62    /**
63    * Get file path out of context information.
64    *
65    * @param context Context information.
66    * @return File path and name.
67    * @deprecated
68    */
 
69  0 toggle public static final String getFileName(final ModuleContext context) {
70  0 return context.getModuleLocation().toString();
71    }
72   
73    /**
74    * Get XPath out of context information.
75    *
76    * @param context Context information.
77    * @return XPath.
78    * @deprecated
79    */
 
80  0 toggle 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    // mime 20050807: what if no Latex, Author, or other, exist? For regular files this is
91    // ok, but if there is no element in the list?
92    // mime 20050708: isn't a replacement only one element by one better?
93  0 xpath = StringUtility.replace(xpath, "Title[", "Title/Latex[");
94    // mime 20050708: definition in XML file only formula
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    * Increment all element occurrence numbers in "[]" by one.
200    *
201    * @param xpath Like "a[0]b[1]".
202    * @return Like "a[1]b[2]".
203    */
 
204  0 toggle 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    }