Clover Coverage Report
Coverage timestamp: Sa Aug 2 2008 13:56:27 CEST
../../../../../img/srcFileCovDistChart0.png 88% of files have more coverage
113   222   35   28,25
36   134   0,31   4
4     8,75  
1    
 
  Context2XPathOld       Line # 52 113 35 0% 0.0
 
No Tests
 
1    /* $Id: Context2XPathOld.java,v 1.1 2008/07/26 08:00:50 m31 Exp $
2    *
3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
4    *
5    * Copyright 2000-2008, Michael Meyling <mime@qedeq.org>.
6    *
7    * "Hilbert II" is free software; you can redistribute
8    * it and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation; either
10    * version 2 of the License, or (at your option) any later version.
11    *
12    * This program is distributed in the hope that it will be useful,
13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    * GNU General Public License for more details.
16    */
17   
18    package org.qedeq.kernel.xml.mapper;
19   
20    import java.util.StringTokenizer;
21   
22    import org.qedeq.base.trace.Trace;
23    import org.qedeq.base.utility.StringUtility;
24    import org.qedeq.kernel.common.ModuleContext;
25    import org.qedeq.kernel.xml.tracker.SimpleXPath;
26   
27    /**
28    * This class is outdated. Worked with XSD version 0.03.01. Can not find locations
29    * within formulas or terms.
30    *
31    * <p>
32    * Map content string to SimpleXPath string. This class makes it possible to transfer an location
33    * of an {@link org.qedeq.kernel.base.module.Qedeq} object into an XPath like position description
34    * for an XML file representation of that object.
35    * <p>
36    * This class has maps something like<br>
37    * <code>
38    * getChapterList().get(4).getSectionList().get(0).getSubsectionList().get(4).getLatex().get(0)
39    * </code><br>
40    * into<br>
41    * <code>QEDEQ/CHAPTER[5]/SECTION/SUBSECTIONS/*[5]/TEXT/LATEX</code>
42    *
43    * mime 20070109: use visitor and Qedeq-Object to get XPath; this is necessary because
44    * an Atom (if it is the first in an ElementList) is always an attribute tag - therefore the
45    * XML element counting doesn't work (you have to subtract one if the first element is an
46    * Atom)
47    *
48    * @version $Revision: 1.1 $
49    * @author Michael Meyling
50    * @deprecated
51    */
 
