Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Jan 26 2008 14:11:34 CET
file stats: LOC: 223   Methods: 4
NCLOC: 134   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Context2XPathOld.java 0% 0% 0% 0%
coverage
 1    /* $Id: Context2XPathOld.java,v 1.4 2008/01/26 12:39:09 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, 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.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    * 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.4 $
 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 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 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 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 = ReplaceUtility.replace(xpath, ".get(", "[");
 87  0 xpath = ReplaceUtility.replace(xpath, "()", "");
 88  0 xpath = ReplaceUtility.replace(xpath, ")", "]");
 89  0 xpath = ReplaceUtility.replace(xpath, ".get", "/");
 90  0 xpath = ReplaceUtility.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 = ReplaceUtility.replace(xpath, "Title[", "Title/Latex[");
 96    // mime 20050708: definition in XML file only formula
 97  0 xpath = ReplaceUtility.replace(xpath, "PredicateDefinition", "DEFINITION_PREDICATE");
 98  0 xpath = ReplaceUtility.replace(xpath, "FunctionDefinition", "DEFINITION_FUNCTION");
 99  0 xpath = ReplaceUtility.replace(xpath, "AuthorList[", "Authors/Author[");
 100  0 xpath = ReplaceUtility.replace(xpath, "ImportList[", "Imports/Import[");
 101  0 xpath = ReplaceUtility.replace(xpath, "LiteratureItemList[", "BIBLIOGRAPHY/ITEM[");
 102  0 xpath = ReplaceUtility.replace(xpath, "LiteratureItemList", "BIBLIOGRAPHY");
 103  0 xpath = ReplaceUtility.replace(xpath, "/Item[", "/Latex[");
 104  0 xpath = ReplaceUtility.replace(xpath, "/Item", "/Latex");
 105  0 xpath = ReplaceUtility.replace(xpath, "UsedByList[", "UsedBy/Specification[");
 106  0 xpath = ReplaceUtility.replace(xpath, "ChapterList[", "Chapter[");
 107  0 xpath = ReplaceUtility.replace(xpath, "AuthorList[", "Author[");
 108  0 xpath = ReplaceUtility.replace(xpath, "AuthorList", "Authors");
 109  0 xpath = ReplaceUtility.replace(xpath, "ImportList", "Imports");
 110  0 xpath = ReplaceUtility.replace(xpath, "LocationList", "Locations");
 111  0 xpath = ReplaceUtility.replace(xpath, "LinkList[", "Link[");
 112  0 xpath = ReplaceUtility.replace(xpath, "SectionList[", "Section[");
 113  0 xpath = ReplaceUtility.replace(xpath, "SubsectionList", "Subsections/*");
 114  0 xpath = ReplaceUtility.replace(xpath, "VariableList", "VARLIST/*");
 115  0 xpath = ReplaceUtility.replace(xpath, "ProofList[", "PROOF[");
 116  0 xpath = ReplaceUtility.replace(xpath, "ProofList", "PROOF");
 117  0 xpath = ReplaceUtility.replace(xpath, "/NodeType", "");
 118  0 xpath = ReplaceUtility.replace(xpath, "Summary", "Abstract/Latex");
 119  0 xpath = ReplaceUtility.replace(xpath, "Introduction", "Introduction/Latex");
 120  0 xpath = ReplaceUtility.replace(xpath, "PrecedingText", "PRECEDING/Latex");
 121  0 xpath = ReplaceUtility.replace(xpath, "SucceedingText", "SUCCEEDING/Latex");
 122  0 xpath = ReplaceUtility.replace(xpath, "Description[", "Description/Latex[");
 123  0 xpath = ReplaceUtility.replace(xpath, "Proposition", "Theorem");
 124  0 xpath = ReplaceUtility.replace(xpath, "Formula/Element/", "Formula/*/");
 125  0 xpath = ReplaceUtility.replace(xpath, "Element", "*");
 126   
 127    // TODO mime 20050807: integrate non formal proofs
 128  0 xpath = ReplaceUtility.replace(xpath, "/NonFormalProof[", "/Latex[");
 129  0 xpath = ReplaceUtility.replace(xpath, "/NonFormalProof", "/Latex");
 130   
 131  0 xpath = ReplaceUtility.replace(xpath, "/List", "");
 132  0 xpath = ReplaceUtility.replace(xpath, "List", "");
 133  0 xpath = ReplaceUtility.replace(xpath, "(", "[");
 134  0 xpath = xpath.toUpperCase();
 135   
 136  0 xpath = incrementNumbers(xpath);
 137   
 138   
 139  0 SimpleXPath sxp = new SimpleXPath(xpath);
 140   
 141  0 final String beforeLast = sxp.getBeforeLastElement();
 142  0 final String last = sxp.getLastElement();
 143  0 if ("EMAIL".equals(last)) {
 144  0 sxp.deleteLastElement();
 145  0 sxp.setAttribute("email");
 146  0 } else if ("LABEL".equals(last)) {
 147  0 sxp.deleteLastElement();
 148  0 sxp.setAttribute("label");
 149  0 } else if ("ID".equals(last)) {
 150  0 sxp.deleteLastElement();
 151  0 sxp.setAttribute("id");
 152  0 } else if ("SPECIFICATION".equals(beforeLast) && "NAME".equals(last)) {
 153  0 sxp.deleteLastElement();
 154  0 sxp.setAttribute("name");
 155  0 } else if ("SPECIFICATION".equals(beforeLast) && "RULEVERSION".equals(last)) {
 156  0 sxp.deleteLastElement();
 157  0 sxp.setAttribute("ruleVersion");
 158  0 } else if ("CHAPTER".equals(beforeLast) && "NONUMBER".equals(last)) {
 159  0 sxp.deleteLastElement();
 160  0 sxp.setAttribute("noNumber");
 161  0 } else if ("SECTION".equals(beforeLast) && "NONUMBER".equals(last)) {
 162  0 sxp.deleteLastElement();
 163  0 sxp.setAttribute("noNumber");
 164  0 } else if ("*".equals(beforeLast) && "LATEX".equals(last)) {
 165  0 sxp.deleteLastElement();
 166  0 sxp.addElement("TEXT");
 167  0 sxp.addElement("LATEX");
 168  0 } else if ("DEFINITION_PREDICATE".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
 169  0 sxp.deleteLastElement();
 170  0 sxp.setAttribute("arguments");
 171  0 } else if ("DEFINITION_PREDICATE".equals(beforeLast) && "NAME".equals(last)) {
 172  0 sxp.deleteLastElement();
 173  0 sxp.setAttribute("name");
 174  0 } else if ("DEFINITION_FUNCTION".equals(beforeLast) && "ARGUMENTNUMBER".equals(last)) {
 175  0 sxp.deleteLastElement();
 176  0 sxp.setAttribute("arguments");
 177  0 } else if ("DEFINITION_FUNCTION".equals(beforeLast) && "NAME".equals(last)) {
 178  0 sxp.deleteLastElement();
 179  0 sxp.setAttribute("name");
 180  0 } else if ("RULE".equals(beforeLast) && "NAME".equals(last)) {
 181  0 sxp.deleteLastElement();
 182  0 sxp.setAttribute("name");
 183  0 } else if ("*".equals(beforeLast) && "LEVEL".equals(last)) {
 184  0 sxp.deleteLastElement();
 185  0 sxp.setAttribute("level");
 186  0 } else if ("*".equals(beforeLast) && "NONUMBER".equals(last)) {
 187  0 sxp.deleteLastElement();
 188  0 sxp.setAttribute("noNumber");
 189  0 } else if ("*".equals(beforeLast) && "NAME".equals(last)) {
 190  0 final int len = sxp.getElementOccurrence(sxp.size() - 1);
 191  0 sxp.deleteLastElement();
 192  0 sxp.addElement("NAME");
 193  0 sxp.addElement("LATEX", len);
 194    }
 195   
 196  0 xpath = sxp.toString();
 197  0 Trace.param(CLASS, method, "xpath", xpath);
 198  0 return xpath;
 199    }
 200   
 201    /**
 202    * Increment all element occurrence numbers in "[]" by one.
 203    *
 204    * @param xpath Like "a[0]b[1]".
 205    * @return Like "a[1]b[2]".
 206    */
 207  0 private static String incrementNumbers(final String xpath) {
 208  0 final StringTokenizer tokenizer = new StringTokenizer(xpath, "/", true);
 209  0 String newXpath = "";
 210  0 while (tokenizer.hasMoreTokens()) {
 211  0 String token = tokenizer.nextToken();
 212  0 if (token.indexOf('[') >= 0) {
 213  0 final StringTokenizer getnu = new StringTokenizer(token, "[]");
 214  0 newXpath += getnu.nextToken() + "[";
 215  0 newXpath += ((new Integer(getnu.nextToken())).intValue() + 1) + "]";
 216    } else {
 217  0 newXpath += token;
 218    }
 219    }
 220  0 return newXpath;
 221    }
 222   
 223    }