52    public final class Context2XPathOld {
53   
54    /** This class. */
55    private static final Class CLASS = Context2XPathOld.class;
56   
57    /**
58    * Constructor.
59    */
 
60  0 toggle private Context2XPathOld() {
61    // nothing to do
62    }
63   
64    /**
65    * Get file path out of context information.
66    *
67    * @param context Context information.
68    * @return File path and name.
69    * @deprecated
70    */
 
71  0 toggle public static final String getFileName(final ModuleContext context) {
72  0 return context.getModuleLocation().toString();
73    }
74   
75    /**
76    * Get XPath out of context information.
77    *
78    * @param context Context information.
79    * @return XPath.
80    * @deprecated
81    */
 
82  0 toggle public static final String getXPath(final ModuleContext context) {
83  0 final String method = "getXPath(String)";
84  0 String xpath = context.getLocationWithinModule();
85  0 Trace.param(CLASS, method, "context", xpath);
86  0 xpath = StringUtility.replace(xpath, ".get(", "[");
87  0 xpath = StringUtility.replace(xpath, "()", "");
88  0 xpath = StringUtility.replace(xpath, ")", "]");
89  0 xpath = StringUtility.replace(xpath, ".get", "/");
90  0 xpath = StringUtility.replace(xpath, "get", "/Qedeq/");
91   
92    // mime 20050807: what if no Latex, Author, or other, exist? For regular files this is
93    // ok, but if there is no element in the list?
94    // mime 20050708: isn't a replacement only one element by one better?
95  0 xpath = StringUtility.replace(xpath, "Title[", "Title/Latex[");
96    // mime 20050708: definition in XML file only formula
97  0 xpath = StringUtility.replace(xpath, "PredicateDefinition", "DEFINITION_PREDICATE");
98  0 xpath = StringUtility.replace(xpath, "FunctionDefinition", "DEFINITION_FUNCTION");
99  0 xpath = StringUtility.replace(xpath, "AuthorList[", "Authors/Author[");
100  0 xpath = StringUtility.replace(xpath, "ImportList[", "Imports/Import[");
101  0 xpath = StringUtility.replace(xpath, "LiteratureItemList[", "BIBLIOGRAPHY/ITEM[");
102  0 xpath = StringUtility.replace(xpath, "LiteratureItemList", "BIBLIOGRAPHY");
103  0 xpath = StringUtility.replace(xpath, "/Item[", "/Latex[");
104  0 xpath = StringUtility.replace(xpath, "/Item", "/Latex");
105  0 xpath = StringUtility.replace(xpath, "UsedByList[", "UsedBy/Specification[");
106  0 xpath = StringUtility.replace(xpath, "ChapterList[", "Chapter[");
107  0 xpath = StringUtility.replace(xpath, "AuthorList[", "Author[");
108  0 xpath = StringUtility.replace(xpath, "AuthorList", "Authors");
109  0 xpath = StringUtility.replace(xpath, "ImportList", "Imports");
110  0 xpath = StringUtility.replace(xpath, "LocationList", "Locations");
111  0 xpath = StringUtility.replace(xpath, "LinkList[", "Link[");
112  0 xpath = StringUtility.replace(xpath, "SectionList[", "Section[");
113  0 xpath = StringUtility.replace(xpath, "SubsectionList", "Subsections/*");
114  0 xpath = StringUtility.replace(xpath, "VariableList", "VARLIST/*");
115  0 xpath = StringUtility.replace(xpath, "ProofList[", "PROOF[");
116  0 xpath = StringUtility.replace(xpath, "ProofList", "PROOF");
117  0 xpath = StringUtility.replace(xpath, "/NodeType", "");
118  0 xpath = StringUtility.replace(xpath, "Summary", "Abstract/Latex");
119  0 xpath = StringUtility.replace(xpath, "Introduction", "Introduction/Latex");
120  0 xpath = StringUtility.replace(xpath, "PrecedingText", "PRECEDING/Latex");
121  0 xpath = StringUtility.replace(xpath, "SucceedingText", "SUCCEEDING/Latex");
122  0 xpath = StringUtility.replace(xpath, "Description[", "Description/Latex[");
123  0 xpath = StringUtility.replace(xpath, "Proposition", "Theorem");
124  0 xpath = StringUtility.replace(xpath, "Formula/Element/", "Formula/*/");
125  0 xpath = StringUtility.replace(xpath, "Element", "*");
126   
127  0 xpath = StringUtility.replace(xpath, "/NonFormalProof[", "/Latex[");
128  0 xpath = StringUtility.replace(xpath, "/NonFormalProof", "/Latex");
129   
130  0 xpath = StringUtility.replace(xpath, "/List", "");
131  0 xpath = StringUtility.replace(xpath, "List", "");
132  0 xpath = StringUtility.replace(xpath, "(", "[");
133  0 xpath = xpath.toUpperCase();
134   
135  0 xpath = incrementNumbers(xpath);
136   
137   
138  0 SimpleXPath sxp = new SimpleXPath(xpath);
139   
140  0 final String beforeLast = sxp.getBeforeLastElement();
141  0 final String last = sxp.getLastElement();
142  0 if ("EMAIL".equals(last)) {
143  0 sxp.deleteLastElement();
144  0 sxp.setAttribute("email");
145  0 } else if ("LABEL".equals(last)) {
146  0 sxp.deleteLastElement();
147  0 sxp.setAttribute("label");
148  0 } else if ("ID".equals(last)) {
149  0 sxp.deleteLastElement();
150  0 sxp.setAttribute("id");
151  0 } else if ("SPECIFICATION".equals(beforeLast) && "NAME".equals(last)) {
152  0 sxp.deleteLastElement();
153  0 sxp.setAttribute("name");
154  0 } else if ("SPECIFICATION".equals(beforeLast) && "RULEVERSION".equals(last)) {
155  0 sxp.deleteLastElement();
156  0 sxp.setAttribute("ruleVersion");
157  0 } else if ("CHAPTER".equals(beforeLast) && "NONUMBER".equals(last)) {
158  0 sxp.deleteLastElement();
159  0 sxp.setAttribute("noNumber");
160  0 } else if ("SECTION".equals(beforeLast) && "NONUMBER".equals(last)) {
161  0 sxp.deleteLastElement();
162  0 sxp.setAttribute("noNumber");
163  0 } else if ("*".equals(beforeLast) && "LATEX".equals(last)) {
164  0 sxp.deleteLastElement();
165  0 sxp.addElement("TEXT");
166  0 sxp.addElement("LATEX");
167  0 } else if ("DEFINITION_PREDICATE".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
168  0 sxp.deleteLastElement();
169  0 sxp.setAttribute("arguments");
170  0 } else if ("DEFINITION_PREDICATE".equals(beforeLast) && "NAME".equals(last)) {
171  0 sxp.deleteLastElement();
172  0 sxp.setAttribute("name");
173  0 } else if ("DEFINITION_FUNCTION".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
174  0 sxp.deleteLastElement();
175  0 sxp.setAttribute("arguments");
176  0 } else if ("DEFINITION_FUNCTION".equals(beforeLast) && "NAME".equals(last)) {
177  0 sxp.deleteLastElement();
178  0 sxp.setAttribute("name");
179  0 } else if ("RULE".equals(beforeLast) && "NAME".equals(last)) {
180  0 sxp.deleteLastElement();
181  0 sxp.setAttribute("name");
182  0 } else if ("*".equals(beforeLast) && "LEVEL".equals(last)) {
183  0 sxp.deleteLastElement();
184  0 sxp.setAttribute("level");
185  0 } else if ("*".equals(beforeLast) && "NONUMBER".equals(last)) {
186  0 sxp.deleteLastElement();
187  0 sxp.setAttribute("noNumber");
188  0 } else if ("*".equals(beforeLast) && "NAME".equals(last)) {
189  0 final int len = sxp.getElementOccurrence(sxp.size() - 1);
190  0 sxp.deleteLastElement();
191  0 sxp.addElement("NAME");
192  0 sxp.addElement("LATEX", len);
193    }
194   
195  0 xpath = sxp.toString();
196  0 Trace.param(CLASS, method, "xpath", xpath);
197  0 return xpath;
198    }
199   
200    /**
201    * Increment all element occurrence numbers in "[]" by one.
202    *
203    * @param xpath Like "a[0]b[1]".
204    * @return Like "a[1]b[2]".
205    */
 
206  0 toggle private static String incrementNumbers(final String xpath) {
207  0 final StringTokenizer tokenizer = new StringTokenizer(xpath, "/", true);
208  0 String newXpath = "";
209  0 while (tokenizer.hasMoreTokens()) {
210  0 String token = tokenizer.nextToken();
211  0 if (token.indexOf('[') >= 0) {
212  0 final StringTokenizer getnu = new StringTokenizer(token, "[]");
213  0 newXpath += getnu.nextToken() + "[";
214  0 newXpath += ((new Integer(getnu.nextToken())).intValue() + 1) + "]";
215    } else {
216  0 newXpath += token;
217    }
218    }
219  0 return newXpath;
220    }
221   
222    }